You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by si...@apache.org on 2015/04/03 02:53:30 UTC
tajo git commit: TAJO-1428: Support min,
max builtin functions for DATE, TIME, TIMESTAMP. (Contributed by Dongjoon Hyun,
Committed by Keuntae Park)
Repository: tajo
Updated Branches:
refs/heads/master f4c9e54c8 -> 0a3a6b958
TAJO-1428: Support min, max builtin functions for DATE, TIME, TIMESTAMP. (Contributed by Dongjoon Hyun, Committed by Keuntae Park)
Closes #449
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/0a3a6b95
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/0a3a6b95
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/0a3a6b95
Branch: refs/heads/master
Commit: 0a3a6b958f9ad348246729f48c6d13c9ef9d2599
Parents: f4c9e54
Author: Keuntae Park <si...@apache.org>
Authored: Fri Apr 3 09:48:54 2015 +0900
Committer: Keuntae Park <si...@apache.org>
Committed: Fri Apr 3 09:48:54 2015 +0900
----------------------------------------------------------------------
CHANGES | 3 +
.../tajo/engine/function/builtin/MaxDate.java | 47 ++++++
.../tajo/engine/function/builtin/MaxTime.java | 47 ++++++
.../engine/function/builtin/MaxTimestamp.java | 47 ++++++
.../tajo/engine/function/builtin/MinDate.java | 48 ++++++
.../tajo/engine/function/builtin/MinTime.java | 48 ++++++
.../engine/function/builtin/MinTimestamp.java | 48 ++++++
.../engine/function/TestBuiltinFunctions.java | 146 +++++++++++++++++++
8 files changed, 434 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 26b24a9..242f359 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,9 @@ Release 0.11.0 - unreleased
IMPROVEMENT
+ TAJO-1428: Support min, max builtin functions for DATE, TIME, TIMESTAMP.
+ (Contributed by Dongjoon Hyun, Committed by Keuntae Park)
+
TAJO-1436: Add Bind method to EvalNode. (Contributed by navis,
Committed by jihoon)
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDate.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDate.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDate.java
new file mode 100644
index 0000000..90ecb76
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDate.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.engine.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+ functionName = "max",
+ description = "the maximum value of expr",
+ example = "> SELECT max(expr);",
+ returnType = Type.DATE,
+ paramTypes = {@ParamTypes(paramTypes = {Type.DATE})}
+)
+public class MaxDate extends Max {
+ public MaxDate() {
+ super(new Column[] {
+ new Column("expr", Type.DATE)
+ });
+ }
+
+ @Override
+ public DataType getPartialResultType() {
+ return CatalogUtil.newSimpleDataType(Type.DATE);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTime.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTime.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTime.java
new file mode 100644
index 0000000..e79d06a
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTime.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.engine.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+ functionName = "max",
+ description = "the maximum value of expr",
+ example = "> SELECT max(expr);",
+ returnType = Type.TIME,
+ paramTypes = {@ParamTypes(paramTypes = {Type.TIME})}
+)
+public class MaxTime extends Max {
+ public MaxTime() {
+ super(new Column[] {
+ new Column("expr", Type.TIME)
+ });
+ }
+
+ @Override
+ public DataType getPartialResultType() {
+ return CatalogUtil.newSimpleDataType(Type.TIME);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTimestamp.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTimestamp.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTimestamp.java
new file mode 100644
index 0000000..5a6a22e
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxTimestamp.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.engine.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+ functionName = "max",
+ description = "the maximum value of expr",
+ example = "> SELECT max(expr);",
+ returnType = Type.TIMESTAMP,
+ paramTypes = {@ParamTypes(paramTypes = {Type.TIMESTAMP})}
+)
+public class MaxTimestamp extends Max {
+ public MaxTimestamp() {
+ super(new Column[] {
+ new Column("expr", Type.TIMESTAMP)
+ });
+ }
+
+ @Override
+ public DataType getPartialResultType() {
+ return CatalogUtil.newSimpleDataType(Type.TIMESTAMP);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDate.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDate.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDate.java
new file mode 100644
index 0000000..aed204d
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDate.java
@@ -0,0 +1,48 @@
+/**
+ * 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.engine.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+ functionName = "min",
+ description = "the minimum value of expr",
+ example = "> SELECT min(expr);",
+ returnType = Type.DATE,
+ paramTypes = {@ParamTypes(paramTypes = {Type.DATE})}
+)
+public class MinDate extends Min {
+
+ public MinDate() {
+ super(new Column[] {
+ new Column("expr", Type.DATE)
+ });
+ }
+
+ @Override
+ public DataType getPartialResultType() {
+ return CatalogUtil.newSimpleDataType(Type.DATE);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTime.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTime.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTime.java
new file mode 100644
index 0000000..4082536
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTime.java
@@ -0,0 +1,48 @@
+/**
+ * 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.engine.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+ functionName = "min",
+ description = "the minimum value of expr",
+ example = "> SELECT min(expr);",
+ returnType = Type.TIME,
+ paramTypes = {@ParamTypes(paramTypes = {Type.TIME})}
+)
+public class MinTime extends Min {
+
+ public MinTime() {
+ super(new Column[] {
+ new Column("expr", Type.TIME)
+ });
+ }
+
+ @Override
+ public DataType getPartialResultType() {
+ return CatalogUtil.newSimpleDataType(Type.TIME);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTimestamp.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTimestamp.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTimestamp.java
new file mode 100644
index 0000000..2dc6752
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinTimestamp.java
@@ -0,0 +1,48 @@
+/**
+ * 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.engine.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+ functionName = "min",
+ description = "the minimum value of expr",
+ example = "> SELECT min(expr);",
+ returnType = Type.TIMESTAMP,
+ paramTypes = {@ParamTypes(paramTypes = {Type.TIMESTAMP})}
+)
+public class MinTimestamp extends Min {
+
+ public MinTimestamp() {
+ super(new Column[] {
+ new Column("expr", Type.TIMESTAMP)
+ });
+ }
+
+ @Override
+ public DataType getPartialResultType() {
+ return CatalogUtil.newSimpleDataType(Type.TIMESTAMP);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/0a3a6b95/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java
index bcc5dd6..d9d9b77 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java
@@ -74,6 +74,152 @@ public class TestBuiltinFunctions extends QueryTestCaseBase {
}
@Test
+ public void testMinMaxDate() throws Exception {
+ KeyValueSet tableOptions = new KeyValueSet();
+ tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+ tableOptions.set(StorageConstants.TEXT_NULL, "\\\\N");
+
+ Schema schema = new Schema();
+ schema.addColumn("value", TajoDataTypes.Type.DATE);
+ String[] data = new String[]{ "2014-01-02", "2014-12-01", "2015-01-01", "1999-08-09", "2000-03-01" };
+ TajoTestingCluster.createTable("table11", schema, tableOptions, data, 1);
+
+ try {
+ ResultSet res = executeString("select min(value) as min_value, max(value) as max_value from table11");
+ String ascExpected = "min_value,max_value\n" +
+ "-------------------------------\n" +
+ "1999-08-09,2015-01-01\n";
+
+ assertEquals(ascExpected, resultSetToString(res));
+ res.close();
+ } finally {
+ executeString("DROP TABLE table11 PURGE");
+ }
+ }
+
+ @Test
+ public void testMinMaxDateWithNull() throws Exception {
+ KeyValueSet tableOptions = new KeyValueSet();
+ tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+ tableOptions.set(StorageConstants.TEXT_NULL, "\\\\N");
+
+ Schema schema = new Schema();
+ schema.addColumn("value", TajoDataTypes.Type.DATE);
+ String[] data = new String[]{ "2014-01-02", "2014-12-01", "\\N", "\\N", "2000-03-01" };
+ TajoTestingCluster.createTable("table11", schema, tableOptions, data, 1);
+
+ try {
+ ResultSet res = executeString("select min(value) as min_value, max(value) as max_value from table11");
+ String ascExpected = "min_value,max_value\n" +
+ "-------------------------------\n" +
+ "2000-03-01,2014-12-01\n";
+
+ assertEquals(ascExpected, resultSetToString(res));
+ res.close();
+ } finally {
+ executeString("DROP TABLE table11 PURGE");
+ }
+ }
+
+ @Test
+ public void testMinMaxTime() throws Exception {
+ KeyValueSet tableOptions = new KeyValueSet();
+ tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+ tableOptions.set(StorageConstants.TEXT_NULL, "\\\\N");
+
+ Schema schema = new Schema();
+ schema.addColumn("value", TajoDataTypes.Type.TIME);
+ String[] data = new String[]{ "11:11:11", "23:12:50", "00:00:01", "09:59:59", "12:13:14" };
+ TajoTestingCluster.createTable("table11", schema, tableOptions, data, 1);
+
+ try {
+ ResultSet res = executeString("select min(value) as min_value, max(value) as max_value from table11");
+ String ascExpected = "min_value,max_value\n" +
+ "-------------------------------\n" +
+ "00:00:01,23:12:50\n";
+
+ assertEquals(ascExpected, resultSetToString(res));
+ res.close();
+ } finally {
+ executeString("DROP TABLE table11 PURGE");
+ }
+ }
+
+ @Test
+ public void testMinMaxTimeWithNull() throws Exception {
+ KeyValueSet tableOptions = new KeyValueSet();
+ tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+ tableOptions.set(StorageConstants.TEXT_NULL, "\\\\N");
+
+ Schema schema = new Schema();
+ schema.addColumn("value", TajoDataTypes.Type.TIME);
+ String[] data = new String[]{ "11:11:11", "\\N", "\\N", "09:59:59", "12:13:14" };
+ TajoTestingCluster.createTable("table11", schema, tableOptions, data, 1);
+
+ try {
+ ResultSet res = executeString("select min(value) as min_value, max(value) as max_value from table11");
+ String ascExpected = "min_value,max_value\n" +
+ "-------------------------------\n" +
+ "09:59:59,12:13:14\n";
+
+ assertEquals(ascExpected, resultSetToString(res));
+ res.close();
+ } finally {
+ executeString("DROP TABLE table11 PURGE");
+ }
+ }
+
+ @Test
+ public void testMinMaxTimestamp() throws Exception {
+ KeyValueSet tableOptions = new KeyValueSet();
+ tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+ tableOptions.set(StorageConstants.TEXT_NULL, "\\\\N");
+
+ Schema schema = new Schema();
+ schema.addColumn("value", TajoDataTypes.Type.TIMESTAMP);
+ String[] data = new String[]{ "1999-01-01 11:11:11", "2015-01-01 23:12:50", "2016-12-24 00:00:01",
+ "1977-05-04 09:59:59", "2002-11-21 12:13:14" };
+ TajoTestingCluster.createTable("table11", schema, tableOptions, data, 1);
+
+ try {
+ ResultSet res = executeString("select min(value) as min_value, max(value) as max_value from table11");
+ String ascExpected = "min_value,max_value\n" +
+ "-------------------------------\n" +
+ "1977-05-04 09:59:59,2016-12-24 00:00:01\n";
+
+ assertEquals(ascExpected, resultSetToString(res));
+ res.close();
+ } finally {
+ executeString("DROP TABLE table11 PURGE");
+ }
+ }
+
+ @Test
+ public void testMinMaxTimestampWithNull() throws Exception {
+ KeyValueSet tableOptions = new KeyValueSet();
+ tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+ tableOptions.set(StorageConstants.TEXT_NULL, "\\\\N");
+
+ Schema schema = new Schema();
+ schema.addColumn("value", TajoDataTypes.Type.TIMESTAMP);
+ String[] data = new String[]{ "1999-01-01 11:11:11", "2015-01-01 23:12:50", "\\N",
+ "\\N", "2002-11-21 12:13:14" };
+ TajoTestingCluster.createTable("table11", schema, tableOptions, data, 1);
+
+ try {
+ ResultSet res = executeString("select min(value) as min_value, max(value) as max_value from table11");
+ String ascExpected = "min_value,max_value\n" +
+ "-------------------------------\n" +
+ "1999-01-01 11:11:11,2015-01-01 23:12:50\n";
+
+ assertEquals(ascExpected, resultSetToString(res));
+ res.close();
+ } finally {
+ executeString("DROP TABLE table11 PURGE");
+ }
+ }
+
+ @Test
public void testMinLong() throws Exception {
ResultSet res = executeQuery();
assertResultSet(res);