DRILL-914: Return milliseconds and second component in extract(second from date_time_types) functions.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/564febcf Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/564febcf Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/564febcf Branch: refs/heads/master Commit: 564febcf273b0c8b0950971b6126e6682d897f3e Parents: 443f990 Author: Mehant Baid <[email protected]> Authored: Fri Jun 6 18:53:54 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Tue Jun 10 18:59:39 2014 -0700 ---------------------------------------------------------------------- .../DateIntervalFunctionTemplates/Extract.java | 17 +++++--- .../physical/impl/TestExtractFunctions.java | 42 ++++++++++---------- .../test/resources/functions/extractFrom.json | 1 - .../drill/jdbc/test/TestFunctionsQuery.java | 14 +++++++ 4 files changed, 46 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/564febcf/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java index 3d3d2da..3f0dcee 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java @@ -40,7 +40,11 @@ public class ${className} { public static class ${toUnit}From${fromUnit} implements DrillSimpleFunc { @Param ${fromUnit}Holder in; + <#if toUnit == "Second"> + @Output Float8Holder out; + <#else> @Output BigIntHolder out; + </#if> @Workspace org.joda.time.MutableDateTime dateTime; public void setup(RecordBatch incoming) { @@ -56,6 +60,7 @@ public class ${className} { <#if toUnit == "Second"> out.value = dateTime.getSecondOfMinute(); + out.value += ((double) dateTime.getMillisOfSecond()) / 1000; <#elseif toUnit = "Minute"> out.value = dateTime.getMinuteOfHour(); <#elseif toUnit = "Hour"> @@ -76,7 +81,11 @@ public class ${className} { public static class ${toUnit}From${fromUnit} implements DrillSimpleFunc { @Param ${fromUnit}Holder in; + <#if toUnit == "Second"> + @Output Float8Holder out; + <#else> @Output BigIntHolder out; + </#if> public void setup(RecordBatch incoming) { } @@ -94,9 +103,7 @@ public class ${className} { int millis = in.milliSeconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); out.value = millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis); <#elseif toUnit == "Second"> - int millis = in.milliSeconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); - millis = millis % (org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis); - out.value = millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.secondsToMillis); + out.value = (double) in.milliSeconds / (org.apache.drill.exec.expr.fn.impl.DateUtility.secondsToMillis); </#if> <#elseif fromUnit == "IntervalDay"> <#if toUnit == "Year" || toUnit == "Month"> @@ -109,9 +116,7 @@ public class ${className} { int millis = in.milliSeconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); out.value = millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis); <#elseif toUnit == "Second"> - int millis = in.milliSeconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); - millis = millis % (org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis); - out.value = millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.secondsToMillis); + out.value = (double) in.milliSeconds/ (org.apache.drill.exec.expr.fn.impl.DateUtility.secondsToMillis); </#if> <#else> <#-- IntervalYear type --> <#if toUnit == "Year"> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/564febcf/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestExtractFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestExtractFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestExtractFunctions.java index 7a983ad..ab00498 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestExtractFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestExtractFunctions.java @@ -47,32 +47,32 @@ public class TestExtractFunctions extends PopUnitTestBase { @Test public void testFromDate() throws Exception { - long expectedValues[][] = { {00, 00, 00, 02, 01, 1970}, {00, 00, 00, 28, 12, 2008}, {00, 00, 00, 27, 02, 2000} }; + long expectedValues[][] = { {00, 00, 02, 01, 1970}, {00, 00, 28, 12, 2008}, {00, 00, 27, 02, 2000} }; testFrom("date", "/test_simple_date.json", "stringdate", expectedValues); } @Test @Ignore // failing due to some issue in castTime(varchar) public void testFromTime() throws Exception { - long expectedValues[][] = { {33, 20, 10, 00, 00, 0000}, {00, 34, 11, 00, 00, 0000}, {00, 24, 14, 00, 00, 0000} }; + long expectedValues[][] = { {20, 10, 00, 00, 0000}, {34, 11, 00, 00, 0000}, {24, 14, 00, 00, 0000} }; testFrom("time", "/test_simple_time.json", "stringtime", expectedValues); } @Test public void testFromTimeStamp() throws Exception { - long expectedValues[][] = { {33, 20, 10, 02, 01, 1970}, {00, 34, 11, 28, 12, 2008}, {00, 24, 14, 27, 02, 2000} }; + long expectedValues[][] = { {20, 10, 02, 01, 1970}, {34, 11, 28, 12, 2008}, {24, 14, 27, 02, 2000} }; testFrom("timestamp", "/test_simple_date.json", "stringdate", expectedValues); } @Test public void testFromInterval() throws Exception { long expectedValues[][] = { - { 35, 20, 01, 01, 02, 02}, - { 00, 00, 00, 00, 02, 02}, - { 35, 20, 01, 00, 00, 00}, - { 35, 20, 01, 01, 02, 02}, - { 35, 00, 00, 00, 00, 00}, - {-25,-39, 00, 01, 10, 01} + { 20, 01, 01, 02, 02}, + { 00, 00, 00, 02, 02}, + { 20, 01, 00, 00, 00}, + { 20, 01, 01, 02, 02}, + { 00, 00, 00, 00, 00}, + { -39, 00, 01, 10, 01} }; testFrom("interval", "/test_simple_interval.json", "stringinterval", expectedValues); } @@ -80,12 +80,12 @@ public class TestExtractFunctions extends PopUnitTestBase { @Test public void testFromIntervalDay() throws Exception { long expectedValues[][] = { - { 35, 20, 01, 01, 00, 00}, - { 00, 00, 00, 00, 00, 00}, - { 35, 20, 01, 00, 00, 00}, - { 35, 20, 01, 01, 00, 00}, - { 35, 00, 00, 00, 00, 00}, - {-25,-39, 00, 01, 00, 00} + {20, 01, 01, 00, 00}, + {00, 00, 00, 00, 00}, + {20, 01, 00, 00, 00}, + {20, 01, 01, 00, 00}, + {00, 00, 00, 00, 00}, + {-39, 00, 01, 00, 00} }; testFrom("intervalday", "/test_simple_interval.json", "stringinterval", expectedValues); } @@ -93,12 +93,12 @@ public class TestExtractFunctions extends PopUnitTestBase { @Test public void testFromIntervalYear() throws Exception { long expectedValues[][] = { - { 00, 00, 00, 00, 02, 02}, - { 00, 00, 00, 00, 02, 02}, - { 00, 00, 00, 00, 00, 00}, - { 00, 00, 00, 00, 02, 02}, - { 00, 00, 00, 00, 00, 00}, - { 00, 00, 00, 00, 10, 01} + {00, 00, 00, 02, 02}, + {00, 00, 00, 02, 02}, + {00, 00, 00, 00, 00}, + {00, 00, 00, 02, 02}, + {00, 00, 00, 00, 00}, + {00, 00, 00, 10, 01} }; testFrom("intervalyear", "/test_simple_interval.json", "stringinterval", expectedValues); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/564febcf/exec/java-exec/src/test/resources/functions/extractFrom.json ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/resources/functions/extractFrom.json b/exec/java-exec/src/test/resources/functions/extractFrom.json index 779581e..4e58a3c 100644 --- a/exec/java-exec/src/test/resources/functions/extractFrom.json +++ b/exec/java-exec/src/test/resources/functions/extractFrom.json @@ -29,7 +29,6 @@ @id:3, child: 2, exprs: [ - { ref: "extractSecond", expr: "extractSecond(castExp)" }, { ref: "extractMinute", expr: "extractMinute(castExp)" }, { ref: "extractHour", expr: "extractHour(castExp)" }, { ref: "extractDay", expr: "extractDay(castExp)" }, http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/564febcf/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java index 082aca4..89224d4 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java @@ -498,4 +498,18 @@ public class TestFunctionsQuery { "LPAD_TRUNC=Sh; " + "RPAD_TRUNC=Sh\n"); } + + @Test + public void testExtractSecond() throws Exception { + String query = "select extract(second from date '2008-2-23') as DATE_EXT, extract(second from timestamp '2008-2-23 10:00:20.123') as TS_EXT, " + + "extract(second from time '10:20:30.303') as TM_EXT " + + "from cp.`employee.json` where employee_id = 1"; + + JdbcAssert.withNoDefaultSchema() + .sql(query) + .returns( + "DATE_EXT=0.0; " + + "TS_EXT=20.123; " + + "TM_EXT=30.303\n"); + } }
