You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hj...@apache.org on 2014/11/05 10:52:00 UTC
[04/30] git commit: TAJO-1114: Improve ConfVars (SessionVar) to take
a validator interface to check its input. (Jihun Kang via hyunsik)
TAJO-1114: Improve ConfVars (SessionVar) to take a validator interface to check its input. (Jihun Kang via hyunsik)
Closes #214
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/ee89c65b
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/ee89c65b
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/ee89c65b
Branch: refs/heads/hbase_storage
Commit: ee89c65b44142ca640020339e7ab5a608c1a8bf9
Parents: b5f3a74
Author: Hyunsik Choi <hy...@apache.org>
Authored: Mon Oct 27 10:08:05 2014 -0700
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Mon Oct 27 10:09:17 2014 -0700
----------------------------------------------------------------------
CHANGES | 3 +
tajo-common/pom.xml | 5 +
.../main/java/org/apache/tajo/ConfigKey.java | 6 +
.../main/java/org/apache/tajo/SessionVars.java | 63 ++-
.../java/org/apache/tajo/conf/TajoConf.java | 155 ++++--
.../java/org/apache/tajo/util/NumberUtil.java | 21 +
.../tajo/validation/AbstractValidator.java | 60 +++
.../tajo/validation/BooleanValidator.java | 57 +++
.../apache/tajo/validation/ClassValidator.java | 57 +++
.../tajo/validation/ConstraintViolation.java | 47 ++
.../ConstraintViolationException.java | 56 +++
.../apache/tajo/validation/GroupValidator.java | 49 ++
.../tajo/validation/JavaStringValidator.java | 32 ++
.../apache/tajo/validation/LengthValidator.java | 57 +++
.../apache/tajo/validation/MaxValidator.java | 83 +++
.../apache/tajo/validation/MinValidator.java | 84 ++++
.../validation/NetworkAddressValidator.java | 103 ++++
.../tajo/validation/NotNullValidator.java | 47 ++
.../apache/tajo/validation/PathValidator.java | 32 ++
.../tajo/validation/PatternValidator.java | 63 +++
.../apache/tajo/validation/RangeValidator.java | 53 ++
.../tajo/validation/ShellVariableValidator.java | 32 ++
.../org/apache/tajo/validation/Validator.java | 29 ++
.../org/apache/tajo/validation/Validators.java | 77 +++
.../apache/tajo/validation/TestValidators.java | 503 +++++++++++++++++++
.../apache/tajo/engine/query/QueryContext.java | 11 +
26 files changed, 1732 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index d239a19..3224a79 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,9 @@ Release 0.9.1 - unreleased
IMPROVEMENT
+ TAJO-1114: Improve ConfVars (SessionVar) to take a validator interface to
+ check its input. (Jihun Kang via hyunsik)
+
TAJO-1132: More detailed version info in tsql. (hyunsik)
TAJO-1125: Separate logical plan and optimizer into a maven module.
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-common/pom.xml b/tajo-common/pom.xml
index d857e0e..820220c 100644
--- a/tajo-common/pom.xml
+++ b/tajo-common/pom.xml
@@ -108,6 +108,11 @@
</goals>
</execution>
</executions>
+ <configuration>
+ <excludes>
+ <exclude>src/test/resources/org/apache/tajo/conf/**</exclude>
+ </excludes>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/ConfigKey.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/ConfigKey.java b/tajo-common/src/main/java/org/apache/tajo/ConfigKey.java
index b9d51ec..6329e77 100644
--- a/tajo-common/src/main/java/org/apache/tajo/ConfigKey.java
+++ b/tajo-common/src/main/java/org/apache/tajo/ConfigKey.java
@@ -18,6 +18,8 @@
package org.apache.tajo;
+import org.apache.tajo.validation.Validator;
+
public interface ConfigKey {
// Client can set or change variables of this mode.
@@ -49,4 +51,8 @@ public interface ConfigKey {
public String keyname();
public ConfigType type();
+
+ public Class<?> valueClass();
+
+ public Validator validator();
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/SessionVars.java b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
index 1229849..dbe949a 100644
--- a/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
+++ b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
@@ -22,6 +22,9 @@ import com.google.common.collect.Maps;
import java.util.Map;
+import org.apache.tajo.validation.Validator;
+import org.apache.tajo.validation.Validators;
+
import static org.apache.tajo.SessionVars.VariableMode.*;
import static org.apache.tajo.conf.TajoConf.ConfVars;
@@ -40,8 +43,8 @@ public enum SessionVars implements ConfigKey {
//-------------------------------------------------------------------------------
// Server Side Only Variables
//-------------------------------------------------------------------------------
- SESSION_ID(ConfVars.$EMPTY, "session variable", SERVER_SIDE_VAR),
- SESSION_LAST_ACCESS_TIME(ConfVars.$EMPTY, "last access time", SERVER_SIDE_VAR),
+ SESSION_ID(ConfVars.$EMPTY, "session variable", SERVER_SIDE_VAR, String.class, Validators.notNull()),
+ SESSION_LAST_ACCESS_TIME(ConfVars.$EMPTY, "last access time", SERVER_SIDE_VAR, Long.class, Validators.min("0")),
USERNAME(ConfVars.USERNAME, "username", SERVER_SIDE_VAR),
CLIENT_HOST(ConfVars.$EMPTY, "client hostname", SERVER_SIDE_VAR),
@@ -53,7 +56,8 @@ public enum SessionVars implements ConfigKey {
//-------------------------------------------------------------------------------
// Client --------------------------------------------------------
- SESSION_EXPIRY_TIME(ConfVars.$CLIENT_SESSION_EXPIRY_TIME, "session expiry time (secs)", DEFAULT),
+ SESSION_EXPIRY_TIME(ConfVars.$CLIENT_SESSION_EXPIRY_TIME, "session expiry time (secs)", DEFAULT,
+ Integer.class, Validators.min("0")),
// Command line interface and its behavior --------------------------------
CLI_COLUMNS(ConfVars.$CLI_MAX_COLUMN, "Sets the width for the wrapped format", CLI_SIDE_VAR),
@@ -87,29 +91,36 @@ public enum SessionVars implements ConfigKey {
// for distributed query strategies
BROADCAST_TABLE_SIZE_LIMIT(ConfVars.$DIST_QUERY_BROADCAST_JOIN_THRESHOLD, "limited size (bytes) of broadcast table",
- DEFAULT),
+ DEFAULT, Long.class, Validators.min("0")),
- JOIN_TASK_INPUT_SIZE(ConfVars.$DIST_QUERY_JOIN_TASK_VOLUME, "join task input size (mb) ", DEFAULT),
+ JOIN_TASK_INPUT_SIZE(ConfVars.$DIST_QUERY_JOIN_TASK_VOLUME, "join task input size (mb) ", DEFAULT,
+ Integer.class, Validators.min("1")),
SORT_TASK_INPUT_SIZE(ConfVars.$DIST_QUERY_SORT_TASK_VOLUME, "sort task input size (mb)", DEFAULT),
GROUPBY_TASK_INPUT_SIZE(ConfVars.$DIST_QUERY_GROUPBY_TASK_VOLUME, "group by task input size (mb)", DEFAULT),
- JOIN_PER_SHUFFLE_SIZE(ConfVars.$DIST_QUERY_JOIN_PARTITION_VOLUME, "shuffle output size for join (mb)", DEFAULT),
- GROUPBY_PER_SHUFFLE_SIZE(ConfVars.$DIST_QUERY_GROUPBY_PARTITION_VOLUME, "shuffle output size for sort (mb)", DEFAULT),
+ JOIN_PER_SHUFFLE_SIZE(ConfVars.$DIST_QUERY_JOIN_PARTITION_VOLUME, "shuffle output size for join (mb)", DEFAULT,
+ Integer.class, Validators.min("1")),
+ GROUPBY_PER_SHUFFLE_SIZE(ConfVars.$DIST_QUERY_GROUPBY_PARTITION_VOLUME, "shuffle output size for sort (mb)", DEFAULT,
+ Integer.class, Validators.min("1")),
TABLE_PARTITION_PER_SHUFFLE_SIZE(ConfVars.$DIST_QUERY_TABLE_PARTITION_VOLUME,
- "shuffle output size for partition table write (mb)", DEFAULT),
+ "shuffle output size for partition table write (mb)", DEFAULT, Long.class, Validators.min("1")),
- GROUPBY_MULTI_LEVEL_ENABLED(ConfVars.$GROUPBY_MULTI_LEVEL_ENABLED, "Multiple level groupby enabled", DEFAULT),
+ GROUPBY_MULTI_LEVEL_ENABLED(ConfVars.$GROUPBY_MULTI_LEVEL_ENABLED, "Multiple level groupby enabled", DEFAULT,
+ Boolean.class, Validators.bool()),
// for physical Executors
- EXTSORT_BUFFER_SIZE(ConfVars.$EXECUTOR_EXTERNAL_SORT_BUFFER_SIZE, "sort buffer size for external sort (mb)", DEFAULT),
- HASH_JOIN_SIZE_LIMIT(ConfVars.$EXECUTOR_HASH_JOIN_SIZE_THRESHOLD, "limited size for hash join (mb)", DEFAULT),
+ EXTSORT_BUFFER_SIZE(ConfVars.$EXECUTOR_EXTERNAL_SORT_BUFFER_SIZE, "sort buffer size for external sort (mb)", DEFAULT,
+ Long.class, Validators.min("0")),
+ HASH_JOIN_SIZE_LIMIT(ConfVars.$EXECUTOR_HASH_JOIN_SIZE_THRESHOLD, "limited size for hash join (mb)", DEFAULT,
+ Long.class, Validators.min("0")),
INNER_HASH_JOIN_SIZE_LIMIT(ConfVars.$EXECUTOR_INNER_HASH_JOIN_SIZE_THRESHOLD,
- "limited size for hash inner join (mb)", DEFAULT),
+ "limited size for hash inner join (mb)", DEFAULT, Long.class, Validators.min("0")),
OUTER_HASH_JOIN_SIZE_LIMIT(ConfVars.$EXECUTOR_OUTER_HASH_JOIN_SIZE_THRESHOLD, "limited size for hash outer join (mb)",
- DEFAULT),
+ DEFAULT, Long.class, Validators.min("0")),
HASH_GROUPBY_SIZE_LIMIT(ConfVars.$EXECUTOR_GROUPBY_INMEMORY_HASH_THRESHOLD, "limited size for hash groupby (mb)",
- DEFAULT),
- MAX_OUTPUT_FILE_SIZE(ConfVars.$MAX_OUTPUT_FILE_SIZE, "Maximum per-output file size (mb). 0 means infinite.", DEFAULT),
+ DEFAULT, Long.class, Validators.min("0")),
+ MAX_OUTPUT_FILE_SIZE(ConfVars.$MAX_OUTPUT_FILE_SIZE, "Maximum per-output file size (mb). 0 means infinite.", DEFAULT,
+ Long.class, Validators.min("0")),
NULL_CHAR(ConfVars.$CSVFILE_NULL, "null char of text file output", DEFAULT),
CODEGEN(ConfVars.$CODEGEN, "Runtime code generation enabled (experiment)", DEFAULT),
@@ -118,7 +129,8 @@ public enum SessionVars implements ConfigKey {
"If true, a running query will be terminated when an overflow or divide-by-zero occurs.", DEFAULT),
// ResultSet ----------------------------------------------------------------
- FETCH_ROWNUM(ConfVars.$RESULT_SET_FETCH_ROWNUM, "Sets the number of rows at a time from Master", DEFAULT),
+ FETCH_ROWNUM(ConfVars.$RESULT_SET_FETCH_ROWNUM, "Sets the number of rows at a time from Master", DEFAULT,
+ Integer.class, Validators.min("0")),
//-------------------------------------------------------------------------------
// Only for Unit Testing
@@ -143,6 +155,9 @@ public enum SessionVars implements ConfigKey {
private final ConfVars key;
private final String description;
private final VariableMode mode;
+
+ private Class<?> valClass;
+ private Validator validator;
public static enum VariableMode {
DEFAULT, // Client can set or change variables of this mode..
@@ -157,6 +172,12 @@ public enum SessionVars implements ConfigKey {
this.description = description;
this.mode = mode;
}
+
+ SessionVars(ConfVars key, String description, VariableMode mode, Class<?> valueClass, Validator validator) {
+ this(key, description, mode);
+ this.valClass = valueClass;
+ this.validator = validator;
+ }
public String keyname() {
return name();
@@ -213,4 +234,14 @@ public enum SessionVars implements ConfigKey {
public static String handleDeprecatedName(String keyname) {
return SessionVars.exists(keyname) ? SessionVars.get(keyname).keyname() : keyname;
}
+
+ @Override
+ public Class<?> valueClass() {
+ return valClass;
+ }
+
+ @Override
+ public Validator validator() {
+ return validator;
+ }
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
index 181ef2e..86f934e 100644
--- a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
+++ b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
@@ -19,14 +19,20 @@
package org.apache.tajo.conf;
import com.google.common.base.Preconditions;
+
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.tajo.ConfigKey;
+import org.apache.tajo.SessionVars;
import org.apache.tajo.TajoConstants;
import org.apache.tajo.util.NetUtils;
+import org.apache.tajo.util.NumberUtil;
import org.apache.tajo.util.TUtil;
import org.apache.tajo.util.datetime.DateTimeConstants;
+import org.apache.tajo.validation.ConstraintViolationException;
+import org.apache.tajo.validation.Validator;
+import org.apache.tajo.validation.Validators;
import java.io.IOException;
import java.io.PrintStream;
@@ -43,6 +49,8 @@ public class TajoConf extends Configuration {
private static final ReentrantReadWriteLock confLock = new ReentrantReadWriteLock();
private static final Lock writeLock = confLock.writeLock();
private static final Lock readLock = confLock.readLock();
+
+ private static final Map<String, ConfVars> vars = TUtil.newHashMap();
static {
Configuration.addDefaultResource("catalog-default.xml");
@@ -53,12 +61,14 @@ public class TajoConf extends Configuration {
Configuration.addDefaultResource("tajo-site.xml");
confStaticInit();
+
+ for (ConfVars confVars: ConfVars.values()) {
+ vars.put(confVars.keyname(), confVars);
+ }
}
private static final String EMPTY_VALUE = "";
- private static final Map<String, ConfVars> vars = TUtil.newHashMap();
-
public TajoConf() {
super();
}
@@ -143,54 +153,61 @@ public class TajoConf extends Configuration {
///////////////////////////////////////////////////////////////////////////////////////
// a username for a running Tajo cluster
- ROOT_DIR("tajo.rootdir", "file:///tmp/tajo-${user.name}/"),
- USERNAME("tajo.username", "${user.name}"),
+ ROOT_DIR("tajo.rootdir", "file:///tmp/tajo-${user.name}/",
+ Validators.groups(Validators.notNull(), Validators.pathUrl())),
+ USERNAME("tajo.username", "${user.name}",
+ Validators.groups(Validators.notNull(), Validators.javaString())),
// Configurable System Directories
- WAREHOUSE_DIR("tajo.warehouse.directory", EMPTY_VALUE),
- STAGING_ROOT_DIR("tajo.staging.directory", "/tmp/tajo-${user.name}/staging"),
+ WAREHOUSE_DIR("tajo.warehouse.directory", EMPTY_VALUE, Validators.pathUrl()),
+ STAGING_ROOT_DIR("tajo.staging.directory", "/tmp/tajo-${user.name}/staging", Validators.pathUrl()),
- SYSTEM_CONF_PATH("tajo.system-conf.path", EMPTY_VALUE),
- SYSTEM_CONF_REPLICA_COUNT("tajo.system-conf.replica-count", 20),
+ SYSTEM_CONF_PATH("tajo.system-conf.path", EMPTY_VALUE, Validators.pathUrl()),
+ SYSTEM_CONF_REPLICA_COUNT("tajo.system-conf.replica-count", 20, Validators.min("1")),
// Tajo Master Service Addresses
- TAJO_MASTER_UMBILICAL_RPC_ADDRESS("tajo.master.umbilical-rpc.address", "localhost:26001"),
- TAJO_MASTER_CLIENT_RPC_ADDRESS("tajo.master.client-rpc.address", "localhost:26002"),
- TAJO_MASTER_INFO_ADDRESS("tajo.master.info-http.address", "0.0.0.0:26080"),
+ TAJO_MASTER_UMBILICAL_RPC_ADDRESS("tajo.master.umbilical-rpc.address", "localhost:26001",
+ Validators.networkAddr()),
+ TAJO_MASTER_CLIENT_RPC_ADDRESS("tajo.master.client-rpc.address", "localhost:26002",
+ Validators.networkAddr()),
+ TAJO_MASTER_INFO_ADDRESS("tajo.master.info-http.address", "0.0.0.0:26080", Validators.networkAddr()),
// Tajo Master HA Configurations
- TAJO_MASTER_HA_ENABLE("tajo.master.ha.enable", false),
+ TAJO_MASTER_HA_ENABLE("tajo.master.ha.enable", false, Validators.bool()),
TAJO_MASTER_HA_MONITOR_INTERVAL("tajo.master.ha.monitor.interval", 5 * 1000), // 5 sec
// Resource tracker service
- RESOURCE_TRACKER_RPC_ADDRESS("tajo.resource-tracker.rpc.address", "localhost:26003"),
+ RESOURCE_TRACKER_RPC_ADDRESS("tajo.resource-tracker.rpc.address", "localhost:26003",
+ Validators.networkAddr()),
RESOURCE_TRACKER_HEARTBEAT_TIMEOUT("tajo.resource-tracker.heartbeat.timeout-secs", 120 * 1000), // seconds
// QueryMaster resource
- TAJO_QUERYMASTER_DISK_SLOT("tajo.qm.resource.disk.slots", 0.0f),
- TAJO_QUERYMASTER_MEMORY_MB("tajo.qm.resource.memory-mb", 512),
+ TAJO_QUERYMASTER_DISK_SLOT("tajo.qm.resource.disk.slots", 0.0f, Validators.min("0.0f")),
+ TAJO_QUERYMASTER_MEMORY_MB("tajo.qm.resource.memory-mb", 512, Validators.min("64")),
// Tajo Worker Service Addresses
- WORKER_INFO_ADDRESS("tajo.worker.info-http.address", "0.0.0.0:28080"),
- WORKER_QM_INFO_ADDRESS("tajo.worker.qm-info-http.address", "0.0.0.0:28081"),
- WORKER_PEER_RPC_ADDRESS("tajo.worker.peer-rpc.address", "0.0.0.0:28091"),
- WORKER_CLIENT_RPC_ADDRESS("tajo.worker.client-rpc.address", "0.0.0.0:28092"),
- WORKER_QM_RPC_ADDRESS("tajo.worker.qm-rpc.address", "0.0.0.0:28093"),
+ WORKER_INFO_ADDRESS("tajo.worker.info-http.address", "0.0.0.0:28080", Validators.networkAddr()),
+ WORKER_QM_INFO_ADDRESS("tajo.worker.qm-info-http.address", "0.0.0.0:28081", Validators.networkAddr()),
+ WORKER_PEER_RPC_ADDRESS("tajo.worker.peer-rpc.address", "0.0.0.0:28091", Validators.networkAddr()),
+ WORKER_CLIENT_RPC_ADDRESS("tajo.worker.client-rpc.address", "0.0.0.0:28092", Validators.networkAddr()),
+ WORKER_QM_RPC_ADDRESS("tajo.worker.qm-rpc.address", "0.0.0.0:28093", Validators.networkAddr()),
// Tajo Worker Temporal Directories
- WORKER_TEMPORAL_DIR("tajo.worker.tmpdir.locations", "/tmp/tajo-${user.name}/tmpdir"),
- WORKER_TEMPORAL_DIR_CLEANUP("tajo.worker.tmpdir.cleanup-at-startup", false),
+ WORKER_TEMPORAL_DIR("tajo.worker.tmpdir.locations", "/tmp/tajo-${user.name}/tmpdir",
+ Validators.pathUrl()),
+ WORKER_TEMPORAL_DIR_CLEANUP("tajo.worker.tmpdir.cleanup-at-startup", false, Validators.bool()),
// Tajo Worker Resources
- WORKER_RESOURCE_AVAILABLE_CPU_CORES("tajo.worker.resource.cpu-cores", 1),
- WORKER_RESOURCE_AVAILABLE_MEMORY_MB("tajo.worker.resource.memory-mb", 1024),
+ WORKER_RESOURCE_AVAILABLE_CPU_CORES("tajo.worker.resource.cpu-cores", 1, Validators.min("1")),
+ WORKER_RESOURCE_AVAILABLE_MEMORY_MB("tajo.worker.resource.memory-mb", 1024, Validators.min("64")),
WORKER_RESOURCE_AVAILABLE_DISKS("tajo.worker.resource.disks", 1.0f),
WORKER_EXECUTION_MAX_SLOTS("tajo.worker.parallel-execution.max-num", 2),
- WORKER_RESOURCE_DFS_DIR_AWARE("tajo.worker.resource.dfs-dir-aware", false),
+ WORKER_RESOURCE_DFS_DIR_AWARE("tajo.worker.resource.dfs-dir-aware", false, Validators.bool()),
// Tajo Worker Dedicated Resources
- WORKER_RESOURCE_DEDICATED("tajo.worker.resource.dedicated", false),
- WORKER_RESOURCE_DEDICATED_MEMORY_RATIO("tajo.worker.resource.dedicated-memory-ratio", 0.8f),
+ WORKER_RESOURCE_DEDICATED("tajo.worker.resource.dedicated", false, Validators.bool()),
+ WORKER_RESOURCE_DEDICATED_MEMORY_RATIO("tajo.worker.resource.dedicated-memory-ratio", 0.8f,
+ Validators.range("0.0f", "1.0f")),
// Tajo Worker History
WORKER_HISTORY_EXPIRE_PERIOD("tajo.worker.history.expire-interval-minutes", 12 * 60), // 12 hours
@@ -198,26 +215,27 @@ public class TajoConf extends Configuration {
WORKER_HEARTBEAT_TIMEOUT("tajo.worker.heartbeat.timeout", 120 * 1000), // 120 sec
// Resource Manager
- RESOURCE_MANAGER_CLASS("tajo.resource.manager", "org.apache.tajo.master.rm.TajoWorkerResourceManager"),
+ RESOURCE_MANAGER_CLASS("tajo.resource.manager", "org.apache.tajo.master.rm.TajoWorkerResourceManager",
+ Validators.groups(Validators.notNull(), Validators.clazz())),
// Catalog
- CATALOG_ADDRESS("tajo.catalog.client-rpc.address", "localhost:26005"),
+ CATALOG_ADDRESS("tajo.catalog.client-rpc.address", "localhost:26005", Validators.networkAddr()),
// for Yarn Resource Manager ----------------------------------------------
/** how many launching TaskRunners in parallel */
- YARN_RM_QUERY_MASTER_MEMORY_MB("tajo.querymaster.memory-mb", 512),
+ YARN_RM_QUERY_MASTER_MEMORY_MB("tajo.querymaster.memory-mb", 512, Validators.min("64")),
YARN_RM_QUERY_MASTER_DISKS("tajo.yarn-rm.querymaster.disks", 1),
YARN_RM_TASKRUNNER_LAUNCH_PARALLEL_NUM("tajo.yarn-rm.parallel-task-runner-launcher-num", 16),
YARN_RM_WORKER_NUMBER_PER_NODE("tajo.yarn-rm.max-worker-num-per-node", 8),
// Query Configuration
- QUERY_SESSION_TIMEOUT("tajo.query.session.timeout-sec", 60),
+ QUERY_SESSION_TIMEOUT("tajo.query.session.timeout-sec", 60, Validators.min("0")),
// Shuffle Configuration --------------------------------------------------
- PULLSERVER_PORT("tajo.pullserver.port", 0),
- SHUFFLE_SSL_ENABLED_KEY("tajo.pullserver.ssl.enabled", false),
+ PULLSERVER_PORT("tajo.pullserver.port", 0, Validators.range("0", "65535")),
+ SHUFFLE_SSL_ENABLED_KEY("tajo.pullserver.ssl.enabled", false, Validators.bool()),
SHUFFLE_FILE_FORMAT("tajo.shuffle.file-format", "RAW"),
SHUFFLE_FETCHER_PARALLEL_EXECUTION_MAX_NUM("tajo.shuffle.fetcher.parallel-execution.max-num", 2),
SHUFFLE_FETCHER_CHUNK_MAX_SIZE("tajo.shuffle.fetcher.chunk.max-size", 8192),
@@ -231,7 +249,7 @@ public class TajoConf extends Configuration {
ROWFILE_SYNC_INTERVAL("rowfile.sync.interval", 100),
MINIMUM_SPLIT_SIZE("tajo.min.split.size", (long) 1),
// for RCFile
- HIVEUSEEXPLICITRCFILEHEADER("tajo.exec.rcfile.use.explicit.header", true),
+ HIVEUSEEXPLICITRCFILEHEADER("tajo.exec.rcfile.use.explicit.header", true, Validators.bool()),
// RPC --------------------------------------------------------------------
RPC_POOL_MAX_IDLE("tajo.rpc.pool.idle.max", 10),
@@ -305,9 +323,9 @@ public class TajoConf extends Configuration {
$DIST_QUERY_SORT_TASK_VOLUME("tajo.dist-query.sort.task-volume-mb", 128),
$DIST_QUERY_GROUPBY_TASK_VOLUME("tajo.dist-query.groupby.task-volume-mb", 128),
- $DIST_QUERY_JOIN_PARTITION_VOLUME("tajo.dist-query.join.partition-volume-mb", 128),
- $DIST_QUERY_GROUPBY_PARTITION_VOLUME("tajo.dist-query.groupby.partition-volume-mb", 256),
- $DIST_QUERY_TABLE_PARTITION_VOLUME("tajo.dist-query.table-partition.task-volume-mb", 256),
+ $DIST_QUERY_JOIN_PARTITION_VOLUME("tajo.dist-query.join.partition-volume-mb", 128, Validators.min("1")),
+ $DIST_QUERY_GROUPBY_PARTITION_VOLUME("tajo.dist-query.groupby.partition-volume-mb", 256, Validators.min("1")),
+ $DIST_QUERY_TABLE_PARTITION_VOLUME("tajo.dist-query.table-partition.task-volume-mb", 256, Validators.min("1")),
$GROUPBY_MULTI_LEVEL_ENABLED("tajo.dist-query.groupby.multi-level-aggr", true),
@@ -366,6 +384,7 @@ public class TajoConf extends Configuration {
public final boolean defaultBoolVal;
private final VarType type;
+ private Validator validator;
ConfVars(String varname, String defaultVal) {
this.varname = varname;
@@ -377,6 +396,11 @@ public class TajoConf extends Configuration {
this.defaultBoolVal = false;
this.type = VarType.STRING;
}
+
+ ConfVars(String varname, String defaultVal, Validator validator) {
+ this(varname, defaultVal);
+ this.validator = validator;
+ }
ConfVars(String varname, int defaultIntVal) {
this.varname = varname;
@@ -388,6 +412,11 @@ public class TajoConf extends Configuration {
this.defaultBoolVal = false;
this.type = VarType.INT;
}
+
+ ConfVars(String varname, int defaultIntVal, Validator validator) {
+ this(varname, defaultIntVal);
+ this.validator = validator;
+ }
ConfVars(String varname, long defaultLongVal) {
this.varname = varname;
@@ -399,6 +428,11 @@ public class TajoConf extends Configuration {
this.defaultBoolVal = false;
this.type = VarType.LONG;
}
+
+ ConfVars(String varname, long defaultLongVal, Validator validator) {
+ this(varname, defaultLongVal);
+ this.validator = validator;
+ }
ConfVars(String varname, float defaultFloatVal) {
this.varname = varname;
@@ -410,6 +444,11 @@ public class TajoConf extends Configuration {
this.defaultBoolVal = false;
this.type = VarType.FLOAT;
}
+
+ ConfVars(String varname, float defaultFloatVal, Validator validator) {
+ this(varname, defaultFloatVal);
+ this.validator = validator;
+ }
ConfVars(String varname, boolean defaultBoolVal) {
this.varname = varname;
@@ -421,6 +460,11 @@ public class TajoConf extends Configuration {
this.defaultBoolVal = defaultBoolVal;
this.type = VarType.BOOLEAN;
}
+
+ ConfVars(String varname, boolean defaultBoolVal, Validator validator) {
+ this(varname, defaultBoolVal);
+ this.validator = validator;
+ }
enum VarType {
STRING { void checkType(String value) throws Exception { } },
@@ -446,6 +490,16 @@ public class TajoConf extends Configuration {
public ConfigType type() {
return ConfigType.SYSTEM;
}
+
+ @Override
+ public Class<?> valueClass() {
+ return valClass;
+ }
+
+ @Override
+ public Validator validator() {
+ return validator;
+ }
}
public static int getIntVar(Configuration conf, ConfVars var) {
@@ -635,4 +689,31 @@ public class TajoConf extends Configuration {
return new Path(systemConfPathStr);
}
}
+
+ /**
+ * validateProperty function will fetch pre-defined configuration property by keyname.
+ * If found, it will validate the supplied value with these validators.
+ *
+ * @param name - a string containing specific key
+ * @param value - a string containing value
+ * @throws ConstraintViolationException
+ */
+ public void validateProperty(String name, String value) throws ConstraintViolationException {
+ ConfigKey configKey = null;
+ configKey = TajoConf.getConfVars(name);
+ if (configKey == null) {
+ configKey = SessionVars.get(name);
+ }
+ if (configKey != null && configKey.validator() != null && configKey.valueClass() != null) {
+ Object valueObj = value;
+ if (Number.class.isAssignableFrom(configKey.valueClass())) {
+ valueObj = NumberUtil.numberValue(configKey.valueClass(), value);
+ if (valueObj == null) {
+ return;
+ }
+ }
+ configKey.validator().validate(valueObj, true);
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
index d52b804..375a2e4 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
@@ -18,6 +18,9 @@
package org.apache.tajo.util;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
public class NumberUtil {
public static final double[] powersOf10 = { /* Table giving binary powers of 10. Entry */
@@ -408,4 +411,22 @@ public class NumberUtil {
}
return result;
}
+
+ public static Number numberValue(Class<?> numberClazz, String value) {
+ Number returnNumber = null;
+
+ if (numberClazz == null && value == null) {
+ return returnNumber;
+ }
+
+ if (Number.class.isAssignableFrom(numberClazz)) {
+ try {
+ Constructor<?> constructor = numberClazz.getConstructor(String.class);
+ returnNumber = (Number) constructor.newInstance(value);
+ } catch (Exception ignored) {
+ }
+ }
+
+ return returnNumber;
+ }
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/AbstractValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/AbstractValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/AbstractValidator.java
new file mode 100644
index 0000000..0f7082b
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/AbstractValidator.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+
+import org.apache.tajo.util.TUtil;
+
+public abstract class AbstractValidator implements Validator {
+
+ protected abstract <T> String getErrorMessage(T object);
+ protected abstract <T> boolean validateInternal(T object);
+ protected abstract Collection<Validator> getDependantValidators();
+
+ @Override
+ public <T> Collection<ConstraintViolation> validate(T object) {
+ Collection<ConstraintViolation> violations = TUtil.newHashSet();
+
+ if (!validateInternal(object)) {
+ ConstraintViolation violation = new ConstraintViolation();
+ violation.setMessage(getErrorMessage(object));
+ violation.setValidatorClazz(this.getClass());
+ violations.add(violation);
+ }
+
+ for (Validator dependantValidator: getDependantValidators()) {
+ violations.addAll(dependantValidator.validate(object));
+ }
+
+ return violations;
+ }
+
+ @Override
+ public <T> void validate(T object, boolean generateThrow) {
+ Collection<ConstraintViolation> violations = validate(object);
+
+ if (violations.size() > 0) {
+ if (generateThrow) {
+ throw new ConstraintViolationException(violations);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/BooleanValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/BooleanValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/BooleanValidator.java
new file mode 100644
index 0000000..b72a5fd
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/BooleanValidator.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class BooleanValidator extends AbstractValidator {
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " is not a valid boolean representation.";
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ if (object instanceof Boolean) {
+ result = true;
+ } else if (object instanceof CharSequence) {
+ String valueString = object.toString();
+ if (Boolean.FALSE.toString().equalsIgnoreCase(valueString) ||
+ Boolean.TRUE.toString().equalsIgnoreCase(valueString)) {
+ result = true;
+ }
+ }
+ } else {
+ result = true;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/ClassValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/ClassValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/ClassValidator.java
new file mode 100644
index 0000000..1b35e6d
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/ClassValidator.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class ClassValidator extends AbstractValidator {
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return "ClassLoader cannot find " + object + " class.";
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ if (object instanceof CharSequence) {
+ String valueString = object.toString();
+ try {
+ Class.forName(valueString);
+ result = true;
+ } catch (ClassNotFoundException e) {
+ result = false;
+ }
+ }
+ } else {
+ result = true;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolation.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolation.java b/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolation.java
new file mode 100644
index 0000000..8d84aa7
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolation.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+public class ConstraintViolation {
+
+ private String message;
+ private Class<? extends Validator> validatorClazz;
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Class<? extends Validator> getValidatorClazz() {
+ return validatorClazz;
+ }
+
+ public void setValidatorClazz(Class<? extends Validator> validatorClazz) {
+ this.validatorClazz = validatorClazz;
+ }
+
+ @Override
+ public String toString() {
+ return "ConstraintViolation [message=" + message + ", validatorClazz=" + validatorClazz + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolationException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolationException.java b/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolationException.java
new file mode 100644
index 0000000..8fda81e
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolationException.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+
+public class ConstraintViolationException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Collection<ConstraintViolation> violations;
+
+ public ConstraintViolationException(Collection<ConstraintViolation> violations) {
+ this.violations = violations;
+ }
+
+ public Collection<ConstraintViolation> getViolations() {
+ return violations;
+ }
+
+ @Override
+ public String getMessage() {
+ if (violations != null) {
+ String errorMessage = "ConstraintViolationException [";
+ int elemIdx = 1;
+ int elemCount = violations.size();
+ for (ConstraintViolation violation: violations) {
+ errorMessage += violation.getMessage();
+ if (elemIdx++ > elemCount) {
+ errorMessage += ",";
+ }
+ }
+ errorMessage += "]";
+ return errorMessage;
+ } else {
+ return super.getMessage();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/GroupValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/GroupValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/GroupValidator.java
new file mode 100644
index 0000000..db2ba51
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/GroupValidator.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+
+public class GroupValidator extends AbstractValidator {
+
+ private final Collection<Validator> dependants;
+
+ public GroupValidator(Collection<Validator> validators) {
+ if (validators.size() == 0) {
+ throw new IllegalArgumentException("Needs at least 1 or more validators.");
+ }
+ this.dependants = validators;
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return "";
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ return true;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return dependants;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/JavaStringValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/JavaStringValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/JavaStringValidator.java
new file mode 100644
index 0000000..a8b1806
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/JavaStringValidator.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+public class JavaStringValidator extends PatternValidator {
+
+ public JavaStringValidator() {
+ super("^(?sU:\\p{Graph})+$");
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " is not a valid string";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/LengthValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/LengthValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/LengthValidator.java
new file mode 100644
index 0000000..e53634b
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/LengthValidator.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class LengthValidator extends AbstractValidator {
+
+ private final int maxLength;
+
+ public LengthValidator(int maxLen) {
+ this.maxLength = maxLen;
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return "Length of " + object + " is greater than " + maxLength;
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ if (object instanceof CharSequence) {
+ result = ((CharSequence)object).length() <= maxLength;
+ }
+ } else {
+ result = true;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/MaxValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/MaxValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/MaxValidator.java
new file mode 100644
index 0000000..300c5ea
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/MaxValidator.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.commons.lang.math.NumberUtils;
+
+public class MaxValidator extends AbstractValidator {
+
+ private final String maxValue;
+
+ public MaxValidator(String maxValue) {
+ if (!NumberUtils.isNumber(maxValue)) {
+ throw new IllegalArgumentException(maxValue + " is not a Java number.");
+ }
+
+ this.maxValue = maxValue;
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " should be less than " + maxValue;
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer)) {
+ Integer objInteger = Integer.decode(object.toString());
+ Integer maxInteger = Integer.decode(maxValue);
+ result = objInteger.compareTo(maxInteger) <= 0;
+ } else if (object instanceof Long) {
+ Long objLong = Long.decode(object.toString());
+ Long maxLong = Long.decode(maxValue);
+ result = objLong.compareTo(maxLong) <= 0;
+ } else if ((object instanceof Float) || (object instanceof Double)) {
+ Double objDouble = Double.valueOf(object.toString());
+ Double maxDouble = Double.valueOf(maxValue);
+ result = objDouble.compareTo(maxDouble) <= 0;
+ } else if (object instanceof BigInteger) {
+ BigInteger objInteger = (BigInteger) object;
+ BigInteger maxInteger = new BigInteger(maxValue);
+ result = objInteger.compareTo(maxInteger) <= 0;
+ } else if (object instanceof BigDecimal) {
+ BigDecimal objDecimal = (BigDecimal) object;
+ BigDecimal maxDecimal = new BigDecimal(maxValue);
+ result = objDecimal.compareTo(maxDecimal) <= 0;
+ }
+ } else {
+ result = true;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/MinValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/MinValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/MinValidator.java
new file mode 100644
index 0000000..431fe9b
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/MinValidator.java
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.commons.lang.math.NumberUtils;
+
+public class MinValidator extends AbstractValidator {
+
+ private final String minValue;
+
+ public MinValidator(String minValue) {
+ if (!NumberUtils.isNumber(minValue)) {
+ throw new IllegalArgumentException(minValue + " is not a Java Number.");
+ }
+
+ this.minValue = minValue;
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " should be greater than " + minValue;
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer)) {
+ Integer objInteger = Integer.decode(object.toString());
+ Integer minInteger = Integer.decode(minValue);
+ result = objInteger.compareTo(minInteger) >= 0;
+ } else if (object instanceof Long) {
+ Long objLong = Long.decode(object.toString());
+ Long minLong = Long.decode(minValue);
+ result = objLong.compareTo(minLong) >= 0;
+ } else if ((object instanceof Float) || (object instanceof Double)) {
+ Double objDouble = Double.valueOf(object.toString());
+ Double minDouble = Double.valueOf(minValue);
+ result = objDouble.compareTo(minDouble) >= 0;
+ } else if (object instanceof BigInteger) {
+ BigInteger objInteger = (BigInteger) object;
+ BigInteger minInteger = new BigInteger(minValue);
+ result = objInteger.compareTo(minInteger) >= 0;
+ } else if (object instanceof BigDecimal) {
+ BigDecimal objDecimal = (BigDecimal) object;
+ BigDecimal minDecimal = new BigDecimal(minValue);
+ result = objDecimal.compareTo(minDecimal) >= 0;
+ }
+ }
+ else {
+ result = true;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/NetworkAddressValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/NetworkAddressValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/NetworkAddressValidator.java
new file mode 100644
index 0000000..7477c4c
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/NetworkAddressValidator.java
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.regex.Pattern;
+
+import org.apache.http.conn.util.InetAddressUtils;
+
+public class NetworkAddressValidator extends AbstractValidator {
+
+ private final Pattern hostnamePattern;
+ private final Pattern portNumberPattern;
+
+ public NetworkAddressValidator() {
+ hostnamePattern = Pattern.compile(
+ "^[a-zA-Z][-a-zA-Z0-9\\\\._]+$");
+ portNumberPattern = Pattern.compile("^[1-6]?[0-9]{1,4}$");
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " is not a valid network address representation.";
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ if (object instanceof CharSequence) {
+ String valueString = object.toString();
+ if (valueString.isEmpty()) {
+ result = true;
+ } else {
+ int separatorIdx = valueString.indexOf(':');
+ String hostOrIpAddress = null;
+
+ if (separatorIdx > -1) {
+ if (valueString.indexOf(':', separatorIdx+1) > -1) {
+ // it is IPV6 representation.
+ int leftBracketsIdx = valueString.indexOf('[');
+ int rightBracketsIdx = valueString.indexOf(']');
+ int periodIdx = valueString.indexOf('.');
+
+ if ((leftBracketsIdx > -1) && (rightBracketsIdx > -1) &&
+ (valueString.length() > (rightBracketsIdx+1)) &&
+ valueString.charAt(rightBracketsIdx+1) == ':') {
+ hostOrIpAddress = valueString.substring(leftBracketsIdx+1, rightBracketsIdx);
+ separatorIdx = rightBracketsIdx+1;
+ } else if ((periodIdx > -1)) {
+ hostOrIpAddress = valueString.substring(0, periodIdx);
+ separatorIdx = periodIdx;
+ } else {
+ separatorIdx = valueString.lastIndexOf(':');
+ hostOrIpAddress = valueString.substring(0, separatorIdx);
+ }
+ } else {
+ hostOrIpAddress = valueString.substring(0, separatorIdx);
+ }
+ } else {
+ hostOrIpAddress = valueString;
+ }
+
+ result = ((hostnamePattern.matcher(hostOrIpAddress).find()) |
+ InetAddressUtils.isIPv4Address(hostOrIpAddress) |
+ InetAddressUtils.isIPv6Address(hostOrIpAddress));
+
+ if (separatorIdx > -1) {
+ result &= portNumberPattern.matcher(valueString.substring(separatorIdx + 1)).find();
+ }
+ }
+ }
+ } else {
+ result = true;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/NotNullValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/NotNullValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/NotNullValidator.java
new file mode 100644
index 0000000..d0ace1f
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/NotNullValidator.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class NotNullValidator extends AbstractValidator {
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return "Object is null";
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ result = true;
+ }
+
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/PathValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/PathValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/PathValidator.java
new file mode 100644
index 0000000..a76587c
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/PathValidator.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+public class PathValidator extends PatternValidator {
+
+ public PathValidator() {
+ super("^(?:[a-zA-Z][a-zA-Z0-9+-.]+:[/]{1,2}[a-zA-Z-.]*[:0-9]*)?(?:/?[a-zA-Z]:)?[/a-zA-Z0-9-_\\\\.\\\\$\\\\{\\\\}]*$");
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " is not valid path.";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/PatternValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/PatternValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/PatternValidator.java
new file mode 100644
index 0000000..2a29671
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/PatternValidator.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.regex.Pattern;
+
+public class PatternValidator extends AbstractValidator {
+
+ private final Pattern pattern;
+
+ public PatternValidator(String patternString) {
+ pattern = Pattern.compile(patternString);
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " does not match to the " + pattern.pattern();
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ boolean result = false;
+
+ if (object != null) {
+ if (object instanceof CharSequence) {
+ String valueString = object.toString();
+ if (valueString.isEmpty()) {
+ result = true;
+ } else {
+ result = pattern.matcher((CharSequence) object).find();
+ }
+ }
+ } else {
+ result = true;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/RangeValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/RangeValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/RangeValidator.java
new file mode 100644
index 0000000..ae6fd76
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/RangeValidator.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class RangeValidator extends AbstractValidator {
+
+ private final String minValue;
+ private final AbstractValidator minValidator;
+ private final String maxValue;
+ private final AbstractValidator maxValidator;
+
+ public RangeValidator(String minValue, String maxValue) {
+ this.minValue = minValue;
+ this.minValidator = new MinValidator(minValue);
+ this.maxValue = maxValue;
+ this.maxValidator = new MaxValidator(maxValue);
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " is not a range of " + minValue + " and " + maxValue;
+ }
+
+ @Override
+ protected <T> boolean validateInternal(T object) {
+ return this.minValidator.validateInternal(object) & this.maxValidator.validateInternal(object);
+ }
+
+ @Override
+ protected Collection<Validator> getDependantValidators() {
+ return Collections.emptySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/ShellVariableValidator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/ShellVariableValidator.java b/tajo-common/src/main/java/org/apache/tajo/validation/ShellVariableValidator.java
new file mode 100644
index 0000000..cfc0cc9
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/ShellVariableValidator.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+public class ShellVariableValidator extends PatternValidator {
+
+ public ShellVariableValidator() {
+ super("^[\\\\$]?[\\\\{]?[a-zA-Z0-9.]+[\\\\}]?$");
+ }
+
+ @Override
+ protected <T> String getErrorMessage(T object) {
+ return object + " is not a valid shell variable";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/Validator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/Validator.java b/tajo-common/src/main/java/org/apache/tajo/validation/Validator.java
new file mode 100644
index 0000000..8f16fda
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/Validator.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import java.util.Collection;
+
+public interface Validator {
+
+ public <T> Collection<ConstraintViolation> validate(T object);
+
+ public <T> void validate(T object, boolean generateThrow);
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/ee89c65b/tajo-common/src/main/java/org/apache/tajo/validation/Validators.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/validation/Validators.java b/tajo-common/src/main/java/org/apache/tajo/validation/Validators.java
new file mode 100644
index 0000000..acd4876
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/validation/Validators.java
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.validation;
+
+import org.apache.tajo.util.TUtil;
+
+public class Validators {
+
+ public static Validator groups(Validator...validators) {
+ return new GroupValidator(TUtil.newHashSet(validators));
+ }
+
+ public static Validator length(int maxLength) {
+ return new LengthValidator(maxLength);
+ }
+
+ public static Validator max(String maxValue) {
+ return new MaxValidator(maxValue);
+ }
+
+ public static Validator min(String minValue) {
+ return new MinValidator(minValue);
+ }
+
+ public static Validator notNull() {
+ return new NotNullValidator();
+ }
+
+ public static Validator patternMatch(String regex) {
+ return new PatternValidator(regex);
+ }
+
+ public static Validator range(String minValue, String maxValue) {
+ return new RangeValidator(minValue, maxValue);
+ }
+
+ public static Validator pathUrl() {
+ return new PathValidator();
+ }
+
+ public static Validator shellVar() {
+ return new ShellVariableValidator();
+ }
+
+ public static Validator networkAddr() {
+ return new NetworkAddressValidator();
+ }
+
+ public static Validator bool() {
+ return new BooleanValidator();
+ }
+
+ public static Validator clazz() {
+ return new ClassValidator();
+ }
+
+ public static Validator javaString() {
+ return new JavaStringValidator();
+ }
+
+}