You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2017/06/06 03:00:36 UTC
[1/5] calcite git commit: [CALCITE-1804] Cannot assign NOT NULL array
to NULLABLE array (Ankit Singhal)
Repository: calcite
Updated Branches:
refs/heads/master 32747d794 -> 419b810fe
[CALCITE-1804] Cannot assign NOT NULL array to NULLABLE array (Ankit Singhal)
Close apache/calcite#456
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/f164fb8e
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/f164fb8e
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/f164fb8e
Branch: refs/heads/master
Commit: f164fb8eaa9dbcbb44b0a3e1cd3427d457ebffb8
Parents: 32747d7
Author: Ankit Singhal <an...@gmail.com>
Authored: Fri Jun 2 17:31:05 2017 +0530
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jun 5 15:52:52 2017 -0700
----------------------------------------------------------------------
.../calcite/jdbc/JavaTypeFactoryImpl.java | 3 ---
.../sql/type/JavaToSqlTypeConversionRules.java | 3 +++
.../sql/type/SqlTypeAssignmentRules.java | 3 +++
.../apache/calcite/sql/type/SqlTypeUtil.java | 7 +++++++
.../apache/calcite/test/SqlValidatorTest.java | 22 ++++++++++++++++++++
5 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/f164fb8e/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java b/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java
index c600d6f..180d445 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java
@@ -44,7 +44,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.math.BigDecimal;
-import java.sql.Array;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
@@ -210,8 +209,6 @@ public class JavaTypeFactoryImpl
case BINARY:
case VARBINARY:
return ByteString.class;
- case ARRAY:
- return Array.class;
case ANY:
return Object.class;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/f164fb8e/core/src/main/java/org/apache/calcite/sql/type/JavaToSqlTypeConversionRules.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/JavaToSqlTypeConversionRules.java b/core/src/main/java/org/apache/calcite/sql/type/JavaToSqlTypeConversionRules.java
index dd5097d..7f06bb6 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/JavaToSqlTypeConversionRules.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/JavaToSqlTypeConversionRules.java
@@ -16,6 +16,8 @@
*/
package org.apache.calcite.sql.type;
+import org.apache.calcite.avatica.util.ArrayImpl;
+
import com.google.common.collect.ImmutableMap;
import java.math.BigDecimal;
@@ -70,6 +72,7 @@ public class JavaToSqlTypeConversionRules {
.put(ResultSet.class, SqlTypeName.CURSOR)
.put(ColumnList.class, SqlTypeName.COLUMN_LIST)
+ .put(ArrayImpl.class, SqlTypeName.ARRAY)
.build();
//~ Methods ----------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/f164fb8e/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
index 27db0a9..9753f46 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
@@ -161,6 +161,9 @@ public class SqlTypeAssignmentRules {
// Timestamp is assignable from ...
rules.put(SqlTypeName.TIMESTAMP, EnumSet.of(SqlTypeName.TIMESTAMP));
+ // Array is assignable from ...
+ rules.put(SqlTypeName.ARRAY, EnumSet.of(SqlTypeName.ARRAY));
+
// Any is assignable from ...
rule = new HashSet<>();
rule.add(SqlTypeName.TINYINT);
http://git-wip-us.apache.org/repos/asf/calcite/blob/f164fb8e/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 0cf85ac..5b4c070 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
@@ -715,6 +715,13 @@ public abstract class SqlTypeUtil {
return true;
}
+ if (fromType.getSqlTypeName() == SqlTypeName.ARRAY) {
+ if (toType.getSqlTypeName() != SqlTypeName.ARRAY) {
+ return false;
+ }
+ return canAssignFrom(toType.getComponentType(), fromType.getComponentType());
+ }
+
if (areCharacterSetsMismatched(toType, fromType)) {
return false;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/f164fb8e/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 1238293..728dc26 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -20,6 +20,7 @@ import org.apache.calcite.avatica.util.Casing;
import org.apache.calcite.avatica.util.Quoting;
import org.apache.calcite.avatica.util.TimeUnit;
import org.apache.calcite.config.Lex;
+import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeSystem;
import org.apache.calcite.sql.SqlCollation;
import org.apache.calcite.sql.SqlOperator;
@@ -27,7 +28,10 @@ import org.apache.calcite.sql.SqlSpecialOperator;
import org.apache.calcite.sql.fun.OracleSqlOperatorTable;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.test.SqlTester;
+import org.apache.calcite.sql.type.ArraySqlType;
+import org.apache.calcite.sql.type.SqlTypeFactoryImpl;
import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.type.SqlTypeUtil;
import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
import org.apache.calcite.sql.validate.SqlAbstractConformance;
import org.apache.calcite.sql.validate.SqlConformance;
@@ -9927,6 +9931,24 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
"Duplicate name 'EXTRA' in column list");
}
+ @Test public void testArrayAssignment() {
+ SqlTypeFactoryImpl typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+ RelDataType sqlBigIntNullable = typeFactory
+ .createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true);
+ RelDataType sqlBigIntNotNull = typeFactory
+ .createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), false);
+ RelDataType sqlDateNotNull = typeFactory
+ .createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE), false);
+ assertThat(SqlTypeUtil.canAssignFrom(sqlBigIntNullable, sqlBigIntNotNull), is(true));
+ assertThat(SqlTypeUtil.canAssignFrom(sqlBigIntNullable, sqlDateNotNull), is(false));
+ RelDataType bigIntArrayNullable = typeFactory
+ .createTypeWithNullability(typeFactory.createArrayType(sqlBigIntNullable, -1), true);
+ RelDataType bigIntArrayNotnull = new ArraySqlType(sqlBigIntNotNull, false);
+ assertThat(SqlTypeUtil.canAssignFrom(bigIntArrayNullable, bigIntArrayNotnull), is(true));
+ RelDataType dateArrayNotnull = new ArraySqlType(sqlDateNotNull, false);
+ assertThat(SqlTypeUtil.canAssignFrom(bigIntArrayNullable, dateArrayNotnull), is(false));
+ }
+
}
// End SqlValidatorTest.java
[2/5] calcite git commit: [CALCITE-1830] ProcessBuilder is security
sensitive; move it to test suite to prevent accidents
Posted by jh...@apache.org.
[CALCITE-1830] ProcessBuilder is security sensitive; move it to test suite to prevent accidents
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/d393cab2
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/d393cab2
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/d393cab2
Branch: refs/heads/master
Commit: d393cab26e72f3c0de5eebcbeac5d94fff87a997
Parents: 4069013
Author: Julian Hyde <jh...@apache.org>
Authored: Mon Jun 5 11:38:12 2017 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jun 5 15:53:34 2017 -0700
----------------------------------------------------------------------
.../main/java/org/apache/calcite/util/Util.java | 117 -------------------
.../concurrent/ConcurrentTestCommandScript.java | 78 ++++++++++++-
pom.xml | 2 +
src/main/config/forbidden-apis/signatures.txt | 9 ++
4 files changed, 86 insertions(+), 120 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/d393cab2/core/src/main/java/org/apache/calcite/util/Util.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Util.java b/core/src/main/java/org/apache/calcite/util/Util.java
index e0746e2..3430f01 100644
--- a/core/src/main/java/org/apache/calcite/util/Util.java
+++ b/core/src/main/java/org/apache/calcite/util/Util.java
@@ -41,8 +41,6 @@ import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -1536,121 +1534,6 @@ public class Util {
}
/**
- * Runs an external application.
- *
- * @param cmdarray command and arguments, see {@link ProcessBuilder}
- * @param logger if not null, command and exit status will be logged
- * @param appInput if not null, data will be copied to application's stdin
- * @param appOutput if not null, data will be captured from application's
- * stdout and stderr
- * @return application process exit value
- * @throws IOException
- * @throws InterruptedException
- */
- @Deprecated // to be removed before 2.0
- public static int runApplication(
- String[] cmdarray,
- Logger logger,
- Reader appInput,
- Writer appOutput) throws IOException, InterruptedException {
- return runAppProcess(
- newAppProcess(cmdarray),
- logger,
- appInput,
- appOutput);
- }
-
- /**
- * Constructs a {@link ProcessBuilder} to run an external application.
- *
- * @param cmdarray command and arguments.
- * @return a ProcessBuilder.
- */
- @Deprecated // to be removed before 2.0
- public static ProcessBuilder newAppProcess(String[] cmdarray) {
- // Concatenate quoted words from cmdarray.
- // REVIEW mb 2/24/09 Why is this needed?
- StringBuilder buf = new StringBuilder();
- for (int i = 0; i < cmdarray.length; ++i) {
- if (i > 0) {
- buf.append(" ");
- }
- buf.append('"');
- buf.append(cmdarray[i]);
- buf.append('"');
- }
- String fullcmd = buf.toString();
- buf.setLength(0);
- return new ProcessBuilder(cmdarray);
- }
-
-
- /**
- * Runs an external application process.
- *
- * @param pb ProcessBuilder for the application; might be
- * returned by {@link #newAppProcess}.
- * @param logger if not null, command and exit status will be logged here
- * @param appInput if not null, data will be copied to application's stdin
- * @param appOutput if not null, data will be captured from application's
- * stdout and stderr
- * @return application process exit value
- * @throws IOException
- * @throws InterruptedException
- */
- public static int runAppProcess(
- ProcessBuilder pb,
- Logger logger,
- Reader appInput,
- Writer appOutput) throws IOException, InterruptedException {
- pb.redirectErrorStream(true);
- if (logger != null) {
- logger.info("start process: " + pb.command());
- }
- Process p = pb.start();
-
- // Setup the input/output streams to the subprocess.
- // The buffering here is arbitrary. Javadocs strongly encourage
- // buffering, but the size needed is very dependent on the
- // specific application being run, the size of the input
- // provided by the caller, and the amount of output expected.
- // Since this method is currently used only by unit tests,
- // large-ish fixed buffer sizes have been chosen. If this
- // method becomes used for something in production, it might
- // be better to have the caller provide them as arguments.
- if (appInput != null) {
- OutputStream out =
- new BufferedOutputStream(
- p.getOutputStream(),
- 100 * 1024);
- int c;
- while ((c = appInput.read()) != -1) {
- out.write(c);
- }
- out.flush();
- }
- if (appOutput != null) {
- InputStream in =
- new BufferedInputStream(
- p.getInputStream(),
- 100 * 1024);
- int c;
- while ((c = in.read()) != -1) {
- appOutput.write(c);
- }
- appOutput.flush();
- in.close();
- }
- p.waitFor();
-
- int status = p.exitValue();
- if (logger != null) {
- logger.info("exit status=" + status + " from " + pb.command());
- }
- return status;
- }
-
- /**
* Converts a list whose members are automatically down-cast to a given
* type.
*
http://git-wip-us.apache.org/repos/asf/calcite/blob/d393cab2/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java b/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
index ab3f7b1..67b790a 100644
--- a/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
+++ b/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
@@ -20,13 +20,21 @@ import org.apache.calcite.jdbc.SqlTimeoutException;
import org.apache.calcite.util.Unsafe;
import org.apache.calcite.util.Util;
+import org.slf4j.Logger;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
+import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
+import java.io.Writer;
import java.lang.reflect.Constructor;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -275,6 +283,68 @@ public class ConcurrentTestCommandScript
}
/**
+ * Runs an external application process.
+ *
+ * @param pb ProcessBuilder for the application
+ * @param logger if not null, command and exit status will be logged here
+ * @param appInput if not null, data will be copied to application's stdin
+ * @param appOutput if not null, data will be captured from application's
+ * stdout and stderr
+ * @return application process exit value
+ */
+ static int runAppProcess(
+ ProcessBuilder pb,
+ Logger logger,
+ Reader appInput,
+ Writer appOutput) throws IOException, InterruptedException {
+ pb.redirectErrorStream(true);
+ if (logger != null) {
+ logger.info("start process: " + pb.command());
+ }
+ Process p = pb.start();
+
+ // Setup the input/output streams to the subprocess.
+ // The buffering here is arbitrary. Javadocs strongly encourage
+ // buffering, but the size needed is very dependent on the
+ // specific application being run, the size of the input
+ // provided by the caller, and the amount of output expected.
+ // Since this method is currently used only by unit tests,
+ // large-ish fixed buffer sizes have been chosen. If this
+ // method becomes used for something in production, it might
+ // be better to have the caller provide them as arguments.
+ if (appInput != null) {
+ OutputStream out =
+ new BufferedOutputStream(
+ p.getOutputStream(),
+ 100 * 1024);
+ int c;
+ while ((c = appInput.read()) != -1) {
+ out.write(c);
+ }
+ out.flush();
+ }
+ if (appOutput != null) {
+ InputStream in =
+ new BufferedInputStream(
+ p.getInputStream(),
+ 100 * 1024);
+ int c;
+ while ((c = in.read()) != -1) {
+ appOutput.write(c);
+ }
+ appOutput.flush();
+ in.close();
+ }
+ p.waitFor();
+
+ int status = p.exitValue();
+ if (logger != null) {
+ logger.info("exit status=" + status + " from " + pb.command());
+ }
+ return status;
+ }
+
+ /**
* Gets ready to execute: loads script FILENAME applying external variable
* BINDINGS
*/
@@ -1497,13 +1567,15 @@ public class ConcurrentTestCommandScript
// argv[0] is found on $PATH. Working directory is the script's home
// directory.
+ //
+ // WARNING: ProcessBuilder is security-sensitive. Its use is currently
+ // safe because this code is under "core/test". Developers must not move
+ // this code into "core/main".
ProcessBuilder pb = new ProcessBuilder(argv);
pb.directory(scriptDirectory);
try {
// direct stdout & stderr to the the threadWriter
- int status =
- Util.runAppProcess(
- pb, null, null, getThreadWriter(threadId));
+ int status = runAppProcess(pb, null, null, getThreadWriter(threadId));
if (status != 0) {
storeMessage(threadId,
"command " + command + ": exited with status " + status);
http://git-wip-us.apache.org/repos/asf/calcite/blob/d393cab2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d2e9a3a..7fc3e9e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -491,6 +491,8 @@ limitations under the License.
<exclude>**/*TokenManager.class</exclude>
<exclude>**/TokenMgrError.class</exclude>
<exclude>**/org/apache/calcite/runtime/Resources$Inst.class</exclude>
+ <exclude>**/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.class</exclude>
+ <exclude>**/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript$ShellCommand.class</exclude>
<exclude>**/org/apache/calcite/util/Unsafe.class</exclude>
</excludes>
</configuration>
http://git-wip-us.apache.org/repos/asf/calcite/blob/d393cab2/src/main/config/forbidden-apis/signatures.txt
----------------------------------------------------------------------
diff --git a/src/main/config/forbidden-apis/signatures.txt b/src/main/config/forbidden-apis/signatures.txt
index a0eb429..4c4a8c5 100644
--- a/src/main/config/forbidden-apis/signatures.txt
+++ b/src/main/config/forbidden-apis/signatures.txt
@@ -39,4 +39,13 @@ java.lang.Runtime#exit(int)
@defaultMessage Don't interrupt threads use FutureUtils#cancel(Future<T>) instead
java.util.concurrent.Future#cancel(boolean)
+@defaultMessage Spawning processes is a potential security issue
+java.lang.ProcessBuilder
+java.lang.Runtime#exec(java.lang.String)
+java.lang.Runtime#exec(java.lang.String[])
+java.lang.Runtime#exec(java.lang.String, java.lang.String[])
+java.lang.Runtime#exec(java.lang.String, java.lang.String[], java.io.File)
+java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
+java.lang.Runtime#exec(java.lang.String[], java.lang.String[], java.io.File)
+
# End signatures.txt
[4/5] calcite git commit: Disable another test pending fix for
[CALCITE-1789] Wikipedia format change breaks file adapter test
Posted by jh...@apache.org.
Disable another test pending fix for [CALCITE-1789] Wikipedia format change breaks file adapter test
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/91d95762
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/91d95762
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/91d95762
Branch: refs/heads/master
Commit: 91d95762158bb8937fedcd0b9ff334cf049fa92b
Parents: d393cab
Author: Julian Hyde <jh...@apache.org>
Authored: Mon Jun 5 15:22:40 2017 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jun 5 15:53:35 2017 -0700
----------------------------------------------------------------------
.../test/java/org/apache/calcite/adapter/file/FileReaderTest.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/91d95762/file/src/test/java/org/apache/calcite/adapter/file/FileReaderTest.java
----------------------------------------------------------------------
diff --git a/file/src/test/java/org/apache/calcite/adapter/file/FileReaderTest.java b/file/src/test/java/org/apache/calcite/adapter/file/FileReaderTest.java
index 345e058..3f4f0fe 100644
--- a/file/src/test/java/org/apache/calcite/adapter/file/FileReaderTest.java
+++ b/file/src/test/java/org/apache/calcite/adapter/file/FileReaderTest.java
@@ -77,6 +77,7 @@ public class FileReaderTest {
}
/** Tests {@link FileReader} URL fetch. */
+ @Ignore("[CALCITE-1789] Wikipedia format change breaks file adapter test")
@Test public void testFileReaderUrlFetch() throws FileReaderException {
Assume.assumeTrue(FileSuite.hazNetwork());
FileReader t =
[5/5] calcite git commit: [CALCITE-1829] Add TIME/TIMESTAMP/DATE
datatype handling to RexImplicationChecker
Posted by jh...@apache.org.
[CALCITE-1829] Add TIME/TIMESTAMP/DATE datatype handling to RexImplicationChecker
Close apache/calcite#467
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/419b810f
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/419b810f
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/419b810f
Branch: refs/heads/master
Commit: 419b810fe67539cf7a3d653e918352fbaf10e8b0
Parents: 91d9576
Author: Minji Kim <mi...@dremio.com>
Authored: Fri Jun 2 13:52:45 2017 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jun 5 18:41:27 2017 -0700
----------------------------------------------------------------------
.../apache/calcite/plan/VisitorDataContext.java | 63 ++++++--------------
.../java/org/apache/calcite/rex/RexLiteral.java | 7 +++
.../calcite/test/RexImplicationCheckerTest.java | 35 +++++++----
3 files changed, 47 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/419b810f/core/src/main/java/org/apache/calcite/plan/VisitorDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/VisitorDataContext.java b/core/src/main/java/org/apache/calcite/plan/VisitorDataContext.java
index e2ab6b5..38b2ce3 100644
--- a/core/src/main/java/org/apache/calcite/plan/VisitorDataContext.java
+++ b/core/src/main/java/org/apache/calcite/plan/VisitorDataContext.java
@@ -36,8 +36,6 @@ import org.apache.calcite.util.trace.CalciteLogger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
-import java.sql.Date;
-import java.util.Calendar;
import java.util.List;
/**
@@ -116,7 +114,7 @@ public class VisitorDataContext implements DataContext {
if (inputRef instanceof RexInputRef
&& literal instanceof RexLiteral) {
final int index = ((RexInputRef) inputRef).getIndex();
- Object value = ((RexLiteral) literal).getValue();
+ final RexLiteral rexLiteral = (RexLiteral) literal;
final RelDataType type = inputRef.getType();
if (type.getSqlTypeName() == null) {
@@ -126,61 +124,36 @@ public class VisitorDataContext implements DataContext {
switch (type.getSqlTypeName()) {
case INTEGER:
- if (value instanceof BigDecimal) {
- return Pair.of(index, ((BigDecimal) value).intValue());
- }
+ return Pair.of(index, rexLiteral.getValueAs(Integer.class));
case DOUBLE:
- if (value instanceof BigDecimal) {
- return Pair.of(index, ((BigDecimal) value).doubleValue());
- }
+ return Pair.of(index, rexLiteral.getValueAs(Double.class));
case REAL:
- if (value instanceof BigDecimal) {
- return Pair.of(index, ((BigDecimal) value).floatValue());
- }
+ return Pair.of(index, rexLiteral.getValueAs(Float.class));
case BIGINT:
- if (value instanceof BigDecimal) {
- return Pair.of(index, ((BigDecimal) value).longValue());
- }
+ return Pair.of(index, rexLiteral.getValueAs(Long.class));
case SMALLINT:
- if (value instanceof BigDecimal) {
- return Pair.of(index, ((BigDecimal) value).shortValue());
- }
+ return Pair.of(index, rexLiteral.getValueAs(Short.class));
case TINYINT:
- if (value instanceof BigDecimal) {
- return Pair.of(index, (short) ((BigDecimal) value).byteValue());
- }
+ return Pair.of(index, rexLiteral.getValueAs(Byte.class));
case DECIMAL:
- if (value instanceof BigDecimal) {
- return Pair.of(index, value);
- }
+ return Pair.of(index, rexLiteral.getValueAs(BigDecimal.class));
case DATE:
- if (value instanceof NlsString) {
- value = ((RexLiteral) literal).getValue2();
- final Date dateValue = Date.valueOf((String) value);
- return Pair.of(index, dateValue);
- } else if (value instanceof Calendar) {
- final long timeInMillis = ((Calendar) value).getTimeInMillis();
- return Pair.of(index, new Date(timeInMillis));
- }
+ case TIME:
+ return Pair.of(index, rexLiteral.getValueAs(Integer.class));
+ case TIMESTAMP:
+ return Pair.of(index, rexLiteral.getValueAs(Long.class));
case CHAR:
- if (value instanceof NlsString) {
- // TODO: Support collation. Not supported in NlsString compare too.
- final NlsString nl = (NlsString) value;
- return Pair.of(index, nl.getValue().charAt(0));
- }
+ return Pair.of(index, rexLiteral.getValueAs(Character.class));
case VARCHAR:
- if (value instanceof NlsString) {
- // TODO: Support coallation. Not supported in {@link #NlsString} compare too.
- return Pair.of(index, ((NlsString) value).getValue());
- }
+ return Pair.of(index, rexLiteral.getValueAs(String.class));
default:
//TODO: Support few more supported cases
LOGGER.warn("{} for value of class {} is being handled in default way",
- type.getSqlTypeName(), value.getClass());
- if (value instanceof NlsString) {
- return Pair.of(index, ((NlsString) value).getValue());
+ type.getSqlTypeName(), rexLiteral.getValue().getClass());
+ if (rexLiteral.getValue() instanceof NlsString) {
+ return Pair.of(index, ((NlsString) rexLiteral.getValue()).getValue());
} else {
- return Pair.of(index, value);
+ return Pair.of(index, rexLiteral.getValue());
}
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/419b810f/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
index 97e3055..674cdd8 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
@@ -718,6 +718,13 @@ public class RexLiteral extends RexNode {
case CHAR:
if (clazz == String.class) {
return clazz.cast(((NlsString) value).getValue());
+ } else if (clazz == Character.class) {
+ return clazz.cast(((NlsString) value).getValue().charAt(0));
+ }
+ break;
+ case VARCHAR:
+ if (clazz == String.class) {
+ return clazz.cast(((NlsString) value).getValue());
}
break;
case DECIMAL:
http://git-wip-us.apache.org/repos/asf/calcite/blob/419b810f/core/src/test/java/org/apache/calcite/test/RexImplicationCheckerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RexImplicationCheckerTest.java b/core/src/test/java/org/apache/calcite/test/RexImplicationCheckerTest.java
index f089170..331fb06 100644
--- a/core/src/test/java/org/apache/calcite/test/RexImplicationCheckerTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexImplicationCheckerTest.java
@@ -43,17 +43,16 @@ import org.apache.calcite.util.TimeString;
import org.apache.calcite.util.TimestampString;
import org.apache.calcite.util.Util;
-import org.junit.Ignore;
import org.junit.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
/**
* Unit tests for {@link RexImplicationChecker}.
*/
@@ -178,36 +177,46 @@ public class RexImplicationCheckerTest {
f.checkImplies(node1, node1);
}
- @Ignore("work in progress")
@Test public void testSimpleDate() {
final Fixture f = new Fixture();
final DateString d = DateString.fromCalendarFields(Util.calendar());
final RexNode node1 = f.ge(f.dt, f.rexBuilder.makeDateLiteral(d));
final RexNode node2 = f.eq(f.dt, f.rexBuilder.makeDateLiteral(d));
-
f.checkImplies(node2, node1);
f.checkNotImplies(node1, node2);
+
+ final DateString dBeforeEpoch1 = DateString.fromDaysSinceEpoch(-12345);
+ final DateString dBeforeEpcoh2 = DateString.fromDaysSinceEpoch(-123);
+ final RexNode nodeBe1 = f.lt(f.dt, f.rexBuilder.makeDateLiteral(dBeforeEpoch1));
+ final RexNode nodeBe2 = f.lt(f.dt, f.rexBuilder.makeDateLiteral(dBeforeEpcoh2));
+ f.checkImplies(nodeBe1, nodeBe2);
+ f.checkNotImplies(nodeBe2, nodeBe1);
}
- @Ignore("work in progress")
@Test public void testSimpleTimeStamp() {
final Fixture f = new Fixture();
final TimestampString ts =
TimestampString.fromCalendarFields(Util.calendar());
- final RexNode node1 = f.le(f.ts, f.timestampLiteral(ts));
+ final RexNode node1 = f.lt(f.ts, f.timestampLiteral(ts));
final RexNode node2 = f.le(f.ts, f.timestampLiteral(ts));
-
f.checkImplies(node1, node2);
f.checkNotImplies(node2, node1);
+
+ final TimestampString tsBeforeEpoch1 =
+ TimestampString.fromMillisSinceEpoch(-1234567890L);
+ final TimestampString tsBeforeEpoch2 =
+ TimestampString.fromMillisSinceEpoch(-1234567L);
+ final RexNode nodeBe1 = f.lt(f.ts, f.timestampLiteral(tsBeforeEpoch1));
+ final RexNode nodeBe2 = f.lt(f.ts, f.timestampLiteral(tsBeforeEpoch2));
+ f.checkImplies(nodeBe1, nodeBe2);
+ f.checkNotImplies(nodeBe2, nodeBe1);
}
- @Ignore("work in progress")
@Test public void testSimpleTime() {
final Fixture f = new Fixture();
final TimeString t = TimeString.fromCalendarFields(Util.calendar());
- final RexNode node1 = f.le(f.ts, f.timeLiteral(t));
- final RexNode node2 = f.le(f.ts, f.timeLiteral(t));
-
+ final RexNode node1 = f.lt(f.t, f.timeLiteral(t));
+ final RexNode node2 = f.le(f.t, f.timeLiteral(t));
f.checkImplies(node1, node2);
f.checkNotImplies(node2, node1);
}
[3/5] calcite git commit: Improved fix for [CALCITE-1810]
Posted by jh...@apache.org.
Improved fix for [CALCITE-1810]
Use SqlOperandTypeInference, and as a result, we can deduce the types
of array constructor arguments during SQL-to-Rel conversion; now
queries work end-to-end. Also works for MULTISET as well as ARRAY.
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/4069013f
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/4069013f
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/4069013f
Branch: refs/heads/master
Commit: 4069013f1b49fc1b83f5e1b608be15f1774b2b38
Parents: f164fb8
Author: Julian Hyde <jh...@apache.org>
Authored: Fri Jun 2 14:52:04 2017 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jun 5 15:53:34 2017 -0700
----------------------------------------------------------------------
.../sql/fun/SqlMultisetValueConstructor.java | 3 +-
.../calcite/sql/validate/SqlValidatorImpl.java | 6 +-
.../apache/calcite/test/SqlValidatorTest.java | 61 +++++++++++++++-----
.../calcite/test/SqlValidatorTestCase.java | 5 ++
core/src/test/resources/sql/misc.iq | 43 ++++++++++++++
5 files changed, 97 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/4069013f/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java
index a517391..b28b5d2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlMultisetValueConstructor.java
@@ -25,6 +25,7 @@ import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperatorBinding;
import org.apache.calcite.sql.SqlSpecialOperator;
import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.type.InferTypes;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;
import org.apache.calcite.sql.type.SqlTypeUtil;
@@ -54,7 +55,7 @@ public class SqlMultisetValueConstructor extends SqlSpecialOperator {
kind, MDX_PRECEDENCE,
false,
ReturnTypes.ARG0,
- null,
+ InferTypes.FIRST_KNOWN,
OperandTypes.VARIADIC);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/4069013f/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 2931a3c..46cd711 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,11 +1762,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
operandTypes);
}
for (int i = 0; i < operands.size(); ++i) {
- RelDataType type = operandTypes[i];
- if (SqlTypeUtil.isArray(inferredType)) {
- type = inferredType.getComponentType();
- }
- inferUnknownTypes(type, scope, operands.get(i));
+ inferUnknownTypes(operandTypes[i], scope, operands.get(i));
}
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/4069013f/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 728dc26..4d1dfeb 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -7256,6 +7256,23 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
"Column 'C1' not found in any table");
}
+ @Test public void testArrayConstructor() {
+ sql("select array[1,2] as a from (values (1))")
+ .columnType("INTEGER NOT NULL ARRAY NOT NULL");
+ sql("select array[1,cast(null as integer), 2] as a\n"
+ + "from (values (1))")
+ .columnType("INTEGER ARRAY NOT NULL");
+ sql("select array[1,null,2] as a from (values (1))")
+ .columnType("INTEGER ARRAY NOT NULL");
+ sql("select array['1',null,'234',''] as a from (values (1))")
+ .columnType("CHAR(3) ARRAY NOT NULL");
+ }
+
+ @Test public void testMultisetConstructor() {
+ sql("select multiset[1,null,2] as a from (values (1))")
+ .columnType("INTEGER MULTISET NOT NULL");
+ }
+
@Test public void testUnnestArrayColumn() {
final String sql = "select d.deptno, e.*\n"
+ "from dept_nested as d,\n"
@@ -9931,22 +9948,36 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
"Duplicate name 'EXTRA' in column list");
}
+ /** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-1804">[CALCITE-1804]
+ * Cannot assign NOT NULL array to nullable array</a>. */
@Test public void testArrayAssignment() {
- SqlTypeFactoryImpl typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
- RelDataType sqlBigIntNullable = typeFactory
- .createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true);
- RelDataType sqlBigIntNotNull = typeFactory
- .createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), false);
- RelDataType sqlDateNotNull = typeFactory
- .createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE), false);
- assertThat(SqlTypeUtil.canAssignFrom(sqlBigIntNullable, sqlBigIntNotNull), is(true));
- assertThat(SqlTypeUtil.canAssignFrom(sqlBigIntNullable, sqlDateNotNull), is(false));
- RelDataType bigIntArrayNullable = typeFactory
- .createTypeWithNullability(typeFactory.createArrayType(sqlBigIntNullable, -1), true);
- RelDataType bigIntArrayNotnull = new ArraySqlType(sqlBigIntNotNull, false);
- assertThat(SqlTypeUtil.canAssignFrom(bigIntArrayNullable, bigIntArrayNotnull), is(true));
- RelDataType dateArrayNotnull = new ArraySqlType(sqlDateNotNull, false);
- assertThat(SqlTypeUtil.canAssignFrom(bigIntArrayNullable, dateArrayNotnull), is(false));
+ final SqlTypeFactoryImpl typeFactory =
+ new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+ final RelDataType bigint = typeFactory.createSqlType(SqlTypeName.BIGINT);
+ final RelDataType bigintNullable =
+ typeFactory.createTypeWithNullability(bigint, true);
+ final RelDataType bigintNotNull =
+ typeFactory.createTypeWithNullability(bigint, false);
+ final RelDataType date = typeFactory.createSqlType(SqlTypeName.DATE);
+ final RelDataType dateNotNull =
+ typeFactory.createTypeWithNullability(date, false);
+ assertThat(SqlTypeUtil.canAssignFrom(bigintNullable, bigintNotNull),
+ is(true));
+ assertThat(SqlTypeUtil.canAssignFrom(bigintNullable, dateNotNull),
+ is(false));
+ final RelDataType bigintNullableArray =
+ typeFactory.createArrayType(bigintNullable, -1);
+ final RelDataType bigintArrayNullable =
+ typeFactory.createTypeWithNullability(bigintNullableArray, true);
+ final RelDataType bigintNotNullArray =
+ new ArraySqlType(bigintNotNull, false);
+ assertThat(SqlTypeUtil.canAssignFrom(bigintArrayNullable, bigintNotNullArray),
+ is(true));
+ final RelDataType dateNotNullArray =
+ new ArraySqlType(dateNotNull, false);
+ assertThat(SqlTypeUtil.canAssignFrom(bigintArrayNullable, dateNotNullArray),
+ is(false));
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/4069013f/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
index b5db2c3..c1833f0 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
@@ -565,6 +565,11 @@ public class SqlValidatorTestCase {
return this;
}
+ public Sql columnType(String expectedType) {
+ tester.checkColumnType(sql, expectedType);
+ return this;
+ }
+
public Sql monotonic(SqlMonotonicity expectedMonotonicity) {
tester.checkMonotonic(sql, expectedMonotonicity);
return this;
http://git-wip-us.apache.org/repos/asf/calcite/blob/4069013f/core/src/test/resources/sql/misc.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/misc.iq b/core/src/test/resources/sql/misc.iq
index 9ecd55d..73bb0f0 100644
--- a/core/src/test/resources/sql/misc.iq
+++ b/core/src/test/resources/sql/misc.iq
@@ -1930,4 +1930,47 @@ select
!ok
+# ARRAY and MULTISET
+select array[1,2] as a from (values (1));
++--------+
+| A |
++--------+
+| [1, 2] |
++--------+
+(1 row)
+
+!ok
+
+select array[1,null,2] as a from (values (1));
++--------------+
+| A |
++--------------+
+| [1, null, 2] |
++--------------+
+(1 row)
+
+!ok
+
+values array['a',null,'bcd'],
+ array['efgh'];
++----------------+
+| EXPR$0 |
++----------------+
+| [a, null, bcd] |
+| [efgh] |
++----------------+
+(2 rows)
+
+!ok
+
+select multiset[1,null,2,2-1] as m from (values (1));
++-----------------+
+| M |
++-----------------+
+| [1, 1, null, 2] |
++-----------------+
+(1 row)
+
+!ok
+
# End misc.iq