You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by mm...@apache.org on 2017/06/02 14:06:37 UTC
calcite git commit: CALCITE-1810 Allow NULL for ARRAY constructor
Repository: calcite
Updated Branches:
refs/heads/master 6cb4d45b0 -> 573ecb5fc
CALCITE-1810 Allow NULL for ARRAY constructor
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/573ecb5f
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/573ecb5f
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/573ecb5f
Branch: refs/heads/master
Commit: 573ecb5fce4846ccdf0c6c2c3af8b7ae965bfa43
Parents: 6cb4d45
Author: Ankit Singhal <an...@gmail.com>
Authored: Tue May 30 18:55:08 2017 +0530
Committer: Michael Mior <mm...@uwaterloo.ca>
Committed: Fri Jun 2 10:06:08 2017 -0400
----------------------------------------------------------------------
.../src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java | 4 ++++
.../java/org/apache/calcite/sql/validate/SqlValidatorImpl.java | 6 +++++-
.../test/java/org/apache/calcite/test/SqlValidatorTest.java | 4 ++++
3 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/573ecb5f/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
index 093a8e2..0cf85ac 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
@@ -1308,6 +1308,10 @@ public abstract class SqlTypeUtil {
}
return Integer.compare(p0, p1);
}
+
+ public static boolean isArray(RelDataType type) {
+ return type.getSqlTypeName() == SqlTypeName.ARRAY;
+ }
}
// End SqlTypeUtil.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/573ecb5f/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 46cd711..2931a3c 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -1762,7 +1762,11 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
operandTypes);
}
for (int i = 0; i < operands.size(); ++i) {
- inferUnknownTypes(operandTypes[i], scope, operands.get(i));
+ RelDataType type = operandTypes[i];
+ if (SqlTypeUtil.isArray(inferredType)) {
+ type = inferredType.getComponentType();
+ }
+ inferUnknownTypes(type, scope, operands.get(i));
}
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/573ecb5f/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 30481d6..1238293 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -7236,10 +7236,14 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
checkColumnType(
"select*from unnest(array['1','22','333','22'])",
"CHAR(3) NOT NULL");
+ checkColumnType(
+ "select*from unnest(array['1','22',null,'22'])",
+ "CHAR(2)");
checkFails(
"select*from ^unnest(1)^",
"(?s).*Cannot apply 'UNNEST' to arguments of type 'UNNEST.<INTEGER>.'.*");
check("select*from unnest(array(select*from dept))");
+ check("select*from unnest(array[1,null])");
check("select c from unnest(array(select deptno from dept)) as t(c)");
checkFails("select c from unnest(array(select * from dept)) as t(^c^)",
"List of column aliases must have same degree as table; table has 2 columns \\('DEPTNO', 'NAME'\\), whereas alias list has 1 columns");