You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by jn...@apache.org on 2015/07/09 07:48:01 UTC
[3/3] drill git commit: DRILL-2053: Fix incorrect query result when
join CTE,
by making Project operator use case-insensitive matching for columns in input
data stream.
DRILL-2053: Fix incorrect query result when join CTE, by making Project operator use case-insensitive matching for columns in input data stream.
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/72f94696
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/72f94696
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/72f94696
Branch: refs/heads/master
Commit: 72f946964bb3a81253d2f9d484de45ff958724c9
Parents: f4bb535
Author: Jinfeng Ni <jn...@apache.org>
Authored: Tue Jul 7 15:09:45 2015 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Wed Jul 8 20:38:16 2015 -0700
----------------------------------------------------------------------
.../impl/project/ProjectRecordBatch.java | 10 +++++-----
.../java/org/apache/drill/TestStarQueries.java | 19 +++++++++++++++++++
2 files changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/72f94696/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
index 946d117..b6e5dc0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
@@ -597,7 +597,7 @@ public class ProjectRecordBatch extends AbstractSingleRecordBatch<Project> {
}
}
// input and output are the same
- else if (expr.getPath().equals(ref.getPath()) && (!exprContainsStar || exprIsFirstWildcard)) {
+ else if (expr.getPath().equalsIgnoreCase(ref.getPath()) && (!exprContainsStar || exprIsFirstWildcard)) {
if (exprContainsStar && exprHasPrefix) {
assert exprPrefix != null;
@@ -618,7 +618,7 @@ public class ProjectRecordBatch extends AbstractSingleRecordBatch<Project> {
continue;
}
final String namePrefix = nameComponents[0];
- if (exprPrefix.equals(namePrefix)) {
+ if (exprPrefix.equalsIgnoreCase(namePrefix)) {
final String newName = incomingName;
if (!result.outputMap.containsKey(newName)) {
result.outputNames.set(k, newName);
@@ -684,12 +684,12 @@ public class ProjectRecordBatch extends AbstractSingleRecordBatch<Project> {
}
final String namePrefix = components[0];
final String nameSuffix = components[1];
- if (exprPrefix.equals(namePrefix)) {
+ if (exprPrefix.equalsIgnoreCase(namePrefix)) { // // case insensitive matching of prefix.
if (refContainsStar) {
// remove the prefix from the incoming column names
final String newName = getUniqueName(nameSuffix, result); // for top level we need to make names unique
result.outputNames.set(k, newName);
- } else if (exprSuffix.equals(nameSuffix)) {
+ } else if (exprSuffix.equalsIgnoreCase(nameSuffix)) { // case insensitive matching of field name.
// example: ref: $f1, expr: T0<PREFIX><column_name>
final String newName = ref.getPath();
result.outputNames.set(k, newName);
@@ -714,7 +714,7 @@ public class ProjectRecordBatch extends AbstractSingleRecordBatch<Project> {
for (final VectorWrapper<?> wrapper : incoming) {
final ValueVector vvIn = wrapper.getValueVector();
final String incomingName = vvIn.getField().getPath().getRootSegment().getPath();
- if (expr.getPath().equals(incomingName)) {
+ if (expr.getPath().equalsIgnoreCase(incomingName)) { // case insensitive matching of field name.
final String newName = ref.getPath();
addToResultMaps(newName, result, true);
}
http://git-wip-us.apache.org/repos/asf/drill/blob/72f94696/exec/java-exec/src/test/java/org/apache/drill/TestStarQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestStarQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestStarQueries.java
index d9ec965..b9dcacd 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestStarQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestStarQueries.java
@@ -23,6 +23,8 @@ import org.apache.drill.common.util.FileUtils;
import org.apache.drill.common.util.TestTools;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class TestStarQueries extends BaseTestQuery{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestStarQueries.class);
static final String WORKING_PATH = TestTools.getWorkingPath();
@@ -476,4 +478,21 @@ public class TestStarQueries extends BaseTestQuery{
}
+ @Test // DRILL-2053 : column name is case-insensitive when join a CTE with a regluar table.
+ public void testCaseSenJoinCTEWithRegTab() throws Exception {
+ final String query1 = "with a as ( select * from cp.`tpch/nation.parquet` ) select * from a, cp.`tpch/region.parquet` b where a.N_REGIONKEY = b.R_REGIONKEY";
+
+ int actualRecordCount = testSql(query1);
+ int expectedRecordCount = 25;
+ assertEquals(String.format("Received unexpected number of rows in output for query:\n%s\n expected=%d, received=%s",
+ query1, expectedRecordCount, actualRecordCount), expectedRecordCount, actualRecordCount);
+
+ final String query2 = "with a as ( select * from cp.`tpch/nation.parquet` ) select * from a, cp.`tpch/region.parquet` b where a.n_regionkey = b.r_regionkey";
+
+ actualRecordCount = testSql(query2);
+ expectedRecordCount = 25;
+ assertEquals(String.format("Received unexpected number of rows in output for query:\n%s\n expected=%d, received=%s",
+ query2, expectedRecordCount, actualRecordCount), expectedRecordCount, actualRecordCount);
+ }
+
}