You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by am...@apache.org on 2018/10/15 19:25:50 UTC
[drill] 03/04: DRILL-6783: CAST string literal as INTERVAL
MONTH/YEAR works inconsistently when selecting from a table with multiple
rows
This is an automated email from the ASF dual-hosted git repository.
amansinha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
commit 2aede3a1cd1532fbcd0a622b49a3b9fce69979ef
Author: Bohdan Kazydub <bo...@gmail.com>
AuthorDate: Mon Oct 8 16:50:22 2018 +0300
DRILL-6783: CAST string literal as INTERVAL MONTH/YEAR works inconsistently when selecting from a table with multiple rows
close apache/drill#1496
---
.../drill/exec/fn/impl/TestCastFunctions.java | 38 +++++++++++++++++++++-
.../main/codegen/templates/FixedValueVectors.java | 3 +-
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
index cb0d022..7768909 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
@@ -19,14 +19,21 @@ package org.apache.drill.exec.fn.impl;
import java.math.BigDecimal;
import java.time.LocalDate;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.drill.categories.SqlFunctionTest;
import org.apache.drill.categories.UnlikelyTest;
import org.apache.drill.common.exceptions.UserRemoteException;
+import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.exec.planner.physical.PlannerSettings;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.vector.IntervalYearVector;
import org.apache.drill.test.BaseTestQuery;
+import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -39,6 +46,7 @@ import org.apache.drill.shaded.guava.com.google.common.collect.Maps;
import mockit.integration.junit4.JMockit;
import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.hasItem;
@RunWith(JMockit.class)
@Category({UnlikelyTest.class, SqlFunctionTest.class})
@@ -664,4 +672,32 @@ public class TestCastFunctions extends BaseTestQuery {
test(query);
}
-}
\ No newline at end of file
+
+ @Test // DRILL-6783
+ public void testCastVarCharIntervalYear() throws Exception {
+ String query = "select cast('P31M' as interval month) as i from cp.`employee.json` limit 10";
+ List<QueryDataBatch> result = testSqlWithResults(query);
+ RecordBatchLoader loader = new RecordBatchLoader(getDrillbitContext().getAllocator());
+
+ QueryDataBatch b = result.get(0);
+ loader.load(b.getHeader().getDef(), b.getData());
+
+ IntervalYearVector vector = (IntervalYearVector) loader.getValueAccessorById(
+ IntervalYearVector.class,
+ loader.getValueVectorId(SchemaPath.getCompoundPath("i")).getFieldIds())
+ .getValueVector();
+
+ Set<String> resultSet = new HashSet<>();
+ for (int i = 0; i < loader.getRecordCount(); i++) {
+ String displayValue = vector.getAccessor().getAsStringBuilder(i).toString();
+ resultSet.add(displayValue);
+ }
+
+ Assert.assertEquals(
+ "Casting literal string as INTERVAL should yield the same result for each row", 1, resultSet.size());
+ Assert.assertThat(resultSet, hasItem("2 years 7 months"));
+
+ b.release();
+ loader.clear();
+ }
+}
diff --git a/exec/vector/src/main/codegen/templates/FixedValueVectors.java b/exec/vector/src/main/codegen/templates/FixedValueVectors.java
index a98aa66..508e484 100644
--- a/exec/vector/src/main/codegen/templates/FixedValueVectors.java
+++ b/exec/vector/src/main/codegen/templates/FixedValueVectors.java
@@ -532,7 +532,8 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F
}
public StringBuilder getAsStringBuilder(int index) {
- return DateUtilities.intervalYearStringBuilder(data.getInt(index));
+ int value = get(index);
+ return DateUtilities.intervalYearStringBuilder(value);
}
<#elseif minor.class == "Time">