[calcite] branch master updated: [CALCITE-5107] Support SQL hint for Filter, SetOp, Sort, Window, Values
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new c98171da57 [CALCITE-5107] Support SQL hint for Filter, SetOp, Sort, Window, Values c98171da57 is described below commit c98171da5790d3d5ee7d2eb48a21d0080d0d68f3 Author: godfreyhe AuthorDate: Thu Apr 21 18:58:08 2022 +0800 [CALCITE-5107] Support SQL hint for Filter, SetOp, Sort, Window, Values close apache/calcite#2775 --- .../java/org/apache/calcite/rel/core/Filter.java | 35 +- .../org/apache/calcite/rel/core/Intersect.java | 16 ++- .../java/org/apache/calcite/rel/core/Minus.java| 10 +- .../java/org/apache/calcite/rel/core/SetOp.java| 25 - .../java/org/apache/calcite/rel/core/Sort.java | 60 +++--- .../java/org/apache/calcite/rel/core/Union.java| 13 ++- .../java/org/apache/calcite/rel/core/Values.java | 36 +- .../java/org/apache/calcite/rel/core/Window.java | 31 +- .../apache/calcite/rel/hint/HintPredicates.java| 25 + .../calcite/rel/hint/NodeTypeHintPredicate.java| 32 +- .../apache/calcite/rel/logical/LogicalFilter.java | 33 +- .../calcite/rel/logical/LogicalIntersect.java | 24 +++- .../apache/calcite/rel/logical/LogicalMinus.java | 20 +++- .../apache/calcite/rel/logical/LogicalSort.java| 20 +++- .../apache/calcite/rel/logical/LogicalUnion.java | 23 +++- .../apache/calcite/rel/logical/LogicalValues.java | 29 - .../apache/calcite/rel/logical/LogicalWindow.java | 31 +- .../org/apache/calcite/test/RelBuilderTest.java| 71 ++-- .../apache/calcite/test/SqlHintsConverterTest.java | 124 - .../apache/calcite/test/SqlHintsConverterTest.xml | 94 +++- 20 files changed, 696 insertions(+), 56 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rel/core/Filter.java b/core/src/main/java/org/apache/calcite/rel/core/Filter.java index ce4e0c0ec6..dbe44e4df0 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/Filter.java +++ b/core/src/main/java/org/apache/calcite/rel/core/Filter.java @@ -24,6 +24,8 @@ import org.apache.calcite.rel.RelInput; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.RelWriter; import org.apache.calcite.rel.SingleRel; +import org.apache.calcite.rel.hint.Hintable; +import org.apache.calcite.rel.hint.RelHint; import org.apache.calcite.rel.metadata.RelMdUtil; import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.apache.calcite.rex.RexChecker; @@ -34,6 +36,8 @@ import org.apache.calcite.rex.RexShuttle; import org.apache.calcite.rex.RexUtil; import org.apache.calcite.util.Litmus; +import com.google.common.collect.ImmutableList; + import org.apiguardian.api.API; import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; import org.checkerframework.checker.nullness.qual.Nullable; @@ -53,11 +57,13 @@ import static java.util.Objects.requireNonNull; * * @see org.apache.calcite.rel.logical.LogicalFilter */ -public abstract class Filter extends SingleRel { +public abstract class Filter extends SingleRel implements Hintable { //~ Instance fields protected final RexNode condition; + protected final ImmutableList hints; + //~ Constructors --- /** @@ -65,6 +71,7 @@ public abstract class Filter extends SingleRel { * * @param cluster Cluster that this relational expression belongs to * @param traitsthe traits of this rel + * @param hints Hints for this node * @param child input relational expression * @param condition boolean expression which determines whether a row is * allowed to pass @@ -73,12 +80,31 @@ public abstract class Filter extends SingleRel { protected Filter( RelOptCluster cluster, RelTraitSet traits, + List hints, RelNode child, RexNode condition) { super(cluster, traits, child); this.condition = requireNonNull(condition, "condition"); assert RexUtil.isFlat(condition) : "RexUtil.isFlat should be true for condition " + condition; assert isValid(Litmus.THROW, null); +this.hints = ImmutableList.copyOf(hints); + } + + /** + * Creates a filter. + * + * @param cluster Cluster that this relational expression belongs to + * @param traitsthe traits of this rel + * @param child input relational expression + * @param condition boolean expression which determines whether a row is + * allowed to pass + */ + protected Filter( + RelOptCluster cluster, + RelTraitSet traits, + RelNode child, + RexNode condition) { +this(cluster, traits, ImmutableList.of
[calcite] branch master updated (ad5cbdb -> f0bd2b2)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from ad5cbdb [CALCITE-4965] IS NOT NULL failed in Elasticsearch Adapter add f0bd2b2 [CALCITE-4967] Support SQL hints for temporal table join No new revisions were added by this update. Summary of changes: .../adapter/enumerable/EnumerableCorrelate.java| 2 +- .../org/apache/calcite/adapter/jdbc/JdbcRules.java | 2 +- .../org/apache/calcite/rel/core/Correlate.java | 24 - .../org/apache/calcite/rel/core/RelFactories.java | 12 +++-- .../apache/calcite/rel/hint/HintPredicates.java| 5 ++ .../calcite/rel/hint/NodeTypeHintPredicate.java| 8 ++- .../calcite/rel/logical/LogicalCorrelate.java | 41 -- .../apache/calcite/rel/mutable/MutableRels.java| 5 +- .../calcite/rel/rules/JoinToCorrelateRule.java | 1 + .../sql2rel/RelStructuredTypeFlattener.java| 1 + .../apache/calcite/sql2rel/SqlToRelConverter.java | 2 +- .../java/org/apache/calcite/tools/RelBuilder.java | 4 +- .../org/apache/calcite/test/RelBuilderTest.java| 30 +++ .../org/apache/calcite/test/RelOptRulesTest.java | 3 +- .../apache/calcite/test/SqlHintsConverterTest.java | 62 +- .../org/apache/calcite/test/SqlToRelTestBase.java | 11 +++- .../apache/calcite/test/SqlHintsConverterTest.xml | 26 + 17 files changed, 218 insertions(+), 21 deletions(-)
[calcite] branch master updated: [CALCITE-4640] Propagate table scan hints to JDBC
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 09a8a2f [CALCITE-4640] Propagate table scan hints to JDBC 09a8a2f is described below commit 09a8a2f74c31e215dfee02c1abdca8d70753157f Author: Ulrich Kramer AuthorDate: Fri Jun 4 15:08:13 2021 +0200 [CALCITE-4640] Propagate table scan hints to JDBC close apache/calcite#2426 --- .../calcite/adapter/jdbc/JdbcImplementor.java | 10 -- .../org/apache/calcite/adapter/jdbc/JdbcTable.java | 2 +- .../apache/calcite/adapter/jdbc/JdbcTableScan.java | 15 +++-- .../calcite/rel/rel2sql/RelToSqlConverter.java | 36 +- .../apache/calcite/rel/rel2sql/SqlImplementor.java | 2 ++ .../java/org/apache/calcite/sql/SqlDialect.java| 5 +++ .../java/org/apache/calcite/sql/SqlTableRef.java | 5 +-- .../apache/calcite/sql/dialect/AnsiSqlDialect.java | 12 .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 31 +++ 9 files changed, 100 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcImplementor.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcImplementor.java index 83e5f64..0695a77 100644 --- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcImplementor.java +++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcImplementor.java @@ -22,8 +22,6 @@ import org.apache.calcite.rel.rel2sql.RelToSqlConverter; import org.apache.calcite.sql.SqlDialect; import org.apache.calcite.util.Util; -import com.google.common.collect.ImmutableList; - /** * State for generating a SQL statement. */ @@ -33,14 +31,6 @@ public class JdbcImplementor extends RelToSqlConverter { Util.discard(typeFactory); } - // CHECKSTYLE: IGNORE 1 - /** @see #dispatch */ - @SuppressWarnings("MissingSummary") - public Result visit(JdbcTableScan scan) { -return result(scan.jdbcTable.tableName(), -ImmutableList.of(Clause.FROM), scan, null); - } - public Result implement(RelNode node) { return dispatch(node); } diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java index 06b59e5..7b2e99a 100644 --- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java +++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java @@ -175,7 +175,7 @@ public class JdbcTable extends AbstractQueryableTable @Override public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) { -return new JdbcTableScan(context.getCluster(), relOptTable, this, +return new JdbcTableScan(context.getCluster(), context.getTableHints(), relOptTable, this, jdbcSchema.convention); } diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java index 6e104d6..7cab213 100644 --- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java +++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTableScan.java @@ -16,11 +16,13 @@ */ package org.apache.calcite.adapter.jdbc; +import org.apache.calcite.plan.Convention; import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelOptTable; import org.apache.calcite.plan.RelTraitSet; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.TableScan; +import org.apache.calcite.rel.hint.RelHint; import com.google.common.collect.ImmutableList; @@ -29,6 +31,8 @@ import java.util.Objects; import static org.apache.calcite.linq4j.Nullness.castNonNull; +import static java.util.Objects.requireNonNull; + /** * Relational expression representing a scan of a table in a JDBC data source. */ @@ -37,21 +41,28 @@ public class JdbcTableScan extends TableScan implements JdbcRel { protected JdbcTableScan( RelOptCluster cluster, + List hints, RelOptTable table, JdbcTable jdbcTable, JdbcConvention jdbcConvention) { -super(cluster, cluster.traitSetOf(jdbcConvention), ImmutableList.of(), table); +super(cluster, cluster.traitSetOf(jdbcConvention), hints, table); this.jdbcTable = Objects.requireNonNull(jdbcTable, "jdbcTable"); } @Override public RelNode copy(RelTraitSet traitSet, List inputs) { assert inputs.isEmpty(); return new JdbcTableScan( -getCluster(), table, jdbcTable, (JdbcConvention) castNonNull(getConvention())); +getCluster(), getHints(), table, jdbcTable, (JdbcConvention) castNonNull(getConvention())); } @Override public JdbcImplementor.Result implement(JdbcImplementor implementor) { return implementor.result(jdbcTable.tableName(), ImmutableList.of(JdbcImp
[calcite] branch master updated: [CALCITE-4548] Support convert subQuery for SqlToRelConverter#convertExpression (jibiyr)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 796675c [CALCITE-4548] Support convert subQuery for SqlToRelConverter#convertExpression (jibiyr) 796675c is described below commit 796675c9b33e0461bc45a72780162d474a4b098b Author: laughing.sheng AuthorDate: Fri Mar 26 17:58:56 2021 +0800 [CALCITE-4548] Support convert subQuery for SqlToRelConverter#convertExpression (jibiyr) close apache/calcite#2382 --- .../apache/calcite/sql2rel/SqlToRelConverter.java | 2 + .../apache/calcite/test/SqlToRelConverterTest.java | 30 +++-- .../org/apache/calcite/test/SqlToRelTestBase.java | 144 - .../apache/calcite/test/SqlToRelConverterTest.xml | 11 ++ 4 files changed, 145 insertions(+), 42 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index d0beac9..a1d14de 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -1940,6 +1940,7 @@ public class SqlToRelConverter { final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator(), nameToTypeMap); final Blackboard bb = createBlackboard(scope, null, false); +replaceSubQueries(bb, node, RelOptUtil.Logic.TRUE_FALSE_UNKNOWN); return bb.convertExpression(node); } @@ -1964,6 +1965,7 @@ public class SqlToRelConverter { final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator(), nameToTypeMap); final Blackboard bb = createBlackboard(scope, nameToNodeMap, false); +replaceSubQueries(bb, node, RelOptUtil.Logic.TRUE_FALSE_UNKNOWN); return bb.convertExpression(node); } diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index b28ef48..e81bb01 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -88,7 +88,12 @@ class SqlToRelConverterTest extends SqlToRelTestBase { /** Sets the SQL statement for a test. */ public final Sql sql(String sql) { return new Sql(sql, true, tester, false, UnaryOperator.identity(), -tester.getConformance()); +tester.getConformance(), true); + } + + public final Sql expr(String expr) { +return new Sql(expr, true, tester, false, UnaryOperator.identity(), +tester.getConformance(), false); } @Test void testDotLiteralAfterNestedRow() { @@ -4192,6 +4197,12 @@ class SqlToRelConverterTest extends SqlToRelTestBase { sql(sql).trim(true).ok(); } + + @Test public void testInWithConstantList() { +String expr = "1 in (1,2,3)"; +expr(expr).ok(); + } + /** * Visitor that checks that every {@link RelNode} in a tree is valid. * @@ -4232,10 +4243,12 @@ class SqlToRelConverterTest extends SqlToRelTestBase { private final boolean trim; private final UnaryOperator config; private final SqlConformance conformance; +private final boolean query; + Sql(String sql, boolean decorrelate, Tester tester, boolean trim, UnaryOperator config, -SqlConformance conformance) { +SqlConformance conformance, boolean query) { this.sql = Objects.requireNonNull(sql, "sql"); if (sql.contains(" \n")) { throw new AssertionError("trailing whitespace"); @@ -4245,6 +4258,7 @@ class SqlToRelConverterTest extends SqlToRelTestBase { this.trim = trim; this.config = Objects.requireNonNull(config, "config"); this.conformance = Objects.requireNonNull(conformance, "conformance"); + this.query = query; } public void ok() { @@ -4256,13 +4270,13 @@ class SqlToRelConverterTest extends SqlToRelTestBase { .withConformance(conformance) .withConfig(config) .withConfig(c -> c.withTrimUnusedFields(true)) - .assertConvertsTo(sql, plan, trim); + .assertConvertsTo(sql, plan, trim, query); } public Sql withConfig(UnaryOperator config) { final UnaryOperator config2 = this.config.andThen(Objects.requireNonNull(config, "config"))::apply; - return new Sql(sql, decorrelate, tester, trim, config2, conformance); + return new Sql(sql, decorrelate, tester, trim, config2, conformance, query); } public Sql expand(boolean expand) { @@ -4270,19 +4284,19 @@ class SqlToRelConverterTest extends SqlToRelTestBase { } public Sql decorrelate(boolean decorrelate) { - return new Sql(sql, d
[calcite] branch master updated (75b9440 -> 39d477d)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. omit 75b9440 [CALCITE-4526] Fixup the unparse's output of SqlSnapshot when the table has alias (jibiyr) new 39d477d [CALCITE-4526] SqlSnapshot unparse lost the AS keyword when the table has alias (jibiyr) This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (75b9440) \ N -- N -- N refs/heads/master (39d477d) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-)
[calcite] 01/01: [CALCITE-4526] SqlSnapshot unparse lost the AS keyword when the table has alias (jibiyr)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit 39d477d96b90eca05e5af1cec0f8ae0617226b5d Author: laughing.sheng AuthorDate: Wed Mar 10 16:46:14 2021 +0800 [CALCITE-4526] SqlSnapshot unparse lost the AS keyword when the table has alias (jibiyr) For SQL: table_name FOR SYSTEM_TIME AS OF time_point AS table_alias, when SqlSnapshot's table has alias(the AS operator), the unparse result is wrong: the alias is missing but the name reference is still hold by other expression. close apache/calcite#2366 --- .../main/java/org/apache/calcite/sql/SqlSnapshot.java | 17 - .../org/apache/calcite/sql/parser/SqlParserTest.java| 9 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java b/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java index 07ecce7..4ccf3d1 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java @@ -127,8 +127,23 @@ public class SqlSnapshot extends SqlCall { int leftPrec, int rightPrec) { final SqlSnapshot snapshot = (SqlSnapshot) call; + SqlNode tableRef = snapshot.tableRef; + + if (tableRef instanceof SqlBasicCall + && ((SqlBasicCall) tableRef).getOperator() instanceof SqlAsOperator) { +SqlBasicCall basicCall = (SqlBasicCall) tableRef; +basicCall.operand(0).unparse(writer, 0, 0); +writer.setNeedWhitespace(true); +writeForSystemTimeAsOf(writer, snapshot); +writer.keyword("AS"); +basicCall.operand(1).unparse(writer, 0, 0); + } else { +tableRef.unparse(writer, 0, 0); +writeForSystemTimeAsOf(writer, snapshot); + } +} - snapshot.tableRef.unparse(writer, 0, 0); +private static void writeForSystemTimeAsOf(SqlWriter writer, SqlSnapshot snapshot) { writer.keyword("FOR SYSTEM_TIME AS OF"); snapshot.period.unparse(writer, 0, 0); } diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java index 1737908..8034698 100644 --- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java +++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java @@ -7766,6 +7766,15 @@ public class SqlParserTest { SqlParserUtil.addCarets("abcdef", 1, 7, 1, 7)); } + @Test void testSnapshotForSystemTimeWithAlias() { +sql("SELECT * FROM orders LEFT JOIN products FOR SYSTEM_TIME AS OF " ++ "orders.proctime as products ON orders.product_id = products.pro_id") +.ok("SELECT *\n" ++ "FROM `ORDERS`\n" ++ "LEFT JOIN `PRODUCTS` FOR SYSTEM_TIME AS OF `ORDERS`.`PROCTIME` AS `PRODUCTS` ON (`ORDERS`" ++ ".`PRODUCT_ID` = `PRODUCTS`.`PRO_ID`)"); + } + @Test protected void testMetadata() { SqlAbstractParserImpl.Metadata metadata = getSqlParser("").getMetadata(); assertThat(metadata.isReservedFunctionName("ABS"), is(true));
[calcite] branch master updated (e447ff8 -> 75b9440)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from e447ff8 [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions (Malte Bellmann) add 75b9440 [CALCITE-4526] Fixup the unparse's output of SqlSnapshot when the table has alias (jibiyr) No new revisions were added by this update. Summary of changes: .../java/org/apache/calcite/sql/SqlSnapshot.java | 23 -- .../apache/calcite/sql/parser/SqlParserTest.java | 9 + 2 files changed, 30 insertions(+), 2 deletions(-)
[calcite] branch master updated: [CALCITE-4265] Improve error message when CAST to unknown type (Louis Kuang)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 207bc8a [CALCITE-4265] Improve error message when CAST to unknown type (Louis Kuang) 207bc8a is described below commit 207bc8a0d731fa40e84309dfea3f8189b383e117 Author: Louis Kuang AuthorDate: Wed Jan 13 21:31:38 2021 -0500 [CALCITE-4265] Improve error message when CAST to unknown type (Louis Kuang) If SqlNode is an Identifier node whose type can not be derived, throws a validation error instead of an UnsupportedOperationException to improve error message. close apache/calcite#2326 --- .../java/org/apache/calcite/sql/validate/SqlValidatorImpl.java | 3 +++ .../test/java/org/apache/calcite/test/SqlValidatorTest.java| 10 +- 2 files changed, 8 insertions(+), 5 deletions(-) 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 53c3f09..e83d213 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 @@ -1759,6 +1759,9 @@ public class SqlValidatorImpl implements SqlValidatorWithHints { @Override public RelDataType getValidatedNodeType(SqlNode node) { RelDataType type = getValidatedNodeTypeIfKnown(node); if (type == null) { + if (node.getKind() == SqlKind.IDENTIFIER) { +throw newValidationError(node, RESOURCE.unknownIdentifier(node.toString())); + } throw Util.needToImplement(node); } else { return type; 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 679464b..cfab141 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -1244,8 +1244,8 @@ public class SqlValidatorTest extends SqlValidatorTestCase { } @Test void testCastRegisteredType() { -expr("cast(123 as customBigInt)") -.fails("class org.apache.calcite.sql.SqlIdentifier: CUSTOMBIGINT"); +expr("cast(123 as ^customBigInt^)") +.fails("Unknown identifier 'CUSTOMBIGINT'"); expr("cast(123 as sales.customBigInt)") .columnType("BIGINT NOT NULL"); expr("cast(123 as catalog.sales.customBigInt)") @@ -1254,7 +1254,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase { @Test void testCastFails() { expr("cast('foo' as ^bar^)") -.fails("class org.apache.calcite.sql.SqlIdentifier: BAR"); +.fails("Unknown identifier 'BAR'"); wholeExpr("cast(multiset[1] as integer)") .fails("(?s).*Cast function cannot convert value of type " + "INTEGER MULTISET to type INTEGER"); @@ -8007,9 +8007,9 @@ public class SqlValidatorTest extends SqlValidatorTestCase { + "VARCHAR(5) NOT NULL ARRAY NOT NULL F1) NOT NULL " + "ARRAY NOT NULL MULTISET NOT NULL"); // test UDT collection type. -sql("select cast(a as MyUDT array multiset) from COMPLEXTYPES.CTC_T1") +sql("select cast(a as ^MyUDT^ array multiset) from COMPLEXTYPES.CTC_T1") .withExtendedCatalog() -.fails("(?s).*class org\\.apache\\.calcite\\.sql\\.SqlIdentifier: MYUDT.*"); +.fails("Unknown identifier 'MYUDT'"); } @Test void testCastAsRowType() {
[calcite] branch master updated: [CALCITE-4479] 'vFloat in (1.0, 2.0)' throws UnsupportedOperationException
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 039fe49 [CALCITE-4479] 'vFloat in (1.0, 2.0)' throws UnsupportedOperationException 039fe49 is described below commit 039fe493e195416ee40c93b720f304ac9fc3c8c8 Author: yuzhao.cyz AuthorDate: Wed Jan 27 16:03:14 2021 +0800 [CALCITE-4479] 'vFloat in (1.0, 2.0)' throws UnsupportedOperationException --- core/src/main/java/org/apache/calcite/rex/RexLiteral.java | 8 +++- .../test/java/org/apache/calcite/rex/RexBuilderTest.java| 13 + 2 files changed, 20 insertions(+), 1 deletion(-) 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 f84ff1e..75da3b3 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java +++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java @@ -393,7 +393,10 @@ public class RexLiteral extends RexNode { } } - /** Returns the strict literal type for a given type. */ + /** + * Returns the strict literal type for a given type. The rules should keep + * sync with what {@link RexBuilder#makeLiteral} defines. + */ public static SqlTypeName strictTypeName(RelDataType type) { final SqlTypeName typeName = type.getSqlTypeName(); switch (typeName) { @@ -401,6 +404,9 @@ public class RexLiteral extends RexNode { case TINYINT: case SMALLINT: return SqlTypeName.DECIMAL; +case REAL: +case FLOAT: + return SqlTypeName.DOUBLE; case VARBINARY: return SqlTypeName.BINARY; case VARCHAR: 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 b4cf1a3..e08cfc4 100644 --- a/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java +++ b/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java @@ -25,6 +25,7 @@ import org.apache.calcite.rel.type.RelDataTypeFieldImpl; import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.rel.type.RelDataTypeSystemImpl; import org.apache.calcite.sql.SqlCollation; +import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.type.BasicSqlType; import org.apache.calcite.sql.type.SqlTypeFactoryImpl; @@ -610,6 +611,18 @@ class RexBuilderTest { checkBigDecimalLiteral(builder, "-73786976294838206464"); } + @Test void testMakeIn() { +final RelDataTypeFactory typeFactory = +new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); +final RexBuilder rexBuilder = new RexBuilder(typeFactory); +final RelDataType floatType = typeFactory.createSqlType(SqlTypeName.FLOAT); +RexNode left = rexBuilder.makeInputRef(floatType, 0); +final RexNode literal1 = rexBuilder.makeLiteral(1.0f, floatType); +final RexNode literal2 = rexBuilder.makeLiteral(2.0f, floatType); +RexNode inCall = rexBuilder.makeIn(left, ImmutableList.of(literal1, literal2)); +assertThat(inCall.getKind(), is(SqlKind.SEARCH)); + } + /** Tests {@link RexCopier#visitOver(RexOver)}. */ @Test void testCopyOver() { final RelDataTypeFactory sourceTypeFactory =
[calcite] branch master updated: [CALCITE-4456] Allows all the value expressions for explicit row value constructor
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 4d413bb [CALCITE-4456] Allows all the value expressions for explicit row value constructor 4d413bb is described below commit 4d413bb21fb0a18882c5066f1d75a02d5b021bac Author: yuzhao.cyz AuthorDate: Tue Jan 5 20:29:34 2021 +0800 [CALCITE-4456] Allows all the value expressions for explicit row value constructor As the SQL standard 2011 7.1 specifies, we should support all the value expression for explicit row value constructor. --- core/src/main/codegen/templates/Parser.jj | 2 +- .../org/apache/calcite/sql/parser/SqlParserTest.java| 8 .../org/apache/calcite/test/SqlToRelConverterTest.java | 9 + .../java/org/apache/calcite/test/SqlValidatorTest.java | 7 +++ .../org/apache/calcite/test/SqlToRelConverterTest.xml | 17 + 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 85f2921..3857911 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -3718,7 +3718,7 @@ SqlNode Expression3(ExprContext exprContext) : { s = span(); } -list = ParenthesizedSimpleIdentifierList() { +list = ParenthesizedQueryOrCommaList(exprContext) { if (exprContext != ExprContext.ACCEPT_ALL && exprContext != ExprContext.ACCEPT_CURSOR && !this.conformance.allowExplicitRowValueConstructor()) diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java index 4e89586..c0a97c5 100644 --- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java +++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java @@ -1287,6 +1287,14 @@ public class SqlParserTest { sql(sql) .withDialect(MSSQL) .ok(expected3); + +conformance = SqlConformanceEnum.DEFAULT; +expr("ROW(EMP.EMPNO, EMP.ENAME)").ok("(ROW(`EMP`.`EMPNO`, `EMP`.`ENAME`))"); +expr("ROW(EMP.EMPNO + 1, EMP.ENAME)").ok("(ROW((`EMP`.`EMPNO` + 1), `EMP`.`ENAME`))"); +expr("ROW((select deptno from dept where dept.deptno = emp.deptno), EMP.ENAME)") +.ok("(ROW((SELECT `DEPTNO`\n" ++ "FROM `DEPT`\n" ++ "WHERE (`DEPT`.`DEPTNO` = `EMP`.`DEPTNO`)), `EMP`.`ENAME`))"); } /** Whether this is a sub-class that tests un-parsing as well as parsing. */ diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 1f7f1a8..1f81198 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -101,6 +101,15 @@ class SqlToRelConverterTest extends SqlToRelTestBase { sql(sql).ok(); } + @Test void testRowValueConstructorWithSubquery() { +final String sql = "select ROW(" ++ "(select deptno\n" ++ "from dept\n" ++ "where dept.deptno = emp.deptno), emp.ename)\n" ++ "from emp"; +sql(sql).ok(); + } + @Test void testIntegerLiteral() { final String sql = "select 1 from emp"; sql(sql).ok(); 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 43f8139..a79d8a3 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -1641,6 +1641,13 @@ public class SqlValidatorTest extends SqlValidatorTestCase { sql("select t.r.\"EXPR$1\".\"EXPR$2\"\n" + "from (select ((1,2),(3,4,5)) r from dept) t") .columnType("INTEGER NOT NULL"); +sql("select row(emp.empno, emp.ename) from emp") +.columnType("RecordType(INTEGER NOT NULL EXPR$0, VARCHAR(20) NOT NULL EXPR$1) NOT NULL"); +sql("select row(emp.empno + 1, emp.ename) from emp") +.columnType("RecordType(INTEGER NOT NULL EXPR$0, VARCHAR(20) NOT NULL EXPR$1) NOT NULL"); +sql("select row((select deptno from dept where dept.deptno = emp.deptno), emp.ename)\n" ++ "from emp") +.columnType("RecordType(INTEGER EXPR$0, VARCHAR(20) NOT NULL EXPR$1) NOT NULL"); } @Test void testRowWithValidDot() { diff --git a/core/src/test/resources/org/apache/cal
[calcite] branch master updated (3846b50 -> 61771cc)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 3846b50 [CALCITE-4277] When rel has been removed from its subset, skip the origin rule match (Jiatao Tao) add 61771cc [CALCITE-4406] SqlTableRef OPERATOR should create a SqlTableRef as the call No new revisions were added by this update. Summary of changes: .../main/java/org/apache/calcite/sql/SqlHint.java | 14 +++--- .../java/org/apache/calcite/sql/SqlTableRef.java | 8 +- .../apache/calcite/sql/parser/SqlParserTest.java | 31 -- 3 files changed, 41 insertions(+), 12 deletions(-)
[calcite] branch master updated (3846b50 -> 61771cc)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 3846b50 [CALCITE-4277] When rel has been removed from its subset, skip the origin rule match (Jiatao Tao) add 61771cc [CALCITE-4406] SqlTableRef OPERATOR should create a SqlTableRef as the call No new revisions were added by this update. Summary of changes: .../main/java/org/apache/calcite/sql/SqlHint.java | 14 +++--- .../java/org/apache/calcite/sql/SqlTableRef.java | 8 +- .../apache/calcite/sql/parser/SqlParserTest.java | 31 -- 3 files changed, 41 insertions(+), 12 deletions(-)
[calcite] branch master updated (c6b3fb7 -> 2d8fc5d)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from c6b3fb7 Add regression warning to prevent users from upgrading to 1.26.0 add 2d8fc5d Following [CALCITE-4364], fix the plan diff of TpcdsTest No new revisions were added by this update. Summary of changes: .../src/test/java/org/apache/calcite/adapter/tpcds/TpcdsTest.java | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-)
[calcite] branch master updated (c6b3fb7 -> 2d8fc5d)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from c6b3fb7 Add regression warning to prevent users from upgrading to 1.26.0 add 2d8fc5d Following [CALCITE-4364], fix the plan diff of TpcdsTest No new revisions were added by this update. Summary of changes: .../src/test/java/org/apache/calcite/adapter/tpcds/TpcdsTest.java | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-)
[calcite] branch master updated: Following 4364, fix the plann diff of TpcdsTest
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new c8b5622 Following 4364, fix the plann diff of TpcdsTest c8b5622 is described below commit c8b5622afc86294996ebec1ac323b4cbd3d478dc Author: yuzhao.cyz AuthorDate: Fri Nov 13 10:49:57 2020 +0800 Following 4364, fix the plann diff of TpcdsTest --- .../src/test/java/org/apache/calcite/adapter/tpcds/TpcdsTest.java | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plus/src/test/java/org/apache/calcite/adapter/tpcds/TpcdsTest.java b/plus/src/test/java/org/apache/calcite/adapter/tpcds/TpcdsTest.java index f0a868e..927167a 100644 --- a/plus/src/test/java/org/apache/calcite/adapter/tpcds/TpcdsTest.java +++ b/plus/src/test/java/org/apache/calcite/adapter/tpcds/TpcdsTest.java @@ -384,11 +384,9 @@ class TpcdsTest { + "LogicalSort(sort0=[$1], sort1=[$0], dir0=[ASC], dir1=[ASC], fetch=[100])\n" + " LogicalAggregate(group=[{84, 90}], AGG1=[AVG($10)], AGG2=[AVG($12)], AGG3=[AVG($19)], AGG4=[AVG($13)])\n" + "LogicalFilter(condition=[AND(=($0, $32), =($2, $89), " -+ "=($7, $60), =($4, $23), SEARCH($24, Sarg['M']:CHAR(1)), " -+ "SEARCH($25, Sarg['S']:CHAR(1)), " -+ "SEARCH($26, Sarg['HIGH SCHOOL']:CHAR(11)), " -+ "SEARCH($38, Sarg[1998]), SEARCH($84, Sarg['CA', 'MD', 'OK', 'OR', " -+ "'TX', 'WA']:CHAR(2)))])\n" ++ "=($7, $60), =($4, $23), =($24, 'M'), " ++ "=($25, 'S'), =($26, 'HIGH SCHOOL'), =($38, 1998), " ++ "SEARCH($84, Sarg['CA', 'MD', 'OK', 'OR', 'TX', 'WA']:CHAR(2)))])\n" + " LogicalJoin(condition=[true], joinType=[inner])\n" + "LogicalTableScan(table=[[TPCDS, STORE_SALES]])\n" + "LogicalJoin(condition=[true], joinType=[inner])\n"
[calcite] branch master updated: [CALCITE-4364] `a IN (1, 2) AND a = 1` should be simplified to `a = 1`
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 5e9943a [CALCITE-4364] `a IN (1, 2) AND a = 1` should be simplified to `a = 1` 5e9943a is described below commit 5e9943aa1f51a97068fc37d53dea1d447570becc Author: yuzhao.cyz AuthorDate: Thu Nov 5 15:01:59 2020 +0800 [CALCITE-4364] `a IN (1, 2) AND a = 1` should be simplified to `a = 1` --- .../java/org/apache/calcite/rex/RexSimplify.java | 90 --- .../main/java/org/apache/calcite/rex/RexUtil.java | 30 - .../java/org/apache/calcite/util/RangeSets.java| 12 ++ .../org/apache/calcite/rex/RexProgramTest.java | 128 ++--- .../org/apache/calcite/test/RelBuilderTest.java| 6 +- .../java/org/apache/calcite/util/RangeSetTest.java | 32 ++ .../org/apache/calcite/test/RelOptRulesTest.xml| 10 +- core/src/test/resources/sql/sub-query.iq | 2 +- .../org/apache/calcite/test/DruidAdapter2IT.java | 8 +- .../org/apache/calcite/test/DruidAdapterIT.java| 8 +- 10 files changed, 250 insertions(+), 76 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java index 65b3ba3..06acfb5 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java @@ -1330,7 +1330,7 @@ public class RexSimplify { final SargCollector sargCollector = new SargCollector(rexBuilder, true); operands.forEach(t -> sargCollector.accept(t, terms)); -if (sargCollector.map.values().stream().anyMatch(b -> b.complexity() > 1)) { +if (sargCollector.needToFix(unknownAs)) { operands.clear(); terms.forEach(t -> operands.add(sargCollector.fix(rexBuilder, t))); } @@ -1797,7 +1797,7 @@ public class RexSimplify { final SargCollector sargCollector = new SargCollector(rexBuilder, false); final List newTerms = new ArrayList<>(); terms.forEach(t -> sargCollector.accept(t, newTerms)); -if (sargCollector.map.values().stream().anyMatch(b -> b.complexity() > 1)) { +if (sargCollector.needToFix(unknownAs)) { terms.clear(); newTerms.forEach(t -> terms.add(sargCollector.fix(rexBuilder, t))); } @@ -2591,6 +2591,12 @@ public class RexSimplify { final Map map = new HashMap<>(); private final RexBuilder rexBuilder; private final boolean negate; +/** + * Count of the new terms after converting all the operands to + * {@code SEARCH} on a {@link Sarg}. It is used to decide whether + * the new terms are simpler. + */ +private int newTermsCount; SargCollector(RexBuilder rexBuilder, boolean negate) { this.rexBuilder = rexBuilder; @@ -2601,6 +2607,7 @@ public class RexSimplify { if (!accept_(term, newTerms)) { newTerms.add(term); } + newTermsCount = newTerms.size(); } private boolean accept_(RexNode e, List newTerms) { @@ -2710,14 +2717,76 @@ public class RexSimplify { } } +/** + * Returns whether the merged {@code sarg} with given {@code unknownAs} keeps the semantics, + * The merge can not go ahead if the semantics change. + * + * @return true if the semantics does not change + */ +private static boolean canMerge(Sarg sarg, RexUnknownAs unknownAs) { + final boolean isAllOrNone = sarg.isAll() || sarg.isNone(); + final boolean containsNull = sarg.containsNull; + switch (unknownAs) { + case UNKNOWN: +// "unknown as unknown" can not be simplified to +// "IS NULL"/"IS NOT NULL"/"TRUE"/"FALSE" +return !isAllOrNone; + case TRUE: +// "unknown as true" can not be simplified to +// "false" or "IS NOT NULL" +return containsNull || !isAllOrNone; + case FALSE: +// "unknown as false" can not be simplified to +// "true" or "IS NULL" +return !containsNull || !isAllOrNone; + default: +return true; + } +} + +/** Returns whether it is worth to fix and convert to {@code SEARCH} calls. */ +boolean needToFix(RexUnknownAs unknownAs) { + // Fix and converts to SEARCH if: + // 1. A Sarg has complexity greater than 1; + // 2. The terms are reduced as simpler Sarg points; + // 3. The terms are reduced as simpler Sarg comparison. + + // Ignore 'negate' just to be compatible with previous versions of this + // method. "build().complexity()" would be a better estimate, if we could + // switch to it breaking lots of plans. + final Collection builders = map.values(); + if
[calcite] branch master updated: [CALCITE-4233] Adding dismax API QueryBuilder (shlok7296)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new b20e0bf [CALCITE-4233] Adding dismax API QueryBuilder (shlok7296) b20e0bf is described below commit b20e0bf6ca9b605fa4a6203bd06454abd6a98ce2 Author: impadmin AuthorDate: Thu Oct 15 17:15:17 2020 +0530 [CALCITE-4233] Adding dismax API QueryBuilder (shlok7296) close apache/calcite#2218 --- .../adapter/elasticsearch/ElasticsearchFilter.java | 17 - .../adapter/elasticsearch/QueryBuilders.java | 37 +++ .../elasticsearch/ElasticSearchAdapterTest.java| 41 ++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchFilter.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchFilter.java index dee9753..ff6e72b 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchFilter.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchFilter.java @@ -23,7 +23,9 @@ import org.apache.calcite.plan.RelTraitSet; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.Filter; import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlKind; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; @@ -31,6 +33,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.io.StringWriter; import java.io.UncheckedIOException; +import java.util.Iterator; import java.util.Objects; /** @@ -82,7 +85,19 @@ public class ElasticsearchFilter extends Filter implements ElasticsearchRel { StringWriter writer = new StringWriter(); JsonGenerator generator = mapper.getFactory().createGenerator(writer); - QueryBuilders.constantScoreQuery(PredicateAnalyzer.analyze(condition)).writeJson(generator); + boolean disMax = condition.isA(SqlKind.OR); + Iterator operands = ((RexCall) condition).getOperands().iterator(); + while (operands.hasNext() && !disMax) { +if (operands.next().isA(SqlKind.OR)) { + disMax = true; + break; +} + } + if (disMax) { + QueryBuilders.disMaxQueryBuilder(PredicateAnalyzer.analyze(condition)).writeJson(generator); + } else { + QueryBuilders.constantScoreQuery(PredicateAnalyzer.analyze(condition)).writeJson(generator); + } generator.flush(); generator.close(); return "{\"query\" : " + writer.toString() + "}"; diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/QueryBuilders.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/QueryBuilders.java index afb4e72..c7fa164 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/QueryBuilders.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/QueryBuilders.java @@ -187,6 +187,16 @@ class QueryBuilders { } /** + * A query that wraps another query and simply returns a dismax score equal to the + * query boost for every document in the query. + * + * @param queryBuilder The query to wrap in a constant score query + */ + static DisMaxQueryBuilder disMaxQueryBuilder(QueryBuilder queryBuilder) { +return new DisMaxQueryBuilder(queryBuilder); + } + + /** * A filter to filter only documents where a field exists in them. * * @param name The name of the field @@ -541,6 +551,33 @@ class QueryBuilders { } /** + * A query that wraps a filter and simply returns a dismax score equal to the + * query boost for every document in the filter. + */ + static class DisMaxQueryBuilder extends QueryBuilder { + +private final QueryBuilder builder; + +private DisMaxQueryBuilder(final QueryBuilder builder) { + this.builder = Objects.requireNonNull(builder, "builder"); +} + +@Override void writeJson(final JsonGenerator generator) throws IOException { + generator.writeStartObject(); + generator.writeFieldName("dis_max"); + generator.writeStartObject(); + generator.writeFieldName("queries"); + generator.writeStartArray(); + builder.writeJson(generator); + generator.writeEndArray(); + generator.writeEndObject(); + generator.writeEndObject(); +} + } + + + + /** * A query that matches on all documents. * * { diff --git a/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/ElasticSearchAdapterTest.java b/
[calcite] branch master updated (d03ce47 -> e7c579f)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from d03ce47 [CALCITE-4352] RexSimplify incorrectly drops IS NULL and IS NOT NULL from SEARCH expressions add e7c579f [CALCITE-4106] Consider "listCoerced" in TypeCoercionImpl#inOperationCoercion (Jiatao Tao) No new revisions were added by this update. Summary of changes: .../java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java | 1 + 1 file changed, 1 insertion(+)
[calcite] branch master updated (c2527cc -> 3c7e2e3)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from c2527cc [CALCITE-4305] Implicit column alias for single-column VALUES, and UNNEST of ARRAY and MULTISET constructors add 3c7e2e3 [CALCITE-4225] Make RelDecorrelator pluggable No new revisions were added by this update. Summary of changes: .../apache/calcite/sql2rel/RelDecorrelator.java| 47 +- 1 file changed, 37 insertions(+), 10 deletions(-)
[calcite] branch master updated: [CALCITE-4240] SqlTypeUtil#getMaxPrecisionScaleDecimal returns a decimal that with same precision and scale (Jiatao Tao)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 16b22b1 [CALCITE-4240] SqlTypeUtil#getMaxPrecisionScaleDecimal returns a decimal that with same precision and scale (Jiatao Tao) 16b22b1 is described below commit 16b22b105dfcb3d95cc7af8eb54105f231d18cc9 Author: Jiatao Tao <245915...@qq.com> AuthorDate: Mon Sep 21 11:07:54 2020 +0800 [CALCITE-4240] SqlTypeUtil#getMaxPrecisionScaleDecimal returns a decimal that with same precision and scale (Jiatao Tao) The SqlTypeUtil#getMaxPrecisionScaleDecimal now returns decimal type with max precision and scale half of that. Previously it returns DECIMAL(19, 19) which is invalid. close apache/calcite#2161 --- .../org/apache/calcite/sql/type/SqlTypeUtil.java | 8 ++--- .../calcite/sql/test/SqlOperatorBaseTest.java | 34 +++--- .../apache/calcite/sql/type/SqlTypeUtilTest.java | 6 .../org/apache/calcite/test/SqlValidatorTest.java | 2 +- .../org/apache/calcite/test/TypeCoercionTest.java | 12 .../apache/calcite/test/SqlToRelConverterTest.xml | 2 +- .../org/apache/calcite/test/TopDownOptTest.xml | 8 ++--- .../org/apache/calcite/test/DruidAdapter2IT.java | 7 ++--- .../org/apache/calcite/test/DruidAdapterIT.java| 7 ++--- 9 files changed, 45 insertions(+), 41 deletions(-) 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 825e9e2..f1cd62b 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 @@ -1702,13 +1702,13 @@ public abstract class SqlTypeUtil { || SqlTypeUtil.isBoolean(type); } - /** Returns a DECIMAL type with the maximum precision/scale for the current + /** Returns a DECIMAL type with the maximum precision for the current * type system. */ public static RelDataType getMaxPrecisionScaleDecimal(RelDataTypeFactory factory) { int maxPrecision = factory.getTypeSystem().getMaxNumericPrecision(); -int maxScale = factory.getTypeSystem().getMaxNumericScale(); - -return factory.createSqlType(SqlTypeName.DECIMAL, maxPrecision, maxScale); +// scale should not greater than precision. +int scale = maxPrecision / 2; +return factory.createSqlType(SqlTypeName.DECIMAL, maxPrecision, scale); } /** diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java index ebf6e5c..ccf4e0c 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java +++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java @@ -3759,7 +3759,7 @@ public abstract class SqlOperatorBaseTest { "'a' + ^- 'b'^ + 'c'", "(?s)Cannot apply '-' to arguments of type '-'.*", false); -tester.checkType("'a' + - 'b' + 'c'", "DECIMAL(19, 19) NOT NULL"); +tester.checkType("'a' + - 'b' + 'c'", "DECIMAL(19, 9) NOT NULL"); tester.checkScalarExact("-1", "-1"); tester.checkScalarExact( "-1.23", @@ -5990,7 +5990,7 @@ public abstract class SqlOperatorBaseTest { "^round('abc', 'def')^", "Cannot apply 'ROUND' to arguments of type 'ROUND\\(, \\)'\\. Supported form\\(s\\): 'ROUND\\(, \\)'", false); -tester.checkType("round('abc', 'def')", "DECIMAL(19, 19) NOT NULL"); +tester.checkType("round('abc', 'def')", "DECIMAL(19, 9) NOT NULL"); tester.checkScalar( "round(42, -1)", 40, @@ -6032,7 +6032,7 @@ public abstract class SqlOperatorBaseTest { "^sign('abc')^", "Cannot apply 'SIGN' to arguments of type 'SIGN\\(\\)'\\. Supported form\\(s\\): 'SIGN\\(\\)'", false); -tester.checkType("sign('abc')", "DECIMAL(19, 19) NOT NULL"); +tester.checkType("sign('abc')", "DECIMAL(19, 9) NOT NULL"); tester.checkScalar( "sign(1)", 1, @@ -6162,7 +6162,7 @@ public abstract class SqlOperatorBaseTest { "^truncate('abc', 'def')^", "Cannot apply 'TRUNCATE' to arguments of type 'TRUNCATE\\(, \\)'\\. Supported form\\(s\\): 'TRUNCATE\\(, \\)'", false); -tester.checkType("truncate('abc', 'def')", "DECIMAL(19, 19) NOT NULL"); +tester.checkType("truncate('abc', 'def')", "DECIMAL(19, 9) NOT NULL"); tester.checkScalar( "truncate(42, -1)", 40, @@ -8520,7 +85
[calcite] branch master updated (ac96eb8 -> 74785aa)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from ac96eb8 [CALCITE-4297] Allow BigQuery to parse and validate Niladic functions (Mr. Swett) add 74785aa [CALCITE-4333] The Sort rel should be decorrelated even though it has fetch or limit when its parent is not a Correlate No new revisions were added by this update. Summary of changes: .../apache/calcite/sql2rel/RelDecorrelator.java| 25 + .../apache/calcite/test/SqlToRelConverterTest.java | 18 +++ .../apache/calcite/test/SqlToRelConverterTest.xml | 26 ++ 3 files changed, 60 insertions(+), 9 deletions(-)
[calcite] 01/01: [CALCITE-4297] Allow BigQuery to parse and validate Niladic functions (Mr. Swett)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit ac96ebc5009e781a31503288adf292000b80 Author: Justin Swett AuthorDate: Thu Oct 8 07:42:01 2020 -0700 [CALCITE-4297] Allow BigQuery to parse and validate Niladic functions (Mr. Swett) * Add CURRENT_DATETIME to SqlStdOperatorTable * Removed current_datetime from reserved words close apache/calcite#2203 --- .../calcite/sql/fun/SqlLibraryOperators.java | 8 ++ .../calcite/sql/validate/SqlConformanceEnum.java | 1 + .../calcite/sql/test/SqlOperatorBaseTest.java | 3 +++ .../org/apache/calcite/test/SqlValidatorTest.java | 31 ++ site/_docs/reference.md| 2 ++ 5 files changed, 45 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java index d578496..57d080e 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java @@ -212,6 +212,14 @@ public abstract class SqlLibraryOperators { ReturnTypes.DATE_NULLABLE, null, OperandTypes.STRING, SqlFunctionCategory.TIMEDATE); + /** The "CURRENT_DATETIME([timezone])" function. */ + @LibraryOperator(libraries = {BIG_QUERY}) + public static final SqlFunction CURRENT_DATETIME = + new SqlFunction("CURRENT_DATETIME", SqlKind.OTHER_FUNCTION, + ReturnTypes.TIMESTAMP.andThen(SqlTypeTransforms.TO_NULLABLE), null, + OperandTypes.or(OperandTypes.NILADIC, OperandTypes.STRING), + SqlFunctionCategory.TIMEDATE); + /** The "DATE_FROM_UNIX_DATE(integer)" function; returns a DATE value * a given number of seconds after 1970-01-01. */ @LibraryOperator(libraries = {BIG_QUERY}) diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java index 0bd37b9..30a41f1 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java @@ -277,6 +277,7 @@ public enum SqlConformanceEnum implements SqlConformance { case BABEL: case LENIENT: case MYSQL_5: +case BIG_QUERY: return true; default: return false; diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java index c4f5612..ebf6e5c 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java +++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java @@ -5642,6 +5642,9 @@ public abstract class SqlOperatorBaseTest { // parser. In the regular parser, DATE is a reserved keyword. tester.checkNull("\"DATE\"(null)"); tester.checkScalar("\"DATE\"('1985-12-06')", "1985-12-06", "DATE NOT NULL"); +tester.checkType("CURRENT_DATETIME()", "TIMESTAMP(0) NOT NULL"); +tester.checkType("CURRENT_DATETIME('America/Los_Angeles')", "TIMESTAMP(0) NOT NULL"); +tester.checkType("CURRENT_DATETIME(CAST(NULL AS VARCHAR(20)))", "TIMESTAMP(0)"); } @Test void testAbsFunc() { 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 8416c6c..70c78f4 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -56,6 +56,7 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.sql.validate.SqlValidatorUtil; import org.apache.calcite.test.catalog.CountingFactory; import org.apache.calcite.testlib.annotations.LocaleEnUs; +import org.apache.calcite.tools.ValidationException; import org.apache.calcite.util.Bug; import org.apache.calcite.util.ImmutableBitSet; @@ -361,6 +362,12 @@ public class SqlValidatorTest extends SqlValidatorTestCase { sql("SELECT +'abc' from (values(true))").ok(); } + @Test void testNiladicForBigQuery() { +sql("select current_time, current_time(), current_date, " ++ "current_date(), current_timestamp, current_timestamp()") +.withConformance(SqlConformanceEnum.BIG_QUERY).ok(); + } + @Test void testEqualNotEqual() { expr("''=''").ok(); expr("'abc'=n''").ok(); @@ -1492,6 +1499,30 @@ public class SqlValidatorTest extends SqlValidatorTestCase { + "Was expecting 2 arguments"); } + @Test void te
[calcite] branch master updated (c1435da -> ac96eb8)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. discard c1435da [CALCITE-4279] Allow BigQuery to parse and validate Niladic functions (Mr. Swett) new ac96eb8 [CALCITE-4297] Allow BigQuery to parse and validate Niladic functions (Mr. Swett) This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (c1435da) \ N -- N -- N refs/heads/master (ac96eb8) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes:
[calcite] branch master updated: [CALCITE-4279] Allow BigQuery to parse and validate Niladic functions (Mr. Swett)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new c1435da [CALCITE-4279] Allow BigQuery to parse and validate Niladic functions (Mr. Swett) c1435da is described below commit c1435da3b24274bb4d0a53a1b7c35a5ce166a5c1 Author: Justin Swett AuthorDate: Thu Oct 8 07:42:01 2020 -0700 [CALCITE-4279] Allow BigQuery to parse and validate Niladic functions (Mr. Swett) * Add CURRENT_DATETIME to SqlStdOperatorTable * Removed current_datetime from reserved words close apache/calcite#2203 --- .../calcite/sql/fun/SqlLibraryOperators.java | 8 ++ .../calcite/sql/validate/SqlConformanceEnum.java | 1 + .../calcite/sql/test/SqlOperatorBaseTest.java | 3 +++ .../org/apache/calcite/test/SqlValidatorTest.java | 31 ++ site/_docs/reference.md| 2 ++ 5 files changed, 45 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java index d578496..57d080e 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java @@ -212,6 +212,14 @@ public abstract class SqlLibraryOperators { ReturnTypes.DATE_NULLABLE, null, OperandTypes.STRING, SqlFunctionCategory.TIMEDATE); + /** The "CURRENT_DATETIME([timezone])" function. */ + @LibraryOperator(libraries = {BIG_QUERY}) + public static final SqlFunction CURRENT_DATETIME = + new SqlFunction("CURRENT_DATETIME", SqlKind.OTHER_FUNCTION, + ReturnTypes.TIMESTAMP.andThen(SqlTypeTransforms.TO_NULLABLE), null, + OperandTypes.or(OperandTypes.NILADIC, OperandTypes.STRING), + SqlFunctionCategory.TIMEDATE); + /** The "DATE_FROM_UNIX_DATE(integer)" function; returns a DATE value * a given number of seconds after 1970-01-01. */ @LibraryOperator(libraries = {BIG_QUERY}) diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java index 0bd37b9..30a41f1 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java @@ -277,6 +277,7 @@ public enum SqlConformanceEnum implements SqlConformance { case BABEL: case LENIENT: case MYSQL_5: +case BIG_QUERY: return true; default: return false; diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java index c4f5612..ebf6e5c 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java +++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java @@ -5642,6 +5642,9 @@ public abstract class SqlOperatorBaseTest { // parser. In the regular parser, DATE is a reserved keyword. tester.checkNull("\"DATE\"(null)"); tester.checkScalar("\"DATE\"('1985-12-06')", "1985-12-06", "DATE NOT NULL"); +tester.checkType("CURRENT_DATETIME()", "TIMESTAMP(0) NOT NULL"); +tester.checkType("CURRENT_DATETIME('America/Los_Angeles')", "TIMESTAMP(0) NOT NULL"); +tester.checkType("CURRENT_DATETIME(CAST(NULL AS VARCHAR(20)))", "TIMESTAMP(0)"); } @Test void testAbsFunc() { 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 8416c6c..70c78f4 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -56,6 +56,7 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.sql.validate.SqlValidatorUtil; import org.apache.calcite.test.catalog.CountingFactory; import org.apache.calcite.testlib.annotations.LocaleEnUs; +import org.apache.calcite.tools.ValidationException; import org.apache.calcite.util.Bug; import org.apache.calcite.util.ImmutableBitSet; @@ -361,6 +362,12 @@ public class SqlValidatorTest extends SqlValidatorTestCase { sql("SELECT +'abc' from (values(true))").ok(); } + @Test void testNiladicForBigQuery() { +sql("select current_time, current_time(), current_date, " ++ "current_date(), current_timestamp, current_timestamp()") +.withConformance(SqlConformanceEnum.BIG_QUERY).ok(); + } + @Test void testEqualNotEqual() { expr("''=''").ok(); expr
[calcite] branch master updated (ebefe52 -> c7fdae2)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from ebefe52 [CALCITE-4034] InnoDB adapter (neoremind) add c7fdae2 [CALCITE-4302] Improve cost propagation in volcano to avoid re-propagation (Botong Huang) No new revisions were added by this update. Summary of changes: .../org/apache/calcite/plan/volcano/RelSet.java| 27 ++-- .../org/apache/calcite/plan/volcano/RelSubset.java | 74 +- .../calcite/plan/volcano/VolcanoPlanner.java | 71 +++-- .../org/apache/calcite/test/DruidAdapter2IT.java | 29 + .../org/apache/calcite/test/DruidAdapterIT.java| 35 ++ 5 files changed, 110 insertions(+), 126 deletions(-)
[calcite] branch master updated (ebefe52 -> c7fdae2)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from ebefe52 [CALCITE-4034] InnoDB adapter (neoremind) add c7fdae2 [CALCITE-4302] Improve cost propagation in volcano to avoid re-propagation (Botong Huang) No new revisions were added by this update. Summary of changes: .../org/apache/calcite/plan/volcano/RelSet.java| 27 ++-- .../org/apache/calcite/plan/volcano/RelSubset.java | 74 +- .../calcite/plan/volcano/VolcanoPlanner.java | 71 +++-- .../org/apache/calcite/test/DruidAdapter2IT.java | 29 + .../org/apache/calcite/test/DruidAdapterIT.java| 35 ++ 5 files changed, 110 insertions(+), 126 deletions(-)
[calcite] branch master updated (0b2dfb7 -> 47f1f92)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 0b2dfb7 [CALCITE-4238] Create a default parser configuration, to reduce redundant information in sub-parsers add 47f1f92 [CALCITE-4210] Replaying subqueries in ON clauses (James Starr) No new revisions were added by this update. Summary of changes: .../apache/calcite/sql2rel/SqlToRelConverter.java | 233 ++--- .../apache/calcite/test/SqlToRelConverterTest.java | 42 .../apache/calcite/test/SqlToRelConverterTest.xml | 58 + 3 files changed, 258 insertions(+), 75 deletions(-)
[calcite] branch master updated (d70039d -> e0fa8ee)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from d70039d [CALCITE-4282] Promote the window table functions window attribute data type with precision 3 add e0fa8ee [CALCITE-4283] Do not force implement SqlTableFunction when creating table function scan No new revisions were added by this update. Summary of changes: .../org/apache/calcite/rel/core/RelFactories.java | 25 -- 1 file changed, 18 insertions(+), 7 deletions(-)
[calcite] branch master updated: [CALCITE-4282] Promote the window table functions window attribute data type with precision 3
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new d70039d [CALCITE-4282] Promote the window table functions window attribute data type with precision 3 d70039d is described below commit d70039ddda15112a6398765073572605fb01e23c Author: yuzhao.cyz AuthorDate: Mon Sep 28 10:13:00 2020 +0800 [CALCITE-4282] Promote the window table functions window attribute data type with precision 3 Now the window_start and window_end has a type of a Timestamp with default system precision. But, actually, many DB vendors has default precision as 6 (which is also defined in the SQL standard). We better promote the precision to 3 because: 1. For windowing, time unit as millisecond is enough 2. Make the precision deterministic instead of overriding by each engine's default one --- .../apache/calcite/sql/SqlWindowTableFunction.java | 6 ++-- .../apache/calcite/test/SqlToRelConverterTest.xml | 34 +++--- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java index e9d4494..82a1d75 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java @@ -103,13 +103,11 @@ public class SqlWindowTableFunction extends SqlFunction private static RelDataType inferRowType(SqlOperatorBinding opBinding) { final RelDataType inputRowType = opBinding.getOperandType(0); final RelDataTypeFactory typeFactory = opBinding.getTypeFactory(); -final RelDataType timestampType = -typeFactory.createSqlType(SqlTypeName.TIMESTAMP); return typeFactory.builder() .kind(inputRowType.getStructKind()) .addAll(inputRowType.getFieldList()) -.add("window_start", timestampType) -.add("window_end", timestampType) +.add("window_start", SqlTypeName.TIMESTAMP, 3) +.add("window_end", SqlTypeName.TIMESTAMP, 3) .build(); } diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index 519feec..85c8f71 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -5064,7 +5064,7 @@ from table(tumble(table Shipments, descriptor(rowtime), INTERVAL '1' MINUTE))]]> @@ -5082,7 +5082,7 @@ tumble( @@ -5100,7 +5100,7 @@ tumble( @@ -5117,10 +5117,10 @@ on a.orderid = b.orderid]]> @@ -5135,7 +5135,7 @@ from table(tumble(table Shipments, descriptor(rowtime), @@ -5149,7 +5149,7 @@ from table(hop(table Shipments, descriptor(rowtime), INTERVAL '1' MINUTE, INTERV @@ -5168,7 +5168,7 @@ hop( @@ -5187,7 +5187,7 @@ hop( @@ -5201,7 +5201,7 @@ from table(hop(table Shipments, descriptor(rowtime), INTERVAL '1' MINUTE, INTERV @@ -5215,7 +5215,7 @@ from table(session(table Shipments, descriptor(rowtime), descriptor(orderId), IN @@ -5234,7 +5234,7 @@ session( @@ -5253,7 +5253,7 @@ session( @@ -5267,7 +5267,7 @@ from table(tumble((select * from Shipments), descriptor(rowtime), INTERVAL '1' M @@ -5281,7 +5281,7 @@ from table(hop((select * from Shipments), descriptor(rowtime), INTERVAL '1' MINU @@ -5295,7 +5295,7 @@ from table(session((select * from Shipments), descriptor(rowtime), descriptor(or @@ -5309,7 +5309,7 @@ from table(session(table Orders, descriptor(rowtime), descriptor(orderId, produc
[calcite] branch master updated: [CALCITE-4206] RelDecorrelator outputs wrong plan for correlate sort with fetch limit
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 6842b70 [CALCITE-4206] RelDecorrelator outputs wrong plan for correlate sort with fetch limit 6842b70 is described below commit 6842b70b52d556f2be973df6090e0cb69d5f565d Author: yuzhao.cyz AuthorDate: Tue Sep 1 19:46:27 2020 +0800 [CALCITE-4206] RelDecorrelator outputs wrong plan for correlate sort with fetch limit Can not decorrelate if the sort has per-correlate-key attributes like offset or fetch limit, because these attributes scope would change to global after decorrelation. They should take effect within the scope of the correlation key actually. --- .../apache/calcite/sql2rel/RelDecorrelator.java| 12 -- .../apache/calcite/test/SqlToRelConverterTest.java | 17 .../apache/calcite/test/SqlToRelConverterTest.xml | 45 ++ 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java index 161439f..3c4020d 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java @@ -438,6 +438,13 @@ public class RelDecorrelator implements ReflectiveVisitor { // If input has not been rewritten, do not rewrite this rel. return null; } +// Can not decorrelate if the sort has per-correlate-key attributes like +// offset or fetch limit, because these attributes scope would change to +// global after decorrelation. They should take effect within the scope +// of the correlation key actually. +if (rel.offset != null || rel.fetch != null) { + return null; +} final RelNode newInput = frame.r; Mappings.TargetMapping mapping = @@ -448,12 +455,9 @@ public class RelDecorrelator implements ReflectiveVisitor { RelCollation oldCollation = rel.getCollation(); RelCollation newCollation = RexUtil.apply(mapping, oldCollation); -final int offset = rel.offset == null ? -1 : RexLiteral.intValue(rel.offset); -final int fetch = rel.fetch == null ? -1 : RexLiteral.intValue(rel.fetch); - final RelNode newSort = relBuilder .push(newInput) -.sortLimit(offset, fetch, relBuilder.fields(newCollation)) +.sortLimit(-1, -1, relBuilder.fields(newCollation)) .build(); // Sort does not change input ordering diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 38053e1..ea756cc 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -1247,6 +1247,23 @@ class SqlToRelConverterTest extends SqlToRelTestBase { sql(sql).ok(); } + /** Test case for + * https://issues.apache.org/jira/browse/CALCITE-4206;>[CALCITE-4206] + * RelDecorrelator outputs wrong plan for correlate sort with fetch limit. */ + @Test void testCorrelateSortWithLimit() { +final String sql = "SELECT deptno, ename \n" ++ "FROM\n" ++ " (SELECT DISTINCT deptno FROM emp) t1,\n" ++ " LATERAL (\n" ++ "SELECT ename, sal\n" ++ "FROM emp\n" ++ "WHERE deptno = t1.deptno\n" ++ "ORDER BY sal\n" ++ "DESC LIMIT 3\n" ++ " )"; +sql(sql).ok(); + } + @Test void testSample() { final String sql = "select * from emp tablesample substitute('DATASET1') where empno > 5"; diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index c3d2d74..b1eab2a 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -521,6 +521,33 @@ LogicalProject(DEPTNO=[$0], NUM=[$2]) ]]> + + + + + + + +
[calcite] branch master updated (103c73f -> e0480a9)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 103c73f [CALCITE-3920] Improve ORDER BY computation in Enumerable convention by exploiting LIMIT (Thomas Rebele) add e0480a9 [CALCITE-3399] Field-pruning for set operators (except UNION ALL) changes query semantics (Jin Xing) No new revisions were added by this update. Summary of changes: .../apache/calcite/sql2rel/RelFieldTrimmer.java| 14 ++- .../apache/calcite/test/SqlToRelConverterTest.java | 54 ++ .../apache/calcite/test/SqlToRelConverterTest.xml | 119 + 3 files changed, 186 insertions(+), 1 deletion(-)
[calcite] branch master updated: [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to retain ORDER BY in sub-query (Jiatao Tao) (part2)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 42785e4 [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to retain ORDER BY in sub-query (Jiatao Tao) (part2) 42785e4 is described below commit 42785e4f63f5d841655a8fdc4f9b81b310e33841 Author: yuzhao.cyz AuthorDate: Fri Sep 4 10:06:51 2020 +0800 [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to retain ORDER BY in sub-query (Jiatao Tao) (part2) Rename 'RemoveSortInSubquery' to 'RemoveSortInSubQuery'. --- .../apache/calcite/sql2rel/SqlToRelConverter.java | 34 +++--- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index 3da06dd..273e4b1 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -824,10 +824,10 @@ public class SqlToRelConverter { List orderExprList, SqlNode offset, SqlNode fetch) { -if (removeSortInSubquery(bb.top) +if (removeSortInSubQuery(bb.top) || select.getOrderList() == null || select.getOrderList().getList().isEmpty()) { - assert removeSortInSubquery(bb.top) || collation.getFieldCollations().isEmpty(); + assert removeSortInSubQuery(bb.top) || collation.getFieldCollations().isEmpty(); if ((offset == null || (offset instanceof SqlLiteral && ((SqlLiteral) offset).bigDecimalValue().equals(BigDecimal.ZERO))) @@ -868,10 +868,10 @@ public class SqlToRelConverter { /** * Returns whether we should remove the sort for the subsequent query conversion. * - * @param topQuery Whether the query is in the top level. + * @param top Whether the rel to convert is the root of the query */ - private boolean removeSortInSubquery(boolean topQuery) { -return config.isRemoveSortInSubquery() && !topQuery; + private boolean removeSortInSubQuery(boolean top) { +return config.isRemoveSortInSubQuery() && !top; } /** @@ -3258,7 +3258,7 @@ public class SqlToRelConverter { return; } -if (removeSortInSubquery(bb.top)) { +if (removeSortInSubQuery(bb.top)) { SqlNode offset = select.getOffset(); if ((offset == null || (offset instanceof SqlLiteral @@ -5882,7 +5882,7 @@ public class SqlToRelConverter { * * Default is true. */ -boolean isRemoveSortInSubquery(); +boolean isRemoveSortInSubQuery(); } /** Builder for a {@link Config}. */ @@ -5892,7 +5892,7 @@ public class SqlToRelConverter { private boolean createValuesRel = true; private boolean explain; private boolean expand = true; -private boolean removeSortInSubquery = true; +private boolean removeSortInSubQuery = true; private int inSubQueryThreshold = DEFAULT_IN_SUB_QUERY_THRESHOLD; private UnaryOperator relBuilderConfigTransform = c -> c.withPushJoinCondition(true); @@ -5908,7 +5908,7 @@ public class SqlToRelConverter { this.createValuesRel = config.isCreateValuesRel(); this.explain = config.isExplain(); this.expand = config.isExpand(); - this.removeSortInSubquery = config.isRemoveSortInSubquery(); + this.removeSortInSubQuery = config.isRemoveSortInSubQuery(); this.inSubQueryThreshold = config.getInSubQueryThreshold(); this.relBuilderConfigTransform = config.getRelBuilderConfigTransform(); this.relBuilderFactory = config.getRelBuilderFactory(); @@ -5941,8 +5941,8 @@ public class SqlToRelConverter { return this; } -public ConfigBuilder withRemoveSortInSubQuery(boolean removeSortInSubquery) { - this.removeSortInSubquery = removeSortInSubquery; +public ConfigBuilder withRemoveSortInSubQuery(boolean removeSortInSubQuery) { + this.removeSortInSubQuery = removeSortInSubQuery; return this; } @@ -5984,7 +5984,7 @@ public class SqlToRelConverter { /** Builds a {@link Config}. */ public Config build() { return new ConfigImpl(decorrelationEnabled, - trimUnusedFields, createValuesRel, explain, expand, removeSortInSubquery, + trimUnusedFields, createValuesRel, explain, expand, removeSortInSubQuery, inSubQueryThreshold, relBuilderConfigTransform, relBuilderFactory, hintStrategyTable); } @@ -5998,7 +5998,7 @@ public class SqlToRelConverter { private final boolean createValuesRel; private final boolean explain; private final boolean expand; -private final boolean removeSortInSubquery; +private final boolean removeSortInSubQuery; private fi
[calcite] branch master updated: [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to retain ORDER BY in sub-query (Jiatao Tao)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 734a7ac [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to retain ORDER BY in sub-query (Jiatao Tao) 734a7ac is described below commit 734a7acd4cef2e3c2ef529844cf34e9fa8173aea Author: Jiatao Tao <245915...@qq.com> AuthorDate: Tue Sep 1 12:50:17 2020 +0800 [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to retain ORDER BY in sub-query (Jiatao Tao) close apache/calcite#2127 --- .../apache/calcite/sql2rel/SqlToRelConverter.java | 41 +++--- .../apache/calcite/test/SqlToRelConverterTest.java | 6 .../apache/calcite/test/SqlToRelConverterTest.xml | 19 ++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index 1b0a25c..3da06dd 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -824,10 +824,10 @@ public class SqlToRelConverter { List orderExprList, SqlNode offset, SqlNode fetch) { -if (!bb.top +if (removeSortInSubquery(bb.top) || select.getOrderList() == null || select.getOrderList().getList().isEmpty()) { - assert !bb.top || collation.getFieldCollations().isEmpty(); + assert removeSortInSubquery(bb.top) || collation.getFieldCollations().isEmpty(); if ((offset == null || (offset instanceof SqlLiteral && ((SqlLiteral) offset).bigDecimalValue().equals(BigDecimal.ZERO))) @@ -866,6 +866,15 @@ public class SqlToRelConverter { } /** + * Returns whether we should remove the sort for the subsequent query conversion. + * + * @param topQuery Whether the query is in the top level. + */ + private boolean removeSortInSubquery(boolean topQuery) { +return config.isRemoveSortInSubquery() && !topQuery; + } + + /** * Returns whether a given node contains a {@link SqlInOperator}. * * @param node a RexNode tree @@ -3249,7 +3258,7 @@ public class SqlToRelConverter { return; } -if (!bb.top) { +if (removeSortInSubquery(bb.top)) { SqlNode offset = select.getOffset(); if ((offset == null || (offset instanceof SqlLiteral @@ -5865,6 +5874,15 @@ public class SqlToRelConverter { * the relational expressions. Default is * {@link HintStrategyTable#EMPTY}. */ HintStrategyTable getHintStrategyTable(); + +/** + * Returns whether to remove sort operator for a sub-query + * if the sort has no offset and fetch limit attributes. + * Because the remove does not change the semantics, in many cases, this is a promotion. + * + * Default is true. + */ +boolean isRemoveSortInSubquery(); } /** Builder for a {@link Config}. */ @@ -5874,6 +5892,7 @@ public class SqlToRelConverter { private boolean createValuesRel = true; private boolean explain; private boolean expand = true; +private boolean removeSortInSubquery = true; private int inSubQueryThreshold = DEFAULT_IN_SUB_QUERY_THRESHOLD; private UnaryOperator relBuilderConfigTransform = c -> c.withPushJoinCondition(true); @@ -5889,6 +5908,7 @@ public class SqlToRelConverter { this.createValuesRel = config.isCreateValuesRel(); this.explain = config.isExplain(); this.expand = config.isExpand(); + this.removeSortInSubquery = config.isRemoveSortInSubquery(); this.inSubQueryThreshold = config.getInSubQueryThreshold(); this.relBuilderConfigTransform = config.getRelBuilderConfigTransform(); this.relBuilderFactory = config.getRelBuilderFactory(); @@ -5921,6 +5941,11 @@ public class SqlToRelConverter { return this; } +public ConfigBuilder withRemoveSortInSubQuery(boolean removeSortInSubquery) { + this.removeSortInSubquery = removeSortInSubquery; + return this; +} + /** Whether to push down join conditions; default true. */ public ConfigBuilder withPushJoinCondition(boolean pushJoinCondition) { return withRelBuilderConfigTransform( @@ -5959,7 +5984,7 @@ public class SqlToRelConverter { /** Builds a {@link Config}. */ public Config build() { return new ConfigImpl(decorrelationEnabled, - trimUnusedFields, createValuesRel, explain, expand, + trimUnusedFields, createValuesRel, explain, expand, removeSortInSubquery, inSubQueryThreshold, relBuilderConfigTransform, relBuilderFactory, hintStrategyTable); } @@ -5973,6 +5998,7 @@ public class SqlToRelConverter { private fina
[calcite] branch master updated: [CALCITE-4180] Supports Elasticsearch basic authentication (fageiguanbing)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new e9f9261 [CALCITE-4180] Supports Elasticsearch basic authentication (fageiguanbing) e9f9261 is described below commit e9f926165c035ff62942dea318c5820ed69c1124 Author: fageiguanbing AuthorDate: Thu Aug 27 16:39:27 2020 +0800 [CALCITE-4180] Supports Elasticsearch basic authentication (fageiguanbing) close apache/calcite#2123 --- .../elasticsearch/ElasticsearchSchemaFactory.java | 23 -- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java index 0cf3ef0..8a1f340 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java @@ -21,11 +21,16 @@ import org.apache.calcite.schema.SchemaFactory; import org.apache.calcite.schema.SchemaPlus; import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; @@ -88,7 +93,9 @@ public class ElasticsearchSchemaFactory implements SchemaFactory { } final String pathPrefix = (String) map.get("pathPrefix"); // create client - final RestClient client = connect(hosts, pathPrefix); + String username = (String) map.get("username"); + String password = (String) map.get("password"); + final RestClient client = connect(hosts, pathPrefix, username, password); final String index = (String) map.get("index"); return new ElasticsearchSchema(client, new ObjectMapper(), index); @@ -101,14 +108,26 @@ public class ElasticsearchSchemaFactory implements SchemaFactory { * Builds Elastic rest client from user configuration. * * @param hosts list of ES HTTP Hosts to connect to + * @param username the username of ES + * @param password the password of ES * @return newly initialized low-level rest http client for ES */ - private static RestClient connect(List hosts, String pathPrefix) { + private static RestClient connect(List hosts, String pathPrefix, +String username, String password) { Objects.requireNonNull(hosts, "hosts or coordinates"); Preconditions.checkArgument(!hosts.isEmpty(), "no ES hosts specified"); RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()])); + +if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) { + CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, + new UsernamePasswordCredentials(username, password)); + builder.setHttpClientConfigCallback(httpClientBuilder -> + httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); +} + if (pathPrefix != null && !pathPrefix.isEmpty()) { builder.setPathPrefix(pathPrefix); }
[calcite] branch master updated: [CALCITE-4172] Expand columnar identifiers before resolving (James Starr)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 468b111 [CALCITE-4172] Expand columnar identifiers before resolving (James Starr) 468b111 is described below commit 468b111b3cae44efd31e60c4bafe0018c8821e9a Author: James Starr AuthorDate: Wed Aug 12 13:16:21 2020 -0700 [CALCITE-4172] Expand columnar identifiers before resolving (James Starr) close apache/calcite#2108 --- .../calcite/sql/validate/SqlValidatorImpl.java | 2 +- .../org/apache/calcite/test/SqlValidatorTest.java | 93 +- 2 files changed, 91 insertions(+), 4 deletions(-) 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 9123f92..5782ee7 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 @@ -3997,7 +3997,6 @@ public class SqlValidatorImpl implements SqlValidatorWithHints { final String clause = "GROUP BY"; validateNoAggs(aggOrOverFinder, groupList, clause); final SqlValidatorScope groupScope = getGroupScope(select); -inferUnknownTypes(unknownType, groupScope, groupList); // expand the expression in group list. List expandedList = new ArrayList<>(); @@ -4007,6 +4006,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints { } groupList = new SqlNodeList(expandedList, groupList.getParserPosition()); select.setGroupBy(groupList); +inferUnknownTypes(unknownType, groupScope, groupList); for (SqlNode groupItem : expandedList) { validateGroupByItem(select, groupItem); } 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 b9d7ed6..3623a18 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -25,31 +25,40 @@ import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.runtime.CalciteContextException; import org.apache.calcite.sql.SqlCollation; +import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.SqlOperatorTable; +import org.apache.calcite.sql.SqlSelect; import org.apache.calcite.sql.SqlSpecialOperator; import org.apache.calcite.sql.fun.SqlLibrary; import org.apache.calcite.sql.fun.SqlLibraryOperatorTableFactory; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParseException; import org.apache.calcite.sql.parser.SqlParser; +import org.apache.calcite.sql.test.SqlTestFactory; +import org.apache.calcite.sql.test.SqlValidatorTester; 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.SqlShuttle; +import org.apache.calcite.sql.validate.SelectScope; import org.apache.calcite.sql.validate.SqlAbstractConformance; import org.apache.calcite.sql.validate.SqlConformance; import org.apache.calcite.sql.validate.SqlConformanceEnum; import org.apache.calcite.sql.validate.SqlDelegatingConformance; import org.apache.calcite.sql.validate.SqlMonotonicity; import org.apache.calcite.sql.validate.SqlValidator; +import org.apache.calcite.sql.validate.SqlValidatorImpl; +import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.sql.validate.SqlValidatorUtil; import org.apache.calcite.test.catalog.CountingFactory; import org.apache.calcite.testlib.annotations.LocaleEnUs; import org.apache.calcite.util.Bug; import org.apache.calcite.util.ImmutableBitSet; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Ordering; @@ -62,7 +71,6 @@ import java.io.StringReader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.Charset; -import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -83,6 +91,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static java.util.Arrays.asList; + /** * Concrete child class of {@link SqlValidatorTestCase}, containing lots of unit * tests. @@ -4082,7 +4092,7 @@ public class SqlValidatorTest extends SqlV
[calcite] branch master updated: [CALCITE-4172] Expand columnar identifiers before resolving (James Starr)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 468b111 [CALCITE-4172] Expand columnar identifiers before resolving (James Starr) 468b111 is described below commit 468b111b3cae44efd31e60c4bafe0018c8821e9a Author: James Starr AuthorDate: Wed Aug 12 13:16:21 2020 -0700 [CALCITE-4172] Expand columnar identifiers before resolving (James Starr) close apache/calcite#2108 --- .../calcite/sql/validate/SqlValidatorImpl.java | 2 +- .../org/apache/calcite/test/SqlValidatorTest.java | 93 +- 2 files changed, 91 insertions(+), 4 deletions(-) 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 9123f92..5782ee7 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 @@ -3997,7 +3997,6 @@ public class SqlValidatorImpl implements SqlValidatorWithHints { final String clause = "GROUP BY"; validateNoAggs(aggOrOverFinder, groupList, clause); final SqlValidatorScope groupScope = getGroupScope(select); -inferUnknownTypes(unknownType, groupScope, groupList); // expand the expression in group list. List expandedList = new ArrayList<>(); @@ -4007,6 +4006,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints { } groupList = new SqlNodeList(expandedList, groupList.getParserPosition()); select.setGroupBy(groupList); +inferUnknownTypes(unknownType, groupScope, groupList); for (SqlNode groupItem : expandedList) { validateGroupByItem(select, groupItem); } 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 b9d7ed6..3623a18 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -25,31 +25,40 @@ import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.runtime.CalciteContextException; import org.apache.calcite.sql.SqlCollation; +import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.SqlOperatorTable; +import org.apache.calcite.sql.SqlSelect; import org.apache.calcite.sql.SqlSpecialOperator; import org.apache.calcite.sql.fun.SqlLibrary; import org.apache.calcite.sql.fun.SqlLibraryOperatorTableFactory; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParseException; import org.apache.calcite.sql.parser.SqlParser; +import org.apache.calcite.sql.test.SqlTestFactory; +import org.apache.calcite.sql.test.SqlValidatorTester; 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.SqlShuttle; +import org.apache.calcite.sql.validate.SelectScope; import org.apache.calcite.sql.validate.SqlAbstractConformance; import org.apache.calcite.sql.validate.SqlConformance; import org.apache.calcite.sql.validate.SqlConformanceEnum; import org.apache.calcite.sql.validate.SqlDelegatingConformance; import org.apache.calcite.sql.validate.SqlMonotonicity; import org.apache.calcite.sql.validate.SqlValidator; +import org.apache.calcite.sql.validate.SqlValidatorImpl; +import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.sql.validate.SqlValidatorUtil; import org.apache.calcite.test.catalog.CountingFactory; import org.apache.calcite.testlib.annotations.LocaleEnUs; import org.apache.calcite.util.Bug; import org.apache.calcite.util.ImmutableBitSet; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Ordering; @@ -62,7 +71,6 @@ import java.io.StringReader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.Charset; -import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -83,6 +91,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static java.util.Arrays.asList; + /** * Concrete child class of {@link SqlValidatorTestCase}, containing lots of unit * tests. @@ -4082,7 +4092,7 @@ public class SqlValidatorTest extends SqlV
[calcite] 01/01: [CALCITE-4171] Support named parameters for table window functions
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit e84f635020a6c3653b4f1456d64edb86efb2fea8 Author: yuzhao.cyz AuthorDate: Mon Aug 17 13:44:41 2020 +0800 [CALCITE-4171] Support named parameters for table window functions * Changes SqlArgumentAssignmentOperator to allow non-scala query as operand * In SqlCallBinding, matches the permuted operand by name with name matcher * Refactor SqlWindowTableFunction and its sub-class to reuse same logic * Do not patch up the SqlWindowTableFunction with DEFAULTs when sql validation --- .../calcite/adapter/enumerable/EnumUtils.java | 1 - .../apache/calcite/runtime/CalciteResource.java| 4 + .../org/apache/calcite/sql/SqlCallBinding.java | 45 +++-- .../apache/calcite/sql/SqlHopTableFunction.java| 88 .../calcite/sql/SqlSessionTableFunction.java | 78 -- .../apache/calcite/sql/SqlTumbleTableFunction.java | 82 --- .../apache/calcite/sql/SqlWindowTableFunction.java | 77 +- .../sql/fun/SqlArgumentAssignmentOperator.java | 4 + .../calcite/sql/validate/SqlValidatorImpl.java | 8 +- .../calcite/runtime/CalciteResource.properties | 1 + .../apache/calcite/test/SqlToRelConverterTest.java | 64 .../org/apache/calcite/test/SqlValidatorTest.java | 98 -- .../apache/calcite/test/SqlToRelConverterTest.xml | 112 + core/src/test/resources/sql/stream.iq | 61 +++ site/_docs/reference.md| 63 ++-- 15 files changed, 646 insertions(+), 140 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java index 87fd196..ae9455f 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java @@ -804,7 +804,6 @@ public class EnumUtils { expressions.add(expression); } final Expression wmColExprToLong = EnumUtils.convert(wmColExpr, long.class); -final Expression shiftExpr = Expressions.constant(1, long.class); // Find the fixed window for a timestamp given a window size and an offset, and return the // window start. diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java index 7987546..3aaec91 100644 --- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java +++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java @@ -220,6 +220,10 @@ public interface CalciteResource { @BaseMessage("Column ''{0}'' is ambiguous") ExInst columnAmbiguous(String a0); + @BaseMessage("Param ''{0}'' not found in function ''{1}''; did you mean ''{2}''?") + ExInst paramNotFoundInFunctionDidYouMean(String a0, + String a1, String a2); + @BaseMessage("Operand {0} must be a query") ExInst needQueryOp(String a0); diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java index d944812..ea6dad8 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java @@ -27,6 +27,7 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.sql.validate.SelectScope; import org.apache.calcite.sql.validate.SqlMonotonicity; +import org.apache.calcite.sql.validate.SqlNameMatcher; import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql.validate.SqlValidatorException; import org.apache.calcite.sql.validate.SqlValidatorNamespace; @@ -34,6 +35,7 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.sql.validate.SqlValidatorUtil; import org.apache.calcite.util.ImmutableNullableList; import org.apache.calcite.util.NlsString; +import org.apache.calcite.util.Pair; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; @@ -161,17 +163,42 @@ public class SqlCallBinding extends SqlOperatorBinding { * formal parameters of the function. */ private List permutedOperands(final SqlCall call) { final SqlFunction operator = (SqlFunction) call.getOperator(); -return Lists.transform(operator.getParamNames(), paramName -> { - for (SqlNode operand2 : call.getOperandList()) { -final SqlCall call2 = (SqlCall) operand2; -assert operand2.getKind() == SqlKind.ARGUMENT_ASSIGNMENT; -final SqlIdentifier id = call2.operand(1); -if (id.getSimple().equals(paramName)) { - return call2.opera
[calcite] branch master updated (ebbb7bb -> e84f635)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. omit ebbb7bb [CALCITE-4171] Support named parameters for table window functions new e84f635 [CALCITE-4171] Support named parameters for table window functions This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (ebbb7bb) \ N -- N -- N refs/heads/master (e84f635) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes:
[calcite] branch master updated (68b02df -> ebbb7bb)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 68b02df [CALCITE-4169] Release Calcite 1.25.0 new c1f8f75 [CALCITE-4167] Group by COALESCE IN throws NullPointerException new ebbb7bb [CALCITE-4171] Support named parameters for table window functions The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../calcite/adapter/enumerable/EnumUtils.java | 1 - .../apache/calcite/runtime/CalciteResource.java| 4 + .../org/apache/calcite/sql/SqlCallBinding.java | 45 ++-- .../apache/calcite/sql/SqlHopTableFunction.java| 88 +++--- .../calcite/sql/SqlSessionTableFunction.java | 78 - .../apache/calcite/sql/SqlTumbleTableFunction.java | 82 -- .../apache/calcite/sql/SqlWindowTableFunction.java | 77 - .../sql/fun/SqlArgumentAssignmentOperator.java | 4 + .../calcite/sql/validate/SqlValidatorImpl.java | 8 +- .../apache/calcite/sql2rel/SqlToRelConverter.java | 4 + .../calcite/runtime/CalciteResource.properties | 1 + .../apache/calcite/test/SqlToRelConverterTest.java | 76 + .../org/apache/calcite/test/SqlValidatorTest.java | 98 ++-- .../apache/calcite/test/SqlToRelConverterTest.xml | 126 + core/src/test/resources/sql/stream.iq | 61 ++ site/_docs/reference.md| 63 ++- 16 files changed, 676 insertions(+), 140 deletions(-)
[calcite] 01/02: [CALCITE-4167] Group by COALESCE IN throws NullPointerException
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit c1f8f7534aa2d27eef86cdf7522067c19f02db6a Author: yuzhao.cyz AuthorDate: Sat Aug 8 13:11:11 2020 +0800 [CALCITE-4167] Group by COALESCE IN throws NullPointerException The root cause is that the COALESCE operand type was wrongly replaced by `SqlToRelConverter#adjustInputRef`, actually, for an agg as bb root, there is no need to do such adjust. Because the nullability does not change and the agg type is not same with the bb's scope. Tweak the `#adjustInputRef` to only fix type nullability, if there are cases that the type name also changes, just return the original node and let the subsequent conversion work flow throw. --- .../java/org/apache/calcite/sql2rel/SqlToRelConverter.java | 4 .../org/apache/calcite/test/SqlToRelConverterTest.java | 12 .../org/apache/calcite/test/SqlToRelConverterTest.xml | 14 ++ 3 files changed, 30 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index 6483786..1b0a25c 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -3968,6 +3968,10 @@ public class SqlToRelConverter { RexInputRef inputRef) { RelDataTypeField field = bb.getRootField(inputRef); if (field != null) { + if (!SqlTypeUtil.equalSansNullability(typeFactory, + field.getType(), inputRef.getType())) { +return inputRef; + } return rexBuilder.makeInputRef( field.getType(), inputRef.getIndex()); diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 6eade46..4100557 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -3861,6 +3861,18 @@ class SqlToRelConverterTest extends SqlToRelTestBase { } /** + * Test case for + * https://issues.apache.org/jira/browse/CALCITE-4167;>[CALCITE-4167] + * Group by COALESCE IN throws NullPointerException. + */ + @Test void testGroupByCoalesceIn() { +final String sql = "select case when coalesce(ename, 'a') in ('1', '2')\n" ++ "then 'CKA' else 'QT' END, count(distinct deptno) from emp\n" ++ "group by case when coalesce(ename, 'a') in ('1', '2') then 'CKA' else 'QT' END"; +sql(sql).ok(); + } + + /** * Visitor that checks that every {@link RelNode} in a tree is valid. * * @see RelNode#isValid(Litmus, RelNode.Context) diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index 2f88b96..2758df7 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -6909,4 +6909,18 @@ LogicalProject(DEPTNO=[$0], F0=[STRUCTURED_FUNC().F0], F1=[STRUCTURED_FUNC().F1] ]]> + + + + + + + +
[calcite] 02/02: [CALCITE-4171] Support named parameters for table window functions
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit ebbb7bb88eb5a732ff954790373fe8d62eb5b8ab Author: yuzhao.cyz AuthorDate: Mon Aug 17 13:44:41 2020 +0800 [CALCITE-4171] Support named parameters for table window functions [CALCITE-4171] Support named parameters for table window functions * Changes SqlArgumentAssignmentOperator to allow non-scala query as operand * In SqlCallBinding, matches the permuted operand by name with name matcher * Refactor SqlWindowTableFunction and its sub-class to reuse same logic * Do not patch up the SqlWindowTableFunction with DEFAULTs when sql validation --- .../calcite/adapter/enumerable/EnumUtils.java | 1 - .../apache/calcite/runtime/CalciteResource.java| 4 + .../org/apache/calcite/sql/SqlCallBinding.java | 45 +++-- .../apache/calcite/sql/SqlHopTableFunction.java| 88 .../calcite/sql/SqlSessionTableFunction.java | 78 -- .../apache/calcite/sql/SqlTumbleTableFunction.java | 82 --- .../apache/calcite/sql/SqlWindowTableFunction.java | 77 +- .../sql/fun/SqlArgumentAssignmentOperator.java | 4 + .../calcite/sql/validate/SqlValidatorImpl.java | 8 +- .../calcite/runtime/CalciteResource.properties | 1 + .../apache/calcite/test/SqlToRelConverterTest.java | 64 .../org/apache/calcite/test/SqlValidatorTest.java | 98 -- .../apache/calcite/test/SqlToRelConverterTest.xml | 112 + core/src/test/resources/sql/stream.iq | 61 +++ site/_docs/reference.md| 63 ++-- 15 files changed, 646 insertions(+), 140 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java index 87fd196..ae9455f 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java @@ -804,7 +804,6 @@ public class EnumUtils { expressions.add(expression); } final Expression wmColExprToLong = EnumUtils.convert(wmColExpr, long.class); -final Expression shiftExpr = Expressions.constant(1, long.class); // Find the fixed window for a timestamp given a window size and an offset, and return the // window start. diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java index 7987546..3aaec91 100644 --- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java +++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java @@ -220,6 +220,10 @@ public interface CalciteResource { @BaseMessage("Column ''{0}'' is ambiguous") ExInst columnAmbiguous(String a0); + @BaseMessage("Param ''{0}'' not found in function ''{1}''; did you mean ''{2}''?") + ExInst paramNotFoundInFunctionDidYouMean(String a0, + String a1, String a2); + @BaseMessage("Operand {0} must be a query") ExInst needQueryOp(String a0); diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java index d944812..ea6dad8 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java @@ -27,6 +27,7 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.sql.validate.SelectScope; import org.apache.calcite.sql.validate.SqlMonotonicity; +import org.apache.calcite.sql.validate.SqlNameMatcher; import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql.validate.SqlValidatorException; import org.apache.calcite.sql.validate.SqlValidatorNamespace; @@ -34,6 +35,7 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.sql.validate.SqlValidatorUtil; import org.apache.calcite.util.ImmutableNullableList; import org.apache.calcite.util.NlsString; +import org.apache.calcite.util.Pair; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; @@ -161,17 +163,42 @@ public class SqlCallBinding extends SqlOperatorBinding { * formal parameters of the function. */ private List permutedOperands(final SqlCall call) { final SqlFunction operator = (SqlFunction) call.getOperator(); -return Lists.transform(operator.getParamNames(), paramName -> { - for (SqlNode operand2 : call.getOperandList()) { -final SqlCall call2 = (SqlCall) operand2; -assert operand2.getKind() == SqlKind.ARGUMENT_ASSIGNMENT; -final S
[calcite] branch master updated: [CALCITE-4167] Group by COALESCE IN throws NullPointerException
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new aadb605 [CALCITE-4167] Group by COALESCE IN throws NullPointerException aadb605 is described below commit aadb605decd6bb6a853e23fac4b0f479b2397e06 Author: yuzhao.cyz AuthorDate: Sat Aug 8 13:11:11 2020 +0800 [CALCITE-4167] Group by COALESCE IN throws NullPointerException The root cause is that the COALESCE operand type was wrongly replaced by `SqlToRelConverter#adjustInputRef`, actually, for an agg as bb root, there is no need to do such adjust. Because the nullability does not change and the agg type is not same with the bb's scope. Tweak the `#adjustInputRef` to only fix type nullability, if there are cases that the type name also changes, just return the original node and let the subsequent conversion work flow throw. --- .../java/org/apache/calcite/sql2rel/SqlToRelConverter.java | 4 .../org/apache/calcite/test/SqlToRelConverterTest.java | 12 .../org/apache/calcite/test/SqlToRelConverterTest.xml | 14 ++ 3 files changed, 30 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index 6483786..1b0a25c 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -3968,6 +3968,10 @@ public class SqlToRelConverter { RexInputRef inputRef) { RelDataTypeField field = bb.getRootField(inputRef); if (field != null) { + if (!SqlTypeUtil.equalSansNullability(typeFactory, + field.getType(), inputRef.getType())) { +return inputRef; + } return rexBuilder.makeInputRef( field.getType(), inputRef.getIndex()); diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 6eade46..4100557 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -3861,6 +3861,18 @@ class SqlToRelConverterTest extends SqlToRelTestBase { } /** + * Test case for + * https://issues.apache.org/jira/browse/CALCITE-4167;>[CALCITE-4167] + * Group by COALESCE IN throws NullPointerException. + */ + @Test void testGroupByCoalesceIn() { +final String sql = "select case when coalesce(ename, 'a') in ('1', '2')\n" ++ "then 'CKA' else 'QT' END, count(distinct deptno) from emp\n" ++ "group by case when coalesce(ename, 'a') in ('1', '2') then 'CKA' else 'QT' END"; +sql(sql).ok(); + } + + /** * Visitor that checks that every {@link RelNode} in a tree is valid. * * @see RelNode#isValid(Litmus, RelNode.Context) diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index 2f88b96..2758df7 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -6909,4 +6909,18 @@ LogicalProject(DEPTNO=[$0], F0=[STRUCTURED_FUNC().F0], F1=[STRUCTURED_FUNC().F1] ]]> + + + + + + + +
[calcite] branch master updated: [CALCITE-4167] Group by COALESCE IN throws NullPointerException
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new aadb605 [CALCITE-4167] Group by COALESCE IN throws NullPointerException aadb605 is described below commit aadb605decd6bb6a853e23fac4b0f479b2397e06 Author: yuzhao.cyz AuthorDate: Sat Aug 8 13:11:11 2020 +0800 [CALCITE-4167] Group by COALESCE IN throws NullPointerException The root cause is that the COALESCE operand type was wrongly replaced by `SqlToRelConverter#adjustInputRef`, actually, for an agg as bb root, there is no need to do such adjust. Because the nullability does not change and the agg type is not same with the bb's scope. Tweak the `#adjustInputRef` to only fix type nullability, if there are cases that the type name also changes, just return the original node and let the subsequent conversion work flow throw. --- .../java/org/apache/calcite/sql2rel/SqlToRelConverter.java | 4 .../org/apache/calcite/test/SqlToRelConverterTest.java | 12 .../org/apache/calcite/test/SqlToRelConverterTest.xml | 14 ++ 3 files changed, 30 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index 6483786..1b0a25c 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -3968,6 +3968,10 @@ public class SqlToRelConverter { RexInputRef inputRef) { RelDataTypeField field = bb.getRootField(inputRef); if (field != null) { + if (!SqlTypeUtil.equalSansNullability(typeFactory, + field.getType(), inputRef.getType())) { +return inputRef; + } return rexBuilder.makeInputRef( field.getType(), inputRef.getIndex()); diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 6eade46..4100557 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -3861,6 +3861,18 @@ class SqlToRelConverterTest extends SqlToRelTestBase { } /** + * Test case for + * https://issues.apache.org/jira/browse/CALCITE-4167;>[CALCITE-4167] + * Group by COALESCE IN throws NullPointerException. + */ + @Test void testGroupByCoalesceIn() { +final String sql = "select case when coalesce(ename, 'a') in ('1', '2')\n" ++ "then 'CKA' else 'QT' END, count(distinct deptno) from emp\n" ++ "group by case when coalesce(ename, 'a') in ('1', '2') then 'CKA' else 'QT' END"; +sql(sql).ok(); + } + + /** * Visitor that checks that every {@link RelNode} in a tree is valid. * * @see RelNode#isValid(Litmus, RelNode.Context) diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index 2f88b96..2758df7 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -6909,4 +6909,18 @@ LogicalProject(DEPTNO=[$0], F0=[STRUCTURED_FUNC().F0], F1=[STRUCTURED_FUNC().F1] ]]> + + + + + + + +
[calcite] branch master updated: [CALCITE-4145] Exception when query from UDF field with structured type
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new c52f0e5 [CALCITE-4145] Exception when query from UDF field with structured type c52f0e5 is described below commit c52f0e527c86f6a6b18e138310359ac0c72ca529 Author: yuzhao.cyz AuthorDate: Wed Jul 29 10:49:50 2020 +0800 [CALCITE-4145] Exception when query from UDF field with structured type --- .../org/apache/calcite/rex/RexFieldAccess.java | 13 - .../org/apache/calcite/sql/type/SqlTypeUtil.java | 8 ++ .../apache/calcite/test/MockSqlOperatorTable.java | 32 ++ .../apache/calcite/test/SqlToRelConverterTest.java | 11 .../apache/calcite/test/SqlToRelConverterTest.xml | 12 5 files changed, 70 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java index a7b318e..bd05202 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java +++ b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java @@ -20,6 +20,8 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.sql.SqlKind; +import com.google.common.base.Preconditions; + /** * Access to a field of a row-expression. * @@ -57,14 +59,23 @@ public class RexFieldAccess extends RexNode { RexFieldAccess( RexNode expr, RelDataTypeField field) { +checkValid(expr, field); this.expr = expr; this.field = field; this.digest = expr + "." + field.getName(); -assert expr.getType().getFieldList().get(field.getIndex()) == field; } //~ Methods + private static void checkValid(RexNode expr, RelDataTypeField field) { +RelDataType exprType = expr.getType(); +int fieldIdx = field.getIndex(); +Preconditions.checkArgument( +fieldIdx < exprType.getFieldList().size() +&& exprType.getFieldList().get(fieldIdx).equals(field), +"Field " + field + " does not exist for expression " + expr); + } + public RelDataTypeField getField() { return field; } 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 eb1aafd..3ba355c 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 @@ -1261,6 +1261,10 @@ public abstract class SqlTypeUtil { * Returns the ordinal of a given field in a record type, or -1 if the field * is not found. * + * The {@code fieldName} is always simple, if the field is nested within a record field, + * returns index of the outer field instead. i.g. for row type + * (a int, b (b1 bigint, b2 varchar(20) not null)), returns 1 for both simple name "b1" and "b2". + * * @param type Record type * @param fieldName Name of field * @return Ordinal of field @@ -1272,6 +1276,10 @@ public abstract class SqlTypeUtil { if (field.getName().equals(fieldName)) { return i; } + final RelDataType fieldType = field.getType(); + if (fieldType.isStruct() && findField(fieldType, fieldName) != -1) { +return i; + } } return -1; } diff --git a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java index 3cced47..8ebcd19 100644 --- a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java +++ b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java @@ -69,9 +69,10 @@ public class MockSqlOperatorTable extends ChainedSqlOperatorTable { opTab.addOperator(new RowFunction()); opTab.addOperator(new NotATableFunction()); opTab.addOperator(new BadTableFunction()); +opTab.addOperator(new StructuredFunction()); } - /** "RAMP" user-defined function. */ + /** "RAMP" user-defined table function. */ public static class RampFunction extends SqlFunction implements SqlTableFunction { public RampFunction() { @@ -128,7 +129,7 @@ public class MockSqlOperatorTable extends ChainedSqlOperatorTable { } } - /** "DEDUP" user-defined function. */ + /** "DEDUP" user-defined table function. */ public static class DedupFunction extends SqlFunction implements SqlTableFunction { public DedupFunction() { @@ -211,13 +212,13 @@ public class MockSqlOperatorTable extends ChainedSqlOperatorTable { } } - /** "ROW_FUNC" user-defined function whose return type
[calcite] branch master updated (8a459d9 -> a412ac1)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 8a459d9 [CALCITE-4022] Support unparse special syntax for INSERT (Xu Zhaohui) add a412ac1 [CALCITE-4114] Remove method CalciteAssert.forceDecorrelate (Jiatao Tao) No new revisions were added by this update. Summary of changes: .../java/org/apache/calcite/test/CalciteAssert.java | 17 ++--- 1 file changed, 6 insertions(+), 11 deletions(-)
[calcite] branch master updated: [CALCITE-4022] Support unparse special syntax for INSERT (Xu Zhaohui)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 8a459d9 [CALCITE-4022] Support unparse special syntax for INSERT (Xu Zhaohui) 8a459d9 is described below commit 8a459d9b17a9403e4e1539ea1c3c8d8f39e30a12 Author: xzh <953396...@qq.com> AuthorDate: Sun Jul 26 11:16:14 2020 +0800 [CALCITE-4022] Support unparse special syntax for INSERT (Xu Zhaohui) close apache/calcite#2082 --- .../java/org/apache/calcite/sql/SqlInsert.java | 12 +- .../apache/calcite/sql/parser/SqlParserTest.java | 28 ++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlInsert.java b/core/src/main/java/org/apache/calcite/sql/SqlInsert.java index dbcf53c..722d0ce 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlInsert.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlInsert.java @@ -29,7 +29,17 @@ import java.util.List; */ public class SqlInsert extends SqlCall { public static final SqlSpecialOperator OPERATOR = - new SqlSpecialOperator("INSERT", SqlKind.INSERT); + new SqlSpecialOperator("INSERT", SqlKind.INSERT) { +@Override public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, +SqlNode... operands) { + return new SqlInsert( + pos, + (SqlNodeList) operands[0], + operands[1], + operands[2], + (SqlNodeList) operands[3]); +} + }; SqlNodeList keywords; SqlNode targetTable; diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java index c7d9ffd..badb4ce 100644 --- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java +++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java @@ -5818,6 +5818,34 @@ public class SqlParserTest { assertTrue(sqlNodeVisited.getKind() == SqlKind.INSERT); } + @Test void testSqlInsertSqlBasicCallToString() throws Exception { +final String sql0 = "insert into emps select * from emps"; +final SqlNode sqlNode0 = getSqlParser(sql0).parseStmt(); +final SqlNode sqlNodeVisited0 = sqlNode0.accept(new SqlShuttle() { + @Override public SqlNode visit(SqlIdentifier identifier) { +return new SqlIdentifier(identifier.names, +identifier.getParserPosition()); + } +}); +final String str0 = "INSERT INTO `EMPS`\n" ++ "(SELECT *\n" ++ "FROM `EMPS`)"; +assertEquals(linux(sqlNodeVisited0.toString()), str0); + +final String sql1 = "insert into emps select empno from emps"; +final SqlNode sqlNode1 = getSqlParser(sql1).parseStmt(); +final SqlNode sqlNodeVisited1 = sqlNode1.accept(new SqlShuttle() { + @Override public SqlNode visit(SqlIdentifier identifier) { +return new SqlIdentifier(identifier.names, +identifier.getParserPosition()); + } +}); +final String str1 = "INSERT INTO `EMPS`\n" ++ "(SELECT `EMPNO`\n" ++ "FROM `EMPS`)"; +assertEquals(linux(sqlNodeVisited1.toString()), str1); + } + /** * Runs tests for INTERVAL... DAY TO HOUR that should pass parser but fail * validator. A substantially identical set of tests exists in
[calcite] branch master updated (4625280 -> 4d345a6)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 4625280 [CALCITE-4111] Remove VolcanoPlannerPhase in Planner (Jiatao Tao) add 4d345a6 [CALCITE-4115] Improve the prompt of using SQL keywords for sql parses (part2) No new revisions were added by this update. Summary of changes: core/src/main/codegen/templates/Parser.jj | 4 +++- .../apache/calcite/sql/parser/SqlParserUtil.java | 24 ++ .../apache/calcite/sql/parser/SqlParserTest.java | 6 +++--- .../calcite/sql/test/SqlOperatorBaseTest.java | 2 +- .../org/apache/calcite/test/SqlValidatorTest.java | 2 +- 5 files changed, 32 insertions(+), 6 deletions(-)
[calcite] 01/01: [CALCITE-4073] Add a new component RexNormalize for more effect rex nodes normalization (part1)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit a4fa05458840cfdd93fb5cba16d102b06197539d Author: yuzhao.cyz AuthorDate: Tue Jul 14 15:38:58 2020 +0800 [CALCITE-4073] Add a new component RexNormalize for more effect rex nodes normalization (part1) * Add a new component named RexNormalize * By default, we only normalize the RexCalls during planning phrase, and there is no way to normalize it when constructing the calls now * Recover the plan diffs * Changes the RexCall#equals to be semantic equivalent, which i think is not a good design, we should promote to have a digest abstraction just like RelNode --- .../main/java/org/apache/calcite/rex/RexCall.java | 107 +++ .../main/java/org/apache/calcite/rex/RexNode.java | 14 -- .../java/org/apache/calcite/rex/RexNormalize.java | 196 + .../main/java/org/apache/calcite/sql/SqlKind.java | 6 +- .../java/org/apache/calcite/sql/SqlOperator.java | 11 ++ .../org/apache/calcite/sql/type/SqlTypeUtil.java | 28 +++ .../calcite/rex/RexCallNormalizationTest.java | 85 - .../org/apache/calcite/rex/RexNormalizeTest.java | 141 +++ .../org/apache/calcite/test/JdbcAdapterTest.java | 4 +- .../java/org/apache/calcite/test/LatticeTest.java | 6 +- .../org/apache/calcite/test/RelBuilderTest.java| 4 +- .../org/apache/calcite/test/RelMetadataTest.java | 8 +- .../test/enumerable/EnumerableCorrelateTest.java | 4 +- .../org/apache/calcite/test/RelOptRulesTest.xml| 74 .../apache/calcite/test/SqlToRelConverterTest.xml | 24 +-- .../org/apache/calcite/test/TopDownOptTest.xml | 4 +- core/src/test/resources/sql/blank.iq | 2 +- core/src/test/resources/sql/sub-query.iq | 4 +- 18 files changed, 470 insertions(+), 252 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexCall.java b/core/src/main/java/org/apache/calcite/rex/RexCall.java index e604820..107d6e2 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexCall.java +++ b/core/src/main/java/org/apache/calcite/rex/RexCall.java @@ -18,12 +18,11 @@ package org.apache.calcite.rex; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.SqlSyntax; -import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.sql.type.SqlTypeUtil; import org.apache.calcite.util.Litmus; import org.apache.calcite.util.Pair; @@ -58,11 +57,16 @@ public class RexCall extends RexNode { public final ImmutableList operands; public final RelDataType type; public final int nodeCount; + /** * Cache of hash code. */ protected int hash = 0; + /** + * Cache of normalized variables used for #equals and #hashCode. + */ + private Pair> normalized; //~ Constructors --- @@ -71,11 +75,8 @@ public class RexCall extends RexNode { SqlOperator op, List operands) { this.type = Objects.requireNonNull(type, "type"); -Objects.requireNonNull(op, "operator"); -final Pair> normalized = -normalize(op, operands); -this.op = normalized.left; -this.operands = normalized.right; +this.op = Objects.requireNonNull(op, "operator"); +this.operands = ImmutableList.copyOf(operands); this.nodeCount = RexUtil.nodeCount(1, this.operands); assert op.getKind() != null : op; assert op.validRexOperands(operands.size(), Litmus.THROW) : this; @@ -119,7 +120,7 @@ public class RexCall extends RexNode { RexNode otherArg = operands.get(1 - i); if ((!(otherArg instanceof RexLiteral) || ((RexLiteral) otherArg).digestIncludesType() == RexDigestIncludeType.NO_TYPE) -&& equalSansNullability(operand.getType(), otherArg.getType())) { +&& SqlTypeUtil.equalSansNullability(operand.getType(), otherArg.getType())) { includeType = RexDigestIncludeType.NO_TYPE; } } @@ -139,81 +140,6 @@ public class RexCall extends RexNode { } } - private Pair> normalize( - SqlOperator operator, - List operands) { -final ImmutableList oldOperands = ImmutableList.copyOf(operands); -final Pair> original = Pair.of(operator, oldOperands); -if (!needNormalize()) { - return original; -} -if (operands.size() != 2 -|| !operands.stream().allMatch(operand -> operand.getClass() == RexInputRef.class)) { - return original; -} -final RexInputRef operand0 = (RexInputRef) op
[calcite] branch master updated (551e3f5 -> a4fa054)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. omit 551e3f5 [CALCITE-4073] Add a new component RexNormalize for more effect rex nodes normalization (part1) new a4fa054 [CALCITE-4073] Add a new component RexNormalize for more effect rex nodes normalization (part1) This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (551e3f5) \ N -- N -- N refs/heads/master (a4fa054) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../main/java/org/apache/calcite/rex/RexCall.java | 11 ++--- .../java/org/apache/calcite/rex/RexNormalize.java | 56 -- .../org/apache/calcite/test/RelMetadataTest.java | 8 +++- 3 files changed, 63 insertions(+), 12 deletions(-)
[calcite] branch master updated: [CALCITE-4073] Add a new component RexNormalize for more effect rex nodes normalization (part1)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 551e3f5 [CALCITE-4073] Add a new component RexNormalize for more effect rex nodes normalization (part1) 551e3f5 is described below commit 551e3f5a182a48e20586e40c378224bb63e4bfb3 Author: yuzhao.cyz AuthorDate: Tue Jul 14 15:38:58 2020 +0800 [CALCITE-4073] Add a new component RexNormalize for more effect rex nodes normalization (part1) * Add a new component named RexNormalize * By default, we only normalize the RexCalls during planning phrase, and there is no way to normalize it when constructing the calls now * Recover the plan diffs * Changes the RexCall#equals to be semantic equivalent, which i think is not a good design, we should promote to have a digest abstraction just like RelNode --- .../main/java/org/apache/calcite/rex/RexCall.java | 108 +++ .../main/java/org/apache/calcite/rex/RexNode.java | 14 -- .../java/org/apache/calcite/rex/RexNormalize.java | 150 + .../main/java/org/apache/calcite/sql/SqlKind.java | 6 +- .../java/org/apache/calcite/sql/SqlOperator.java | 11 ++ .../org/apache/calcite/sql/type/SqlTypeUtil.java | 28 .../calcite/rex/RexCallNormalizationTest.java | 85 .../org/apache/calcite/rex/RexNormalizeTest.java | 141 +++ .../org/apache/calcite/test/JdbcAdapterTest.java | 4 +- .../java/org/apache/calcite/test/LatticeTest.java | 6 +- .../org/apache/calcite/test/RelBuilderTest.java| 4 +- .../test/enumerable/EnumerableCorrelateTest.java | 4 +- .../org/apache/calcite/test/RelOptRulesTest.xml| 74 +- .../apache/calcite/test/SqlToRelConverterTest.xml | 24 ++-- .../org/apache/calcite/test/TopDownOptTest.xml | 4 +- core/src/test/resources/sql/blank.iq | 2 +- core/src/test/resources/sql/sub-query.iq | 4 +- 17 files changed, 418 insertions(+), 251 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexCall.java b/core/src/main/java/org/apache/calcite/rex/RexCall.java index e604820..776fb29 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexCall.java +++ b/core/src/main/java/org/apache/calcite/rex/RexCall.java @@ -18,12 +18,11 @@ package org.apache.calcite.rex; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.SqlSyntax; -import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.sql.type.SqlTypeUtil; import org.apache.calcite.util.Litmus; import org.apache.calcite.util.Pair; @@ -58,11 +57,16 @@ public class RexCall extends RexNode { public final ImmutableList operands; public final RelDataType type; public final int nodeCount; + /** * Cache of hash code. */ protected int hash = 0; + /** + * Cache of normalized variables used for #equals and #hashCode. + */ + private Pair> normalized; //~ Constructors --- @@ -71,11 +75,8 @@ public class RexCall extends RexNode { SqlOperator op, List operands) { this.type = Objects.requireNonNull(type, "type"); -Objects.requireNonNull(op, "operator"); -final Pair> normalized = -normalize(op, operands); -this.op = normalized.left; -this.operands = normalized.right; +this.op = Objects.requireNonNull(op, "operator"); +this.operands = ImmutableList.copyOf(operands); this.nodeCount = RexUtil.nodeCount(1, this.operands); assert op.getKind() != null : op; assert op.validRexOperands(operands.size(), Litmus.THROW) : this; @@ -119,7 +120,7 @@ public class RexCall extends RexNode { RexNode otherArg = operands.get(1 - i); if ((!(otherArg instanceof RexLiteral) || ((RexLiteral) otherArg).digestIncludesType() == RexDigestIncludeType.NO_TYPE) -&& equalSansNullability(operand.getType(), otherArg.getType())) { +&& SqlTypeUtil.equalSansNullability(operand.getType(), otherArg.getType())) { includeType = RexDigestIncludeType.NO_TYPE; } } @@ -139,81 +140,6 @@ public class RexCall extends RexNode { } } - private Pair> normalize( - SqlOperator operator, - List operands) { -final ImmutableList oldOperands = ImmutableList.copyOf(operands); -final Pair> original = Pair.of(operator, oldOperands); -if (!needNormalize()) { - return original; -} -if (operands.size() != 2 -
[calcite] branch master updated: [CALCITE-4085] Improve return type nullability for SqlDotOperator & SqlItemOperator (Dawid Wysakowicz)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new e2942fe [CALCITE-4085] Improve return type nullability for SqlDotOperator & SqlItemOperator (Dawid Wysakowicz) e2942fe is described below commit e2942feef4d52c577a46cc3f2b92fa462035bb20 Author: Dawid Wysakowicz AuthorDate: Mon Jun 22 12:28:37 2020 +0200 [CALCITE-4085] Improve return type nullability for SqlDotOperator & SqlItemOperator (Dawid Wysakowicz) This PR introduces a logic that makes the accesed field nullable if the accessed row is nullable. Make the AliasNamespace keep the original nullability & StructKing of the aliased record. close apache/calcite#2042 --- .../org/apache/calcite/sql/fun/SqlDotOperator.java | 3 ++ .../apache/calcite/sql/fun/SqlItemOperator.java| 6 +++- .../calcite/sql/validate/AliasNamespace.java | 12 ++- .../apache/calcite/test/MockSqlOperatorTable.java | 41 ++ .../org/apache/calcite/test/SqlValidatorTest.java | 15 .../test/catalog/MockCatalogReaderExtended.java| 33 + 6 files changed, 108 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java index 6855df1..7e7af24 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java @@ -111,6 +111,9 @@ public class SqlDotOperator extends SqlSpecialOperator { Static.RESOURCE.unknownField(fieldName)); } RelDataType type = field.getType(); +if (nodeType.isNullable()) { + type = validator.getTypeFactory().createTypeWithNullability(type, true); +} // Validate and determine coercibility and resulting collation // name of binary operator if needed. diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java index 8bbcdcd..cd2ffe6 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java @@ -135,7 +135,11 @@ class SqlItemOperator extends SqlSpecialOperator { throw new AssertionError("Cannot infer type of field '" + fieldName + "' within ROW type: " + operandType); } else { -return field.getType(); +RelDataType fieldType = field.getType(); +if (operandType.isNullable()) { + fieldType = typeFactory.createTypeWithNullability(fieldType, true); +} +return fieldType; } case ANY: case DYNAMIC_STAR: diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AliasNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/AliasNamespace.java index 0cc24af..4abd72e 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/AliasNamespace.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/AliasNamespace.java @@ -17,6 +17,7 @@ package org.apache.calcite.sql.validate; import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.RelDataTypeFactoryImpl; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.sql.SqlCall; import org.apache.calcite.sql.SqlIdentifier; @@ -91,9 +92,18 @@ public class AliasNamespace extends AbstractNamespace { for (RelDataTypeField field : rowType.getFieldList()) { typeList.add(field.getType()); } -return validator.getTypeFactory().createStructType( +final RelDataType aliasedType = validator.getTypeFactory().createStructType( +rowType.getStructKind(), typeList, nameList); + +// As per suggestion in CALCITE-4085, JavaType has its special nullability handling. +if (rowType instanceof RelDataTypeFactoryImpl.JavaType) { + return aliasedType; +} else { + return validator.getTypeFactory() + .createTypeWithNullability(aliasedType, rowType.isNullable()); +} } private String getString(RelDataType rowType) { diff --git a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java index b1ac440..0da69b8 100644 --- a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java +++ b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java @@ -18,6 +18,9 @@ package org.apache.calcite.test; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeFactory; +import org.apache.calcite.rel.type.RelDataTypeFieldImpl; +import org.apache.calcite.rel.type.RelRecordType; +import org.apache.calc
[calcite] branch master updated (7ab6435 -> 8f1fabb)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 7ab6435 [CALCITE-4105] Replace Pair with Flat2List in RelDigestWriter add 8f1fabb Following [CALCITE-4115], add expected tokens to the error message No new revisions were added by this update. Summary of changes: core/src/main/codegen/templates/Parser.jj | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-)
[calcite] branch master updated: Following [CALCITE-3753], add log when aborting optimization due to VolcanoTimeoutException (Jiatao Tao)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 9f18c85 Following [CALCITE-3753], add log when aborting optimization due to VolcanoTimeoutException (Jiatao Tao) 9f18c85 is described below commit 9f18c85f5dd8a3a4e9381d5d871ab1e812ffea24 Author: Jiatao Tao <245915...@qq.com> AuthorDate: Tue Jul 7 17:17:30 2020 +0800 Following [CALCITE-3753], add log when aborting optimization due to VolcanoTimeoutException (Jiatao Tao) close apache/calcite#2057 --- core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java index d367612..54615db 100644 --- a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java +++ b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java @@ -519,6 +519,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner { try { match.onMatch(); } catch (VolcanoTimeoutException e) { + LOGGER.warn("Volcano planning times out, cancels the subsequent optimization."); root = canonize(root); ruleQueue.phaseCompleted(phase); break PLANNING;
[calcite] branch master updated (32fc1f4 -> e7aca69)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 32fc1f4 [CALCITE-4098] Remove redundant code in RelJson.toJson(RelDistribution) (Jiatao Tao) add e7aca69 [CALCITE-4101] Calcite PR CI often failed due to `elasticsearch:test`, disable the related tests first (Jiatao Tao) No new revisions were added by this update. Summary of changes: .../java/org/apache/calcite/adapter/elasticsearch/AggregationTest.java | 2 ++ .../java/org/apache/calcite/adapter/elasticsearch/BooleanLogicTest.java | 2 ++ .../apache/calcite/adapter/elasticsearch/ElasticSearchAdapterTest.java | 2 ++ .../test/java/org/apache/calcite/adapter/elasticsearch/MatchTest.java | 2 ++ .../java/org/apache/calcite/adapter/elasticsearch/Projection2Test.java | 2 ++ .../java/org/apache/calcite/adapter/elasticsearch/ProjectionTest.java | 2 ++ .../java/org/apache/calcite/adapter/elasticsearch/ScrollingTest.java| 1 + 7 files changed, 13 insertions(+)
[calcite] branch master updated (8db7c9d -> 32fc1f4)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 8db7c9d [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types (Jiatao Tao) add 32fc1f4 [CALCITE-4098] Remove redundant code in RelJson.toJson(RelDistribution) (Jiatao Tao) No new revisions were added by this update. Summary of changes: .../apache/calcite/rel/externalize/RelJson.java| 13 +-- .../org/apache/calcite/plan/RelWriterTest.java | 43 ++ 2 files changed, 45 insertions(+), 11 deletions(-)
[calcite] branch master updated (a329e88 -> 8db7c9d)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from a329e88 [CALCITE-4059] SqlTypeUtil#equalSansNullability consider Array/Map type (Jiatao Tao) add 8db7c9d [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types (Jiatao Tao) No new revisions were added by this update. Summary of changes: .../org/apache/calcite/sql/type/SqlTypeUtil.java | 61 +- .../apache/calcite/sql/type/SqlTypeUtilTest.java | 39 ++ 2 files changed, 88 insertions(+), 12 deletions(-)
[calcite] branch master updated (2ef46dc -> a329e88)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 2ef46dc [CALCITE-4026] CassandraFilter has generated wrong condition expression for filter with non string literal (Wenhui Tang) add a329e88 [CALCITE-4059] SqlTypeUtil#equalSansNullability consider Array/Map type (Jiatao Tao) No new revisions were added by this update. Summary of changes: .../org/apache/calcite/sql/type/SqlTypeUtil.java | 82 +- .../apache/calcite/sql/type/SqlTypeFixture.java| 6 ++ .../apache/calcite/sql/type/SqlTypeUtilTest.java | 24 +++ 3 files changed, 110 insertions(+), 2 deletions(-)
[calcite] branch master updated (c2df42e -> 2ef46dc)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from c2df42e [CALCITE-4077] Exception when joined with built-in table functions add 2ef46dc [CALCITE-4026] CassandraFilter has generated wrong condition expression for filter with non string literal (Wenhui Tang) No new revisions were added by this update. Summary of changes: .../calcite/adapter/cassandra/CassandraFilter.java | 28 .../test/CassandraAdapterDataTypesTest.java| 29 + cassandra/src/test/resources/datatypes.cql | 12 + .../java/org/apache/calcite/sql/SqlDialect.java| 9 +++ .../apache/calcite/util/DateTimeStringUtils.java | 30 ++ .../calcite/sql/test/SqlOperatorBaseTest.java | 4 +-- .../org/apache/calcite/test/CalciteAssert.java | 15 --- .../calcite/adapter/druid/DruidConnectionImpl.java | 11 +++- .../calcite/adapter/druid/DruidJsonFilter.java | 16 .../adapter/druid/ExtractionDimensionSpec.java | 3 ++- .../adapter/druid/TimeExtractionFunction.java | 8 +++--- 11 files changed, 119 insertions(+), 46 deletions(-)
[calcite] branch master updated: [CALCITE-4077] Exception when joined with built-in table functions
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new c2df42e [CALCITE-4077] Exception when joined with built-in table functions c2df42e is described below commit c2df42eff1615bfcd46ae3db5099c9785b04d420 Author: yuzhao.cyz AuthorDate: Wed Jul 1 18:09:23 2020 +0800 [CALCITE-4077] Exception when joined with built-in table functions The scope of SqlWindowTableFunction is special because all its operands (except the first) should have the fucntion's first operand's scope, the first operand is always an explicit table reference. While this is not the perfect solution, the more proper way is to refactor the CURSOR constructor, and always uses its queries scope. The current CURSOR has some problems: * It always has a type with name SqlTypeName#CURSOR, in the table function senario, it is hard to do an auxiliary fields type infernece; * It finally translates as an invocation with format "cast($0): CURSOR", the '$0' means the first input, which is a wrong translation; * It does not belong to the SQL standard. A 'TABLE' constructor may be a good substitution. --- .../org/apache/calcite/sql/SqlHopTableFunction.java | 6 +++--- .../apache/calcite/sql/SqlTumbleTableFunction.java | 8 +--- .../apache/calcite/sql/SqlWindowTableFunction.java | 9 + .../calcite/sql/validate/SqlValidatorImpl.java | 17 - .../apache/calcite/sql2rel/SqlToRelConverter.java| 2 +- .../apache/calcite/test/SqlToRelConverterTest.java | 8 .../apache/calcite/test/SqlToRelConverterTest.xml| 20 7 files changed, 58 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlHopTableFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlHopTableFunction.java index 43b2b91..a3c67ff 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlHopTableFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlHopTableFunction.java @@ -24,9 +24,9 @@ import org.apache.calcite.sql.validate.SqlValidator; /** * SqlHopTableFunction implements an operator for hopping. It allows four parameters: - * 1. a table. - * 2. a descriptor to provide a watermarked column name from the input table. - * 3. an interval parameter to specify the length of window shifting. + * 1. a table; + * 2. a descriptor to provide a watermarked column name from the input table; + * 3. an interval parameter to specify the length of window shifting; * 4. an interval parameter to specify the length of window size. */ public class SqlHopTableFunction extends SqlWindowTableFunction { diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTumbleTableFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlTumbleTableFunction.java index e3a5001..882e7e2 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlTumbleTableFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlTumbleTableFunction.java @@ -23,9 +23,11 @@ import org.apache.calcite.sql.type.SqlTypeUtil; import org.apache.calcite.sql.validate.SqlValidator; /** - * SqlTumbleTableFunction implements an operator for tumbling. It allows three parameters: - * 1. a table. - * 2. a descriptor to provide a watermarked column name from the input table. + * SqlTumbleTableFunction implements an operator for tumbling. + * + * It allows three parameters: + * 1. a table; + * 2. a descriptor to provide a watermarked column name from the input table; * 3. an interval parameter to specify the length of window size. */ public class SqlTumbleTableFunction extends SqlWindowTableFunction { diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java index e86551b..00c715a 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java @@ -70,8 +70,9 @@ public class SqlWindowTableFunction extends SqlFunction { } /** - * The first parameter of table-value function windowing is a TABLE parameter, - * which is not scalar. So need to override SqlOperator.argumentMustBeScalar. + * Overrides SqlOperator.argumentMustBeScalar because the first parameter of + * table-value function windowing is an explicit TABLE parameter, + * which is not scalar. */ @Override public boolean argumentMustBeScalar(int ordinal) { return ordinal != 0; @@ -83,8 +84,8 @@ public class SqlWindowTableFunction extends SqlFunction { * additional fields: * * - * window_start. TIMESTAMP type to indicate a window's start. - * window_end. TIMESTAMP type to indicate a window's end. + * window_start: TIME
[calcite] branch master updated: [CALCITE-4033] Does not produce parenthesized table expressions for UNNEST (Rui Wang)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 2d6e57f [CALCITE-4033] Does not produce parenthesized table expressions for UNNEST (Rui Wang) 2d6e57f is described below commit 2d6e57f00e6ade5ef534bb4404184a44c2f149f8 Author: amaliujia AuthorDate: Sat Jun 13 12:07:06 2020 -0700 [CALCITE-4033] Does not produce parenthesized table expressions for UNNEST (Rui Wang) Before this change, Calcite parser produces "(UNEST(...))". However, Calcite parser fails to parse UNNEST as parenthesized table expressions: "JOIN (SELECT * FROM ^(UNNEST(...))^)". This change stops produces parenthesized table expressions for UNNEST to fix this problem. close apache/calcite#2025 --- .../main/java/org/apache/calcite/sql/SqlKind.java | 3 ++- .../apache/calcite/sql/parser/SqlParserTest.java | 29 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlKind.java b/core/src/main/java/org/apache/calcite/sql/SqlKind.java index f98a0c2..f1cfb08 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlKind.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlKind.java @@ -1240,6 +1240,7 @@ public enum SqlKind { * {@link #ORDER_BY}, * {@link #COLLECTION_TABLE}, * {@link #TABLESAMPLE}, + * {@link #UNNEST} * or an aggregate function, DML or DDL. */ public static final Set EXPRESSION = @@ -1254,7 +1255,7 @@ public enum SqlKind { LITERAL_CHAIN, JDBC_FN, PRECEDING, FOLLOWING, ORDER_BY, NULLS_FIRST, NULLS_LAST, COLLECTION_TABLE, TABLESAMPLE, VALUES, WITH, WITH_ITEM, ITEM, SKIP_TO_FIRST, SKIP_TO_LAST, - JSON_VALUE_EXPRESSION), + JSON_VALUE_EXPRESSION, UNNEST), AGGREGATE, DML, DDL)); /** diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java index e5d3cec..19cd942 100644 --- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java +++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java @@ -7155,10 +7155,10 @@ public class SqlParserTest { @Test void testUnnest() { sql("select*from unnest(x)") .ok("SELECT *\n" -+ "FROM (UNNEST(`X`))"); ++ "FROM UNNEST(`X`)"); sql("select*from unnest(x) AS T") .ok("SELECT *\n" -+ "FROM (UNNEST(`X`)) AS `T`"); ++ "FROM UNNEST(`X`) AS `T`"); // UNNEST cannot be first word in query sql("^unnest^(x)") @@ -7169,24 +7169,41 @@ public class SqlParserTest { + "unnest(dept.employees, dept.managers)"; final String expected = "SELECT *\n" + "FROM `DEPT`,\n" -+ "(UNNEST(`DEPT`.`EMPLOYEES`, `DEPT`.`MANAGERS`))"; ++ "UNNEST(`DEPT`.`EMPLOYEES`, `DEPT`.`MANAGERS`)"; sql(sql).ok(expected); // LATERAL UNNEST is not valid sql("select * from dept, lateral ^unnest^(dept.employees)") .fails("(?s)Encountered \"unnest\" at .*"); + +// Does not generate extra parentheses around UNNEST because UNNEST is +// a table expression. +final String sql1 = "" ++ "SELECT\n" ++ " item.name,\n" ++ " relations.*\n" ++ "FROM dfs.tmp item\n" ++ "JOIN (\n" ++ " SELECT * FROM UNNEST(item.related) i(rels)\n" ++ ") relations\n" ++ "ON TRUE"; +final String expected1 = "SELECT `ITEM`.`NAME`, `RELATIONS`.*\n" ++ "FROM `DFS`.`TMP` AS `ITEM`\n" ++ "INNER JOIN (SELECT *\n" ++ "FROM UNNEST(`ITEM`.`RELATED`) AS `I` (`RELS`)) AS `RELATIONS` ON TRUE"; +sql(sql1).ok(expected1); } @Test void testUnnestWithOrdinality() { sql("select * from unnest(x) with ordinality") .ok("SELECT *\n" -+ "FROM (UNNEST(`X`) WITH ORDINALITY)"); ++ "FROM UNNEST(`X`) WITH ORDINALITY"); sql("select*from unnest(x) with ordinality AS T") .ok("SELECT *\n" -+ "FROM (UNNEST(`X`) WITH ORDINALITY) AS `T`"); ++ "FROM UNNEST(`X`) WITH ORDINALITY AS `T`"); sql("select*from unnest(x) with ordinality AS T(c, o)") .ok("SELECT *\n" -+ "FROM (UNNEST(`X`) WITH ORDINALITY) AS `T` (`C`, `O`)"); ++ "FROM UNNEST(`X`) WITH ORDINALITY AS `T` (`C`, `O`)"); sql("select*from unnest(x) as T ^with^ ordinality") .fails("(?s)Encountered \"with\" at .*"); }
[calcite] branch master updated: [CALCITE-3786] Add Digest interface to enable efficient hashCode(equals) for RexNode and RelNode (part2)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new b184707 [CALCITE-3786] Add Digest interface to enable efficient hashCode(equals) for RexNode and RelNode (part2) b184707 is described below commit b18470797eaec8c4e64382c0b742ae83f758275f Author: yuzhao.cyz AuthorDate: Fri Jun 19 12:16:36 2020 +0800 [CALCITE-3786] Add Digest interface to enable efficient hashCode(equals) for RexNode and RelNode (part2) Tweak based on the review concerns. --- .../main/java/org/apache/calcite/plan/Digest.java | 42 +- .../org/apache/calcite/plan/hep/HepRelVertex.java | 2 +- .../org/apache/calcite/plan/volcano/RelSubset.java | 2 +- .../org/apache/calcite/rel/AbstractRelNode.java| 2 +- .../test/enumerable/EnumerableCorrelateTest.java | 4 +-- 5 files changed, 14 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/plan/Digest.java b/core/src/main/java/org/apache/calcite/plan/Digest.java index 494cb14..e7375bf 100644 --- a/core/src/main/java/org/apache/calcite/plan/Digest.java +++ b/core/src/main/java/org/apache/calcite/plan/Digest.java @@ -24,7 +24,6 @@ import org.apache.calcite.util.Pair; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; import javax.annotation.Nonnull; /** @@ -61,7 +60,7 @@ public class Digest implements Comparable { * Creates a digest with given rel and properties. * * @param rel The rel - * @param items The properties, e.g. the inputs, the type, the traits and so on + * @param items The properties, e.g. the inputs, the operands and so on */ private Digest(RelNode rel, List> items) { this.rel = rel; @@ -69,14 +68,6 @@ public class Digest implements Comparable { this.hashCode = computeIdentity(rel, this.items); } - /** - * Creates a digest with given rel, the digest is computed as simple, - * see {@link #simpleRelDigest(RelNode)}. - */ - private Digest(RelNode rel) { -this(rel, simpleRelDigest(rel)); - } - /** Creates a digest with given rel and string format digest. */ private Digest(RelNode rel, String digest) { this.rel = rel; @@ -87,7 +78,7 @@ public class Digest implements Comparable { /** Returns the identity of this digest which is used to speedup hashCode and equals. */ private static int computeIdentity(RelNode rel, List> contents) { -return Objects.hash(collect(rel, contents, false)); +return collect(rel, contents, false).hashCode(); } /** @@ -104,7 +95,7 @@ public class Digest implements Comparable { * @param contents The rel properties should be considered in digest * @param withType Whether to involve the row type */ - private static Object[] collect( + private static List collect( RelNode rel, List> contents, boolean withType) { @@ -130,14 +121,14 @@ public class Digest implements Comparable { } // The rel node contents(e.g. the inputs or exprs). hashCodeItems.addAll(contents); -return hashCodeItems.toArray(); +return hashCodeItems; } /** Normalizes the rel node properties, currently, just to replace the * {@link RelNode} with a simple string format digest. **/ private static List> normalizeContents( List> items) { -List> normalized = new ArrayList<>(); +List> normalized = new ArrayList<>(items.size()); for (Pair item : items) { if (item.right instanceof RelNode) { RelNode input = (RelNode) item.right; @@ -208,17 +199,9 @@ public class Digest implements Comparable { * reduce mem consumption. */ private boolean deepEquals(Digest other) { -Object[] thisItems = collect(this.rel, this.items, true); -Object[] thatItems = collect(other.rel, other.items, true); -if (thisItems.length != thatItems.length) { - return false; -} -for (int i = 0; i < thisItems.length; i++) { - if (!Objects.equals(thisItems[i], thatItems[i])) { -return false; - } -} -return true; +List thisItems = collect(this.rel, this.items, true); +List thatItems = collect(other.rel, other.items, true); +return thisItems.equals(thatItems); } @Override public int hashCode() { @@ -233,13 +216,6 @@ public class Digest implements Comparable { } /** - * Creates a digest with given rel. - */ - public static Digest create(RelNode rel) { -return new Digest(rel); - } - - /** * Creates a digest with given rel and string format digest */ public static Digest create(RelNode rel, String digest) { @@ -250,7 +226,7 @@ public class Digest implements Comparable { * Instantiates a digest with solid string format digest, this digest should only * be used a
[calcite] branch master updated: Revert "[CALCITE-4056] Remove Digest from RelNode and RexCall"
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new a551d4b Revert "[CALCITE-4056] Remove Digest from RelNode and RexCall" a551d4b is described below commit a551d4bfa3b97c42e74fe4e30ca66ba493719c96 Author: yuzhao.cyz AuthorDate: Thu Jun 18 14:39:38 2020 +0800 Revert "[CALCITE-4056] Remove Digest from RelNode and RexCall" This reverts commit b00c1fd6 --- .../adapter/enumerable/EnumerableAggregate.java| 8 - .../adapter/enumerable/EnumerableFilter.java | 8 - .../adapter/enumerable/EnumerableHashJoin.java | 8 - .../adapter/enumerable/EnumerableMergeJoin.java| 8 - .../enumerable/EnumerableNestedLoopJoin.java | 8 - .../adapter/enumerable/EnumerableProject.java | 8 - .../enumerable/EnumerableSortedAggregate.java | 8 - .../main/java/org/apache/calcite/plan/Digest.java | 256 + .../java/org/apache/calcite/plan/RelDigest.java| 52 - .../java/org/apache/calcite/plan/RelOptNode.java | 15 +- .../java/org/apache/calcite/plan/RelOptUtil.java | 1 - .../org/apache/calcite/plan/hep/HepPlanner.java| 12 +- .../org/apache/calcite/plan/hep/HepRelVertex.java | 15 +- .../org/apache/calcite/plan/volcano/RelSubset.java | 36 +-- .../calcite/plan/volcano/VolcanoPlanner.java | 55 ++--- .../org/apache/calcite/rel/AbstractRelNode.java| 135 ++- .../main/java/org/apache/calcite/rel/RelNode.java | 7 +- .../java/org/apache/calcite/rel/SingleRel.java | 1 - .../org/apache/calcite/rel/core/Aggregate.java | 21 -- .../java/org/apache/calcite/rel/core/Filter.java | 19 -- .../java/org/apache/calcite/rel/core/Join.java | 22 -- .../java/org/apache/calcite/rel/core/Project.java | 21 -- .../java/org/apache/calcite/rel/core/Values.java | 18 -- .../java/org/apache/calcite/rel/core/Window.java | 5 +- .../calcite/rel/logical/LogicalAggregate.java | 8 - .../apache/calcite/rel/logical/LogicalFilter.java | 12 - .../apache/calcite/rel/logical/LogicalJoin.java| 13 -- .../apache/calcite/rel/logical/LogicalProject.java | 8 - .../rel/metadata/JaninoRelMetadataProvider.java| 7 +- .../org/apache/calcite/rel/rules/MultiJoin.java| 1 - .../main/java/org/apache/calcite/rex/RexCall.java | 18 +- .../org/apache/calcite/rex/RexDynamicParam.java| 6 +- .../java/org/apache/calcite/rex/RexLiteral.java| 8 +- .../main/java/org/apache/calcite/rex/RexNode.java | 5 - .../main/java/org/apache/calcite/rex/RexOver.java | 6 +- .../java/org/apache/calcite/rex/RexSubQuery.java | 8 +- .../org/apache/calcite/test/HepPlannerTest.java| 2 +- 37 files changed, 354 insertions(+), 495 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java index 9967e2a..a0dee72 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java @@ -105,14 +105,6 @@ public class EnumerableAggregate extends Aggregate implements EnumerableRel { } } - @Override public boolean digestEquals(Object obj) { -return digestEquals0(obj); - } - - @Override public int digestHash() { -return digestHash0(); - } - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { final JavaTypeFactory typeFactory = implementor.getTypeFactory(); final BlockBuilder builder = new BlockBuilder(); diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java index 8d26c7e..5af195c 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableFilter.java @@ -71,14 +71,6 @@ public class EnumerableFilter return new EnumerableFilter(getCluster(), traitSet, input, condition); } - @Override public boolean digestEquals(Object obj) { -return digestEquals0(obj); - } - - @Override public int digestHash() { -return digestHash0(); - } - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { // EnumerableCalc is always better throw new UnsupportedOperationException(); diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java index 41d5d50..918919e 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java +++ b/core/src/main/java/org/apache/calcit
[calcite] branch master updated (b00c1fd -> 69f2586)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. omit b00c1fd [CALCITE-4056] Remove Digest from RelNode and RexCall This update removed existing revisions from the reference, leaving the reference pointing at a previous point in the repository history. * -- * -- N refs/heads/master (69f2586) \ O -- O -- O (b00c1fd) Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. No new revisions were added by this update. Summary of changes: .../adapter/enumerable/EnumerableAggregate.java| 8 - .../adapter/enumerable/EnumerableFilter.java | 8 - .../adapter/enumerable/EnumerableHashJoin.java | 8 - .../adapter/enumerable/EnumerableMergeJoin.java| 8 - .../enumerable/EnumerableNestedLoopJoin.java | 8 - .../adapter/enumerable/EnumerableProject.java | 8 - .../enumerable/EnumerableSortedAggregate.java | 8 - .../main/java/org/apache/calcite/plan/Digest.java | 256 + .../java/org/apache/calcite/plan/RelDigest.java| 52 - .../java/org/apache/calcite/plan/RelOptNode.java | 15 +- .../java/org/apache/calcite/plan/RelOptUtil.java | 1 - .../org/apache/calcite/plan/hep/HepPlanner.java| 12 +- .../org/apache/calcite/plan/hep/HepRelVertex.java | 15 +- .../org/apache/calcite/plan/volcano/RelSubset.java | 36 +-- .../calcite/plan/volcano/VolcanoPlanner.java | 55 ++--- .../org/apache/calcite/rel/AbstractRelNode.java| 135 ++- .../main/java/org/apache/calcite/rel/RelNode.java | 7 +- .../java/org/apache/calcite/rel/SingleRel.java | 1 - .../org/apache/calcite/rel/core/Aggregate.java | 21 -- .../java/org/apache/calcite/rel/core/Filter.java | 19 -- .../java/org/apache/calcite/rel/core/Join.java | 22 -- .../java/org/apache/calcite/rel/core/Project.java | 21 -- .../java/org/apache/calcite/rel/core/Values.java | 18 -- .../java/org/apache/calcite/rel/core/Window.java | 5 +- .../calcite/rel/logical/LogicalAggregate.java | 8 - .../apache/calcite/rel/logical/LogicalFilter.java | 12 - .../apache/calcite/rel/logical/LogicalJoin.java| 13 -- .../apache/calcite/rel/logical/LogicalProject.java | 8 - .../rel/metadata/JaninoRelMetadataProvider.java| 7 +- .../org/apache/calcite/rel/rules/MultiJoin.java| 1 - .../main/java/org/apache/calcite/rex/RexCall.java | 18 +- .../org/apache/calcite/rex/RexDynamicParam.java| 6 +- .../java/org/apache/calcite/rex/RexLiteral.java| 8 +- .../main/java/org/apache/calcite/rex/RexNode.java | 5 - .../main/java/org/apache/calcite/rex/RexOver.java | 6 +- .../java/org/apache/calcite/rex/RexSubQuery.java | 8 +- .../org/apache/calcite/test/HepPlannerTest.java| 2 +- 37 files changed, 354 insertions(+), 495 deletions(-) create mode 100644 core/src/main/java/org/apache/calcite/plan/Digest.java delete mode 100644 core/src/main/java/org/apache/calcite/plan/RelDigest.java
[calcite] annotated tag v1.23.0-rc1 updated (ebc5070 -> 1731895)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to annotated tag v1.23.0-rc1 in repository https://gitbox.apache.org/repos/asf/calcite.git. *** WARNING: tag v1.23.0-rc1 was modified! *** from ebc5070 (commit) to 1731895 (tag) tagging ebc5070e27caa2cbe1cf3e3b78f6f93edfc4c6ce (commit) replaces calcite-1.21.0 by yuzhao.cyz on Fri Mar 6 22:40:38 2020 +0800 - Log - --- No new revisions were added by this update. Summary of changes:
[calcite] branch master updated: [CALCITE-3786] Add Digest interface to enable efficient hashCode(equals) for RexNode and RelNode
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 69f2586 [CALCITE-3786] Add Digest interface to enable efficient hashCode(equals) for RexNode and RelNode 69f2586 is described below commit 69f25863f5f4197c17927a39a82cbf1cffd12b80 Author: yuzhao.cyz AuthorDate: Tue Jun 9 21:16:22 2020 +0800 [CALCITE-3786] Add Digest interface to enable efficient hashCode(equals) for RexNode and RelNode * Add class Digest used to identify the node; * There is a pre-computed hashcode to speedup #hashCode and #equals; * Change RexCall to use object#equals instead of pure string digest comparison; * We only support RexInputRef normalization which is the most common case; * Remove RexNode#toStringRaw because it makes the thing complicated, RexNode can always be normalized(default true). --- .../org/apache/calcite/adapter/jdbc/JdbcRules.java | 2 +- .../apache/calcite/plan/AbstractRelOptPlanner.java | 14 -- .../main/java/org/apache/calcite/plan/Digest.java | 256 + .../plan/MaterializedViewSubstitutionVisitor.java | 2 +- .../java/org/apache/calcite/plan/RelOptNode.java | 2 +- .../java/org/apache/calcite/plan/RelOptUtil.java | 19 +- .../org/apache/calcite/plan/hep/HepPlanner.java| 13 +- .../org/apache/calcite/plan/hep/HepRelVertex.java | 5 +- .../org/apache/calcite/plan/volcano/RelSubset.java | 10 +- .../calcite/plan/volcano/VolcanoPlanner.java | 39 ++-- .../org/apache/calcite/rel/AbstractRelNode.java| 81 ++- .../main/java/org/apache/calcite/rel/RelNode.java | 3 +- .../java/org/apache/calcite/rel/RelWriter.java | 15 -- .../java/org/apache/calcite/rel/core/Match.java| 10 + .../java/org/apache/calcite/rel/core/Window.java | 22 +- .../calcite/rel/externalize/RelJsonWriter.java | 5 +- .../calcite/rel/externalize/RelWriterImpl.java | 21 +- .../rel/metadata/RelMdExpressionLineage.java | 2 +- .../calcite/rel/rel2sql/RelToSqlConverter.java | 4 +- .../rel/rules/JoinProjectTransposeRule.java| 4 +- .../rel/rules/ProjectWindowTransposeRule.java | 4 +- .../materialize/MaterializedViewAggregateRule.java | 22 +- .../materialize/MaterializedViewJoinRule.java | 4 +- .../rules/materialize/MaterializedViewRule.java| 2 +- .../main/java/org/apache/calcite/rex/RexCall.java | 148 +--- .../main/java/org/apache/calcite/rex/RexNode.java | 63 + .../main/java/org/apache/calcite/rex/RexOver.java | 21 ++ .../java/org/apache/calcite/rex/RexSubQuery.java | 10 + .../main/java/org/apache/calcite/sql/SqlKind.java | 19 ++ .../calcite/sql/fun/SqlStdOperatorTable.java | 20 ++ .../calcite/materialize/LatticeSuggesterTest.java | 4 +- .../org/apache/calcite/plan/RelOptUtilTest.java| 8 +- .../calcite/plan/volcano/TraitPropagationTest.java | 4 +- .../calcite/plan/volcano/VolcanoPlannerTest.java | 10 +- .../calcite/rel/rules/DateRangeRulesTest.java | 4 +- .../calcite/rex/RexCallNormalizationTest.java | 76 +++--- .../org/apache/calcite/rex/RexProgramTest.java | 8 +- .../org/apache/calcite/rex/RexProgramTestBase.java | 39 ++-- .../rex/RexSqlStandardConvertletTableTest.java | 6 +- .../org/apache/calcite/test/HepPlannerTest.java| 6 +- .../org/apache/calcite/test/JdbcAdapterTest.java | 4 +- .../java/org/apache/calcite/test/LatticeTest.java | 6 +- .../test/MaterializedViewRelOptRulesTest.java | 3 +- .../MaterializedViewSubstitutionVisitorTest.java | 10 +- .../org/apache/calcite/test/RelBuilderTest.java| 6 +- .../org/apache/calcite/test/RelMetadataTest.java | 14 +- .../org/apache/calcite/test/RelOptRulesTest.java | 2 +- .../apache/calcite/test/RexTransformerTest.java| 4 +- .../apache/calcite/test/SqlHintsConverterTest.java | 6 +- .../test/enumerable/EnumerableCorrelateTest.java | 8 +- .../org/apache/calcite/test/RelOptRulesTest.xml| 74 +++--- .../apache/calcite/test/SqlToRelConverterTest.xml | 24 +- .../org/apache/calcite/test/TopDownOptTest.xml | 4 +- core/src/test/resources/sql/blank.iq | 2 +- core/src/test/resources/sql/sub-query.iq | 4 +- .../apache/calcite/adapter/druid/DruidRules.java | 2 +- .../calcite/piglet/PigToSqlAggregateRule.java | 6 +- 57 files changed, 664 insertions(+), 522 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java index 4b9b1b4..438781b 100644 --- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java +++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java @@ -523,7 +523,7 @@ public class JdbcRules { private
[calcite] branch master updated: [CALCITE-3724] Presto dialect implementation
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new f577b7e [CALCITE-3724] Presto dialect implementation f577b7e is described below commit f577b7e3d91191051cfdaade27e0a74f3603648a Author: XuQianJin-Stars AuthorDate: Thu Jan 30 14:49:20 2020 +0800 [CALCITE-3724] Presto dialect implementation Fixup (by Danny): - Add a new tool RelToSqlConverterUtil#specialOperatorByName and remove ClickHouseSqlDialect.CLICKHOUSE_SUBSTRING - Remove the common code in PrestoSqlDialect and reuse codes from other dialect instances close apache#calcite#1776 --- .../java/org/apache/calcite/sql/SqlDialect.java| 11 ++ .../apache/calcite/sql/SqlDialectFactoryImpl.java | 3 + .../calcite/sql/dialect/ClickHouseSqlDialect.java | 24 +--- .../calcite/sql/dialect/PrestoSqlDialect.java | 129 + .../apache/calcite/util/RelToSqlConverterUtil.java | 23 .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 94 +-- 6 files changed, 251 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java index 2ef11f9..4924232 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java @@ -291,6 +291,8 @@ public class SqlDialect { return DatabaseProduct.ORACLE; case "PHOENIX": return DatabaseProduct.PHOENIX; +case "PRESTO": + return DatabaseProduct.PRESTO; case "MYSQL (INFOBRIGHT)": return DatabaseProduct.INFOBRIGHT; case "MYSQL": @@ -921,6 +923,11 @@ public class SqlDialect { protected final void unparseFetchUsingLimit(SqlWriter writer, SqlNode offset, SqlNode fetch) { Preconditions.checkArgument(fetch != null || offset != null); +unparseLimit(writer, fetch); +unparseOffset(writer, offset); + } + + protected final void unparseLimit(SqlWriter writer, SqlNode fetch) { if (fetch != null) { writer.newlineAndIndent(); final SqlWriter.Frame fetchFrame = @@ -929,6 +936,9 @@ public class SqlDialect { fetch.unparse(writer, -1, -1); writer.endList(fetchFrame); } + } + + protected final void unparseOffset(SqlWriter writer, SqlNode offset) { if (offset != null) { writer.newlineAndIndent(); final SqlWriter.Frame offsetFrame = @@ -1245,6 +1255,7 @@ public class SqlDialect { INTERBASE("Interbase", null, NullCollation.HIGH), PHOENIX("Phoenix", "\"", NullCollation.HIGH), POSTGRESQL("PostgreSQL", "\"", NullCollation.HIGH), +PRESTO("Presto", "\"", NullCollation.LOW), NETEZZA("Netezza", "\"", NullCollation.HIGH), INFOBRIGHT("Infobright", "`", NullCollation.HIGH), NEOVIEW("Neoview", null, NullCollation.HIGH), diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java b/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java index 82d07cf..d150794 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java @@ -43,6 +43,7 @@ import org.apache.calcite.sql.dialect.OracleSqlDialect; import org.apache.calcite.sql.dialect.ParaccelSqlDialect; import org.apache.calcite.sql.dialect.PhoenixSqlDialect; import org.apache.calcite.sql.dialect.PostgresqlSqlDialect; +import org.apache.calcite.sql.dialect.PrestoSqlDialect; import org.apache.calcite.sql.dialect.RedshiftSqlDialect; import org.apache.calcite.sql.dialect.SnowflakeSqlDialect; import org.apache.calcite.sql.dialect.SparkSqlDialect; @@ -289,6 +290,8 @@ public class SqlDialectFactoryImpl implements SqlDialectFactory { return PhoenixSqlDialect.DEFAULT; case POSTGRESQL: return PostgresqlSqlDialect.DEFAULT; +case PRESTO: + return PrestoSqlDialect.DEFAULT; case REDSHIFT: return RedshiftSqlDialect.DEFAULT; case SYBASE: diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java index a05799d..c78662c 100644 --- a/core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java @@ -25,10 +25,8 @@ import org.apache.calcite.sql.SqlCall; import org.apache.calcite.sql.SqlDataTypeSpec; import org.apache.calcite.sql.SqlDateLiteral; import org.apache.calcite.sql.SqlDialect; -import org.apache.calcite.sql.SqlKind; import
[calcite] branch master updated: [CALCITE-4053] RexSimplify should not pass exprs containing non-const subExprs to RexExecutor (Shuo Cheng)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new ac51ce7 [CALCITE-4053] RexSimplify should not pass exprs containing non-const subExprs to RexExecutor (Shuo Cheng) ac51ce7 is described below commit ac51ce70b79f58e463c409f3b36f6ba2790b4369 Author: shuo.cs AuthorDate: Tue Jun 9 13:47:51 2020 +0800 [CALCITE-4053] RexSimplify should not pass exprs containing non-const subExprs to RexExecutor (Shuo Cheng) Currently in RexSimplify#simplifyCast, if an expression is judged as a const expression but the outer CAST can not be removed, we pass the original expression to RexExecutor to reduce the expression which may leads to unexpected exception when the original expression contains RexInputRef. close apache/calcite#2012 --- core/src/main/java/org/apache/calcite/rex/RexSimplify.java | 3 ++- .../java/org/apache/calcite/test/SqlToRelConverterTest.java | 5 + .../org/apache/calcite/test/SqlToRelConverterTest.xml | 13 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java index 41eceb2..f43da20 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java @@ -1950,7 +1950,8 @@ public class RexSimplify { break; } final List reducedValues = new ArrayList<>(); - executor.reduce(rexBuilder, ImmutableList.of(e), reducedValues); + final RexNode simplifiedExpr = rexBuilder.makeCast(e.getType(), operand); + executor.reduce(rexBuilder, ImmutableList.of(simplifiedExpr), reducedValues); return Objects.requireNonNull( Iterables.getOnlyElement(reducedValues)); default: diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index a82a108..114adda 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -2610,6 +2610,11 @@ class SqlToRelConverterTest extends SqlToRelTestBase { sql(sql).decorrelate(true).ok(); } + @Test void testReduceConstExpr() { +final String sql = "select sum(case when 'y' = 'n' then ename else 1 end) from emp"; +sql(sql).ok(); + } + /** * Test case for * https://issues.apache.org/jira/browse/CALCITE-695;>[CALCITE-695] diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index 1bc57e3..bff936c 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -3717,6 +3717,18 @@ LogicalProject(DEPTNO=[$7]) ]]> + + + + + + + + +
[calcite] branch master updated: Following CALCITE-4031, some code style promotion
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 8dec7ba Following CALCITE-4031, some code style promotion 8dec7ba is described below commit 8dec7ba9a7c4969eb2e376c6f80f529e52f884e3 Author: yuzhao.cyz AuthorDate: Mon Jun 8 15:45:58 2020 +0800 Following CALCITE-4031, some code style promotion * Remove useless code in SqlValidatorImpl and SqlToRelConverter * Mark SqlValidator#setValidatedNodeType interval instead of deprecated * Implement Symbolizable where possible * Some cosmetic changes --- .../java/org/apache/calcite/plan/RelOptNode.java | 2 +- .../org/apache/calcite/sql/JoinConditionType.java | 14 +-- .../main/java/org/apache/calcite/sql/JoinType.java | 13 +-- .../java/org/apache/calcite/sql/SqlExplain.java| 12 +-- .../org/apache/calcite/sql/SqlExplainFormat.java | 14 +-- .../org/apache/calcite/sql/SqlExplainLevel.java| 14 +-- .../org/apache/calcite/sql/SqlInsertKeyword.java | 14 +-- .../apache/calcite/sql/SqlJdbcDataTypeName.java| 10 +- .../org/apache/calcite/sql/SqlMatchRecognize.java | 10 +- .../org/apache/calcite/sql/SqlSelectKeyword.java | 14 +-- .../java/org/apache/calcite/sql/SqlWindow.java | 10 +- .../apache/calcite/sql/fun/SqlTrimFunction.java| 11 +-- .../apache/calcite/sql/validate/SqlValidator.java | 7 +- .../calcite/sql/validate/SqlValidatorImpl.java | 109 +++-- .../validate/implicit/AbstractTypeCoercion.java| 1 - .../apache/calcite/sql2rel/SqlToRelConverter.java | 16 ++- 16 files changed, 41 insertions(+), 230 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptNode.java b/core/src/main/java/org/apache/calcite/plan/RelOptNode.java index 6ba931b..2a0f077 100644 --- a/core/src/main/java/org/apache/calcite/plan/RelOptNode.java +++ b/core/src/main/java/org/apache/calcite/plan/RelOptNode.java @@ -35,7 +35,7 @@ public interface RelOptNode { /** * Returns a string which concisely describes the definition of this * relational expression. Two relational expressions are equivalent if - * their digests and {@link #getRowType()} are the same. + * their digests and {@link #getRowType()} (except the field names) are the same. * * The digest does not contain the relational expression's identity -- * that would prevent similar relational expressions from ever comparing diff --git a/core/src/main/java/org/apache/calcite/sql/JoinConditionType.java b/core/src/main/java/org/apache/calcite/sql/JoinConditionType.java index ce32ba4..421af6f 100644 --- a/core/src/main/java/org/apache/calcite/sql/JoinConditionType.java +++ b/core/src/main/java/org/apache/calcite/sql/JoinConditionType.java @@ -16,12 +16,10 @@ */ package org.apache.calcite.sql; -import org.apache.calcite.sql.parser.SqlParserPos; - /** * Enumerates the types of condition in a join expression. */ -public enum JoinConditionType { +public enum JoinConditionType implements Symbolizable { /** * Join clause has no condition, for example "FROM EMP, DEPT" */ @@ -37,13 +35,5 @@ public enum JoinConditionType { * Join clause has a USING condition, for example "FROM EMP JOIN DEPT * USING (DEPTNO)" */ - USING; - - /** - * Creates a parse-tree node representing an occurrence of this join - * type at a particular position in the parsed text. - */ - public SqlLiteral symbol(SqlParserPos pos) { -return SqlLiteral.createSymbol(this, pos); - } + USING } diff --git a/core/src/main/java/org/apache/calcite/sql/JoinType.java b/core/src/main/java/org/apache/calcite/sql/JoinType.java index 698097e..fa689c6 100644 --- a/core/src/main/java/org/apache/calcite/sql/JoinType.java +++ b/core/src/main/java/org/apache/calcite/sql/JoinType.java @@ -16,14 +16,12 @@ */ package org.apache.calcite.sql; -import org.apache.calcite.sql.parser.SqlParserPos; - import java.util.Locale; /** * Enumerates the types of join. */ -public enum JoinType { +public enum JoinType implements Symbolizable { /** * Inner join. */ @@ -81,13 +79,4 @@ public enum JoinType { public boolean generatesNullsOnRight() { return this == LEFT || this == FULL; } - - /** - * Creates a parse-tree node representing an occurrence of this - * condition type keyword at a particular position in the parsed - * text. - */ - public SqlLiteral symbol(SqlParserPos pos) { -return SqlLiteral.createSymbol(this, pos); - } } diff --git a/core/src/main/java/org/apache/calcite/sql/SqlExplain.java b/core/src/main/java/org/apache/calcite/sql/SqlExplain.java index 4c96177..caa434f 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlExplain.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlExplain.java @@ -40,16 +40,8 @@ public class SqlExp
[calcite] branch master updated: [CALCITE-4031] Remove code to be removed before 1.24
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 61bba25 [CALCITE-4031] Remove code to be removed before 1.24 61bba25 is described below commit 61bba252075abad42f4b239636367acead838144 Author: yuzhao.cyz AuthorDate: Fri May 29 16:57:42 2020 +0800 [CALCITE-4031] Remove code to be removed before 1.24 * Remove code to be removed before 1.24; * Make sure that any code labelled @Deprecated is followed by a comment 'to be removed before x.x'; * Fix some code which uses Bug.upgrade(); * Some cosmetic changes. --- .../calcite/config/CalciteConnectionProperty.java | 26 +--- .../org/apache/calcite/interpreter/Bindables.java | 13 -- .../apache/calcite/jdbc/ContextSqlValidator.java | 3 +- .../apache/calcite/plan/AbstractRelOptPlanner.java | 4 - .../org/apache/calcite/plan/RelOptPlanner.java | 19 --- .../java/org/apache/calcite/plan/RelTraitDef.java | 18 --- .../calcite/plan/volcano/VolcanoPlanner.java | 8 -- .../apache/calcite/rel/hint/HintOptionChecker.java | 11 +- .../org/apache/calcite/rel/hint/HintStrategy.java | 4 +- .../apache/calcite/rel/hint/HintStrategyTable.java | 23 +-- .../java/org/apache/calcite/rel/hint/RelHint.java | 67 + .../apache/calcite/rel/rules/DateRangeRules.java | 3 - .../main/java/org/apache/calcite/rex/RexUtil.java | 2 +- .../main/java/org/apache/calcite/runtime/Hook.java | 4 +- .../org/apache/calcite/runtime/SqlFunctions.java | 10 +- .../org/apache/calcite/sql/advise/SqlAdvisor.java | 2 +- .../apache/calcite/sql/advise/SqlSimpleParser.java | 4 +- .../apache/calcite/sql/validate/SqlValidator.java | 155 - .../calcite/sql/validate/SqlValidatorImpl.java | 19 --- .../validate/implicit/AbstractTypeCoercion.java| 10 +- .../sql/validate/implicit/TypeCoercion.java| 24 ++-- .../org/apache/calcite/util/ImmutableIntList.java | 10 +- .../calcite/test/AbstractMaterializedViewTest.java | 82 ++- .../org/apache/calcite/test/CalciteAssert.java | 13 -- .../apache/calcite/linq4j/function/Functions.java | 7 +- .../calcite/linq4j/function/FunctionTest.java | 7 +- 26 files changed, 135 insertions(+), 413 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java b/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java index a061fb7..f09b052 100644 --- a/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java +++ b/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java @@ -21,16 +21,15 @@ import org.apache.calcite.avatica.util.Casing; import org.apache.calcite.avatica.util.Quoting; import org.apache.calcite.model.JsonSchema; import org.apache.calcite.sql.validate.SqlConformanceEnum; -import org.apache.calcite.util.Bug; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.TimeZone; import static org.apache.calcite.avatica.ConnectionConfigImpl.PropEnv; +import static org.apache.calcite.avatica.ConnectionConfigImpl.parse; /** * Properties that may be specified on the JDBC connect string. @@ -222,27 +221,6 @@ public enum CalciteConnectionProperty implements ConnectionProperty { } public PropEnv wrap(Properties properties) { -return new PropEnv(parse2(properties, NAME_TO_PROPS), this); +return new PropEnv(parse(properties, NAME_TO_PROPS), this); } - - /** Fixed version of - * {@link org.apache.calcite.avatica.ConnectionConfigImpl#parse} - * until we upgrade Avatica. */ - private static Map parse2(Properties properties, - Map nameToProps) { -Bug.upgrade("avatica-1.10"); -final Map map = new LinkedHashMap<>(); -for (String name : properties.stringPropertyNames()) { - final ConnectionProperty connectionProperty = - nameToProps.get(name.toUpperCase(Locale.ROOT)); - if (connectionProperty == null) { -// For now, don't throw. It messes up sub-projects. -//throw new RuntimeException("Unknown property '" + name + "'"); -continue; - } - map.put(connectionProperty, properties.getProperty(name)); -} -return map; - } - } diff --git a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java index 8490405..958437a 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java +++ b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java @@ -521,19 +521,6 @@ public class Bindables { } } - @Deprecated // Use BindableSetOpRule instead, to be removed before 1.24.0 - public st
[calcite] branch master updated: [CALCITE-3973] Hints should not unparse as enclosed in parentheses (Alex Baden)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 22fca8e [CALCITE-3973] Hints should not unparse as enclosed in parentheses (Alex Baden) 22fca8e is described below commit 22fca8e43d62ffae12b7d7e1a50438f257ac88b3 Author: Alex Baden AuthorDate: Wed May 6 00:05:14 2020 -0600 [CALCITE-3973] Hints should not unparse as enclosed in parentheses (Alex Baden) close apache/calcite#1961 --- core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java | 2 +- .../test/java/org/apache/calcite/sql/parser/SqlParserTest.java| 8 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java index f55072c..5d12b71 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java @@ -147,7 +147,7 @@ public class SqlSelectOperator extends SqlOperator { if (select.hasHints()) { writer.sep("/*+"); - select.hints.unparse(writer, leftPrec, rightPrec); + select.hints.unparse(writer, 0, 0); writer.print("*/"); writer.newlineAndIndent(); } diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java index fa31a6d..21b664f 100644 --- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java +++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java @@ -8664,6 +8664,14 @@ public class SqlParserTest { + "`EMPNO`\n" + "FROM `EMPS`"; sql(sql2).ok(expected2); +// Hint item without parentheses +final String sql3 = "select /*+ simple_hint */ empno, ename, deptno from emps limit 2"; +final String expected3 = "SELECT\n" ++ "/*+ `SIMPLE_HINT` */\n" ++ "`EMPNO`, `ENAME`, `DEPTNO`\n" ++ "FROM `EMPS`\n" ++ "FETCH NEXT 2 ROWS ONLY"; +sql(sql3).ok(expected3); } @Test void testTableHintsInQuery() {
[calcite] branch master updated (9adf4a4 -> f1c0756)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from 9adf4a4 [CALCITE-3938] Support LogicalCalc in RelShuttle (dz) add f1c0756 [CALCITE-3962] Make JSON_VALUE operands varadic No new revisions were added by this update. Summary of changes: core/src/main/codegen/templates/Parser.jj | 39 ++--- .../calcite/adapter/enumerable/RexImpTable.java| 84 - .../org/apache/calcite/runtime/JsonFunctions.java | 10 +- .../org/apache/calcite/sql/SqlInfixOperator.java | 4 - .../apache/calcite/sql/SqlJsonEmptyOrError.java| 4 +- .../calcite/sql/SqlJsonExistsErrorBehavior.java| 2 +- .../sql/SqlJsonValueEmptyOrErrorBehavior.java | 11 +- ...lAccessEnum.java => SqlJsonValueReturning.java} | 6 +- .../{SqlSelectKeyword.java => Symbolizable.java} | 13 +- .../calcite/sql/fun/SqlDatetimePlusOperator.java | 5 - .../sql/fun/SqlDatetimeSubtractionOperator.java| 5 - .../calcite/sql/fun/SqlJsonExistsFunction.java | 13 +- .../calcite/sql/fun/SqlJsonValueFunction.java | 192 +++-- .../org/apache/calcite/sql/fun/SqlRowOperator.java | 7 - .../calcite/sql/fun/SqlStdOperatorTable.java | 5 +- .../calcite/sql2rel/StandardConvertletTable.java | 35 ++-- .../org/apache/calcite/util/BuiltInMethod.java | 3 +- .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 4 +- .../apache/calcite/sql/parser/SqlParserTest.java | 2 +- .../calcite/sql/test/SqlOperatorBaseTest.java | 1 - .../apache/calcite/test/SqlJsonFunctionsTest.java | 8 +- .../org/apache/calcite/test/SqlValidatorTest.java | 1 + .../apache/calcite/test/SqlToRelConverterTest.xml | 2 +- 23 files changed, 207 insertions(+), 249 deletions(-) copy core/src/main/java/org/apache/calcite/sql/{SqlAccessEnum.java => SqlJsonValueReturning.java} (86%) copy core/src/main/java/org/apache/calcite/sql/{SqlSelectKeyword.java => Symbolizable.java} (80%)
[calcite] branch master updated: [CALCITE-3789] Supports Presto style unnest with items alias (Will Yu)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new e44beba [CALCITE-3789] Supports Presto style unnest with items alias (Will Yu) e44beba is described below commit e44beba286ea9049c5fd00c3a3b0e4a4f1c03356 Author: Will Yu AuthorDate: Tue Feb 25 19:44:26 2020 -0800 [CALCITE-3789] Supports Presto style unnest with items alias (Will Yu) This patch also add a new PRESTO conformance. Fix-up (by Danny): - Fix SqlTypeUtil#flattenRecordType to not append field index if there are no duplicates - Rename SqlConformance#allowAliasUnnestColumns to SqlConformance#allowAliasUnnestItems - Fix RelStructuredTypeFlattener to not generate flattenned field based on struct field - Promote SqlToRelConverter#convertFrom to allow specify field aliases - Add comment to RelBuilder#uncollect close apache/calcite#1811 --- .../adapter/enumerable/EnumerableUncollect.java| 3 +- .../org/apache/calcite/rel/core/Uncollect.java | 63 - .../calcite/rel/logical/ToLogicalConverter.java| 6 +- .../apache/calcite/rel/mutable/MutableRels.java| 4 +- .../org/apache/calcite/sql/SqlUnnestOperator.java | 11 ++- .../org/apache/calcite/sql/type/SqlTypeUtil.java | 15 +++- .../sql/validate/SqlAbstractConformance.java | 3 + .../calcite/sql/validate/SqlConformance.java | 64 - .../calcite/sql/validate/SqlConformanceEnum.java | 21 ++ .../sql/validate/SqlDelegatingConformance.java | 4 ++ .../sql2rel/RelStructuredTypeFlattener.java| 20 ++ .../apache/calcite/sql2rel/SqlToRelConverter.java | 80 ++ .../java/org/apache/calcite/tools/RelBuilder.java | 22 ++ .../apache/calcite/sql/test/SqlAdvisorTest.java| 1 + .../apache/calcite/test/SqlToRelConverterTest.java | 26 ++- .../org/apache/calcite/test/SqlValidatorTest.java | 37 ++ .../org/apache/calcite/test/catalog/Fixture.java | 5 +- .../test/catalog/MockCatalogReaderSimple.java | 10 +++ .../apache/calcite/test/SqlToRelConverterTest.xml | 30 +++- .../org/apache/calcite/piglet/PigRelBuilder.java | 8 ++- 20 files changed, 355 insertions(+), 78 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java index cf7..6608dda 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java @@ -32,6 +32,7 @@ import org.apache.calcite.util.BuiltInMethod; import com.google.common.primitives.Ints; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** Implementation of {@link org.apache.calcite.rel.core.Uncollect} in @@ -48,7 +49,7 @@ public class EnumerableUncollect extends Uncollect implements EnumerableRel { * Use {@link #create} unless you know what you're doing. */ public EnumerableUncollect(RelOptCluster cluster, RelTraitSet traitSet, RelNode child, boolean withOrdinality) { -super(cluster, traitSet, child, withOrdinality); +super(cluster, traitSet, child, withOrdinality, Collections.emptyList()); assert getConvention() instanceof EnumerableConvention; assert getConvention() == child.getConvention(); } diff --git a/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java b/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java index c519552..45caa41 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java +++ b/core/src/main/java/org/apache/calcite/rel/core/Uncollect.java @@ -30,6 +30,9 @@ import org.apache.calcite.sql.SqlUnnestOperator; import org.apache.calcite.sql.type.MapSqlType; import org.apache.calcite.sql.type.SqlTypeName; +import com.google.common.collect.ImmutableList; + +import java.util.Collections; import java.util.List; /** @@ -46,21 +49,31 @@ import java.util.List; public class Uncollect extends SingleRel { public final boolean withOrdinality; + // To alias the items in Uncollect list, + // i.e., "UNNEST(a, b, c) as T(d, e, f)" + // outputs as row type Record(d, e, f) where the field "d" has element type of "a", + // field "e" has element type of "b"(Presto dialect). + + // Without the aliases, the expression "UNNEST(a)" outputs row type + // same with element type of "a". + private final List itemAliases; + //~ Constructors --- @Deprecated // to be removed before 2.0 public Uncollect(RelOptCluster cluster, RelTraitSet traitSet, RelNode
[calcite] branch master updated (f62d6b9 -> 2129000)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from f62d6b9 [CALCITE-3955] Remove the first operand of RexCall from SqlWindowTableFunction add 2129000 [CALCITE-3954] Always compare types using equals No new revisions were added by this update. Summary of changes: core/src/main/java/org/apache/calcite/plan/RelOptUtil.java| 4 ++-- .../main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java| 8 +++- core/src/main/java/org/apache/calcite/rex/RexLocalRef.java| 2 +- core/src/main/java/org/apache/calcite/rex/RexUtil.java| 4 ++-- core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-)
[calcite] branch master updated: [CALCITE-3955] Remove the first operand of RexCall from SqlWindowTableFunction
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new f62d6b9 [CALCITE-3955] Remove the first operand of RexCall from SqlWindowTableFunction f62d6b9 is described below commit f62d6b9a2f3dd877d4e2e5cbd2ff5d0d5f0efff1 Author: yuzhao.cyz AuthorDate: Fri Apr 24 17:42:42 2020 +0800 [CALCITE-3955] Remove the first operand of RexCall from SqlWindowTableFunction In CALCITE-3382, we introduced TUMBLE window function to replace the deprecated group tumble window. But for query ```sql select * from table(tumble(table Shipments, descriptor(rowtime), INTERVAL '1' MINUTE)) ``` the output plan is ```xml LogicalProject LogicalTableFunctionScan(invocation=[TUMBLE($1, ...)], rowType=...) LogicalProject LogicalTableScan ``` The first operand of TUMBLE rex call is always the last input field, but actually it represents the source table which is the input rel node. Removes the first operand from the RexCall because it is useless and confusing. --- .../apache/calcite/adapter/enumerable/RexImpTable.java | 6 -- .../apache/calcite/sql2rel/StandardConvertletTable.java | 17 + .../org/apache/calcite/test/SqlToRelConverterTest.java | 4 .../org/apache/calcite/test/SqlToRelConverterTest.xml | 4 ++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java index d095c79..669c316 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java @@ -3129,8 +3129,10 @@ public class RexImpTable { @Override public Expression implement(RexToLixTranslator translator, Expression inputEnumerable, RexCall call, PhysType inputPhysType, PhysType outputPhysType) { - Expression intervalExpression = translator.translate(call.getOperands().get(2)); - RexCall descriptor = (RexCall) call.getOperands().get(1); + // The table operand is removed from the RexCall because it + // represents the input, see StandardConvertletTable#convertWindowFunction. + Expression intervalExpression = translator.translate(call.getOperands().get(1)); + RexCall descriptor = (RexCall) call.getOperands().get(0); List translatedOperands = new ArrayList<>(); final ParameterExpression parameter = Expressions.parameter(Primitive.box(inputPhysType.getJavaRowType()), "_input"); diff --git a/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java b/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java index 245320b..747ac8e 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java @@ -46,6 +46,7 @@ import org.apache.calcite.sql.SqlNodeList; import org.apache.calcite.sql.SqlNumericLiteral; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.SqlUtil; +import org.apache.calcite.sql.SqlWindowTableFunction; import org.apache.calcite.sql.fun.SqlArrayValueConstructor; import org.apache.calcite.sql.fun.SqlBetweenOperator; import org.apache.calcite.sql.fun.SqlCase; @@ -663,6 +664,22 @@ public class StandardConvertletTable extends ReflectiveConvertletTable { return cx.getRexBuilder().makeCall(returnType, fun, exprs); } + public RexNode convertWindowFunction( + SqlRexContext cx, + SqlWindowTableFunction fun, + SqlCall call) { +// The first operand of window function is actually a query, skip that. +final List operands = Util.skip(call.getOperandList(), 1); +final List exprs = convertExpressionList(cx, operands, +SqlOperandTypeChecker.Consistency.NONE); +RelDataType returnType = +cx.getValidator().getValidatedNodeTypeIfKnown(call); +if (returnType == null) { + returnType = cx.getRexBuilder().deriveReturnType(fun, exprs); +} +return cx.getRexBuilder().makeCall(returnType, fun, exprs); + } + public RexNode convertSequenceValue( SqlRexContext cx, SqlSequenceValueOperator fun, diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 36c2914..338b99e 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -1776,16 +1776,12 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
[calcite] branch master updated: [CALCITE-3942] Move type-coercion configurations into SqlValidator.Config
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 3807696 [CALCITE-3942] Move type-coercion configurations into SqlValidator.Config 3807696 is described below commit 38076961698c5354375be7856944809e71cd5a21 Author: yuzhao.cyz AuthorDate: Tue Apr 21 15:01:02 2020 +0800 [CALCITE-3942] Move type-coercion configurations into SqlValidator.Config SqlValidator.Config is the new role to config all kinds of configurations of SqlValidator. --- .../calcite/sql/type/SqlTypeCoercionRule.java | 5 +-- .../apache/calcite/sql/validate/SqlValidator.java | 40 +- .../calcite/sql/validate/SqlValidatorImpl.java | 6 ++-- .../validate/implicit/AbstractTypeCoercion.java| 7 ++-- ...TypeCoercions.java => TypeCoercionFactory.java} | 31 +++-- .../sql/validate/implicit/TypeCoercionImpl.java| 5 +-- .../sql/validate/implicit/TypeCoercions.java | 10 +++--- 7 files changed, 78 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeCoercionRule.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeCoercionRule.java index f819d5a..fc785d9 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeCoercionRule.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeCoercionRule.java @@ -62,8 +62,9 @@ import java.util.Set; * SqlTypeCoercionRules typeCoercionRules = SqlTypeCoercionRules.instance(builder.map); * * // Set the SqlTypeCoercionRules instance into the SqlValidator. - * SqlValidator validator ...; - * validator.setSqlTypeCoercionRules(typeCoercionRules); + * SqlValidator.Config validatorConf ...; + * validatorConf.withTypeCoercionRules(typeCoercionRules); + * // Use this conf to initialize the SqlValidator. * */ public class SqlTypeCoercionRule implements SqlTypeMappingRule { diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidator.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidator.java index e461034..620703c 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidator.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidator.java @@ -44,6 +44,8 @@ import org.apache.calcite.sql.SqlWith; import org.apache.calcite.sql.SqlWithItem; import org.apache.calcite.sql.type.SqlTypeCoercionRule; import org.apache.calcite.sql.validate.implicit.TypeCoercion; +import org.apache.calcite.sql.validate.implicit.TypeCoercionFactory; +import org.apache.calcite.sql.validate.implicit.TypeCoercions; import org.apache.calcite.util.ImmutableBeans; import org.apiguardian.api.API; @@ -868,7 +870,10 @@ public interface SqlValidator { * {@link org.apache.calcite.sql.validate.implicit.TypeCoercionImpl}. * * @param typeCoercion {@link TypeCoercion} instance + * + * @deprecated Use {@link Config#withTypeCoercionFactory} */ + @Deprecated // to be removed before 1.24 void setTypeCoercion(TypeCoercion typeCoercion); /** Get the type coercion instance. */ @@ -884,7 +889,10 @@ public interface SqlValidator { * * @param typeCoercionRules The {@link SqlTypeCoercionRule} instance, see its documentation * for how to customize the rules. + * + * @deprecated Use {@link Config#withTypeCoercionRules} */ + @Deprecated // to be removed before 1.24 void setSqlTypeCoercionRules(SqlTypeCoercionRule typeCoercionRules); /** Returns the config of the validator. */ @@ -908,7 +916,8 @@ public interface SqlValidator { */ public interface Config { /** Default configuration. */ -SqlValidator.Config DEFAULT = ImmutableBeans.create(Config.class); +SqlValidator.Config DEFAULT = ImmutableBeans.create(Config.class) +.withTypeCoercionFactory(TypeCoercions::createTypeCoercion); /** * Returns whether to enable rewrite of "macro-like" calls such as COALESCE. @@ -1001,6 +1010,35 @@ public interface SqlValidator { */ Config withTypeCoercionEnabled(boolean enabled); +/** Returns the type coercion factory. */ +@ImmutableBeans.Property +TypeCoercionFactory typeCoercionFactory(); + +/** + * Sets a factory to create type coercion instance that overrides the + * default coercion rules defined in + * {@link org.apache.calcite.sql.validate.implicit.TypeCoercionImpl}. + * + * @param factory Factory to create {@link TypeCoercion} instance + */ +Config withTypeCoercionFactory(TypeCoercionFactory factory); + +/** Returns the type coercion rules for explicit type coercion. */ +@ImmutableBeans.Property +SqlTypeCoercionRule typeCoercionRules(); + +/** + * Sets the {@link SqlTypeCoercionRule} instance which defines the typ
[calcite] branch master updated: [CALCITE-3940] Hint item can not parse correctly if the name is right after token /*+
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new eed3d1b [CALCITE-3940] Hint item can not parse correctly if the name is right after token /*+ eed3d1b is described below commit eed3d1b408f7720b7dae1c8529a4236895617f67 Author: yuzhao.cyz AuthorDate: Mon Apr 20 12:07:18 2020 +0800 [CALCITE-3940] Hint item can not parse correctly if the name is right after token /*+ --- core/src/main/codegen/templates/Parser.jj | 2 +- .../java/org/apache/calcite/sql/parser/SqlParserTest.java | 13 ++--- .../java/org/apache/calcite/sql/test/SqlAdvisorTest.java| 12 +++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index db60271..cefe343 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -7643,7 +7643,7 @@ of the 'normal states'. TOKEN : { -< HINT_BEG: "/*+" ~["/"] > +< HINT_BEG: "/*+"> | < COMMENT_END: "*/" > } diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java index df6c180..8340105 100644 --- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java +++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java @@ -8644,19 +8644,26 @@ public class SqlParserTest { } @Test void testQueryHint() { -final String sql = "select " +final String sql1 = "select " + "/*+ properties(k1='v1', k2='v2', 'a.b.c'='v3'), " + "no_hash_join, Index(idx1, idx2), " + "repartition(3) */ " + "empno, ename, deptno from emps"; -final String expected = "SELECT\n" +final String expected1 = "SELECT\n" + "/*+ `PROPERTIES`(`K1` = 'v1', `K2` = 'v2', 'a.b.c' = 'v3'), " + "`NO_HASH_JOIN`, " + "`INDEX`(`IDX1`, `IDX2`), " + "`REPARTITION`(3) */\n" + "`EMPNO`, `ENAME`, `DEPTNO`\n" + "FROM `EMPS`"; -sql(sql).ok(expected); +sql(sql1).ok(expected1); +// Hint item right after the token "/*+" +final String sql2 = "select /*+properties(k1='v1', k2='v2')*/ empno from emps"; +final String expected2 = "SELECT\n" ++ "/*+ `PROPERTIES`(`K1` = 'v1', `K2` = 'v2') */\n" ++ "`EMPNO`\n" ++ "FROM `EMPS`"; +sql(sql2).ok(expected2); } @Test void testTableHintsInQuery() { diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java index d0f9788..ebfd102 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java +++ b/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java @@ -58,7 +58,7 @@ class SqlAdvisorTest extends SqlValidatorTestCase { SqlTestFactory.INSTANCE.withValidator(SqlAdvisorValidator::new); private static final List STAR_KEYWORD = - Arrays.asList( + Collections.singletonList( "KEYWORD(*)"); protected static final List FROM_KEYWORDS = @@ -105,7 +105,7 @@ class SqlAdvisorTest extends SqlValidatorTestCase { "TABLE(B)"); private static final List EMP_TABLE = - Arrays.asList( + Collections.singletonList( "TABLE(EMP)"); protected static final List FETCH_OFFSET = @@ -242,7 +242,8 @@ class SqlAdvisorTest extends SqlValidatorTestCase { "KEYWORD(ALL)", "KEYWORD(DISTINCT)", "KEYWORD(STREAM)", - "KEYWORD(*)"); + "KEYWORD(*)", + "KEYWORD(/*+)"); private static final List ORDER_KEYWORDS = Arrays.asList( @@ -325,7 +326,7 @@ class SqlAdvisorTest extends SqlValidatorTestCase { "KEYWORD(WINDOW)"); private static final List A_TABLE = - Arrays.asList( + Collections.singletonList( "TABLE(A)"); protected static final List JOIN_KEYWORDS = @@ -339,6 +340,7 @@ class SqlAdvisorTest extends SqlValidatorTestCase { "KEYWORD(ORDER)", "KEYWORD(()", "KEYWORD(EXTEND)", + "KEYWORD(/*+)", "KEYWORD(AS)", "KEYWORD(USING)", "KEYWORD(OUTER)", @@ -1579,6 +1581,6 @@ class SqlAdvisorTest extends SqlValidatorTestCase { String simplified = "SELECT * FROM [DEPT] a WHERE _suggest_ and deptno < 5"; assertSimplify(sql, simplified); -assertComplete(sql, EXPR_KEYWORDS, Arrays.asList("TABLE(a)"), DEPT_COLUMNS); +assertComplete(sql, EXPR_KEYWORDS, Collections.singletonList("TABLE(a)"), DEPT_COLUMNS); } }
[calcite] branch master updated: [CALCITE-3931] Add LOOKAHEAD(2) for methods defined in createStatementParserMethods
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 5c2b158 [CALCITE-3931] Add LOOKAHEAD(2) for methods defined in createStatementParserMethods 5c2b158 is described below commit 5c2b15814b4fbe42a4f1d720ad99719c68c0448b Author: yuzhao.cyz AuthorDate: Thu Apr 16 19:38:42 2020 +0800 [CALCITE-3931] Add LOOKAHEAD(2) for methods defined in createStatementParserMethods The default LOOKAHEAD is 1 which is very probably to conflict, especially for custom parse block like SqlCreate. Sets the LOOKAHEAD(2) to reduce conflict. --- core/src/main/codegen/templates/Parser.jj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index eebd80c..db60271 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -3938,7 +3938,7 @@ SqlCreate SqlCreate() : <#-- additional literal parser methods are included here --> <#list parser.createStatementParserMethods as method> create = ${method}(s, replace) -<#sep>| +<#sep>| LOOKAHEAD(2) ) {
[calcite] branch master updated: [CALCITE-3934] Allow type-coercion in CONCAT operator
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 238cf03 [CALCITE-3934] Allow type-coercion in CONCAT operator 238cf03 is described below commit 238cf037ebcd0e0e6f121f2304fa46a61c90632b Author: yuzhao.cyz AuthorDate: Fri Apr 17 14:47:00 2020 +0800 [CALCITE-3934] Allow type-coercion in CONCAT operator Such as CONCAT(123, 'abc', DATE '2020-04-17') yields '123abc2020-04-17'. This change actually enables implicit type coercion for all the operators with repeat type families. --- .../sql/type/CompositeOperandTypeChecker.java | 48 ++ .../validate/implicit/AbstractTypeCoercion.java| 32 +++ .../sql/validate/implicit/TypeCoercionImpl.java| 43 ++- .../org/apache/calcite/test/SqlValidatorTest.java | 21 -- 4 files changed, 84 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/type/CompositeOperandTypeChecker.java b/core/src/main/java/org/apache/calcite/sql/type/CompositeOperandTypeChecker.java index 4bfad35..71bd867 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/CompositeOperandTypeChecker.java +++ b/core/src/main/java/org/apache/calcite/sql/type/CompositeOperandTypeChecker.java @@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableList; import java.util.AbstractList; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -274,6 +275,9 @@ public class CompositeOperandTypeChecker implements SqlOperandTypeChecker { callBinding.getCall().operand(operand), 0, false)) { +if (callBinding.isTypeCoercionEnabled()) { + return coerceOperands(callBinding, true); +} return false; } } @@ -293,23 +297,7 @@ public class CompositeOperandTypeChecker implements SqlOperandTypeChecker { 0, false)) { if (callBinding.isTypeCoercionEnabled()) { -// Try type coercion for the call, -// collect SqlTypeFamily and data type of all the operands. -final List families = allowedRules.stream() -.filter(r -> r instanceof ImplicitCastOperandTypeChecker) -.map(r -> ((ImplicitCastOperandTypeChecker) r).getOperandSqlTypeFamily(0)) -.collect(Collectors.toList()); -if (families.size() < allowedRules.size()) { - // Not all the checkers are ImplicitCastOperandTypeChecker, returns early. - return false; -} -final List operandTypes = new ArrayList<>(); -for (int i = 0; i < callBinding.getOperandCount(); i++) { - operandTypes.add(callBinding.getOperandType(i)); -} -TypeCoercion typeCoercion = callBinding.getValidator().getTypeCoercion(); -return typeCoercion.builtinFunctionCoercion(callBinding, -operandTypes, families); +return coerceOperands(callBinding, false); } return false; } @@ -347,6 +335,32 @@ public class CompositeOperandTypeChecker implements SqlOperandTypeChecker { } } + /** Tries to coerce the operands based on the defined type families. */ + private boolean coerceOperands(SqlCallBinding callBinding, boolean repeat) { +// Type coercion for the call, +// collect SqlTypeFamily and data type of all the operands. +List families = allowedRules.stream() +.filter(r -> r instanceof ImplicitCastOperandTypeChecker) +// All the rules are SqlSingleOperandTypeChecker. +.map(r -> ((ImplicitCastOperandTypeChecker) r).getOperandSqlTypeFamily(0)) +.collect(Collectors.toList()); +if (families.size() < allowedRules.size()) { + // Not all the checkers are ImplicitCastOperandTypeChecker, returns early. + return false; +} +if (repeat) { + assert families.size() == 1; + families = Collections.nCopies(callBinding.getOperandCount(), families.get(0)); +} +final List operandTypes = new ArrayList<>(); +for (int i = 0; i < callBinding.getOperandCount(); i++) { + operandTypes.add(callBinding.getOperandType(i)); +} +TypeCoercion typeCoercion = callBinding.getValidator().getTypeCoercion(); +return typeCoercion.builtinFunctionCoercion(callBinding, +operandTypes, families); + } + private boolean checkWithoutTypeCoercion(SqlCallBinding callBinding) { if (!callBinding.isTypeCoercionEnabled()) { return false; diff --git a/core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java b/core/src/main/
[calcite] branch master updated: Disable SourceTest#testAbsoluteFileToUrl until we really fix that
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 33daf82 Disable SourceTest#testAbsoluteFileToUrl until we really fix that 33daf82 is described below commit 33daf827b3b8cfa255dc7018d7fcfc9384a13542 Author: yuzhao.cyz AuthorDate: Sat Apr 18 11:38:56 2020 +0800 Disable SourceTest#testAbsoluteFileToUrl until we really fix that --- core/src/test/java/org/apache/calcite/util/SourceTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/org/apache/calcite/util/SourceTest.java b/core/src/test/java/org/apache/calcite/util/SourceTest.java index f1ab5c8..1be1b31 100644 --- a/core/src/test/java/org/apache/calcite/util/SourceTest.java +++ b/core/src/test/java/org/apache/calcite/util/SourceTest.java @@ -18,6 +18,7 @@ package org.apache.calcite.util; import com.google.common.io.CharSource; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -106,6 +107,7 @@ class SourceTest { @ParameterizedTest @MethodSource("relativePaths") + @Disabled // Open when we really fix that void testAbsoluteFileToUrl(String path, String expectedUrl) throws URISyntaxException { File absoluteFile = new File(path).getAbsoluteFile(); URL url = of(absoluteFile).url();
[calcite] branch master updated: [CALCITE-2157] ClickHouse dialect implementation (Chris Baynes)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 39e5856 [CALCITE-2157] ClickHouse dialect implementation (Chris Baynes) 39e5856 is described below commit 39e58566c1ac02824d99ae9260d3315539efd57e Author: Chris Baynes AuthorDate: Tue Jan 30 14:13:12 2018 +0100 [CALCITE-2157] ClickHouse dialect implementation (Chris Baynes) close apache/calcite#618 --- .../java/org/apache/calcite/sql/SqlDialect.java| 4 + .../apache/calcite/sql/SqlDialectFactoryImpl.java | 5 + .../calcite/sql/dialect/ClickHouseSqlDialect.java | 242 + .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 83 ++- 4 files changed, 333 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java index 07f82c6..2ef11f9 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java @@ -274,6 +274,9 @@ public class SqlDialect { case "ACCESS": return DatabaseProduct.ACCESS; case "APACHE DERBY": + return DatabaseProduct.DERBY; +case "CLICKHOUSE": + return DatabaseProduct.CLICKHOUSE; case "DBMS:CLOUDSCAPE": return DatabaseProduct.DERBY; case "HIVE": @@ -1226,6 +1229,7 @@ public class SqlDialect { ACCESS("Access", "\"", NullCollation.HIGH), BIG_QUERY("Google BigQuery", "`", NullCollation.LOW), CALCITE("Apache Calcite", "\"", NullCollation.HIGH), +CLICKHOUSE("ClickHouse", "`", NullCollation.LOW), MSSQL("Microsoft SQL Server", "[", NullCollation.HIGH), MYSQL("MySQL", "`", NullCollation.LOW), ORACLE("Oracle", "\"", NullCollation.HIGH), diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java b/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java index 6d265f1..82d07cf 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDialectFactoryImpl.java @@ -22,6 +22,7 @@ import org.apache.calcite.sql.dialect.AccessSqlDialect; import org.apache.calcite.sql.dialect.AnsiSqlDialect; import org.apache.calcite.sql.dialect.BigQuerySqlDialect; import org.apache.calcite.sql.dialect.CalciteSqlDialect; +import org.apache.calcite.sql.dialect.ClickHouseSqlDialect; import org.apache.calcite.sql.dialect.Db2SqlDialect; import org.apache.calcite.sql.dialect.DerbySqlDialect; import org.apache.calcite.sql.dialect.FirebirdSqlDialect; @@ -102,6 +103,8 @@ public class SqlDialectFactoryImpl implements SqlDialectFactory { return new AccessSqlDialect(c); case "APACHE DERBY": return new DerbySqlDialect(c); +case "CLICKHOUSE": + return new ClickHouseSqlDialect(c); case "DBMS:CLOUDSCAPE": return new DerbySqlDialect(c); case "HIVE": @@ -244,6 +247,8 @@ public class SqlDialectFactoryImpl implements SqlDialectFactory { return BigQuerySqlDialect.DEFAULT; case CALCITE: return CalciteSqlDialect.DEFAULT; +case CLICKHOUSE: + return ClickHouseSqlDialect.DEFAULT; case DB2: return Db2SqlDialect.DEFAULT; case DERBY: diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java new file mode 100644 index 000..a05799d --- /dev/null +++ b/core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.calcite.sql.dialect; + +import org.apache.calcite.avatica.util.TimeUnitRange; +import org.apache.calcite.config.NullCollation; +import org.apache.calcite.rel.type.Re
[calcite] branch master updated (dfb842e -> 2798d90)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. from dfb842e [CALCITE-3924] Fix flakey test to handle TIMESTAMP and TIMESTAMP(0) correctly (neoReMinD) add 2798d90 [CALCITE-3894] SET operation between DATE and TIMESTAMP returns a wrong result No new revisions were added by this update. Summary of changes: .../apache/calcite/sql/type/SqlTypeAssignmentRule.java | 2 -- .../test/java/org/apache/calcite/test/JdbcTest.java| 14 ++ .../apache/calcite/test/TypeCoercionConverterTest.java | 7 +++ .../java/org/apache/calcite/test/TypeCoercionTest.java | 18 ++ .../apache/calcite/test/TypeCoercionConverterTest.xml | 13 + 5 files changed, 52 insertions(+), 2 deletions(-)
[calcite] branch CALCITE-3894 updated (8654d4d -> d63438d)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch CALCITE-3894 in repository https://gitbox.apache.org/repos/asf/calcite.git. discard 8654d4d [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result add d63438d [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (8654d4d) \ N -- N -- N refs/heads/CALCITE-3894 (d63438d) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. No new revisions were added by this update. Summary of changes:
[calcite] 01/01: [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch CALCITE-3894 in repository https://gitbox.apache.org/repos/asf/calcite.git commit 8654d4d8c9c20685c80ff633e505302be86c9697 Author: yuzhao.cyz AuthorDate: Thu Apr 16 11:48:40 2020 +0800 [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result The RelDataTypeFactory#leastRestrictive finds the common type for IN, CASE and SET operations. For common type with DATE and TIMESTAMP, it returns DATE. The root cause is that rules in SqlTypeAssignmentRule decide that DATE is assignable from TIMESTAMP and TIMESTAMP is assignable from DATE, which is actually wrong. Although in Java, this assignment makes sense but that does not mean it's true in SQL, because DATE and TIMESTAMP have different time unit. Fix the rules in SqlTypeAssignmentRule and let the implicit type coercion rule trigger. --- .../apache/calcite/sql/type/SqlTypeAssignmentRule.java | 2 -- .../test/java/org/apache/calcite/test/JdbcTest.java| 14 ++ .../apache/calcite/test/TypeCoercionConverterTest.java | 7 +++ .../java/org/apache/calcite/test/TypeCoercionTest.java | 18 ++ .../apache/calcite/test/TypeCoercionConverterTest.xml | 13 + 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java index 86be0fa..c345105 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java @@ -162,13 +162,11 @@ public class SqlTypeAssignmentRule implements SqlTypeMappingRule { // DATE is assignable from... rule.clear(); rule.add(SqlTypeName.DATE); -rule.add(SqlTypeName.TIMESTAMP); rules.add(SqlTypeName.DATE, rule); // TIME is assignable from... rule.clear(); rule.add(SqlTypeName.TIME); -rule.add(SqlTypeName.TIMESTAMP); rules.add(SqlTypeName.TIME, rule); // TIME WITH LOCAL TIME ZONE is assignable from... diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java index bbf3071..5e36781 100644 --- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java +++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java @@ -7401,6 +7401,20 @@ public class JdbcTest { .runs(); } + /** + * Test case for + * https://issues.apache.org/jira/browse/CALCITE-3894;>[CALCITE-3894] + * The Union operation between DATE with TIMESTAMP returns a wrong result. + */ + @Test public void testUnionDateTime() { +CalciteAssert.AssertThat assertThat = CalciteAssert.that(); +String query = "select * from (\n" ++ "select \"id\" from (VALUES(DATE '2018-02-03')) \"foo\"(\"id\")\n" ++ "union\n" ++ "select \"id\" from (VALUES(TIMESTAMP '2008-03-31 12:23:34')) \"foo\"(\"id\"))"; +assertThat.query(query).returns("id=2008-03-31 12:23:34\nid=2018-02-03 00:00:00\n"); + } + private static String sums(int n, boolean c) { final StringBuilder b = new StringBuilder(); for (int i = 0; i < n; i++) { diff --git a/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java b/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java index 03a5fbb..029f44f 100644 --- a/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java @@ -61,6 +61,13 @@ class TypeCoercionConverterTest extends SqlToRelTestBase { + "from (values (true, true, true))"); } + /** Test cases for {@link TypeCoercion#inOperationCoercion}. */ + @Test void testInDateTimestamp() { +checkPlanEquals("select (t1_timestamp, t1_date)\n" ++ "in ((DATE '2020-04-16', TIMESTAMP '2020-04-16 11:40:53'))\n" ++ "from t1"); + } + /** Test cases for * {@link org.apache.calcite.sql.validate.implicit.TypeCoercionImpl#booleanEquality}. */ @Test void testBooleanEquality() { diff --git a/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java b/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java index b41c7f6..ddd0a47 100644 --- a/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java +++ b/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java @@ -483,6 +483,12 @@ class TypeCoercionTest extends SqlValidatorTestCase { + "union select t1_int from t1") .columnType("VARCHAR NOT NULL"); +// date union timestamp +sql("select t1_date, t1_timestamp from t1
[calcite] branch CALCITE-3894 updated (f343263 -> 8654d4d)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch CALCITE-3894 in repository https://gitbox.apache.org/repos/asf/calcite.git. discard f343263 [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result new 8654d4d [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (f343263) \ N -- N -- N refs/heads/CALCITE-3894 (8654d4d) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes:
[calcite] branch CALCITE-3894 created (now f343263)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch CALCITE-3894 in repository https://gitbox.apache.org/repos/asf/calcite.git. at f343263 [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result This branch includes the following new commits: new f343263 [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
[calcite] 01/01: [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch CALCITE-3894 in repository https://gitbox.apache.org/repos/asf/calcite.git commit f34326382b28128dee9fb7fc4fd8f48ab111e271 Author: yuzhao.cyz AuthorDate: Thu Apr 16 11:48:40 2020 +0800 [CALCITE-3894] The Union operation between DATE with TIMESTAMP returns a wrong result The RelDataTypeFactory#leastRestrictive finds the common type for IN, CASE and SET operations. For common type with DATE and TIMESTAMP, it returns DATE. The root cause is that rules in SqlTypeAssignmentRule decide that DATE is assignable from TIMESTAMP and TIMESTAMP is assignable from DATE, which is actually wrong. Although in Java, this assignment makes sense but that does not mean it's true in SQL, because DATE and TIMESTAMP have different time unit. --- .../apache/calcite/sql/type/SqlTypeAssignmentRule.java | 2 -- .../test/java/org/apache/calcite/test/JdbcTest.java| 14 ++ .../apache/calcite/test/TypeCoercionConverterTest.java | 7 +++ .../java/org/apache/calcite/test/TypeCoercionTest.java | 18 ++ .../apache/calcite/test/TypeCoercionConverterTest.xml | 13 + 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java index 86be0fa..c345105 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java @@ -162,13 +162,11 @@ public class SqlTypeAssignmentRule implements SqlTypeMappingRule { // DATE is assignable from... rule.clear(); rule.add(SqlTypeName.DATE); -rule.add(SqlTypeName.TIMESTAMP); rules.add(SqlTypeName.DATE, rule); // TIME is assignable from... rule.clear(); rule.add(SqlTypeName.TIME); -rule.add(SqlTypeName.TIMESTAMP); rules.add(SqlTypeName.TIME, rule); // TIME WITH LOCAL TIME ZONE is assignable from... diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java index bbf3071..5e36781 100644 --- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java +++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java @@ -7401,6 +7401,20 @@ public class JdbcTest { .runs(); } + /** + * Test case for + * https://issues.apache.org/jira/browse/CALCITE-3894;>[CALCITE-3894] + * The Union operation between DATE with TIMESTAMP returns a wrong result. + */ + @Test public void testUnionDateTime() { +CalciteAssert.AssertThat assertThat = CalciteAssert.that(); +String query = "select * from (\n" ++ "select \"id\" from (VALUES(DATE '2018-02-03')) \"foo\"(\"id\")\n" ++ "union\n" ++ "select \"id\" from (VALUES(TIMESTAMP '2008-03-31 12:23:34')) \"foo\"(\"id\"))"; +assertThat.query(query).returns("id=2008-03-31 12:23:34\nid=2018-02-03 00:00:00\n"); + } + private static String sums(int n, boolean c) { final StringBuilder b = new StringBuilder(); for (int i = 0; i < n; i++) { diff --git a/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java b/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java index 03a5fbb..029f44f 100644 --- a/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java @@ -61,6 +61,13 @@ class TypeCoercionConverterTest extends SqlToRelTestBase { + "from (values (true, true, true))"); } + /** Test cases for {@link TypeCoercion#inOperationCoercion}. */ + @Test void testInDateTimestamp() { +checkPlanEquals("select (t1_timestamp, t1_date)\n" ++ "in ((DATE '2020-04-16', TIMESTAMP '2020-04-16 11:40:53'))\n" ++ "from t1"); + } + /** Test cases for * {@link org.apache.calcite.sql.validate.implicit.TypeCoercionImpl#booleanEquality}. */ @Test void testBooleanEquality() { diff --git a/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java b/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java index b41c7f6..ddd0a47 100644 --- a/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java +++ b/core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java @@ -483,6 +483,12 @@ class TypeCoercionTest extends SqlValidatorTestCase { + "union select t1_int from t1") .columnType("VARCHAR NOT NULL"); +// date union timestamp +sql("select t1_date, t1_timestamp from t1\n" ++ "union select t2_timestamp, t2_date from t2") +.type(
[calcite] branch master updated: [CALCITE-3924] Fix flakey test to handle TIMESTAMP and TIMESTAMP(0) correctly (neoReMinD)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new dfb842e [CALCITE-3924] Fix flakey test to handle TIMESTAMP and TIMESTAMP(0) correctly (neoReMinD) dfb842e is described below commit dfb842e55e1fa7037c8a731341010ed1c0cfb6f7 Author: xu AuthorDate: Wed Apr 15 09:27:45 2020 +0800 [CALCITE-3924] Fix flakey test to handle TIMESTAMP and TIMESTAMP(0) correctly (neoReMinD) The whole if block should be removed. Not only the DATETIME_TYPES has this problem, all the types that allows precision could have such a problem, the root cause is that BasicSqlType#toString and digest has different handling of printing non specified precision. One way to solve is to not fire caching of types without precision and with default precision. close apache/calcite#1916 --- .../org/apache/calcite/sql/type/BasicSqlType.java | 13 --- .../calcite/sql/type/SqlTypeFactoryTest.java | 42 ++ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java index f8323c5..bea494e 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java +++ b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java @@ -179,19 +179,6 @@ public class BasicSqlType extends AbstractSqlType { boolean printPrecision = precision != PRECISION_NOT_SPECIFIED; boolean printScale = scale != SCALE_NOT_SPECIFIED; -// for the digest, print the precision when defaulted, -// since (for instance) TIME is equivalent to TIME(0). -if (withDetail) { - // -1 means there is no default value for precision - if (typeName.allowsPrec() - && typeSystem.getDefaultPrecision(typeName) > -1) { -printPrecision = true; - } - if (typeName.getDefaultScale() > -1) { -printScale = true; - } -} - if (printPrecision) { sb.append('('); sb.append(getPrecision()); diff --git a/core/src/test/java/org/apache/calcite/sql/type/SqlTypeFactoryTest.java b/core/src/test/java/org/apache/calcite/sql/type/SqlTypeFactoryTest.java index e573413..f1c63fd 100644 --- a/core/src/test/java/org/apache/calcite/sql/type/SqlTypeFactoryTest.java +++ b/core/src/test/java/org/apache/calcite/sql/type/SqlTypeFactoryTest.java @@ -170,4 +170,46 @@ class SqlTypeFactoryTest { } } + /** Test case for + * https://issues.apache.org/jira/browse/CALCITE-3924;>[CALCITE-3924] + * Fix flakey test to handle TIMESTAMP and TIMESTAMP(0) correctly. */ + @Test void testCreateSqlTypeWithPrecision() { +SqlTypeFixture f = new SqlTypeFixture(); +checkCreateSqlTypeWithPrecision(f.typeFactory, SqlTypeName.TIME); +checkCreateSqlTypeWithPrecision(f.typeFactory, SqlTypeName.TIMESTAMP); +checkCreateSqlTypeWithPrecision(f.typeFactory, SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE); +checkCreateSqlTypeWithPrecision(f.typeFactory, SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE); + } + + private void checkCreateSqlTypeWithPrecision( + RelDataTypeFactory typeFactory, SqlTypeName sqlTypeName) { +RelDataType ts = typeFactory.createSqlType(sqlTypeName); +RelDataType tsWithoutPrecision = typeFactory.createSqlType(sqlTypeName, -1); +RelDataType tsWithPrecision0 = typeFactory.createSqlType(sqlTypeName, 0); +RelDataType tsWithPrecision1 = typeFactory.createSqlType(sqlTypeName, 1); +RelDataType tsWithPrecision2 = typeFactory.createSqlType(sqlTypeName, 2); +RelDataType tsWithPrecision3 = typeFactory.createSqlType(sqlTypeName, 3); +// for instance, 8 exceeds max precision for timestamp which is 3 +RelDataType tsWithPrecision8 = typeFactory.createSqlType(sqlTypeName, 8); + +assertThat(ts.toString(), is(sqlTypeName.getName() + "(0)")); +assertThat(ts.getFullTypeString(), is(sqlTypeName.getName() + "(0) NOT NULL")); +assertThat(tsWithoutPrecision.toString(), is(sqlTypeName.getName())); +assertThat(tsWithoutPrecision.getFullTypeString(), is(sqlTypeName.getName() + " NOT NULL")); +assertThat(tsWithPrecision0.toString(), is(sqlTypeName.getName() + "(0)")); +assertThat(tsWithPrecision0.getFullTypeString(), is(sqlTypeName.getName() + "(0) NOT NULL")); +assertThat(tsWithPrecision1.toString(), is(sqlTypeName.getName() + "(1)")); +assertThat(tsWithPrecision1.getFullTypeString(), is(sqlTypeName.getName() + "(1) NOT NULL")); +assertThat(tsWithPrecision2.toString(), is(sqlTypeName.getName() + "(2)")); +assertThat(tsWithPrecision2.getFullTypeString(), is(sqlTypeName.getName() + "(2) NOT NULL")); +assertThat(tsWithPr
[calcite] branch master updated: [CALCITE-3881] SqlFunctions#addMonths yields incorrect results in some corner case (Zhenghua Gao)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 43261e4 [CALCITE-3881] SqlFunctions#addMonths yields incorrect results in some corner case (Zhenghua Gao) 43261e4 is described below commit 43261e4094a37ce23eb181a6a8f653dabc4db599 Author: Zhenghua Gao AuthorDate: Mon Mar 30 16:26:38 2020 +0800 [CALCITE-3881] SqlFunctions#addMonths yields incorrect results in some corner case (Zhenghua Gao) SqlFunctions#addMonths use DateTimeUtils#ymdToUnixDate to calculate the JDN(julian day number). But in some corner cases it yields incorrent results. The root cause is: the algorithm of DateTimeUtils#ymdToUnixDate requires reasonable month(1 to 12)[1], but SqlFunctions#addMonths may pass in a month out of the reasonable range. This PR will fix it. close apache/calcite#1890 --- .../java/org/apache/calcite/runtime/SqlFunctions.java | 12 +--- .../apache/calcite/sql/test/SqlOperatorBaseTest.java| 17 + .../java/org/apache/calcite/test/SqlFunctionsTest.java | 2 ++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java index 43934f3..4b89963 100644 --- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java +++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java @@ -2702,9 +2702,15 @@ public class SqlFunctions { int y0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.YEAR, date); int m0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.MONTH, date); int d0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.DAY, date); -int y = m / 12; -y0 += y; -m0 += m - y * 12; +m0 += m; +int deltaYear = (int) DateTimeUtils.floorDiv(m0, 12); +y0 += deltaYear; +m0 = (int) DateTimeUtils.floorMod(m0, 12); +if (m0 == 0) { + y0 -= 1; + m0 += 12; +} + int last = lastDay(y0, m0); if (d0 > last) { d0 = last; diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java index 638682f..b631878 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java +++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java @@ -1990,6 +1990,9 @@ public abstract class SqlOperatorBaseTest { tester.checkScalar("{fn TIMESTAMPDIFF(HOUR," + " TIMESTAMP '2014-03-29 12:34:56'," + " TIMESTAMP '2014-03-29 12:34:56')}", "0", "INTEGER NOT NULL"); +tester.checkScalar("{fn TIMESTAMPDIFF(MONTH," ++ " TIMESTAMP '2019-09-01 00:00:00'," ++ " TIMESTAMP '2020-03-01 00:00:00')}", "6", "INTEGER NOT NULL"); if (Bug.CALCITE_2539_FIXED) { tester.checkFails("{fn WEEK(DATE '2014-12-10')}", @@ -8283,6 +8286,14 @@ public abstract class SqlOperatorBaseTest { + "timestamp '2014-02-24 12:42:25', " + "timestamp '2016-02-24 12:42:25')", "24", "INTEGER NOT NULL"); +tester.checkScalar("timestampdiff(MONTH, " ++ "timestamp '2019-09-01 00:00:00', " ++ "timestamp '2020-03-01 00:00:00')", +"6", "INTEGER NOT NULL"); +tester.checkScalar("timestampdiff(MONTH, " ++ "timestamp '2019-09-01 00:00:00', " ++ "timestamp '2016-08-01 00:00:00')", +"-37", "INTEGER NOT NULL"); tester.checkScalar("timestampdiff(QUARTER, " + "timestamp '2014-02-24 12:42:25', " + "timestamp '2016-02-24 12:42:25')", @@ -8305,6 +8316,12 @@ public abstract class SqlOperatorBaseTest { "timestampdiff(MONTH, date '2016-03-15', date '2016-06-14')", "2", "INTEGER NOT NULL"); +tester.checkScalar("timestampdiff(MONTH, date '2019-09-01', date '2020-03-01')", +"6", +"INTEGER NOT NULL"); +tester.checkScalar("timestampdiff(MONTH, date '2019-09-01', date '2016-08-01')", +"-37", +"INTEGER NOT NULL"); tester.checkScalar( "timestampdiff(DAY, date '2016-06-15', date '2016-06-14')", "-1", diff --git a/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java b/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java index 75779b1..bb494d4 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java +++ b/core/src/test/java/or
[calcite] branch master updated: [CALCITE-3900] Add Config for SqlValidator
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 4e98700 [CALCITE-3900] Add Config for SqlValidator 4e98700 is described below commit 4e9870078fcaa7da9e475c94f43309cc3244fa22 Author: yuzhao.cyz AuthorDate: Thu Apr 9 10:56:51 2020 +0800 [CALCITE-3900] Add Config for SqlValidator The SqlValidator now has 7 setXXX methods for all kinds of control flags, which is hard for code evolving. There is also no way to config these things through the FrameworkConfig. Add a SqlValidator.Config to solve these problems. --- .../apache/calcite/jdbc/CalciteConnectionImpl.java | 4 +- .../apache/calcite/prepare/CalcitePrepareImpl.java | 11 +- .../calcite/prepare/CalciteSqlValidator.java | 5 +- .../org/apache/calcite/prepare/PlannerImpl.java| 27 ++- .../org/apache/calcite/sql/SqlCallBinding.java | 8 + .../java/org/apache/calcite/sql/SqlFunction.java | 4 +- .../java/org/apache/calcite/sql/SqlOperator.java | 4 +- .../java/org/apache/calcite/sql/SqlWindow.java | 8 +- .../calcite/sql/advise/SqlAdvisorValidator.java| 7 +- .../apache/calcite/sql/fun/SqlCaseOperator.java| 4 +- .../org/apache/calcite/sql/fun/SqlInOperator.java | 4 +- .../sql/type/ComparableOperandTypeChecker.java | 2 +- .../sql/type/CompositeOperandTypeChecker.java | 6 +- .../calcite/sql/type/FamilyOperandTypeChecker.java | 4 +- .../SameOperandTypeExceptLastOperandChecker.java | 2 +- .../calcite/sql/type/SetopOperandTypeChecker.java | 2 +- .../calcite/sql/validate/IdentifierNamespace.java | 2 +- .../apache/calcite/sql/validate/OrderByScope.java | 2 +- .../apache/calcite/sql/validate/SqlValidator.java | 183 - .../calcite/sql/validate/SqlValidatorImpl.java | 128 +++--- .../calcite/sql/validate/SqlValidatorUtil.java | 8 +- .../apache/calcite/sql2rel/SqlToRelConverter.java | 10 +- .../org/apache/calcite/tools/FrameworkConfig.java | 6 + .../java/org/apache/calcite/tools/Frameworks.java | 18 +- .../org/apache/calcite/util/ImmutableBeans.java| 9 +- .../rel/logical/ToLogicalConverterTest.java| 2 - .../apache/calcite/sql/test/SqlAdvisorTest.java| 4 +- .../apache/calcite/sql/test/SqlTestFactory.java| 10 +- .../java/org/apache/calcite/test/SqlTestGen.java | 2 +- .../org/apache/calcite/test/SqlToRelTestBase.java | 29 ++-- .../calcite/test/SqlValidatorFeatureTest.java | 5 +- .../org/apache/calcite/test/SqlValidatorTest.java | 4 +- .../apache/calcite/test/SqlValidatorTestCase.java | 18 +- 33 files changed, 372 insertions(+), 170 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java index a274793..48b1d36 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java @@ -58,7 +58,7 @@ import org.apache.calcite.sql.advise.SqlAdvisor; import org.apache.calcite.sql.advise.SqlAdvisorValidator; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.parser.SqlParser; -import org.apache.calcite.sql.validate.SqlConformanceEnum; +import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql.validate.SqlValidatorWithHints; import org.apache.calcite.tools.RelRunner; import org.apache.calcite.util.BuiltInMethod; @@ -472,7 +472,7 @@ abstract class CalciteConnectionImpl new SqlAdvisorValidator(SqlStdOperatorTable.instance(), new CalciteCatalogReader(rootSchema, schemaPath, typeFactory, con.config()), - typeFactory, SqlConformanceEnum.DEFAULT); + typeFactory, SqlValidator.Config.DEFAULT); final CalciteConnectionConfig config = con.config(); // This duplicates org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_ final SqlParser.Config parserConfig = SqlParser.configBuilder() diff --git a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java index 3118958..b121f3a 100644 --- a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java +++ b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java @@ -628,8 +628,6 @@ public class CalcitePrepareImpl implements CalcitePrepare { final SqlValidator validator = createSqlValidator(context, catalogReader); - validator.setIdentifierExpansion(true); - validator.setDefaultNullCollation(config.defaultNullCollation()); preparedResult = preparingStmt.prepareSql( sqlNode, Object.class, validator, true
[calcite] branch master updated: [CALCITE-3871] Remove dependency of org.apiguardian:apiguardian-api
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new ebbba56 [CALCITE-3871] Remove dependency of org.apiguardian:apiguardian-api ebbba56 is described below commit ebbba566fbdbdd0923adda596467090d708cc14b Author: yuzhao.cyz AuthorDate: Wed Mar 25 14:49:30 2020 +0800 [CALCITE-3871] Remove dependency of org.apiguardian:apiguardian-api Also fix the pigunit version to 0.16.0. --- bom/build.gradle.kts | 1 - core/build.gradle.kts | 1 - .../java/org/apache/calcite/rel/RelWriter.java | 3 +- .../main/java/org/apache/calcite/rex/RexNode.java | 3 +- .../main/java/org/apache/calcite/rex/RexUtil.java | 3 +- .../main/java/org/apache/calcite/runtime/Hook.java | 3 +- .../main/java/org/apache/calcite/sql/SqlKind.java | 2 +- gradle.properties | 3 +- linq4j/build.gradle.kts| 2 - .../main/java/org/apache/calcite/linq4j/API.java | 120 + .../apache/calcite/linq4j/EnumerableDefaults.java | 2 - 11 files changed, 126 insertions(+), 17 deletions(-) diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index ed4e16d..4dc2867 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -104,7 +104,6 @@ dependencies { apiv("org.apache.pig:pig") apiv("org.apache.pig:pigunit", "pig") apiv("org.apache.spark:spark-core_2.10", "spark") -apiv("org.apiguardian:apiguardian-api") apiv("org.bouncycastle:bcpkix-jdk15on", "bouncycastle") apiv("org.bouncycastle:bcprov-jdk15on", "bouncycastle") apiv("org.cassandraunit:cassandra-unit") diff --git a/core/build.gradle.kts b/core/build.gradle.kts index f80da4c..caa7df2 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -41,7 +41,6 @@ dependencies { api("com.fasterxml.jackson.core:jackson-annotations") api("org.apache.calcite.avatica:avatica-core") -api("org.apiguardian:apiguardian-api") implementation("com.esri.geometry:esri-geometry-api") implementation("com.fasterxml.jackson.core:jackson-core") diff --git a/core/src/main/java/org/apache/calcite/rel/RelWriter.java b/core/src/main/java/org/apache/calcite/rel/RelWriter.java index 4f6d114..883d8bb 100644 --- a/core/src/main/java/org/apache/calcite/rel/RelWriter.java +++ b/core/src/main/java/org/apache/calcite/rel/RelWriter.java @@ -16,12 +16,11 @@ */ package org.apache.calcite.rel; +import org.apache.calcite.linq4j.API; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlExplainLevel; import org.apache.calcite.util.Pair; -import org.apiguardian.api.API; - import java.util.List; /** diff --git a/core/src/main/java/org/apache/calcite/rex/RexNode.java b/core/src/main/java/org/apache/calcite/rex/RexNode.java index 7a8f058..37b3987 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexNode.java +++ b/core/src/main/java/org/apache/calcite/rex/RexNode.java @@ -17,11 +17,10 @@ package org.apache.calcite.rex; import org.apache.calcite.config.CalciteSystemProperty; +import org.apache.calcite.linq4j.API; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.SqlKind; -import org.apiguardian.api.API; - import java.util.Collection; import java.util.concurrent.atomic.AtomicInteger; diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java b/core/src/main/java/org/apache/calcite/rex/RexUtil.java index 7dd6a9d..c53a7ea 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java +++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java @@ -16,6 +16,7 @@ */ package org.apache.calcite.rex; +import org.apache.calcite.linq4j.API; import org.apache.calcite.linq4j.function.Predicate1; import org.apache.calcite.plan.RelOptPredicateList; import org.apache.calcite.plan.RelOptUtil; @@ -50,8 +51,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import org.apiguardian.api.API; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; diff --git a/core/src/main/java/org/apache/calcite/runtime/Hook.java b/core/src/main/java/org/apache/calcite/runtime/Hook.java index 22ac163..c97d5f7 100644 --- a/core/src/main/java/org/apache/calcite/runtime/Hook.java +++ b/core/src/main/java/org/apache/calcite/runtime/Hook.java @@ -16,11 +16,10 @@ */ package org.apache.calcite.runtime; +import org.apache.calcite.linq4j.API; import org.apache.calcite.rel.RelRoot; import org.apache.calcite.util.Holder; -impo
[calcite] branch master updated: [CALCITE-3647] MySQL COMPRESS function support (ritesh-kapoor)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 468f019 [CALCITE-3647] MySQL COMPRESS function support (ritesh-kapoor) 468f019 is described below commit 468f0190bbd1777671916c0adc57c7c6bd23a7a0 Author: Ritesh Kapoor AuthorDate: Fri Mar 6 11:44:48 2020 +0530 [CALCITE-3647] MySQL COMPRESS function support (ritesh-kapoor) close apache/calcite#1847 --- .../calcite/adapter/enumerable/RexImpTable.java| 4 ++ .../calcite/runtime/CompressionFunctions.java | 65 ++ .../calcite/sql/fun/SqlLibraryOperators.java | 6 ++ .../org/apache/calcite/util/BuiltInMethod.java | 2 + .../calcite/sql/test/SqlOperatorBaseTest.java | 17 ++ core/src/test/resources/sql/functions.iq | 13 + site/_docs/reference.md| 1 + 7 files changed, 108 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java index dc2a6d2..2d713da 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java @@ -97,6 +97,7 @@ import static org.apache.calcite.linq4j.tree.ExpressionType.OrElse; import static org.apache.calcite.linq4j.tree.ExpressionType.Subtract; import static org.apache.calcite.linq4j.tree.ExpressionType.UnaryPlus; import static org.apache.calcite.sql.fun.SqlLibraryOperators.CHR; +import static org.apache.calcite.sql.fun.SqlLibraryOperators.COMPRESS; import static org.apache.calcite.sql.fun.SqlLibraryOperators.COSH; import static org.apache.calcite.sql.fun.SqlLibraryOperators.DAYNAME; import static org.apache.calcite.sql.fun.SqlLibraryOperators.DIFFERENCE; @@ -546,6 +547,9 @@ public class RexImpTable { defineMethod(CURRENT_VALUE, BuiltInMethod.SEQUENCE_CURRENT_VALUE.method, NullPolicy.STRICT); defineMethod(NEXT_VALUE, BuiltInMethod.SEQUENCE_NEXT_VALUE.method, NullPolicy.STRICT); +// Compression Operators +defineMethod(COMPRESS, BuiltInMethod.COMPRESS.method, NullPolicy.ARG0); + // Xml Operators defineMethod(EXTRACT_VALUE, BuiltInMethod.EXTRACT_VALUE.method, NullPolicy.ARG0); defineMethod(XML_TRANSFORM, BuiltInMethod.XML_TRANSFORM.method, NullPolicy.ARG0); diff --git a/core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java b/core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java new file mode 100644 index 000..d16c434 --- /dev/null +++ b/core/src/main/java/org/apache/calcite/runtime/CompressionFunctions.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.calcite.runtime; + +import org.apache.calcite.avatica.util.ByteString; + +import org.apache.commons.lang3.StringUtils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.charset.Charset; +import java.util.zip.DeflaterOutputStream; + +/** + * A collection of functions used in compression and decompression. + */ +public class CompressionFunctions { + + private CompressionFunctions() { + } + + /** + * MySql Compression is based on zlib. + * https://docs.oracle.com/javase/8/docs/api/java/util/zip/Deflater.html;>Deflater + * is used to implement compression. + */ + public static ByteString compress(String data) { +try { + if (data == null) { +return null; + } + if (StringUtils.isEmpty(data)) { +return new ByteString(new byte[0]); + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ByteBuffer dataLength = ByteBuffer.allocate(4); + dataLength.order(ByteOrder.LITTLE_ENDIAN); + dataLength.putInt(data.length()); + outputStream.write(dataLength.array()); + DeflaterOutputStream inflaterStream = new DeflaterOutputStream(outputStream); + inflaterStream.write(data.getBytes
[calcite] branch master updated: [CALCITE-3726] Allow declaring type objects (ritesh-kapoor)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 6dfcfb4 [CALCITE-3726] Allow declaring type objects (ritesh-kapoor) 6dfcfb4 is described below commit 6dfcfb421aec315b50c9b5ca923f3d0d0f3568b8 Author: Ritesh Kapoor AuthorDate: Mon Jan 13 08:51:22 2020 +0530 [CALCITE-3726] Allow declaring type objects (ritesh-kapoor) close apache/calcite#1750 --- .../calcite/adapter/enumerable/RexImpTable.java| 3 + .../java/org/apache/calcite/sql/SqlFunction.java | 15 +++-- .../calcite/sql/SqlTypeConstructorFunction.java| 52 +++ .../sql/type/ExplicitOperandTypeChecker.java | 75 ++ .../org/apache/calcite/test/SqlValidatorTest.java | 2 +- .../java/org/apache/calcite/test/ServerTest.java | 25 server/src/test/resources/sql/type.iq | 34 ++ 7 files changed, 201 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java index 629e2bd..dc2a6d2 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java @@ -50,6 +50,7 @@ import org.apache.calcite.sql.SqlBinaryOperator; import org.apache.calcite.sql.SqlJsonConstructorNullClause; import org.apache.calcite.sql.SqlMatchFunction; import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlTypeConstructorFunction; import org.apache.calcite.sql.SqlWindowTableFunction; import org.apache.calcite.sql.fun.SqlJsonArrayAggAggFunction; import org.apache.calcite.sql.fun.SqlJsonObjectAggAggFunction; @@ -910,6 +911,8 @@ public class RexImpTable { + " must implement ImplementableFunction"); } return ((ImplementableFunction) udf).getImplementor(); +} else if (operator instanceof SqlTypeConstructorFunction) { + return map.get(SqlStdOperatorTable.ROW); } return map.get(operator); } diff --git a/core/src/main/java/org/apache/calcite/sql/SqlFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlFunction.java index 6b8899a..8c2be4a 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlFunction.java @@ -291,13 +291,20 @@ public class SqlFunction extends SqlOperator { } } } + +// check if the identifier represents type +final SqlFunction x = (SqlFunction) call.getOperator(); +final SqlIdentifier identifier = Util.first(x.getSqlIdentifier(), +new SqlIdentifier(x.getName(), SqlParserPos.ZERO)); +RelDataType type = validator.getCatalogReader().getNamedType(identifier); +if (type != null) { + function = new SqlTypeConstructorFunction(identifier, type); + break validCoercionType; +} + // if function doesn't exist within operator table and known function // handling is turned off then create a more permissive function if (function == null && validator.isLenientOperatorLookup()) { - final SqlFunction x = (SqlFunction) call.getOperator(); - final SqlIdentifier identifier = - Util.first(x.getSqlIdentifier(), - new SqlIdentifier(x.getName(), SqlParserPos.ZERO)); function = new SqlUnresolvedFunction(identifier, null, null, OperandTypes.VARIADIC, null, x.getFunctionType()); break validCoercionType; diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTypeConstructorFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlTypeConstructorFunction.java new file mode 100644 index 000..9979855 --- /dev/null +++ b/core/src/main/java/org/apache/calcite/sql/SqlTypeConstructorFunction.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.calcite.sql; + +import org.apache
[calcite] branch master updated: [CALCITE-3856] Remove code to be removed before 1.23
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 4c3cef9 [CALCITE-3856] Remove code to be removed before 1.23 4c3cef9 is described below commit 4c3cef95377ea16efca037012385c40822b4426e Author: yuzhao.cyz AuthorDate: Thu Mar 12 16:48:10 2020 +0800 [CALCITE-3856] Remove code to be removed before 1.23 --- .../org/apache/calcite/rel/core/RelFactories.java | 79 +--- .../apache/calcite/rel/logical/LogicalJoin.java| 30 .../apache/calcite/rel/logical/LogicalProject.java | 12 --- .../calcite/rel/logical/LogicalTableScan.java | 6 -- .../calcite/rel/rel2sql/RelToSqlConverter.java | 5 +- .../org/apache/calcite/rel/stream/StreamRules.java | 16 +++- .../apache/calcite/sql2rel/SqlToRelConverter.java | 18 - .../apache/calcite/sql/parser/SqlParserTest.java | 33 - .../org/apache/calcite/test/RelOptTestBase.java| 33 - .../apache/calcite/test/SqlToRelConverterTest.java | 7 -- .../apache/calcite/test/SqlValidatorTestCase.java | 86 -- .../calcite/adapter/pig/PigRelFactories.java | 6 -- 12 files changed, 18 insertions(+), 313 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rel/core/RelFactories.java b/core/src/main/java/org/apache/calcite/rel/core/RelFactories.java index 55d3a9f..4d838e0 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/RelFactories.java +++ b/core/src/main/java/org/apache/calcite/rel/core/RelFactories.java @@ -22,7 +22,6 @@ import org.apache.calcite.plan.Contexts; import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelOptTable; import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.plan.ViewExpanders; import org.apache.calcite.rel.RelCollation; import org.apache.calcite.rel.RelDistribution; import org.apache.calcite.rel.RelNode; @@ -49,7 +48,6 @@ import org.apache.calcite.rel.metadata.RelColumnMapping; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rex.RexLiteral; import org.apache.calcite.rex.RexNode; -import org.apache.calcite.schema.TranslatableTable; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.tools.RelBuilderFactory; @@ -162,12 +160,6 @@ public class RelFactories { */ RelNode createProject(RelNode input, List hints, List childExprs, List fieldNames); - -@Deprecated // to be removed before 1.23 -default RelNode createProject(RelNode input, -List childExprs, List fieldNames) { - return createProject(input, ImmutableList.of(), childExprs, fieldNames); -} } /** @@ -296,20 +288,6 @@ public class RelFactories { /** Creates an aggregate. */ RelNode createAggregate(RelNode input, List hints, ImmutableBitSet groupSet, ImmutableList groupSets, List aggCalls); - -@Deprecated // to be removed before 1.23 -default RelNode createAggregate(RelNode input, ImmutableBitSet groupSet, -ImmutableList groupSets, List aggCalls) { - return createAggregate(input, ImmutableList.of(), groupSet, groupSets, aggCalls); -} - -@Deprecated // to be removed before 1.23 -default RelNode createAggregate(RelNode input, boolean indicator, -ImmutableBitSet groupSet, ImmutableList groupSets, -List aggCalls) { - Aggregate.checkIndicator(indicator); - return createAggregate(input, ImmutableList.of(), groupSet, groupSets, aggCalls); -} } /** @@ -386,22 +364,6 @@ public class RelFactories { RelNode createJoin(RelNode left, RelNode right, List hints, RexNode condition, Set variablesSet, JoinRelType joinType, boolean semiJoinDone); - -@Deprecated // to be removed before 1.23 -default RelNode createJoin(RelNode left, RelNode right, RexNode condition, -Set variablesSet, JoinRelType joinType, -boolean semiJoinDone) { - return createJoin(left, right, ImmutableList.of(), condition, variablesSet, - joinType, semiJoinDone); -} - -@Deprecated // to be removed before 1.23 -default RelNode createJoin(RelNode left, RelNode right, RexNode condition, -JoinRelType joinType, Set variablesStopped, -boolean semiJoinDone) { - return createJoin(left, right, ImmutableList.of(), condition, - CorrelationId.setOf(variablesStopped), joinType, semiJoinDone); -} } /** @@ -479,8 +441,8 @@ public class RelFactories { private static class SemiJoinFactoryImpl implements SemiJoinFactory { public RelNode createSemiJoin(RelNode left, RelNode right, RexNode condition) { - return LogicalJoin.create(left, right, condition, ImmutableSet.of(), JoinRelType.SEMI, - false, ImmutableList.of()); + return
[calcite] branch master updated: [CALCITE-3855] Supports snapshot on table with virtual columns during sql-to-rel conversion
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new b523007 [CALCITE-3855] Supports snapshot on table with virtual columns during sql-to-rel conversion b523007 is described below commit b5230070e5f495e2c5a7e4baa726a9f7a8877630 Author: yuzhao.cyz AuthorDate: Thu Mar 12 16:01:18 2020 +0800 [CALCITE-3855] Supports snapshot on table with virtual columns during sql-to-rel conversion In SqlToRelConverter#convertTemporalTable, we actually should not assume that the rel to snapshot is always a TableScan. --- .../apache/calcite/sql2rel/SqlToRelConverter.java | 4 +- .../apache/calcite/test/SqlToRelConverterTest.java | 31 ++-- .../test/catalog/MockCatalogReaderExtended.java| 6 ++- .../catalog/VirtualColumnsExpressionFactory.java | 18 +++ .../apache/calcite/test/SqlToRelConverterTest.xml | 58 -- 5 files changed, 106 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index 783e981..f249643 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -47,7 +47,6 @@ import org.apache.calcite.rel.core.Project; import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.rel.core.Sample; import org.apache.calcite.rel.core.Sort; -import org.apache.calcite.rel.core.TableScan; import org.apache.calcite.rel.core.Uncollect; import org.apache.calcite.rel.core.Values; import org.apache.calcite.rel.hint.HintStrategyTable; @@ -2490,9 +2489,8 @@ public class SqlToRelConverter { // convert inner query, could be a table name or a derived table SqlNode expr = snapshot.getTableRef(); convertFrom(bb, expr); -final TableScan scan = (TableScan) bb.root; -final RelNode snapshotRel = relBuilder.push(scan).snapshot(period).build(); +final RelNode snapshotRel = relBuilder.push(bb.root).snapshot(period).build(); bb.setRoot(snapshotRel, false); } diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index dc133ea..ac78d1b 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -1121,13 +1121,20 @@ public class SqlToRelConverterTest extends SqlToRelTestBase { sql("select * from dept, lateral table(ramp(deptno))").ok(); } - @Test public void testSnapshotOnTemporalTable() { + @Test public void testSnapshotOnTemporalTable1() { final String sql = "select * from products_temporal " + "for system_time as of TIMESTAMP '2011-01-02 00:00:00'"; sql(sql).ok(); } - @Test public void testJoinTemporalTableOnSpecificTime() { + @Test public void testSnapshotOnTemporalTable2() { +// Test temporal table with virtual columns. +final String sql = "select * from VIRTUALCOLUMNS.VC_T1 " ++ "for system_time as of TIMESTAMP '2011-01-02 00:00:00'"; +sql(sql).with(getExtendedTester()).ok(); + } + + @Test public void testJoinTemporalTableOnSpecificTime1() { final String sql = "select stream *\n" + "from orders,\n" + " products_temporal for system_time as of\n" @@ -1135,7 +1142,16 @@ public class SqlToRelConverterTest extends SqlToRelTestBase { sql(sql).ok(); } - @Test public void testJoinTemporalTableOnColumnReference() { + @Test public void testJoinTemporalTableOnSpecificTime2() { +// Test temporal table with virtual columns. +final String sql = "select stream *\n" ++ "from orders,\n" ++ " VIRTUALCOLUMNS.VC_T1 for system_time as of\n" ++ "TIMESTAMP '2011-01-02 00:00:00'"; +sql(sql).with(getExtendedTester()).ok(); + } + + @Test public void testJoinTemporalTableOnColumnReference1() { final String sql = "select stream *\n" + "from orders\n" + "join products_temporal for system_time as of orders.rowtime\n" @@ -1143,6 +1159,15 @@ public class SqlToRelConverterTest extends SqlToRelTestBase { sql(sql).ok(); } + @Test public void testJoinTemporalTableOnColumnReference2() { +// Test temporal table with virtual columns. +final String sql = "select stream *\n" ++ "from orders\n" ++ "join VIRTUALCOLUMNS.VC_T1 for system_time as of orders.rowtime\n" ++ "on orders.productid = VIRTUALCOLUMNS.VC_T1.a"; +sql(sql).with(getExtend
[calcite] branch master updated: [CALCITE-3847] Decorrelation for join with lateral table outputs wrong plan if the join condition contains correlation variables
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/master by this push: new 8d4820f [CALCITE-3847] Decorrelation for join with lateral table outputs wrong plan if the join condition contains correlation variables 8d4820f is described below commit 8d4820f208cd69f4377fca175c8b83ff16b1a912 Author: yuzhao.cyz AuthorDate: Mon Mar 9 20:03:13 2020 +0800 [CALCITE-3847] Decorrelation for join with lateral table outputs wrong plan if the join condition contains correlation variables --- .../java/org/apache/calcite/sql2rel/RelDecorrelator.java | 8 .../org/apache/calcite/test/SqlToRelConverterTest.java | 11 +++ .../org/apache/calcite/test/SqlToRelConverterTest.xml| 16 3 files changed, 35 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java index 61b6422..65eee02 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java @@ -48,6 +48,7 @@ import org.apache.calcite.rel.logical.LogicalFilter; import org.apache.calcite.rel.logical.LogicalJoin; import org.apache.calcite.rel.logical.LogicalProject; import org.apache.calcite.rel.logical.LogicalSnapshot; +import org.apache.calcite.rel.logical.LogicalTableFunctionScan; import org.apache.calcite.rel.metadata.RelMdUtil; import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.apache.calcite.rel.rules.FilterCorrelateRule; @@ -1032,6 +1033,13 @@ public class RelDecorrelator implements ReflectiveVisitor { return decorrelateRel((RelNode) rel); } + public Frame decorrelateRel(LogicalTableFunctionScan rel) { +if (RexUtil.containsCorrelation(rel.getCall())) { + return null; +} +return decorrelateRel((RelNode) rel); + } + public Frame decorrelateRel(LogicalFilter rel) { return decorrelateRel((Filter) rel); } diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index b24e2f3..dc133ea 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -1195,6 +1195,17 @@ public class SqlToRelConverterTest extends SqlToRelTestBase { sql("select * from dept, lateral table(DEDUP(dept.deptno, dept.name))").ok(); } + /** Test case for + * https://issues.apache.org/jira/browse/CALCITE-3847;>[CALCITE-3847] + * Decorrelation for join with lateral table outputs wrong plan if the join + * condition contains correlation variables. */ + @Test public void testJoinLateralTableWithConditionCorrelated() { +final String sql = "select deptno, r.num from dept join\n" ++ " lateral table(ramp(dept.deptno)) as r(num)\n" ++ " on deptno=num"; +sql(sql).ok(); + } + @Test public void testSample() { final String sql = "select * from emp tablesample substitute('DATASET1') where empno > 5"; diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index e710248..92ad19a 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -453,6 +453,22 @@ LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2]) ]]> + + + + + + + +
[calcite] branch site updated (98b61a4 -> 200a136)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to branch site in repository https://gitbox.apache.org/repos/asf/calcite.git. discard 98b61a4 Site: Fix links to javadoc discard bca73e2 Add 1.22.0 release announcement add 4bd1328 Add 1.22.0 release announcement add ebc5070 Site: Fix links to javadoc add e9d302f [CALCITE-3837] AntiJoin with empty right input can always be transformed as its left input add 3c70ca4 [CALCITE-3820] EnumerableDefaults#orderBy should be lazily computed + support enumerator re-initialization add bfde14b [CALCITE-3828] MergeJoin throws NPE in case of null keys add 200a136 [CALCITE-3809] RexSimplify simplifies nondeterministic function incorrectly This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (98b61a4) \ N -- N -- N refs/heads/site (200a136) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. No new revisions were added by this update. Summary of changes: .../apache/calcite/rel/rules/PruneEmptyRules.java | 7 +- .../java/org/apache/calcite/rex/RexAnalyzer.java | 6 +- .../org/apache/calcite/rex/RexInterpreter.java | 12 +++ .../java/org/apache/calcite/rex/RexSimplify.java | 2 +- .../org/apache/calcite/rex/RexProgramTest.java | 18 .../apache/calcite/runtime/EnumerablesTest.java| 100 - .../org/apache/calcite/test/RelOptRulesTest.java | 2 +- .../test/enumerable/EnumerableJoinTest.java| 80 + .../org/apache/calcite/test/RelOptRulesTest.xml| 4 +- .../apache/calcite/linq4j/EnumerableDefaults.java | 38 ++-- 10 files changed, 223 insertions(+), 46 deletions(-)
[calcite] tag calcite-1.22.0 created (now 537b8db)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to tag calcite-1.22.0 in repository https://gitbox.apache.org/repos/asf/calcite.git. at 537b8db (commit) No new revisions were added by this update.
[calcite] branch site updated: Site: Fix links to javadoc
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a commit to branch site in repository https://gitbox.apache.org/repos/asf/calcite.git The following commit(s) were added to refs/heads/site by this push: new 98b61a4 Site: Fix links to javadoc 98b61a4 is described below commit 98b61a4b1eed2992a25aed0d3995109ec45faa4a Author: yuzhao.cyz AuthorDate: Thu Mar 5 06:31:45 2020 -0600 Site: Fix links to javadoc --- site/README.md | 18 -- site/_config.yml| 10 +++--- site/_data/docs.yml | 1 - site/_docs/api.md | 2 +- site/_docs/testapi.md | 28 site/_includes/section_nav.html | 2 +- site/docker-compose.yml | 2 +- 7 files changed, 14 insertions(+), 49 deletions(-) diff --git a/site/README.md b/site/README.md index 13c1ed5..8cbac2b 100644 --- a/site/README.md +++ b/site/README.md @@ -42,12 +42,12 @@ Site generation currently works best with ruby-2.5.1. 1. `cd ..` 2. `./gradlew javadocAggregate` -3. `rm -rf site/target/apidocs site/target/testapidocs` - `rmdir site\target\apidocs site\target\testapidocs /S /Q` (Windows) +3. `rm -rf site/target/javadocAggregate` + `rmdir site\target\javadocAggregate /S /Q` (Windows) 4. `mkdir site/target` `mkdir site\target` (Windows) -4. `mv build/docs/javadocAggregate site/target/apidocs` - `for /d %a in (target\site\apidocs* target\site\testapidocs*) do move %a site\target` (Windows) +4. `mv build/docs/javadocAggregate site/target` + `for /d %a in (build\docs\javadocAggregate*) do move %a site\target` (Windows) ### Running locally @@ -94,15 +94,13 @@ As you make changes to the site, the site will automatically rebuild. If you have not regenerated the javadoc and they are missing, restore them: -6. `git reset -- apidocs/` -7. `git reset -- testapidocs/` -8. `git checkout -- apidocs/` -9. `git checkout -- testapidocs/` +6. `git reset -- javadocAggregate/` +7. `git checkout -- javadocAggregate/` Restore the avatica site -10. `git reset -- avatica/` -11. `git checkout -- avatica/` +8. `git reset -- avatica/` +9. `git checkout -- avatica/` 10. `git add .` 11. Commit: `git commit -m "Your commit message goes here"` diff --git a/site/_config.yml b/site/_config.yml index c9fa570..402c7d0 100644 --- a/site/_config.yml +++ b/site/_config.yml @@ -21,7 +21,7 @@ excerpt_separator: "" repository: https://github.com/apache/calcite destination: target exclude: [README.md,Gemfile*] -keep_files: [".git", ".svn", "apidocs", "testapidocs", "avatica", "docs/cassandra.html"] +keep_files: [".git", ".svn", "javadocAggregate", "avatica", "docs/cassandra.html"] collections: docs: @@ -31,12 +31,8 @@ collections: sourceRoot: https://github.com/apache/calcite/blob/master # The URL where Javadocs are located -apiRoot: /apidocs -# apiRoot: http://calcite.apache.org/apidocs - -# The URL where Test Javadocs are located -testApiRoot: /testapidocs -# testApiRoot: http://calcite.apache.org/testapidocs +apiRoot: /javadocAggregate +# apiRoot: http://calcite.apache.org/javadocAggregate # The URL where Avatica's Javadocs are located avaticaApiRoot: /avatica/apidocs diff --git a/site/_data/docs.yml b/site/_data/docs.yml index 3a13d5d..5a6a714 100644 --- a/site/_data/docs.yml +++ b/site/_data/docs.yml @@ -49,5 +49,4 @@ - history - powered_by - api - - testapi # End docs.yml diff --git a/site/_docs/api.md b/site/_docs/api.md index 5ad8688..d9d9419 100644 --- a/site/_docs/api.md +++ b/site/_docs/api.md @@ -1,7 +1,7 @@ --- title: API layout: external -external_url: /apidocs +external_url: /javadocAggregate --- {% comment %} Ideally, we want to use {{ site.apiRoot }} instead of hardcoding diff --git a/site/_docs/testapi.md b/site/_docs/testapi.md deleted file mode 100644 index 661f374..000 --- a/site/_docs/testapi.md +++ /dev/null @@ -1,28 +0,0 @@ -title: Test API -layout: external -external_url: /testapidocs -{% comment %} -Ideally, we want to use {{ site.apiRoot }} instead of hardcoding -the above external_url value, but I don't believe there's a way to do that -{% endcomment %} - - diff --git a/site/_includes/section_nav.html b/site/_includes/section_nav.html index e154275..48b112f 100644 --- a/site/_includes/section_nav.html +++ b/site/_includes/section_nav.html @@ -33,7 +33,7 @@ next, lets build a link to it. {% comment %} See CALCITE-2036 for an explanation of the replacement below {% endcomment %} -Next +Next {% endif %} diff --git a/site/docker-compose.yml b/site/docker-compose.yml index 9ae4fbc..8299e3f 100644 --- a/site/docker-compose.yml +++ b/site/docker-compose.yml @@ -31,7 +31,7 @@ services: generate-javadoc: image:
[calcite] annotated tag v1.22.0-rc0 updated (213904c -> c0d0a0d)
This is an automated email from the ASF dual-hosted git repository. danny0405 pushed a change to annotated tag v1.22.0-rc0 in repository https://gitbox.apache.org/repos/asf/calcite.git. *** WARNING: tag v1.22.0-rc0 was modified! *** from 213904c (commit) to c0d0a0d (tag) tagging 213904cd07c840e1653bbc782cce4e8dc829b9a1 (commit) replaces calcite-1.21.0 by yuzhao.cyz on Fri Mar 6 22:50:08 2020 +0800 - Log - --- No new revisions were added by this update. Summary of changes:
svn commit: r38424 - in /dev/calcite/apache-calcite-1.22.0-rc0: apache-calcite-1.22.0-src.tar.gz apache-calcite-1.22.0-src.tar.gz.asc apache-calcite-1.22.0-src.tar.gz.sha512
Author: danny0405 Date: Fri Mar 6 14:50:30 2020 New Revision: 38424 Log: Uploading release candidate Apache Calcite v1.22.0-rc0 to dev area Modified: dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.asc dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.sha512 Modified: dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz == Binary files dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz (original) and dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz Fri Mar 6 14:50:30 2020 differ Modified: dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.asc == --- dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.asc (original) +++ dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.asc Fri Mar 6 14:50:30 2020 @@ -1,17 +1,17 @@ -BEGIN PGP SIGNATURE- Version: BCPG v1.63 -iQIzBAABCAAdFiEEmkiSL2gqsF0a5KPnwpMeS9sD1a4FAl5Tos4ACgkQwpMeS9sD -1a6zrhAAlTc3T05WLvYad9rx0cFMvxlG6jR3CovUi+tm4R6YM8pYsKDXgf6pbKG7 -vsHewxhn5NaI9FJFcOwwn2loiqaYtXzgtLylwvIvpPY/7JopS78sx8/nsXVHWbm6 -z7dxoRmyQ1sn4vSRyDxYEPj9a12tMUFssDUpqnubrGhROpVYzPWJqJIkBoe2J5sf -tSOwdXvzJRnr+qjl2QpBEUa3Eb3ieSpqXKQe9zPBdCOqoHJetAE/JHDtHsmIIRfa -V0zNrV5HCBv7qb/xSRlFJ+HWpown0i6PxNiOlPFfOmXzWSWiHi0IE4ZQs9K0Yb1g -ENAIrDa7BMlNcA7eoIB+cL4tyyiwigPGgqnoj+XG50yqxMQPsInNOYTDaNQH2muU -RunObxo3B9PWzfsXKj1KLkIRp+w/s/XiZ3dCxl2vLU9010dRpLHwRen/m7XmlHwu -T0Jvc+zeMy52XVo1CFgQ9aBwA+D9s2h+HyTi/mPMrFNAeA64wXLddKeFgXqx7Obo -Z7MMpQegvPXrwLNJR6iVa5zQxXiBA6FFfGmjdg57Nt0lfT395weILCZ5W/+Xvyrz -nN4KZqpnvEk+oxikI2aKd+JjI9tgtEunUv1HiHrujLAzHAbbLZ4p/hq3ccLNewOR -LpzmjjrhMQtzdDW5g+SlLegbYhRWdbNYkmcrnX104RRrEQFc2lE= -=cogD +iQIzBAABCAAdFiEEmkiSL2gqsF0a5KPnwpMeS9sD1a4FAl5iYyEACgkQwpMeS9sD +1a7wlRAA1PBpEdkPGbswLEObafBDfnRlNROrxjCrjLcYZEjvTECOhZO+hWvoXxK0 +EJypL8ezN9Y7h38/GX06btr4T5dx0sS2e29Lb12Bh3U/4bD4MEFNe5Obsne50QFT +AAVNXuTyu9CJa/kuneGG6wQJ8HIDUWzk5ZQTznVA5phwreIoyDaVc6O1QUQEbygP +j1A3BTSdHSpmCHAQkZllUIrocrmOlxyP8FYRRYg7Gpf/fFujau+KMWZepTQh9ir7 +27Mey7GKCq17Zmq9MFxZikGWI8lv+UXkoZmivU7kaUtIs3dGIUQ29A5+Wzo/2xnN +dy3gg+2//7kEQvc/zUgHoaY4VroqB+z/WR/wiQGc3zbu+FYH8FxqLoK2Ltu4Yz/s +BUbSuSBbMiDcGKEzSJG51bna61aclXH8yrdy0m1gUTY+T3DoyEQ0b2RxMm9d856r +3JOKJHs2TnsQKSRyokXm3IqigvmoK5YPrM2BinO694lfC5Vbxzif9rNq1ZfXkEtM +t27H2Y0Hi79cimfYnof6YF+xZdQd1BpozeVonHk+iosxVNrvu4OzgKmz9rtaXmGv +1QxcA1kj4PbfvdnkPjGR8l1wM+WrObZIZQGrNPtmWUhBz+AD9+El+tiP8dHfHXD8 +m25VLCPlKvRCX+fs0n3ogW7IR2268JuzHHshWlx4PbmFNoNCzjo= +=M5cq -END PGP SIGNATURE- Modified: dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.sha512 == --- dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.sha512 (original) +++ dev/calcite/apache-calcite-1.22.0-rc0/apache-calcite-1.22.0-src.tar.gz.sha512 Fri Mar 6 14:50:30 2020 @@ -1 +1 @@ -f9333b4ce327f7715c71a6d14a8aaeafc140992e3751e1aeb9faf5635db44974b5a44f183644a91700378a06b68a29fa27bd9e8609cdcf1e61836c76a4402351 *apache-calcite-1.22.0-src.tar.gz +ea2a48ae527edec91a0dc9b74d7f03d667da685e8715d2e398084d80e297e39541c711e079a6c8d707c2a83f214a296ed5d28bda1d09629d3aaacbb57dfa942c *apache-calcite-1.22.0-src.tar.gz