You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by so...@apache.org on 2019/05/04 02:20:56 UTC
[drill] 02/03: DRILL-7050: RexNode convert exception in sub-query
closes #1770
This is an automated email from the ASF dual-hosted git repository.
sorabh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
commit 7e0e583c968aea62eb73c154f66c76136f2f9c12
Author: Volodymyr Vysotskyi <vv...@gmail.com>
AuthorDate: Mon Apr 22 14:49:53 2019 +0300
DRILL-7050: RexNode convert exception in sub-query
closes #1770
---
.../drill/exec/planner/sql/SqlConverter.java | 13 +++++++++++
.../java/org/apache/drill/TestCorrelation.java | 25 +++++++++++++++++++++-
.../java/org/apache/drill/exec/sql/TestCTTAS.java | 19 ++++++++++++++++
pom.xml | 2 +-
4 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
index 59ac5ab..135ee26 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
@@ -330,6 +330,19 @@ public class SqlConverter {
}
}
+ @Override
+ protected void inferUnknownTypes(
+ RelDataType inferredType,
+ SqlValidatorScope scope,
+ SqlNode node) {
+ // calls validateQuery() for SqlSelect to be sure that temporary table name will be changed
+ // for the case when it is used in sub-select
+ if (node.getKind() == SqlKind.SELECT) {
+ validateQuery(node, scope, inferredType);
+ }
+ super.inferUnknownTypes(inferredType, scope, node);
+ }
+
private void changeNamesIfTableIsTemporary(SqlIdentifier tempNode) {
List<String> temporaryTableNames = ((SqlConverter.DrillCalciteCatalogReader) getCatalogReader()).getTemporaryNames(tempNode.names);
if (temporaryTableNames != null) {
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestCorrelation.java b/exec/java-exec/src/test/java/org/apache/drill/TestCorrelation.java
index d40540e..fcdd32b 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestCorrelation.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestCorrelation.java
@@ -104,4 +104,27 @@ public class TestCorrelation extends PlanTestBase {
.expectsEmptyResultSet()
.go();
}
-}
\ No newline at end of file
+
+ @Test // DRILL-7050
+ public void testCorrelatedSubQueryInSelect() throws Exception {
+ String tableName = "dfs.tmp.source";
+ String query =
+ "select t1.id,\n" +
+ "(select count(t2.id)\n" +
+ "from %1$s t2 where t2.id = t1.id) as c\n" +
+ "from %1$s t1";
+ try {
+ test("create table %s as (select 1 as id union all select 2 as id)", tableName);
+
+ testBuilder()
+ .sqlQuery(query, tableName)
+ .unOrdered()
+ .baselineColumns("id", "c")
+ .baselineValues(1, 1L)
+ .baselineValues(2, 1L)
+ .go();
+ } finally {
+ test("drop table if exists %s", tableName);
+ }
+ }
+}
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java
index ab13a50..e616984 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java
@@ -507,6 +507,25 @@ public class TestCTTAS extends BaseTestQuery {
}
}
+ @Test // DRILL-7050
+ public void testTemporaryTableInSubQuery() throws Exception {
+ test("create temporary table source as (select 1 as id union all select 2 as id)");
+
+ String query =
+ "select t1.id as id,\n" +
+ "(select count(t2.id)\n" +
+ "from source t2 where t2.id = t1.id) as c\n" +
+ "from source t1";
+
+ testBuilder()
+ .sqlQuery(query)
+ .ordered()
+ .baselineColumns("id", "c")
+ .baselineValues(1, 1L)
+ .baselineValues(2, 1L)
+ .go();
+ }
+
private void expectUserRemoteExceptionWithMessage(String message) {
thrown.expect(UserRemoteException.class);
thrown.expectMessage(containsString(message));
diff --git a/pom.xml b/pom.xml
index 2080964..f2b626d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
<guava.version>19.0</guava.version>
<forkCount>2</forkCount>
<parquet.version>1.10.0</parquet.version>
- <calcite.version>1.18.0-drill-r0</calcite.version>
+ <calcite.version>1.18.0-drill-r1</calcite.version>
<avatica.version>1.13.0</avatica.version>
<janino.version>3.0.11</janino.version>
<sqlline.version>1.7.0</sqlline.version>