Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRILL-4782 / DRILL-7139: Fix DATE_ADD and TO_TIME functions
- cast function for the day interval changed to round milliseconds to complete days - ToDateTypeFunctions#toTime now returning milliseconds of day - updated the way how DayInterval subtracts and adds, to follow the cast function logic UT core updates: - added vectorValue function to the queryBuilder to simplify retrieving value of the vector - refactored singleton query result functions at queryBuilder
- Loading branch information
1 parent
e8b921b
commit 2615d68
Showing
7 changed files
with
304 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
.../java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestIntervalDayFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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.expr.fn.impl; | ||
|
||
import org.apache.drill.exec.vector.IntervalDayVector; | ||
import org.apache.drill.test.ClusterFixture; | ||
import org.apache.drill.test.ClusterTest; | ||
import org.apache.drill.test.QueryBuilder; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class TestIntervalDayFunctions extends ClusterTest { | ||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
startCluster(ClusterFixture.builder(dirTestWatcher)); | ||
} | ||
|
||
@Test | ||
public void testIntervalDaySubtractFunction() throws Exception { | ||
QueryBuilder.VectorQueryReader<String,IntervalDayVector> vectorQueryReader = | ||
(recordsCount, vector) -> vector.getAccessor().getAsStringBuilder(0).toString(); | ||
|
||
String result = queryBuilder() | ||
.sql("select cast('P6D' as interval day) - cast('P5DT4M20S' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("0 days 23:55:40", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('P4D' as interval day) - cast('P4DT4M' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("0 days 0:-4:00", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('P4D' as interval day) - cast('PT4M' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("3 days 23:56:00", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('P4D' as interval day) - cast('P5D' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("-1 day 0:00:00", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('P4D' as interval day) - cast('P4DT23H59M59S' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("0 days -23:-59:-59", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('P4D' as interval day) - cast('P5DT23H59S' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("-1 day -23:00:-59", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('P2D' as interval day) - cast('P1DT4M' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("0 days 23:56:00", result); | ||
} | ||
|
||
@Test | ||
public void testIntervalDayPlusFunction() throws Exception { | ||
QueryBuilder.VectorQueryReader<String,IntervalDayVector> vectorQueryReader = | ||
(recordsCount, vector) -> vector.getAccessor().getAsStringBuilder(0).toString(); | ||
|
||
String result = queryBuilder() | ||
.sql("select cast('P1D' as interval day) + cast('P2DT1H' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("3 days 1:00:00", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('PT12H' as interval day) + cast('PT12H' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("1 day 0:00:00", result); | ||
|
||
result = queryBuilder() | ||
.sql("select cast('PT11H' as interval day) + cast('PT12H59M60S' as interval day) as i") | ||
.vectorValue("i", IntervalDayVector.class, vectorQueryReader); | ||
Assert.assertEquals("1 day 0:00:00", result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.