Repository: drill
Updated Branches:
  refs/heads/master f5b975adf -> 35a1ec667


DRILL-4722: Fix EqualityVisitor for interval day expressions with millis

closes #861


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/0b830ef5
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/0b830ef5
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/0b830ef5

Branch: refs/heads/master
Commit: 0b830ef5370ad865c13da64121cd8a0e366dfd7b
Parents: f5b975a
Author: Volodymyr Vysotskyi <[email protected]>
Authored: Mon Jun 26 18:12:34 2017 +0000
Committer: Paul Rogers <[email protected]>
Committed: Mon Jul 3 18:00:20 2017 -0700

----------------------------------------------------------------------
 .../apache/drill/exec/expr/EqualityVisitor.java |  6 +-
 .../exec/fn/impl/TestDateAddFunctions.java      | 79 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/0b830ef5/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java
index 5f79f32..44ff78c 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -44,7 +44,6 @@ import 
org.apache.drill.common.expression.ValueExpressions.QuotedString;
 import org.apache.drill.common.expression.ValueExpressions.TimeExpression;
 import org.apache.drill.common.expression.ValueExpressions.TimeStampExpression;
 import org.apache.drill.common.expression.visitors.AbstractExprVisitor;
-import org.apache.drill.exec.compile.sig.GeneratorMapping;
 
 import java.util.List;
 
@@ -169,7 +168,8 @@ class EqualityVisitor extends 
AbstractExprVisitor<Boolean,LogicalExpression,Runt
     if (!(value instanceof IntervalDayExpression)) {
       return false;
     }
-    return intExpr.getIntervalDay() == ((IntervalDayExpression) 
value).getIntervalDay();
+    return intExpr.getIntervalDay() == ((IntervalDayExpression) 
value).getIntervalDay()
+            && intExpr.getIntervalMillis() == ((IntervalDayExpression) 
value).getIntervalMillis();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/0b830ef5/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestDateAddFunctions.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestDateAddFunctions.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestDateAddFunctions.java
new file mode 100644
index 0000000..7a5a49a
--- /dev/null
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestDateAddFunctions.java
@@ -0,0 +1,79 @@
+/*
+* 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.drill.exec.fn.impl;
+
+import org.apache.drill.BaseTestQuery;
+import org.joda.time.DateTime;
+import org.junit.Test;
+
+public class TestDateAddFunctions extends BaseTestQuery {
+
+  @Test
+  public void testDateAddIntervalDay() throws Exception {
+    String query = "select date_add(timestamp '2015-01-24 07:27:05.0', 
interval '3' day) as col1,\n" +
+                          "date_add(timestamp '2015-01-24 07:27:05.0', 
interval '5' day) as col2,\n" +
+                          "date_add(timestamp '2015-01-24 07:27:05.0', 
interval '5' hour) as col3,\n" +
+                          "date_add(timestamp '2015-01-24 07:27:05.0', 
interval '5' minute) as col4,\n" +
+                          "date_add(timestamp '2015-01-24 07:27:05.0', 
interval '5' second) as col5,\n" +
+                          "date_add(timestamp '2015-01-24 07:27:05.0', 
interval '5 10:20:30' day to second) as col6\n" +
+                   "from (values(1))";
+
+    testBuilder()
+      .sqlQuery(query)
+      .unOrdered()
+      .baselineColumns("col1", "col2", "col3", "col4", "col5", "col6")
+      .baselineValues(DateTime.parse("2015-01-27T07:27:05.0"),
+                      DateTime.parse("2015-01-29T07:27:05.0"),
+                      DateTime.parse("2015-01-24T12:27:05.0"),
+                      DateTime.parse("2015-01-24T07:32:05.0"),
+                      DateTime.parse("2015-01-24T07:27:10.0"),
+                      DateTime.parse("2015-01-29T17:47:35.0"))
+      .go();
+  }
+
+  @Test
+  public void testDateAddIntervalYear() throws Exception {
+    String query = "select date_add(date '2015-01-24', interval '3' month) as 
col1,\n" +
+                          "date_add(date '2015-01-24', interval '5' month) as 
col2,\n" +
+                          "date_add(date '2015-01-24', interval '5' year) as 
col3\n" +
+                   "from (values(1))";
+
+    testBuilder()
+      .sqlQuery(query)
+      .unOrdered()
+      .baselineColumns("col1", "col2", "col3")
+      .baselineValues(DateTime.parse("2015-04-24"),
+                      DateTime.parse("2015-06-24"),
+                      DateTime.parse("2020-01-24"))
+      .go();
+  }
+
+  @Test
+  public void testDateAddIntegerAsDay() throws Exception {
+    String query = "select date_add(date '2015-01-24', 3) as col1,\n" +
+                          "date_add(date '2015-01-24', 5) as col2\n" +
+                   "from (values(1))";
+
+    testBuilder()
+      .sqlQuery(query)
+      .unOrdered()
+      .baselineColumns("col1", "col2")
+      .baselineValues(DateTime.parse("2015-01-27"),
+                      DateTime.parse("2015-01-29"))
+      .go();
+  }
+}

Reply via email to