Revert "TAJO-1114: Improve ConfVars (SessionVar) to take a validator interface to check its input. (Jihun Kang via hyunsik)"
This reverts commit ee89c65b44142ca640020339e7ab5a608c1a8bf9. Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/8741e682 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/8741e682 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/8741e682 Branch: refs/heads/hbase_storage Commit: 8741e68291cb8dccb64d4c2e0b872cc56a4dbf3f Parents: 58b8eb4 Author: Hyunsik Choi <[email protected]> Authored: Mon Oct 27 18:17:04 2014 -0700 Committer: Hyunsik Choi <[email protected]> Committed: Mon Oct 27 18:17:04 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, 53 insertions(+), 1732 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/8741e682/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 3224a79..d239a19 100644 --- a/CHANGES +++ b/CHANGES @@ -11,9 +11,6 @@ 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/8741e682/tajo-common/pom.xml ---------------------------------------------------------------------- diff --git a/tajo-common/pom.xml b/tajo-common/pom.xml index 820220c..d857e0e 100644 --- a/tajo-common/pom.xml +++ b/tajo-common/pom.xml @@ -108,11 +108,6 @@ </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/8741e682/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 6329e77..b9d51ec 100644 --- a/tajo-common/src/main/java/org/apache/tajo/ConfigKey.java +++ b/tajo-common/src/main/java/org/apache/tajo/ConfigKey.java @@ -18,8 +18,6 @@ package org.apache.tajo; -import org.apache.tajo.validation.Validator; - public interface ConfigKey { // Client can set or change variables of this mode. @@ -51,8 +49,4 @@ 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/8741e682/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 dbe949a..1229849 100644 --- a/tajo-common/src/main/java/org/apache/tajo/SessionVars.java +++ b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java @@ -22,9 +22,6 @@ 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; @@ -43,8 +40,8 @@ public enum SessionVars implements ConfigKey { //------------------------------------------------------------------------------- // Server Side Only Variables //------------------------------------------------------------------------------- - 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")), + SESSION_ID(ConfVars.$EMPTY, "session variable", SERVER_SIDE_VAR), + SESSION_LAST_ACCESS_TIME(ConfVars.$EMPTY, "last access time", SERVER_SIDE_VAR), USERNAME(ConfVars.USERNAME, "username", SERVER_SIDE_VAR), CLIENT_HOST(ConfVars.$EMPTY, "client hostname", SERVER_SIDE_VAR), @@ -56,8 +53,7 @@ public enum SessionVars implements ConfigKey { //------------------------------------------------------------------------------- // Client -------------------------------------------------------- - SESSION_EXPIRY_TIME(ConfVars.$CLIENT_SESSION_EXPIRY_TIME, "session expiry time (secs)", DEFAULT, - Integer.class, Validators.min("0")), + SESSION_EXPIRY_TIME(ConfVars.$CLIENT_SESSION_EXPIRY_TIME, "session expiry time (secs)", DEFAULT), // Command line interface and its behavior -------------------------------- CLI_COLUMNS(ConfVars.$CLI_MAX_COLUMN, "Sets the width for the wrapped format", CLI_SIDE_VAR), @@ -91,36 +87,29 @@ 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, Long.class, Validators.min("0")), + DEFAULT), - JOIN_TASK_INPUT_SIZE(ConfVars.$DIST_QUERY_JOIN_TASK_VOLUME, "join task input size (mb) ", DEFAULT, - Integer.class, Validators.min("1")), + JOIN_TASK_INPUT_SIZE(ConfVars.$DIST_QUERY_JOIN_TASK_VOLUME, "join task input size (mb) ", DEFAULT), 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, - 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")), + 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), TABLE_PARTITION_PER_SHUFFLE_SIZE(ConfVars.$DIST_QUERY_TABLE_PARTITION_VOLUME, - "shuffle output size for partition table write (mb)", DEFAULT, Long.class, Validators.min("1")), + "shuffle output size for partition table write (mb)", DEFAULT), - GROUPBY_MULTI_LEVEL_ENABLED(ConfVars.$GROUPBY_MULTI_LEVEL_ENABLED, "Multiple level groupby enabled", DEFAULT, - Boolean.class, Validators.bool()), + GROUPBY_MULTI_LEVEL_ENABLED(ConfVars.$GROUPBY_MULTI_LEVEL_ENABLED, "Multiple level groupby enabled", DEFAULT), // for physical Executors - 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")), + 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), INNER_HASH_JOIN_SIZE_LIMIT(ConfVars.$EXECUTOR_INNER_HASH_JOIN_SIZE_THRESHOLD, - "limited size for hash inner join (mb)", DEFAULT, Long.class, Validators.min("0")), + "limited size for hash inner join (mb)", DEFAULT), OUTER_HASH_JOIN_SIZE_LIMIT(ConfVars.$EXECUTOR_OUTER_HASH_JOIN_SIZE_THRESHOLD, "limited size for hash outer join (mb)", - DEFAULT, Long.class, Validators.min("0")), + DEFAULT), HASH_GROUPBY_SIZE_LIMIT(ConfVars.$EXECUTOR_GROUPBY_INMEMORY_HASH_THRESHOLD, "limited size for hash groupby (mb)", - 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")), + DEFAULT), + MAX_OUTPUT_FILE_SIZE(ConfVars.$MAX_OUTPUT_FILE_SIZE, "Maximum per-output file size (mb). 0 means infinite.", DEFAULT), NULL_CHAR(ConfVars.$CSVFILE_NULL, "null char of text file output", DEFAULT), CODEGEN(ConfVars.$CODEGEN, "Runtime code generation enabled (experiment)", DEFAULT), @@ -129,8 +118,7 @@ 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, - Integer.class, Validators.min("0")), + FETCH_ROWNUM(ConfVars.$RESULT_SET_FETCH_ROWNUM, "Sets the number of rows at a time from Master", DEFAULT), //------------------------------------------------------------------------------- // Only for Unit Testing @@ -155,9 +143,6 @@ 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.. @@ -172,12 +157,6 @@ 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(); @@ -234,14 +213,4 @@ 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/8741e682/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 86f934e..181ef2e 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,20 +19,14 @@ 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; @@ -49,8 +43,6 @@ 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"); @@ -61,14 +53,12 @@ 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(); } @@ -153,61 +143,54 @@ public class TajoConf extends Configuration { /////////////////////////////////////////////////////////////////////////////////////// // a username for a running Tajo cluster - 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())), + ROOT_DIR("tajo.rootdir", "file:///tmp/tajo-${user.name}/"), + USERNAME("tajo.username", "${user.name}"), // Configurable System Directories - WAREHOUSE_DIR("tajo.warehouse.directory", EMPTY_VALUE, Validators.pathUrl()), - STAGING_ROOT_DIR("tajo.staging.directory", "/tmp/tajo-${user.name}/staging", Validators.pathUrl()), + WAREHOUSE_DIR("tajo.warehouse.directory", EMPTY_VALUE), + STAGING_ROOT_DIR("tajo.staging.directory", "/tmp/tajo-${user.name}/staging"), - SYSTEM_CONF_PATH("tajo.system-conf.path", EMPTY_VALUE, Validators.pathUrl()), - SYSTEM_CONF_REPLICA_COUNT("tajo.system-conf.replica-count", 20, Validators.min("1")), + SYSTEM_CONF_PATH("tajo.system-conf.path", EMPTY_VALUE), + SYSTEM_CONF_REPLICA_COUNT("tajo.system-conf.replica-count", 20), // Tajo Master Service Addresses - 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_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 HA Configurations - TAJO_MASTER_HA_ENABLE("tajo.master.ha.enable", false, Validators.bool()), + TAJO_MASTER_HA_ENABLE("tajo.master.ha.enable", false), 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", - Validators.networkAddr()), + RESOURCE_TRACKER_RPC_ADDRESS("tajo.resource-tracker.rpc.address", "localhost:26003"), 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, Validators.min("0.0f")), - TAJO_QUERYMASTER_MEMORY_MB("tajo.qm.resource.memory-mb", 512, Validators.min("64")), + TAJO_QUERYMASTER_DISK_SLOT("tajo.qm.resource.disk.slots", 0.0f), + TAJO_QUERYMASTER_MEMORY_MB("tajo.qm.resource.memory-mb", 512), // Tajo Worker Service Addresses - 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()), + 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"), // Tajo Worker Temporal Directories - 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()), + WORKER_TEMPORAL_DIR("tajo.worker.tmpdir.locations", "/tmp/tajo-${user.name}/tmpdir"), + WORKER_TEMPORAL_DIR_CLEANUP("tajo.worker.tmpdir.cleanup-at-startup", false), // Tajo Worker Resources - 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_CPU_CORES("tajo.worker.resource.cpu-cores", 1), + WORKER_RESOURCE_AVAILABLE_MEMORY_MB("tajo.worker.resource.memory-mb", 1024), 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, Validators.bool()), + WORKER_RESOURCE_DFS_DIR_AWARE("tajo.worker.resource.dfs-dir-aware", false), // Tajo Worker Dedicated Resources - 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")), + WORKER_RESOURCE_DEDICATED("tajo.worker.resource.dedicated", false), + WORKER_RESOURCE_DEDICATED_MEMORY_RATIO("tajo.worker.resource.dedicated-memory-ratio", 0.8f), // Tajo Worker History WORKER_HISTORY_EXPIRE_PERIOD("tajo.worker.history.expire-interval-minutes", 12 * 60), // 12 hours @@ -215,27 +198,26 @@ 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", - Validators.groups(Validators.notNull(), Validators.clazz())), + RESOURCE_MANAGER_CLASS("tajo.resource.manager", "org.apache.tajo.master.rm.TajoWorkerResourceManager"), // Catalog - CATALOG_ADDRESS("tajo.catalog.client-rpc.address", "localhost:26005", Validators.networkAddr()), + CATALOG_ADDRESS("tajo.catalog.client-rpc.address", "localhost:26005"), // for Yarn Resource Manager ---------------------------------------------- /** how many launching TaskRunners in parallel */ - YARN_RM_QUERY_MASTER_MEMORY_MB("tajo.querymaster.memory-mb", 512, Validators.min("64")), + YARN_RM_QUERY_MASTER_MEMORY_MB("tajo.querymaster.memory-mb", 512), 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, Validators.min("0")), + QUERY_SESSION_TIMEOUT("tajo.query.session.timeout-sec", 60), // Shuffle Configuration -------------------------------------------------- - PULLSERVER_PORT("tajo.pullserver.port", 0, Validators.range("0", "65535")), - SHUFFLE_SSL_ENABLED_KEY("tajo.pullserver.ssl.enabled", false, Validators.bool()), + PULLSERVER_PORT("tajo.pullserver.port", 0), + SHUFFLE_SSL_ENABLED_KEY("tajo.pullserver.ssl.enabled", false), 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), @@ -249,7 +231,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, Validators.bool()), + HIVEUSEEXPLICITRCFILEHEADER("tajo.exec.rcfile.use.explicit.header", true), // RPC -------------------------------------------------------------------- RPC_POOL_MAX_IDLE("tajo.rpc.pool.idle.max", 10), @@ -323,9 +305,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, 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")), + $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), $GROUPBY_MULTI_LEVEL_ENABLED("tajo.dist-query.groupby.multi-level-aggr", true), @@ -384,7 +366,6 @@ public class TajoConf extends Configuration { public final boolean defaultBoolVal; private final VarType type; - private Validator validator; ConfVars(String varname, String defaultVal) { this.varname = varname; @@ -396,11 +377,6 @@ 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; @@ -412,11 +388,6 @@ 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; @@ -428,11 +399,6 @@ 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; @@ -444,11 +410,6 @@ 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; @@ -460,11 +421,6 @@ 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 { } }, @@ -490,16 +446,6 @@ 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) { @@ -689,31 +635,4 @@ 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/8741e682/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 375a2e4..d52b804 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,9 +18,6 @@ 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 */ @@ -411,22 +408,4 @@ 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/8741e682/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 deleted file mode 100644 index 0f7082b..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/AbstractValidator.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index b72a5fd..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/BooleanValidator.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 1b35e6d..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/ClassValidator.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 8d84aa7..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolation.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 8fda81e..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/ConstraintViolationException.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index db2ba51..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/GroupValidator.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index a8b1806..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/JavaStringValidator.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index e53634b..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/LengthValidator.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 300c5ea..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/MaxValidator.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 431fe9b..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/MinValidator.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 7477c4c..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/NetworkAddressValidator.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index d0ace1f..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/NotNullValidator.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index a76587c..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/PathValidator.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 2a29671..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/PatternValidator.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index ae6fd76..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/RangeValidator.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index cfc0cc9..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/ShellVariableValidator.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index 8f16fda..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/Validator.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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/8741e682/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 deleted file mode 100644 index acd4876..0000000 --- a/tajo-common/src/main/java/org/apache/tajo/validation/Validators.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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(); - } - -}
