You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2014/06/12 18:34:54 UTC
[03/24] git commit: DRILL-944: Fix overflow while adding Time +
Interval data type
DRILL-944: Fix overflow while adding Time + Interval data type
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/72084e32
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/72084e32
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/72084e32
Branch: refs/heads/master
Commit: 72084e32c08d3136de4d6940c0965c0c8ed6b04a
Parents: 564f969
Author: Mehant Baid <me...@gmail.com>
Authored: Tue Jun 10 17:40:42 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Wed Jun 11 09:03:24 2014 -0700
----------------------------------------------------------------------
.../DateIntervalArithmeticFunctions.java | 23 +++++++-------------
.../apache/drill/jdbc/test/TestJdbcQuery.java | 14 ++++++++++--
2 files changed, 20 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/72084e32/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java
index 4fbfdf9..634e41a 100644
--- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java
@@ -176,24 +176,17 @@ import org.apache.drill.exec.expr.fn.impl.DateUtility;
public class ${datetype}${intervaltype}Functions {
<#macro timeIntervalArithmeticBlock left right temp op output intervaltype>
- <#if intervaltype == "Interval">
- if (${right}.months != 0 || ${right}.days != 0) {
- throw new UnsupportedOperationException("Cannot add interval type with months or days to TIME");
- }
- ${output} = ${left}.value ${op} ${right}.milliSeconds;
- <#elseif intervaltype == "IntervalYear">
- if (1 == 1) {
- throw new UnsupportedOperationException("Cannot add IntervalYear to TIME");
- }
- <#elseif intervaltype == "IntervalDay">
- if (${right}.days != 0) {
- throw new UnsupportedOperationException("Cannot add days to TIME");
- }
- ${output} = ${left}.value ${op} ${right}.milliSeconds;
- <#elseif intervaltype == "Int" || intervaltype == "BigInt">
+ <#if intervaltype == "Int" || intervaltype == "BigInt">
if (1 == 1) {
throw new UnsupportedOperationException("Cannot add integer to TIME, cast it to specific interval");
}
+ <#elseif intervaltype == "IntervalYear">
+ // Needn't add anything to time from interval year data type. Output is same as input
+ ${output} = ${left}.value;
+ <#else>
+ ${output} = ${left}.value ${op} ${right}.milliSeconds;
+ // Wrap around 24 hour clock if we exceeded it while adding the time component
+ ${output} = ${output} % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis;
</#if>
</#macro>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/72084e32/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
index 0412f00..2a69469 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
@@ -409,8 +409,8 @@ public class TestJdbcQuery extends JdbcTest{
"from cp.`employee.json` limit 1")
.returns(
"LEFT_STR=ab; " +
- "RIGHT_STR=ef; " +
- "REPLACE_STR=zzcdef\n"
+ "RIGHT_STR=ef; " +
+ "REPLACE_STR=zzcdef\n"
);
}
@@ -421,6 +421,16 @@ public class TestJdbcQuery extends JdbcTest{
"from cp.`employee.json` where employee_id = 1")
.returns(
"L_UTF8=5\n"
+ );
+ }
+
+ @Test
+ public void testTimeIntervalAddOverflow() throws Exception {
+ JdbcAssert.withNoDefaultSchema()
+ .sql("select extract(hour from (interval '10 20' day to hour + time '10:00:00')) as TIME_INT_ADD " +
+ "from cp.`employee.json` where employee_id = 1")
+ .returns(
+ "TIME_INT_ADD=6\n"
);
}
}