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 2018/12/04 07:07:09 UTC
[1/4] calcite git commit: [CALCITE-2719] In JDBC adapter for MySQL,
fix cast to INTEGER and BIGINT (Piotr Bojko)
Repository: calcite
Updated Branches:
refs/heads/master 6c7a7edd1 -> efec74deb
[CALCITE-2719] In JDBC adapter for MySQL, fix cast to INTEGER and BIGINT (Piotr Bojko)
MySQL does not support casts to INTEGER and BIGINT; instead we must
cast to SIGNED.
Close apache/calcite#953
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/dfb29f76
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/dfb29f76
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/dfb29f76
Branch: refs/heads/master
Commit: dfb29f7627d02f6e4414be7bc42822a26684778c
Parents: 6c7a7ed
Author: Piotr Bojko <pt...@gmail.com>
Authored: Sun Dec 2 23:04:12 2018 +0100
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Dec 3 17:08:11 2018 -0800
----------------------------------------------------------------------
.../calcite/sql/dialect/MysqlSqlDialect.java | 3 ++-
.../rel/rel2sql/RelToSqlConverterTest.java | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/dfb29f76/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
index 807ba6c..6446386 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
@@ -105,7 +105,8 @@ public class MysqlSqlDialect extends SqlDialect {
return new SqlDataTypeSpec(new SqlIdentifier("CHAR", SqlParserPos.ZERO),
type.getPrecision(), -1, null, null, SqlParserPos.ZERO);
case INTEGER:
- return new SqlDataTypeSpec(new SqlIdentifier("_UNSIGNED", SqlParserPos.ZERO),
+ case BIGINT:
+ return new SqlDataTypeSpec(new SqlIdentifier("_SIGNED", SqlParserPos.ZERO),
type.getPrecision(), -1, null, null, SqlParserPos.ZERO);
}
return super.getCastSpec(type);
http://git-wip-us.apache.org/repos/asf/calcite/blob/dfb29f76/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index ca27782..fb6a539 100644
--- a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -646,6 +646,26 @@ public class RelToSqlConverterTest {
sql(query).dialect(HiveSqlDialect.DEFAULT).ok(expected);
}
+ @Test public void testMysqlCastToBigint() {
+ // MySQL does not allow cast to BIGINT; instead cast to SIGNED.
+ final String query = "select cast(\"product_id\" as bigint) from \"product\"";
+ final String expected = "SELECT CAST(`product_id` AS SIGNED)\n"
+ + "FROM `foodmart`.`product`";
+ sql(query).withMysql().ok(expected);
+ }
+
+
+ @Test public void testMysqlCastToInteger() {
+ // MySQL does not allow cast to INTEGER; instead cast to SIGNED.
+ final String query = "select \"employee_id\",\n"
+ + " cast(\"salary_paid\" * 10000 as integer)\n"
+ + "from \"salary\"";
+ final String expected = "SELECT `employee_id`,"
+ + " CAST(`salary_paid` * 10000 AS SIGNED)\n"
+ + "FROM `foodmart`.`salary`";
+ sql(query).withMysql().ok(expected);
+ }
+
@Test public void testHiveSelectQueryWithOrderByDescAndHighNullsWithVersionGreaterThanOrEq21() {
final HiveSqlDialect hive2_1Dialect =
new HiveSqlDialect(SqlDialect.EMPTY_CONTEXT
[3/4] calcite git commit: [CALCITE-2716] Upgrade to Avatica 1.13.0
Posted by jh...@apache.org.
[CALCITE-2716] Upgrade to Avatica 1.13.0
Also upgrade to
jetty 9.4.11.v20180605
maven-scm-provider 1.10.0
mockito 2.22.0
owasp-dependency-check 3.3.2
slf4j 1.7.25
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/efec74de
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/efec74de
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/efec74de
Branch: refs/heads/master
Commit: efec74deb80da1708fd42bcc2b57289840869346
Parents: 5c6d3c2
Author: Julian Hyde <jh...@apache.org>
Authored: Wed Nov 28 15:53:56 2018 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Dec 3 19:16:15 2018 -0800
----------------------------------------------------------------------
pom.xml | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/efec74de/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 45b017d..727ed35 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,7 +65,7 @@ limitations under the License.
<!-- This list is in alphabetical order. -->
<airlift-tpch.version>0.1</airlift-tpch.version>
- <avatica.version>1.12.0</avatica.version>
+ <avatica.version>1.13.0</avatica.version>
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
<cassandra-driver-core.version>3.4.0</cassandra-driver-core.version>
<cassandra-unit.version>3.5.0.1</cassandra-unit.version>
@@ -107,7 +107,7 @@ limitations under the License.
<java-diff.version>1.1.2</java-diff.version>
<javacc-maven-plugin.version>2.4</javacc-maven-plugin.version>
<jcip-annotations.version>1.0-1</jcip-annotations.version>
- <jetty.version>9.2.19.v20160908</jetty.version>
+ <jetty.version>9.4.11.v20180605</jetty.version>
<jmh.version>1.12</jmh.version>
<jsoup.version>1.11.3</jsoup.version>
<junit.version>4.12</junit.version>
@@ -116,22 +116,22 @@ limitations under the License.
<maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version>
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
- <maven-scm-provider.version>1.9.5</maven-scm-provider.version>
- <mockito.version>2.21.0</mockito.version>
+ <maven-scm-provider.version>1.10.0</maven-scm-provider.version>
+ <mockito.version>2.22.0</mockito.version>
<mongo-java-driver.version>3.5.0</mongo-java-driver.version>
<mysql-driver.version>5.1.20</mysql-driver.version>
<natty.version>0.13</natty.version>
<opencsv.version>2.3</opencsv.version>
<oracle-jdbc6-driver.version>11.2.0.2.0</oracle-jdbc6-driver.version>
- <owasp-dependency-check.version>3.3.1</owasp-dependency-check.version>
+ <owasp-dependency-check.version>3.3.2</owasp-dependency-check.version>
<pig.version>0.16.0</pig.version>
<aggdesigner.version>6.0</aggdesigner.version>
<postgresql.version>9.3-1102-jdbc3</postgresql.version>
<quidem.version>0.9</quidem.version>
<scala.version>2.10.3</scala.version>
<scott-data-hsqldb.version>0.1</scott-data-hsqldb.version>
- <servlet.version>3.0.1</servlet.version>
- <slf4j.version>1.7.13</slf4j.version>
+ <servlet.version>4.0.1</servlet.version>
+ <slf4j.version>1.7.25</slf4j.version>
<log4j2.version>2.11.0</log4j2.version>
<spark.version>2.2.0</spark.version>
<sqlline.version>1.6.0</sqlline.version>
[4/4] calcite git commit: [CALCITE-2596] When translating correlated
variables in enumerable convention,
convert not-null boxed primitive values to primitive (Stamatis Zampetakis)
Posted by jh...@apache.org.
[CALCITE-2596] When translating correlated variables in enumerable convention, convert not-null boxed primitive values to primitive (Stamatis Zampetakis)
Apply nullAs policy when translating expressions with correlated variables.
Close apache/calcite#868
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/5c6d3c22
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/5c6d3c22
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/5c6d3c22
Branch: refs/heads/master
Commit: 5c6d3c22cd77e3fd6427f327187b3e0bfd8a2a81
Parents: 0ad68c3
Author: Stamatis Zampetakis <za...@gmail.com>
Authored: Wed Sep 26 14:03:29 2018 +0200
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Dec 3 19:16:15 2018 -0800
----------------------------------------------------------------------
.../adapter/enumerable/RexToLixTranslator.java | 30 +++++++++++++-------
.../enumerable/EnumerableCorrelateTest.java | 12 ++++++++
2 files changed, 32 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/5c6d3c22/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
index e28a8d0..1a63068 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
@@ -571,6 +571,18 @@ public class RexToLixTranslator {
return scaleIntervalToNumber(sourceType, targetType, convert);
}
+ private Expression handleNullUnboxingIfNecessary(
+ Expression input,
+ RexImpTable.NullAs nullAs,
+ Type storageType) {
+ if (RexImpTable.NullAs.NOT_POSSIBLE == nullAs && input.type.equals(storageType)) {
+ // When we asked for not null input that would be stored as box, avoid
+ // unboxing which may occur in the handleNull method below.
+ return input;
+ }
+ return handleNull(input, nullAs);
+ }
+
/** Adapts an expression with "normal" result to one that adheres to
* this particular policy. Wraps the result expression into a new
* parameter if need be.
@@ -624,18 +636,13 @@ public class RexToLixTranslator {
nullAs = RexImpTable.NullAs.NOT_POSSIBLE;
}
switch (expr.getKind()) {
- case INPUT_REF:
+ case INPUT_REF: {
final int index = ((RexInputRef) expr).getIndex();
Expression x = inputGetter.field(list, index, storageType);
Expression input = list.append("inp" + index + "_", x); // safe to share
- if (nullAs == RexImpTable.NullAs.NOT_POSSIBLE
- && input.type.equals(storageType)) {
- // When we asked for not null input that would be stored as box, avoid
- // unboxing via nullAs.handle below.
- return input;
- }
- return handleNull(input, nullAs);
+ return handleNullUnboxingIfNecessary(input, nullAs, storageType);
+ }
case LOCAL_REF:
return translate(
deref(expr),
@@ -655,7 +662,7 @@ public class RexToLixTranslator {
case CORREL_VARIABLE:
throw new RuntimeException("Cannot translate " + expr + ". Correlated"
+ " variables should always be referenced by field access");
- case FIELD_ACCESS:
+ case FIELD_ACCESS: {
RexFieldAccess fieldAccess = (RexFieldAccess) expr;
RexNode target = deref(fieldAccess.getReferenceExpr());
int fieldIndex = fieldAccess.getField().getIndex();
@@ -668,7 +675,9 @@ public class RexToLixTranslator {
}
InputGetter getter =
correlates.apply(((RexCorrelVariable) target).getName());
- return getter.field(list, fieldIndex, storageType);
+ Expression y = getter.field(list, fieldIndex, storageType);
+ Expression input = list.append("corInp" + fieldIndex + "_", y); // safe to share
+ return handleNullUnboxingIfNecessary(input, nullAs, storageType);
default:
RexNode rxIndex = builder.makeLiteral(fieldIndex, typeFactory.createType(int.class), true);
RexNode rxName = builder.makeLiteral(fieldName, typeFactory.createType(String.class), true);
@@ -678,6 +687,7 @@ public class RexToLixTranslator {
ImmutableList.of(target, rxIndex, rxName));
return translateCall(accessCall, nullAs);
}
+ }
default:
if (expr instanceof RexCall) {
return translateCall((RexCall) expr, nullAs);
http://git-wip-us.apache.org/repos/asf/calcite/blob/5c6d3c22/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
index 2edc6b9..876c18f 100644
--- a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
+++ b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
@@ -95,6 +95,18 @@ public class EnumerableCorrelateTest {
"empid=150; name=Sebastian");
}
+ @Test public void simpleCorrelateWithConditionIncludingBoxedPrimitive() {
+ final String sql = "select empid from emps e where not exists (\n"
+ + " select 1 from depts d where d.deptno=e.commission)";
+ tester(false, new JdbcTest.HrSchema())
+ .query(sql)
+ .returnsUnordered(
+ "empid=100",
+ "empid=110",
+ "empid=150",
+ "empid=200");
+ }
+
private CalciteAssert.AssertThat tester(boolean forceDecorrelate,
Object schema) {
return CalciteAssert.that()
[2/4] calcite git commit: [CALCITE-2684] RexBuilder gives
AssertionError when creating integer literal larger than 2^63 (Ruben Quesada
Lopez)
Posted by jh...@apache.org.
[CALCITE-2684] RexBuilder gives AssertionError when creating integer literal larger than 2^63 (Ruben Quesada Lopez)
Close apache/calcite#928
For [CALCITE-2701]:
Close apache/calcite#935
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/0ad68c31
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/0ad68c31
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/0ad68c31
Branch: refs/heads/master
Commit: 0ad68c3194c7bca24dfd21302418636730274312
Parents: dfb29f7
Author: rubenada <ru...@gmail.com>
Authored: Mon Nov 19 16:46:02 2018 +0100
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Dec 3 19:16:15 2018 -0800
----------------------------------------------------------------------
.../java/org/apache/calcite/rex/RexBuilder.java | 12 +++++++---
.../org/apache/calcite/rex/RexBuilderTest.java | 24 ++++++++++++++++++++
2 files changed, 33 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/0ad68c31/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
index d346ec7..696b63b 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
@@ -78,6 +78,14 @@ public class RexBuilder {
public static final SqlSpecialOperator GET_OPERATOR =
new SqlSpecialOperator("_get", SqlKind.OTHER_FUNCTION);
+ /** The smallest valid {@code int} value, as a {@link BigDecimal}. */
+ private static final BigDecimal INT_MIN =
+ BigDecimal.valueOf(Integer.MIN_VALUE);
+
+ /** The largest valid {@code int} value, as a {@link BigDecimal}. */
+ private static final BigDecimal INT_MAX =
+ BigDecimal.valueOf(Integer.MAX_VALUE);
+
//~ Instance fields --------------------------------------------------------
protected final RelDataTypeFactory typeFactory;
@@ -928,12 +936,10 @@ public class RexBuilder {
public RexLiteral makeExactLiteral(BigDecimal bd) {
RelDataType relType;
int scale = bd.scale();
- long l = bd.unscaledValue().longValue();
assert scale >= 0;
assert scale <= typeFactory.getTypeSystem().getMaxNumericScale() : scale;
- assert BigDecimal.valueOf(l, scale).equals(bd);
if (scale == 0) {
- if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) {
+ if (bd.compareTo(INT_MIN) >= 0 && bd.compareTo(INT_MAX) <= 0) {
relType = typeFactory.createSqlType(SqlTypeName.INTEGER);
} else {
relType = typeFactory.createSqlType(SqlTypeName.BIGINT);
http://git-wip-us.apache.org/repos/asf/calcite/blob/0ad68c31/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java b/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
index 1445e95..7475044 100644
--- a/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
@@ -32,6 +32,7 @@ import org.apache.calcite.util.Util;
import org.junit.Test;
+import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.TimeZone;
@@ -539,6 +540,29 @@ public class RexBuilderTest {
assertEquals("_UTF8'foobar'", literal.toString());
}
+ /** Tests {@link RexBuilder#makeExactLiteral(java.math.BigDecimal)}. */
+ @Test public void testBigDecimalLiteral() {
+ final RelDataTypeFactory typeFactory =
+ new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+ final RexBuilder builder = new RexBuilder(typeFactory);
+ checkBigDecimalLiteral(builder, "25");
+ checkBigDecimalLiteral(builder, "9.9");
+ checkBigDecimalLiteral(builder, "0");
+ checkBigDecimalLiteral(builder, "-75.5");
+ checkBigDecimalLiteral(builder, "10000000");
+ checkBigDecimalLiteral(builder, "100000.111111111111111111");
+ checkBigDecimalLiteral(builder, "-100000.111111111111111111");
+ checkBigDecimalLiteral(builder, "73786976294838206464"); // 2^66
+ checkBigDecimalLiteral(builder, "-73786976294838206464");
+ }
+
+ private void checkBigDecimalLiteral(RexBuilder builder, String val) {
+ final RexLiteral literal = builder.makeExactLiteral(new BigDecimal(val));
+ assertThat("builder.makeExactLiteral(new BigDecimal(" + val
+ + ")).getValueAs(BigDecimal.class).toString()",
+ literal.getValueAs(BigDecimal.class).toString(), is(val));
+ }
+
}
// End RexBuilderTest.java