[calcite] 01/02: [CALCITE-3095] Add several system properties to control enabling/disabling of rules and traits
This is an automated email from the ASF dual-hosted git repository. hongze pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit 5650beb9e81a5706d614140b43060084b955ce29 Author: Hongze Zhang AuthorDate: Tue May 28 15:17:25 2019 +0800 [CALCITE-3095] Add several system properties to control enabling/disabling of rules and traits Also, add utility class RelOptRules to reorganize built-in rules from different places. Close apache/calcite#1237 --- .../adapter/enumerable/EnumerableRules.java| 37 +++- .../calcite/config/CalciteSystemProperty.java | 16 ++ .../java/org/apache/calcite/plan/RelOptRules.java | 195 + .../java/org/apache/calcite/plan/RelOptUtil.java | 116 +--- .../calcite/plan/volcano/VolcanoPlanner.java | 32 +--- .../apache/calcite/prepare/CalcitePrepareImpl.java | 186 +++- .../apache/calcite/prepare/RelOptTableImpl.java| 5 +- .../java/org/apache/calcite/tools/Programs.java| 29 +-- 8 files changed, 367 insertions(+), 249 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java index a99337f..e7f4bc6 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java @@ -20,8 +20,12 @@ import org.apache.calcite.plan.RelOptRule; import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.util.trace.CalciteTrace; +import com.google.common.collect.ImmutableList; + import org.slf4j.Logger; +import java.util.List; + /** * Rules and relational operators for the * {@link EnumerableConvention enumerable calling convention}. @@ -31,6 +35,9 @@ public class EnumerableRules { public static final boolean BRIDGE_METHODS = true; + private EnumerableRules() { + } + public static final RelOptRule ENUMERABLE_JOIN_RULE = new EnumerableJoinRule(); @@ -44,9 +51,6 @@ public class EnumerableRules { public static final RelOptRule ENUMERABLE_CORRELATE_RULE = new EnumerableCorrelateRule(RelFactories.LOGICAL_BUILDER); - private EnumerableRules() { - } - public static final EnumerableProjectRule ENUMERABLE_PROJECT_RULE = new EnumerableProjectRule(); @@ -106,6 +110,33 @@ public class EnumerableRules { public static final EnumerableTableFunctionScanRule ENUMERABLE_TABLE_FUNCTION_SCAN_RULE = new EnumerableTableFunctionScanRule(RelFactories.LOGICAL_BUILDER); + + public static final List ENUMERABLE_RULES = ImmutableList.of( + EnumerableRules.ENUMERABLE_JOIN_RULE, + EnumerableRules.ENUMERABLE_MERGE_JOIN_RULE, + EnumerableRules.ENUMERABLE_SEMI_JOIN_RULE, + EnumerableRules.ENUMERABLE_CORRELATE_RULE, + EnumerableRules.ENUMERABLE_PROJECT_RULE, + EnumerableRules.ENUMERABLE_FILTER_RULE, + EnumerableRules.ENUMERABLE_AGGREGATE_RULE, + EnumerableRules.ENUMERABLE_SORT_RULE, + EnumerableRules.ENUMERABLE_LIMIT_RULE, + EnumerableRules.ENUMERABLE_COLLECT_RULE, + EnumerableRules.ENUMERABLE_UNCOLLECT_RULE, + EnumerableRules.ENUMERABLE_UNION_RULE, + EnumerableRules.ENUMERABLE_REPEAT_UNION_RULE, + EnumerableRules.ENUMERABLE_TABLE_SPOOL_RULE, + EnumerableRules.ENUMERABLE_INTERSECT_RULE, + EnumerableRules.ENUMERABLE_MINUS_RULE, + EnumerableRules.ENUMERABLE_TABLE_MODIFICATION_RULE, + EnumerableRules.ENUMERABLE_VALUES_RULE, + EnumerableRules.ENUMERABLE_WINDOW_RULE, + EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE, + EnumerableRules.ENUMERABLE_TABLE_FUNCTION_SCAN_RULE); + + public static List rules() { +return ENUMERABLE_RULES; + } } // End EnumerableRules.java diff --git a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java index d1f3a5a..92b1142 100644 --- a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java +++ b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java @@ -66,6 +66,22 @@ public final class CalciteSystemProperty { public static final CalciteSystemProperty COMMUTE = booleanProperty("calcite.enable.join.commute", false); + /** Whether to enable the collation trait in the default planner configuration. + * + * Some extra optimizations are possible if enabled, but queries should work either way. + * At some point this will become a preference, or we will run multiple phases: first + * disabled, then enabled. */ + public static final CalciteSystemProperty ENABLE_COLLATION_TRAIT = + booleanProperty("calcite.enable.collation.trait", true); + + /** Whether the enumerable convention is enabled in the default planner configuration. */ + public static final CalciteSystemProper
[calcite] branch master updated (7302314 -> 037250b)
This is an automated email from the ASF dual-hosted git repository. hongze pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. omit 7302314 [CALCITE-3095] Add several system properties to control rules and traits new 5650beb [CALCITE-3095] Add several system properties to control enabling/disabling of rules and traits new 037250b [CALCITE-3093] Remove JDBC connection calls from PlannerImpl 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 (7302314) \ N -- N -- N refs/heads/master (037250b) 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 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: .../org/apache/calcite/prepare/PlannerImpl.java| 84 -- .../java/org/apache/calcite/tools/Frameworks.java | 2 + 2 files changed, 48 insertions(+), 38 deletions(-)
[calcite] 02/02: [CALCITE-3093] Remove JDBC connection calls from PlannerImpl
This is an automated email from the ASF dual-hosted git repository. hongze pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git commit 037250b99d6db8a605b64780a3643f784d07d308 Author: Hongze Zhang AuthorDate: Mon May 27 17:33:28 2019 +0800 [CALCITE-3093] Remove JDBC connection calls from PlannerImpl Close apache/calcite#1241 --- .../org/apache/calcite/prepare/PlannerImpl.java| 84 -- .../java/org/apache/calcite/tools/Frameworks.java | 2 + 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java index 5305e91..ec0f8d9 100644 --- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java +++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java @@ -20,19 +20,27 @@ import org.apache.calcite.adapter.java.JavaTypeFactory; import org.apache.calcite.config.CalciteConnectionConfig; import org.apache.calcite.config.CalciteConnectionConfigImpl; import org.apache.calcite.config.CalciteConnectionProperty; +import org.apache.calcite.config.CalciteSystemProperty; import org.apache.calcite.jdbc.CalciteSchema; +import org.apache.calcite.jdbc.JavaTypeFactoryImpl; import org.apache.calcite.plan.Context; +import org.apache.calcite.plan.ConventionTraitDef; import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelOptPlanner; import org.apache.calcite.plan.RelOptTable.ViewExpander; +import org.apache.calcite.plan.RelOptUtil; import org.apache.calcite.plan.RelTraitDef; import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.plan.volcano.VolcanoPlanner; +import org.apache.calcite.rel.RelCollationTraitDef; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.RelRoot; import org.apache.calcite.rel.metadata.CachingRelMetadataProvider; import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexExecutor; +import org.apache.calcite.runtime.Hook; import org.apache.calcite.schema.SchemaPlus; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlOperatorTable; @@ -44,14 +52,12 @@ import org.apache.calcite.sql2rel.RelDecorrelator; import org.apache.calcite.sql2rel.SqlRexConvertletTable; import org.apache.calcite.sql2rel.SqlToRelConverter; import org.apache.calcite.tools.FrameworkConfig; -import org.apache.calcite.tools.Frameworks; import org.apache.calcite.tools.Planner; import org.apache.calcite.tools.Program; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.tools.RelConversionException; import org.apache.calcite.tools.ValidationException; import org.apache.calcite.util.Pair; -import org.apache.calcite.util.Util; import com.google.common.collect.ImmutableList; @@ -63,7 +69,9 @@ import java.util.Properties; public class PlannerImpl implements Planner, ViewExpander { private final SqlOperatorTable operatorTable; private final ImmutableList programs; - private final FrameworkConfig config; + private final FrameworkConfig frameworkConfig; + private final Context context; + private final CalciteConnectionConfig connectionConfig; /** Holds the trait definitions to be registered with planner. May be null. */ private final ImmutableList traitDefs; @@ -84,7 +92,7 @@ public class PlannerImpl implements Planner, ViewExpander { private RexExecutor executor; // set in STATE_4_VALIDATE - private CalciteSqlValidator validator; + private SqlValidator validator; private SqlNode validatedSqlNode; // set in STATE_5_CONVERT @@ -93,7 +101,7 @@ public class PlannerImpl implements Planner, ViewExpander { /** Creates a planner. Not a public API; call * {@link org.apache.calcite.tools.Frameworks#getPlanner} instead. */ public PlannerImpl(FrameworkConfig config) { -this.config = config; +this.frameworkConfig = config; this.defaultSchema = config.getDefaultSchema(); this.operatorTable = config.getOperatorTable(); this.programs = config.getPrograms(); @@ -103,9 +111,24 @@ public class PlannerImpl implements Planner, ViewExpander { this.traitDefs = config.getTraitDefs(); this.convertletTable = config.getConvertletTable(); this.executor = config.getExecutor(); +this.context = config.getContext(); +this.connectionConfig = connConfig(); reset(); } + private CalciteConnectionConfig connConfig() { +CalciteConnectionConfig unwrapped = context.unwrap(CalciteConnectionConfig.class); +if (unwrapped != null) { + return unwrapped; +} +Properties properties = new Properties(); + properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), +String.valueOf(parserConfig.caseSensitive())); +properties.setProperty
[calcite] branch master updated: [CALCITE-3095] Add several system properties to control rules and traits
This is an automated email from the ASF dual-hosted git repository. hongze 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 7302314 [CALCITE-3095] Add several system properties to control rules and traits 7302314 is described below commit 73023148e7f37d494f6caf92b01b090f6dde13cd Author: Hongze Zhang AuthorDate: Tue May 28 15:17:25 2019 +0800 [CALCITE-3095] Add several system properties to control rules and traits Also, add utility class RelOptRules to reorganize built-in rules from different places. --- .../adapter/enumerable/EnumerableRules.java| 37 +++- .../calcite/config/CalciteSystemProperty.java | 16 ++ .../java/org/apache/calcite/plan/RelOptRules.java | 195 + .../java/org/apache/calcite/plan/RelOptUtil.java | 116 +--- .../calcite/plan/volcano/VolcanoPlanner.java | 32 +--- .../apache/calcite/prepare/CalcitePrepareImpl.java | 186 +++- .../apache/calcite/prepare/RelOptTableImpl.java| 5 +- .../java/org/apache/calcite/tools/Programs.java| 29 +-- 8 files changed, 367 insertions(+), 249 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java index a99337f..e7f4bc6 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java @@ -20,8 +20,12 @@ import org.apache.calcite.plan.RelOptRule; import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.util.trace.CalciteTrace; +import com.google.common.collect.ImmutableList; + import org.slf4j.Logger; +import java.util.List; + /** * Rules and relational operators for the * {@link EnumerableConvention enumerable calling convention}. @@ -31,6 +35,9 @@ public class EnumerableRules { public static final boolean BRIDGE_METHODS = true; + private EnumerableRules() { + } + public static final RelOptRule ENUMERABLE_JOIN_RULE = new EnumerableJoinRule(); @@ -44,9 +51,6 @@ public class EnumerableRules { public static final RelOptRule ENUMERABLE_CORRELATE_RULE = new EnumerableCorrelateRule(RelFactories.LOGICAL_BUILDER); - private EnumerableRules() { - } - public static final EnumerableProjectRule ENUMERABLE_PROJECT_RULE = new EnumerableProjectRule(); @@ -106,6 +110,33 @@ public class EnumerableRules { public static final EnumerableTableFunctionScanRule ENUMERABLE_TABLE_FUNCTION_SCAN_RULE = new EnumerableTableFunctionScanRule(RelFactories.LOGICAL_BUILDER); + + public static final List ENUMERABLE_RULES = ImmutableList.of( + EnumerableRules.ENUMERABLE_JOIN_RULE, + EnumerableRules.ENUMERABLE_MERGE_JOIN_RULE, + EnumerableRules.ENUMERABLE_SEMI_JOIN_RULE, + EnumerableRules.ENUMERABLE_CORRELATE_RULE, + EnumerableRules.ENUMERABLE_PROJECT_RULE, + EnumerableRules.ENUMERABLE_FILTER_RULE, + EnumerableRules.ENUMERABLE_AGGREGATE_RULE, + EnumerableRules.ENUMERABLE_SORT_RULE, + EnumerableRules.ENUMERABLE_LIMIT_RULE, + EnumerableRules.ENUMERABLE_COLLECT_RULE, + EnumerableRules.ENUMERABLE_UNCOLLECT_RULE, + EnumerableRules.ENUMERABLE_UNION_RULE, + EnumerableRules.ENUMERABLE_REPEAT_UNION_RULE, + EnumerableRules.ENUMERABLE_TABLE_SPOOL_RULE, + EnumerableRules.ENUMERABLE_INTERSECT_RULE, + EnumerableRules.ENUMERABLE_MINUS_RULE, + EnumerableRules.ENUMERABLE_TABLE_MODIFICATION_RULE, + EnumerableRules.ENUMERABLE_VALUES_RULE, + EnumerableRules.ENUMERABLE_WINDOW_RULE, + EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE, + EnumerableRules.ENUMERABLE_TABLE_FUNCTION_SCAN_RULE); + + public static List rules() { +return ENUMERABLE_RULES; + } } // End EnumerableRules.java diff --git a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java index d1f3a5a..92b1142 100644 --- a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java +++ b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java @@ -66,6 +66,22 @@ public final class CalciteSystemProperty { public static final CalciteSystemProperty COMMUTE = booleanProperty("calcite.enable.join.commute", false); + /** Whether to enable the collation trait in the default planner configuration. + * + * Some extra optimizations are possible if enabled, but queries should work either way. + * At some point this will become a preference, or we will run multiple phases: first + * disabled, then enabled. */ + public static final CalciteSystemProperty ENABLE_COLLATION_TRAIT = + booleanProperty("calcite.enable.collation.trait", true);
[calcite] branch master updated: [CALCITE-35] More test cases to guard against providing a broken fix for parenthesized join (Muhammad Gelbana)
This is an automated email from the ASF dual-hosted git repository. hongze 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 ee14e01 [CALCITE-35] More test cases to guard against providing a broken fix for parenthesized join (Muhammad Gelbana) ee14e01 is described below commit ee14e012ecbd775c9f845682ddf02bf65204a0f7 Author: Muhammad Gelbana AuthorDate: Wed May 22 21:59:00 2019 +0200 [CALCITE-35] More test cases to guard against providing a broken fix for parenthesized join (Muhammad Gelbana) Close apache/calcite#1228 --- .../java/org/apache/calcite/sql/parser/SqlParserTest.java| 12 1 file changed, 12 insertions(+) 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 f145379..d04bde1 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 @@ -8768,6 +8768,18 @@ public class SqlParserTest { + "FROM \"doublequotedtable\"")); } + @Test public void testParenthesizedSubQueries() { +final String expected = "SELECT *\n" ++ "FROM (SELECT *\n" ++ "FROM `TAB`) AS `X`"; + +final String sql1 = "SELECT * FROM (((SELECT * FROM tab))) X"; +sql(sql1).ok(expected); + +final String sql2 = "SELECT * FROM SELECT * FROM tab X"; +sql(sql2).ok(expected); + } + protected void checkDialect(SqlDialect dialect, String sql, Matcher matcher) throws SqlParseException { final SqlParser parser = getDialectSqlParser(sql, dialect);
[calcite] branch master updated: [CALCITE-2985] Implement JSON_STORAGE_SIZE function (xuqianjin)
This is an automated email from the ASF dual-hosted git repository. hongze 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 b42029f [CALCITE-2985] Implement JSON_STORAGE_SIZE function (xuqianjin) b42029f is described below commit b42029fd46958ddf4d62a29182a2dbee66c1adef Author: XuQianJin-Stars AuthorDate: Thu May 23 15:53:05 2019 +0800 [CALCITE-2985] Implement JSON_STORAGE_SIZE function (xuqianjin) Also, correct content about error handling of MySQL JSON functions in documentation. Close apache/calcite#1150 --- .../calcite/adapter/enumerable/RexImpTable.java| 2 + .../apache/calcite/runtime/CalciteResource.java| 3 + .../org/apache/calcite/runtime/JsonFunctions.java | 13 .../sql/fun/SqlJsonStorageSizeFunction.java| 42 +++ .../calcite/sql/fun/SqlLibraryOperators.java | 3 + .../calcite/sql/fun/SqlStdOperatorTable.java | 3 + .../org/apache/calcite/util/BuiltInMethod.java | 1 + .../calcite/runtime/CalciteResource.properties | 1 + .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 7 ++ .../apache/calcite/sql/parser/SqlParserTest.java | 7 ++ .../calcite/sql/test/SqlOperatorBaseTest.java | 22 ++ .../java/org/apache/calcite/test/JdbcTest.java | 11 +++ .../apache/calcite/test/SqlJsonFunctionsTest.java | 84 -- .../org/apache/calcite/test/SqlValidatorTest.java | 6 ++ site/_docs/reference.md| 25 ++- 15 files changed, 191 insertions(+), 39 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 ab7e7ae..4093c2a 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.sql.fun.SqlLibraryOperators.JSON_KEYS; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_LENGTH; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_PRETTY; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_REMOVE; +import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_STORAGE_SIZE; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_TYPE; import static org.apache.calcite.sql.fun.SqlLibraryOperators.REPEAT; import static org.apache.calcite.sql.fun.SqlLibraryOperators.REVERSE; @@ -474,6 +475,7 @@ public class RexImpTable { defineMethod(JSON_PRETTY, BuiltInMethod.JSON_PRETTY.method, NullPolicy.ARG0); defineMethod(JSON_LENGTH, BuiltInMethod.JSON_LENGTH.method, NullPolicy.ARG0); defineMethod(JSON_REMOVE, BuiltInMethod.JSON_REMOVE.method, NullPolicy.ARG0); +defineMethod(JSON_STORAGE_SIZE, BuiltInMethod.JSON_STORAGE_SIZE.method, NullPolicy.ARG0); defineMethod(JSON_OBJECT, BuiltInMethod.JSON_OBJECT.method, NullPolicy.NONE); defineMethod(JSON_ARRAY, BuiltInMethod.JSON_ARRAY.method, NullPolicy.NONE); aggMap.put(JSON_OBJECTAGG.with(SqlJsonConstructorNullClause.ABSENT_ON_NULL), 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 3a4033b..8f1c6c6 100644 --- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java +++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java @@ -885,6 +885,9 @@ public interface CalciteResource { @BaseMessage("Invalid input for JSON_REMOVE: document: ''{0}'', jsonpath expressions: ''{1}''") ExInst invalidInputForJsonRemove(String value, String pathSpecs); + + @BaseMessage("Not a valid input for JSON_STORAGE_SIZE: ''{0}''") + ExInst invalidInputForJsonStorageSize(String value); } // End CalciteResource.java diff --git a/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java b/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java index cf38f8c..f77b87e 100644 --- a/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java +++ b/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java @@ -631,6 +631,19 @@ public class JsonFunctions { } } + public static Integer jsonStorageSize(String input) { +return jsonStorageSize(jsonValueExpression(input)); + } + + public static Integer jsonStorageSize(JsonValueContext input) { +try { + return JSON_PATH_JSON_PROVIDER.getObjectMapper() + .writeValueAsBytes(input.obj).length; +} catch (Exception e) { + throw RESOURCE.invalidInputForJsonStorageSize(Objects.toString(input.obj)).ex(); +} + } + public static boolean isJsonValue(String input) { try { dejsonize(input); diff --git a/core/src/
[calcite] branch master updated: [CALCITE-3067] Splunk adapter cannot parse right session keys from Splunk 7.2 (Shawn Chen)
This is an automated email from the ASF dual-hosted git repository. hongze 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 2765791 [CALCITE-3067] Splunk adapter cannot parse right session keys from Splunk 7.2 (Shawn Chen) 2765791 is described below commit 2765791e60c46e0d66a3c510a5c91d16fe757720 Author: Shawn Chen AuthorDate: Mon May 20 17:41:40 2019 +0800 [CALCITE-3067] Splunk adapter cannot parse right session keys from Splunk 7.2 (Shawn Chen) Close apache/calcite#1222 --- .../org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java b/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java index 9664e92..e973898 100644 --- a/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java +++ b/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java @@ -58,7 +58,7 @@ public class SplunkConnectionImpl implements SplunkConnection { private static final Pattern SESSION_KEY = Pattern.compile( - "\\s*([0-9a-f]+)\\s*"); + "([0-9a-zA-Z^_]+)"); final URL url; final String username;
[calcite] branch master updated: [CALCITE-3074] Move MySQL's JSON operators to SqlLibraryOperators
This is an automated email from the ASF dual-hosted git repository. hongze 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 ca92ce2 [CALCITE-3074] Move MySQL's JSON operators to SqlLibraryOperators ca92ce2 is described below commit ca92ce27ce9f9a40d755a165041d64538a467a10 Author: Hongze Zhang AuthorDate: Thu May 16 22:52:58 2019 +0800 [CALCITE-3074] Move MySQL's JSON operators to SqlLibraryOperators --- .../calcite/adapter/enumerable/RexImpTable.java| 2 +- .../calcite/sql/fun/SqlLibraryOperators.java | 13 + .../calcite/sql/fun/SqlStdOperatorTable.java | 31 +- 3 files changed, 27 insertions(+), 19 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 c5237ee..f1fe432 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 @@ -95,6 +95,7 @@ import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_DEPTH; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_KEYS; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_LENGTH; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_PRETTY; +import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_REMOVE; import static org.apache.calcite.sql.fun.SqlLibraryOperators.JSON_TYPE; import static org.apache.calcite.sql.fun.SqlLibraryOperators.TRANSLATE3; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.ABS; @@ -172,7 +173,6 @@ import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_EXISTS; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECT; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECTAGG; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_QUERY; -import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_REMOVE; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_VALUE_ANY; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_VALUE_EXPRESSION; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.LAG; 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 9a536e3..c48387a 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 @@ -133,19 +133,22 @@ public abstract class SqlLibraryOperators { public static final SqlFunction TRANSLATE3 = new SqlTranslate3Function(); @LibraryOperator(libraries = {MYSQL}) - public static final SqlFunction JSON_TYPE = SqlStdOperatorTable.JSON_TYPE; + public static final SqlFunction JSON_TYPE = new SqlJsonTypeFunction(); @LibraryOperator(libraries = {MYSQL}) - public static final SqlFunction JSON_DEPTH = SqlStdOperatorTable.JSON_DEPTH; + public static final SqlFunction JSON_DEPTH = new SqlJsonDepthFunction(); @LibraryOperator(libraries = {MYSQL}) - public static final SqlFunction JSON_LENGTH = SqlStdOperatorTable.JSON_LENGTH; + public static final SqlFunction JSON_LENGTH = new SqlJsonLengthFunction(); @LibraryOperator(libraries = {MYSQL}) - public static final SqlFunction JSON_KEYS = SqlStdOperatorTable.JSON_KEYS; + public static final SqlFunction JSON_KEYS = new SqlJsonKeysFunction(); @LibraryOperator(libraries = {MYSQL}) - public static final SqlFunction JSON_PRETTY = SqlStdOperatorTable.JSON_PRETTY; + public static final SqlFunction JSON_PRETTY = new SqlJsonPrettyFunction(); + + @LibraryOperator(libraries = {MYSQL}) + public static final SqlFunction JSON_REMOVE = new SqlJsonRemoveFunction(); } // End SqlLibraryOperators.java diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java index 2c6fe37..9f97d71 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java @@ -1299,11 +1299,6 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable { public static final SqlFunction JSON_VALUE = new SqlJsonValueFunction("JSON_VALUE", false); - public static final SqlFunction JSON_KEYS = new SqlJsonKeysFunction(); - - public static final SqlFunction JSON_PRETTY = - new SqlJsonPrettyFunction(); - public static final SqlFunction JSON_VALUE_ANY = new SqlJsonValueFunction("JSON_VALUE_ANY", true); @@ -1311,20 +1306,30 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable { public static
[calcite] branch master updated: [CALCITE-2975] Implement JSON_REMOVE function (xuqianjin)
This is an automated email from the ASF dual-hosted git repository. hongze 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 999c41d [CALCITE-2975] Implement JSON_REMOVE function (xuqianjin) 999c41d is described below commit 999c41d5ff893a30b2622442a448102c72fc475e Author: XuQianJin-Stars AuthorDate: Wed Apr 3 23:32:08 2019 +0800 [CALCITE-2975] Implement JSON_REMOVE function (xuqianjin) Close apache/calcite#1146 --- .../calcite/adapter/enumerable/RexImpTable.java| 2 + .../apache/calcite/runtime/CalciteResource.java| 5 +- .../org/apache/calcite/runtime/JsonFunctions.java | 26 .../calcite/sql/fun/SqlJsonRemoveFunction.java | 73 ++ .../calcite/sql/fun/SqlStdOperatorTable.java | 2 + .../org/apache/calcite/util/BuiltInMethod.java | 1 + .../calcite/runtime/CalciteResource.properties | 3 +- .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 7 +++ .../apache/calcite/sql/parser/SqlParserTest.java | 7 +++ .../calcite/sql/test/SqlOperatorBaseTest.java | 20 ++ .../java/org/apache/calcite/test/JdbcTest.java | 8 +++ .../apache/calcite/test/SqlJsonFunctionsTest.java | 21 ++- .../org/apache/calcite/test/SqlValidatorTest.java | 7 +++ site/_docs/reference.md| 20 +- 14 files changed, 197 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 5a9f835..c5237ee 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 @@ -172,6 +172,7 @@ import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_EXISTS; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECT; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECTAGG; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_QUERY; +import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_REMOVE; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_VALUE_ANY; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_VALUE_EXPRESSION; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.LAG; @@ -462,6 +463,7 @@ public class RexImpTable { defineMethod(JSON_KEYS, BuiltInMethod.JSON_KEYS.method, NullPolicy.ARG0); defineMethod(JSON_PRETTY, BuiltInMethod.JSON_PRETTY.method, NullPolicy.ARG0); defineMethod(JSON_LENGTH, BuiltInMethod.JSON_LENGTH.method, NullPolicy.ARG0); +defineMethod(JSON_REMOVE, BuiltInMethod.JSON_REMOVE.method, NullPolicy.ARG0); defineMethod(JSON_OBJECT, BuiltInMethod.JSON_OBJECT.method, NullPolicy.NONE); defineMethod(JSON_ARRAY, BuiltInMethod.JSON_ARRAY.method, NullPolicy.NONE); aggMap.put(JSON_OBJECTAGG.with(SqlJsonConstructorNullClause.ABSENT_ON_NULL), 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 3d12aee..3a4033b 100644 --- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java +++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java @@ -874,7 +874,7 @@ public interface CalciteResource { @BaseMessage("Not a valid input for JSON_DEPTH: ''{0}''") ExInst invalidInputForJsonDepth(String value); - @BaseMessage("Cannot serialize object to JSON, and the object is: ''{0}''") + @BaseMessage("Cannot serialize object to JSON: ''{0}''") ExInst exceptionWhileSerializingToJson(String value); @BaseMessage("Not a valid input for JSON_LENGTH: ''{0}''") @@ -882,6 +882,9 @@ public interface CalciteResource { @BaseMessage("Not a valid input for JSON_KEYS: ''{0}''") ExInst invalidInputForJsonKeys(String value); + + @BaseMessage("Invalid input for JSON_REMOVE: document: ''{0}'', jsonpath expressions: ''{1}''") + ExInst invalidInputForJsonRemove(String value, String pathSpecs); } // End CalciteResource.java diff --git a/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java b/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java index c268708..cf38f8c 100644 --- a/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java +++ b/core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java @@ -36,6 +36,7 @@ import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; import com.jayway.jsonpath.spi.mapper.MappingProvider; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Coll
[calcite] branch master updated: [CALCITE-3017] Improve null handling of JsonValueExpressionOperator
This is an automated email from the ASF dual-hosted git repository. hongze 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 e98c779 [CALCITE-3017] Improve null handling of JsonValueExpressionOperator e98c779 is described below commit e98c779d1ec0bc87c81a72b974c89a41a7222a07 Author: Hongze Zhang AuthorDate: Thu Apr 25 02:17:35 2019 +0800 [CALCITE-3017] Improve null handling of JsonValueExpressionOperator * Remove SqlJsonApiCommonSyntaxOperator; * Move implementation methods of JSON functions from SqlFunctions to JsonFunctions; * Add new null policy NullPolicy.ARG0 (currently used by some JSON functions only); * Change return type to nullable for some operators of JSON functions; * In code generation, perform regular null semantic check on operands of a call when NullAs.IS_NULL/IS_NOT_NULL is used. --- core/src/main/codegen/templates/Parser.jj | 59 +- .../calcite/adapter/enumerable/NullPolicy.java | 2 + .../calcite/adapter/enumerable/RexImpTable.java| 49 +- .../org/apache/calcite/runtime/JsonFunctions.java | 757 + .../org/apache/calcite/runtime/SqlFunctions.java | 580 +--- .../main/java/org/apache/calcite/sql/SqlKind.java | 7 +- .../sql/fun/SqlJsonApiCommonSyntaxOperator.java| 64 -- .../calcite/sql/fun/SqlJsonExistsFunction.java | 18 +- .../calcite/sql/fun/SqlJsonKeysFunction.java | 3 +- .../calcite/sql/fun/SqlJsonPrettyFunction.java | 3 +- .../calcite/sql/fun/SqlJsonQueryFunction.java | 20 +- .../calcite/sql/fun/SqlJsonTypeFunction.java | 5 +- .../calcite/sql/fun/SqlJsonValueFunction.java | 88 +-- .../calcite/sql/fun/SqlStdOperatorTable.java | 3 - .../calcite/sql2rel/StandardConvertletTable.java | 73 +- .../org/apache/calcite/util/BuiltInMethod.java | 45 +- .../main/java/org/apache/calcite/util/Util.java| 12 + .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 18 +- .../calcite/sql/test/SqlOperatorBaseTest.java | 112 ++- .../apache/calcite/test/SqlJsonFunctionsTest.java | 320 - .../org/apache/calcite/test/SqlValidatorTest.java | 11 +- .../apache/calcite/test/SqlToRelConverterTest.xml | 16 +- site/_docs/reference.md| 3 +- 23 files changed, 1212 insertions(+), 1056 deletions(-) diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index ab706f1..192f65b 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -4988,48 +4988,41 @@ SqlNode JsonPathSpec() : } } -SqlNode JsonApiCommonSyntax(boolean acceptNonPath) : +List JsonApiCommonSyntax() : { SqlNode e; List args = new ArrayList(); -Span span; } { e = Expression(ExprContext.ACCEPT_NON_QUERY) { args.add(e); -span = Span.of(e); } ( e = Expression(ExprContext.ACCEPT_NON_QUERY) { args.add(e); } -| -{ -if (!acceptNonPath) { - throw new ParseException(RESOURCE.jsonPathMustBeSpecified().str()); -} -} ) [ +// We currently don't support JSON passing clause, leave the java code blocks no-op e = Expression(ExprContext.ACCEPT_NON_QUERY) { -args.add(e); +// no-op } e = SimpleIdentifier() { -args.add(e); +// no-op } ( e = Expression(ExprContext.ACCEPT_NON_QUERY) { -args.add(e); +// no-op } e = SimpleIdentifier() { -args.add(e); +// no-op } )* ] { -return SqlStdOperatorTable.JSON_API_COMMON_SYNTAX.createCall(span.end(this), args); +return args; } } @@ -5050,15 +5043,15 @@ SqlJsonExistsErrorBehavior JsonExistsErrorBehavior() : SqlCall JsonExistsFunctionCall() : { List args; -SqlNode e; +List commonSyntax; final Span span; SqlJsonExistsErrorBehavior errorBehavior; } { { span = span(); } - e = JsonApiCommonSyntax(false) { + commonSyntax = JsonApiCommonSyntax() { args = new ArrayList(); -args.add(e); +args.addAll(commonSyntax); } [ errorBehavior = JsonExistsErrorBehavior() { args.add(SqlLiteral.createSymbol(errorBehavior, getPos())); } @@ -5106,19 +5099,21 @@ List JsonValueEmptyOrErrorBehavior() : SqlCall JsonValueFunctionCall() : { -final SqlNode[] args = new SqlNode[6]; +final SqlNode[] args = new SqlNode[7]; SqlNode e; +List commonSyntax; final Span span; List behavior; } { { span = span(); } - e = JsonApiCommonSyntax(false) { -a
[calcite] branch master updated: [CALCITE-3046] CompileException when inserting casted value of composited user defined type into table
This is an automated email from the ASF dual-hosted git repository. hongze 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 b8bdfb0 [CALCITE-3046] CompileException when inserting casted value of composited user defined type into table b8bdfb0 is described below commit b8bdfb074be12f90c98f9f1fa2af8cf46f2d36f1 Author: Hongze Zhang AuthorDate: Sun May 5 17:23:45 2019 +0800 [CALCITE-3046] CompileException when inserting casted value of composited user defined type into table Also, add several test cases for EnumerableRelImplementor.TypeFinder. --- .../enumerable/EnumerableRelImplementor.java | 36 +- .../calcite/adapter/enumerable/TypeFinderTest.java | 132 + .../java/org/apache/calcite/test/CalciteSuite.java | 2 + .../java/org/apache/calcite/test/ServerTest.java | 17 +++ 4 files changed, 184 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java index b902926..683f53a 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java @@ -27,7 +27,9 @@ import org.apache.calcite.linq4j.tree.ClassDeclaration; import org.apache.calcite.linq4j.tree.ConditionalStatement; import org.apache.calcite.linq4j.tree.ConstantExpression; import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.linq4j.tree.ExpressionType; import org.apache.calcite.linq4j.tree.Expressions; +import org.apache.calcite.linq4j.tree.FunctionExpression; import org.apache.calcite.linq4j.tree.GotoStatement; import org.apache.calcite.linq4j.tree.MemberDeclaration; import org.apache.calcite.linq4j.tree.MethodCallExpression; @@ -37,6 +39,7 @@ import org.apache.calcite.linq4j.tree.ParameterExpression; import org.apache.calcite.linq4j.tree.Primitive; import org.apache.calcite.linq4j.tree.Statement; import org.apache.calcite.linq4j.tree.Types; +import org.apache.calcite.linq4j.tree.UnaryExpression; import org.apache.calcite.linq4j.tree.VisitorImpl; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.runtime.Bindable; @@ -44,6 +47,7 @@ import org.apache.calcite.sql.validate.SqlConformance; import org.apache.calcite.sql.validate.SqlConformanceEnum; import org.apache.calcite.util.BuiltInMethod; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -464,7 +468,8 @@ public class EnumerableRelImplementor extends JavaRelImplementor { } /** Visitor that finds types in an {@link Expression} tree. */ - private static class TypeFinder extends VisitorImpl { + @VisibleForTesting + static class TypeFinder extends VisitorImpl { private final Collection types; TypeFinder(Collection types) { @@ -490,11 +495,36 @@ public class EnumerableRelImplementor extends JavaRelImplementor { } @Override public Void visit(ConstantExpression constantExpression) { - if (constantExpression.value instanceof Type) { -types.add((Type) constantExpression.value); + final Object value = constantExpression.value; + if (value instanceof Type) { +types.add((Type) value); + } + if (value == null) { +// null literal +Type type = constantExpression.getType(); +types.add(type); } return super.visit(constantExpression); } + +@Override public Void visit(FunctionExpression functionExpression) { + final List list = functionExpression.parameterList; + for (ParameterExpression pe : list) { +types.add(pe.getType()); + } + if (functionExpression.body == null) { +return super.visit(functionExpression); + } + types.add(functionExpression.body.getType()); + return super.visit(functionExpression); +} + +@Override public Void visit(UnaryExpression unaryExpression) { + if (unaryExpression.nodeType == ExpressionType.Convert) { +types.add(unaryExpression.getType()); + } + return super.visit(unaryExpression); +} } /** Adds a declaration of each synthetic type found in a code block. */ diff --git a/core/src/test/java/org/apache/calcite/adapter/enumerable/TypeFinderTest.java b/core/src/test/java/org/apache/calcite/adapter/enumerable/TypeFinderTest.java new file mode 100644 index 000..4866eb0 --- /dev/null +++ b/core/src/test/java/org/apache/calcite/adapter/enumerable/TypeFinderTest.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE
[calcite] branch master updated: Oops, remove a println
This is an automated email from the ASF dual-hosted git repository. hongze 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 0d504d2 Oops, remove a println 0d504d2 is described below commit 0d504d20d47542e8d461982512ae0e7a94e4d6cb Author: Hongze Zhang AuthorDate: Sun May 5 14:50:43 2019 +0800 Oops, remove a println --- core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java | 1 - 1 file changed, 1 deletion(-) 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 74d3625..b981201 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -3103,7 +3103,6 @@ public class SqlToRelConverterTest extends SqlToRelTestBase { + "ename format json encoding utf16,\n" + "ename format json encoding utf32\n" + "from emp"; -System.out.println(sql); sql(sql).ok(); }
[calcite] branch master updated: [CALCITE-3045] NullPointerException when casting null literal to composite user defined type
This is an automated email from the ASF dual-hosted git repository. hongze 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 a8f4623 [CALCITE-3045] NullPointerException when casting null literal to composite user defined type a8f4623 is described below commit a8f46239509f01162c4e3ecf640a59cf0e0dfcad Author: Hongze Zhang AuthorDate: Wed May 1 20:57:16 2019 +0800 [CALCITE-3045] NullPointerException when casting null literal to composite user defined type --- .../org/apache/calcite/sql2rel/StandardConvertletTable.java | 12 ++-- core/src/test/java/org/apache/calcite/test/UdtTest.java | 9 + 2 files changed, 15 insertions(+), 6 deletions(-) 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 aa0db73..f79e247 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java @@ -527,18 +527,18 @@ public class StandardConvertletTable extends ReflectiveConvertletTable { } SqlDataTypeSpec dataType = (SqlDataTypeSpec) right; RelDataType type = dataType.deriveType(typeFactory); -if (SqlUtil.isNullLiteral(left, false)) { - final SqlValidatorImpl validator = (SqlValidatorImpl) cx.getValidator(); - validator.setValidatedNodeType(left, type); - return cx.convertExpression(left); -} -RexNode arg = cx.convertExpression(left); if (type == null) { type = cx.getValidator().getValidatedNodeType(dataType.getTypeName()); } +RexNode arg = cx.convertExpression(left); if (arg.getType().isNullable()) { type = typeFactory.createTypeWithNullability(type, true); } +if (SqlUtil.isNullLiteral(left, false)) { + final SqlValidatorImpl validator = (SqlValidatorImpl) cx.getValidator(); + validator.setValidatedNodeType(left, type); + return cx.convertExpression(left); +} if (null != dataType.getCollectionsTypeName()) { final RelDataType argComponentType = arg.getType().getComponentType(); diff --git a/core/src/test/java/org/apache/calcite/test/UdtTest.java b/core/src/test/java/org/apache/calcite/test/UdtTest.java index 8741844..127eb3d 100644 --- a/core/src/test/java/org/apache/calcite/test/UdtTest.java +++ b/core/src/test/java/org/apache/calcite/test/UdtTest.java @@ -58,6 +58,15 @@ public class UdtTest { + "from (VALUES ROW(1, 'SameName')) AS \"t\" (\"id\", \"desc\")"; withUdt().query(sql).returns("LD=1\n"); } + + /** Test case for + * https://issues.apache.org/jira/browse/CALCITE-3045";>[CALCITE-3045] + * NullPointerException when casting null literal to composite user defined type. */ + @Test public void testCastNullLiteralToCompositeUdt() { +final String sql = "select CAST(null AS \"adhoc\".mytype2) as c " ++ "from (VALUES (1))"; +withUdt().query(sql).returns("C=null\n"); + } } // End UdtTest.java
[calcite] branch master updated: [CALCITE-3029] Java-oriented field type is wrongly forced to be NOT NULL after being converted to SQL-oriented
This is an automated email from the ASF dual-hosted git repository. hongze 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 37002c1 [CALCITE-3029] Java-oriented field type is wrongly forced to be NOT NULL after being converted to SQL-oriented 37002c1 is described below commit 37002c1399cea1464b5d53c0fc4e5ec90f831f1b Author: Hongze Zhang AuthorDate: Sun Apr 28 18:21:00 2019 +0800 [CALCITE-3029] Java-oriented field type is wrongly forced to be NOT NULL after being converted to SQL-oriented --- .../apache/calcite/jdbc/JavaTypeFactoryImpl.java | 32 +- .../apache/calcite/jdbc/JavaTypeFactoryTest.java | 16 +++ .../java/org/apache/calcite/tools/PlannerTest.java | 19 + 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java b/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java index d51de1c..40e462a 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java @@ -37,8 +37,6 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.collect.Lists; - import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.Type; @@ -49,6 +47,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; /** * Implementation of {@link JavaTypeFactory}. @@ -240,26 +239,21 @@ public class JavaTypeFactoryImpl /** Converts a type in Java format to a SQL-oriented type. */ public static RelDataType toSql(final RelDataTypeFactory typeFactory, RelDataType type) { -return toSql(typeFactory, type, true); - } - - private static RelDataType toSql(final RelDataTypeFactory typeFactory, - RelDataType type, boolean mustSetNullability) { -RelDataType sqlType = type; if (type instanceof RelRecordType) { - // We do not need to change the nullability of the nested fields, - // since it can be overridden by the existing implementation of createTypeWithNullability - // when we treat the nullability of the root struct type. - sqlType = typeFactory.createStructType( - Lists.transform(type.getFieldList(), -field -> toSql(typeFactory, field.getType(), false)), - type.getFieldNames()); + return typeFactory.createTypeWithNullability( + typeFactory.createStructType( + type.getFieldList() + .stream() + .map(field -> toSql(typeFactory, field.getType())) + .collect(Collectors.toList()), + type.getFieldNames()), + type.isNullable()); } else if (type instanceof JavaType) { - sqlType = typeFactory.createSqlType(type.getSqlTypeName()); + return typeFactory.createTypeWithNullability( + typeFactory.createSqlType(type.getSqlTypeName()), + type.isNullable()); } -return mustSetNullability -? typeFactory.createTypeWithNullability(sqlType, type.isNullable()) -: sqlType; +return type; } public Type createSyntheticType(List types) { diff --git a/core/src/test/java/org/apache/calcite/jdbc/JavaTypeFactoryTest.java b/core/src/test/java/org/apache/calcite/jdbc/JavaTypeFactoryTest.java index cd0ba7a..0980e1d 100644 --- a/core/src/test/java/org/apache/calcite/jdbc/JavaTypeFactoryTest.java +++ b/core/src/test/java/org/apache/calcite/jdbc/JavaTypeFactoryTest.java @@ -18,6 +18,7 @@ package org.apache.calcite.jdbc; import org.apache.calcite.linq4j.tree.Types; import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.sql.test.SqlTests; import org.apache.calcite.sql.type.SqlTypeName; import com.google.common.collect.ImmutableList; @@ -73,6 +74,21 @@ public final class JavaTypeFactoryTest { assertRecordType(TYPE_FACTORY.getJavaClass(structWithTwoFields)); } + /** Test case for + * https://issues.apache.org/jira/browse/CALCITE-3029";>[CALCITE-3029] + * Java-oriented field type is wrongly forced to be NOT NULL after being converted to + * SQL-oriented. */ + @Test public void testFieldNullabilityAfterConvertingToSqlStructType() { +RelDataType javaStructType = TYPE_FACTORY.createStructType( +ImmutableList.of( +TYPE_FACTORY.createJavaType(Integer.class), +TYPE_FACTORY.createJavaType(int.class)), +ImmutableList.of("a", "b")); +RelDataType sqlStructType = TYPE_FACTORY.toSql(javaStructType); +assertEquals("RecordType(INTEGER a, INTEGER NOT NULL b) NOT NULL", +SqlTests.getTypeString(sqlStructType));
[calcite] branch master updated: [CALCITE-2982] SqlItemOperator should throw understandable exception message for incorrect operand type (pengzhiwei)
This is an automated email from the ASF dual-hosted git repository. hongze 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 eed664d [CALCITE-2982] SqlItemOperator should throw understandable exception message for incorrect operand type (pengzhiwei) eed664d is described below commit eed664de8c45af1423d692af88cc98395adcb072 Author: pengzhiwei AuthorDate: Mon Apr 8 15:35:10 2019 +0800 [CALCITE-2982] SqlItemOperator should throw understandable exception message for incorrect operand type (pengzhiwei) Close apache/calcite#1149 --- .../src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java | 8 core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java | 7 +++ 2 files changed, 11 insertions(+), 4 deletions(-) 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 b9f029f..1fcc1cf 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 @@ -87,13 +87,13 @@ class SqlItemOperator extends SqlSpecialOperator { throwOnFailure)) { return false; } -final RelDataType operandType = callBinding.getOperandType(0); -final SqlSingleOperandTypeChecker checker = getChecker(operandType); +final SqlSingleOperandTypeChecker checker = getChecker(callBinding); return checker.checkSingleOperandType(callBinding, right, 0, throwOnFailure); } - private SqlSingleOperandTypeChecker getChecker(RelDataType operandType) { + private SqlSingleOperandTypeChecker getChecker(SqlCallBinding callBinding) { +final RelDataType operandType = callBinding.getOperandType(0); switch (operandType.getSqlTypeName()) { case ARRAY: return OperandTypes.family(SqlTypeFamily.INTEGER); @@ -106,7 +106,7 @@ class SqlItemOperator extends SqlSpecialOperator { OperandTypes.family(SqlTypeFamily.INTEGER), OperandTypes.family(SqlTypeFamily.CHARACTER)); default: - throw new AssertionError(operandType.getSqlTypeName()); + throw callBinding.newValidationSignatureError(); } } 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 a70664c..de5c333 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -8127,6 +8127,13 @@ public class SqlValidatorTest extends SqlValidatorTestCase { .type("RecordType(VARCHAR(10) OA) NOT NULL"); } + @Test public void testItemOperatorException() { +sql("select ^name[0]^ from dept") +.fails("Cannot apply 'ITEM' to arguments of type 'ITEM\\(, " + + "\\)'\\. Supported form\\(s\\): \\[\\]\n" + + "\\[\\].*"); + } + /** Test case for * https://issues.apache.org/jira/browse/CALCITE-497";>[CALCITE-497] * Support optional qualifier for column name references. */
[calcite] branch master updated: Following [CALCITE-3010], remove redundant non-reserved keyword definitions
This is an automated email from the ASF dual-hosted git repository. hongze 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 79df7f9 Following [CALCITE-3010], remove redundant non-reserved keyword definitions 79df7f9 is described below commit 79df7f9df496959c3cfebc80bc545ac9946bd7a0 Author: Hongze Zhang AuthorDate: Tue Apr 23 23:15:46 2019 +0800 Following [CALCITE-3010], remove redundant non-reserved keyword definitions --- babel/src/main/codegen/config.fmpp| 9 - core/src/main/codegen/config.fmpp | 5 - core/src/main/codegen/templates/Parser.jj | 5 - core/src/test/codegen/config.fmpp | 5 - server/src/main/codegen/config.fmpp | 5 - site/_docs/reference.md | 5 - 6 files changed, 34 deletions(-) diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index dc9f513..9ff0556 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -140,11 +140,6 @@ data: { "ISOLATION" "JAVA" "JSON" -"JSON_DEPTH" -"JSON_KEYS" -"JSON_LENGTH" -"JSON_PRETTY" -"JSON_TYPE" "K" "KEY" "KEY_MEMBER" @@ -558,14 +553,10 @@ data: { # "JOIN", "JSON_ARRAY", "JSON_ARRAYAGG", -"JSON_DEPTH", "JSON_EXISTS", -"JSON_KEYS", "JSON_OBJECT", "JSON_OBJECTAGG", -"JSON_PRETTY", "JSON_QUERY", -"JSON_TYPE", "JSON_VALUE", # "KEEP", # not a keyword in Calcite "KEY", diff --git a/core/src/main/codegen/config.fmpp b/core/src/main/codegen/config.fmpp index 0138304..278e0d0 100644 --- a/core/src/main/codegen/config.fmpp +++ b/core/src/main/codegen/config.fmpp @@ -160,11 +160,6 @@ data: { "ISOLATION" "JAVA" "JSON" -"JSON_DEPTH" -"JSON_KEYS" -"JSON_LENGTH" -"JSON_PRETTY" -"JSON_TYPE" "K" "KEY" "KEY_MEMBER" diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index f9af1f0..e83c946 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -6406,15 +6406,10 @@ SqlPostfixOperator PostfixRowOperator() : | < JSON: "JSON" > | < JSON_ARRAY: "JSON_ARRAY"> | < JSON_ARRAYAGG: "JSON_ARRAYAGG"> -| < JSON_DEPTH: "JSON_DEPTH"> | < JSON_EXISTS: "JSON_EXISTS" > -| < JSON_KEYS: "JSON_KEYS" > -| < JSON_LENGTH: "JSON_LENGTH"> | < JSON_OBJECT: "JSON_OBJECT"> | < JSON_OBJECTAGG: "JSON_OBJECTAGG"> -| < JSON_PRETTY: "JSON_PRETTY" > | < JSON_QUERY: "JSON_QUERY" > -| < JSON_TYPE: "JSON_TYPE"> | < JSON_VALUE: "JSON_VALUE" > | < K: "K" > | < KEY: "KEY" > diff --git a/core/src/test/codegen/config.fmpp b/core/src/test/codegen/config.fmpp index 7c24366..a135836 100644 --- a/core/src/test/codegen/config.fmpp +++ b/core/src/test/codegen/config.fmpp @@ -144,11 +144,6 @@ data: { "ISOLATION" "JAVA" "JSON" -"JSON_DEPTH" -"JSON_KEYS" -"JSON_LENGTH" -"JSON_PRETTY" -"JSON_TYPE" "K" "KEY" "KEY_MEMBER" diff --git a/server/src/main/codegen/config.fmpp b/server/src/main/codegen/config.fmpp index 296db46..faa22dd 100644 --- a/server/src/main/codegen/config.fmpp +++ b/server/src/main/codegen/config.fmpp @@ -152,11 +152,6 @@ data: { "ISOLATION" "JAVA" "JSON" -"JSON_DEPTH" -"JSON_KEYS" -"JSON_LENGTH" -"JSON_PRETTY" -"JSON_TYPE" "K" "KEY" "KEY_MEMBER" diff --git a/site/_docs/reference.md b/site/_docs/reference.md index 5868e89..8ac4581 100644 --- a/site/_docs/reference.md +++ b/site/_docs/reference.md @@ -565,15 +565,10 @@ JAVA, JSON, **JSON_ARRAY**, **JSON_ARRAYAGG**, -JSON_DEPTH, **JSON_EXISTS**, -JSON_KEYS, -JSON_LENGTH, **JSON_OBJECT**, **JSON_OBJECTAGG**, -JSON_PRETTY, **JSON_QUERY**, -JSON_TYPE, **JSON_VALUE**, K, KEY,
[calcite] branch master updated: [CALCITE-2993] ParseException may be thrown for legal SQL queries due to incorrect "LOOKAHEAD(1)" hints
This is an automated email from the ASF dual-hosted git repository. hongze 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 577e72c [CALCITE-2993] ParseException may be thrown for legal SQL queries due to incorrect "LOOKAHEAD(1)" hints 577e72c is described below commit 577e72cb95e5d4d88f187909c14d8691c266ac4c Author: Hongze Zhang AuthorDate: Sat Apr 13 04:43:44 2019 +0800 [CALCITE-2993] ParseException may be thrown for legal SQL queries due to incorrect "LOOKAHEAD(1)" hints Also: * Following [CALCITE-883], add absent non-reserved keywords to config.fmpp files; * Remove redundant "LOOKAHEAD(1)" hints; * The case "select json_object(key: value) from t" is added to unit test but not fixed. See the reason from method "SqlParserTest#testJsonObject". --- babel/src/main/codegen/config.fmpp | 2 + core/src/main/codegen/templates/Parser.jj | 19 ++--- core/src/test/codegen/config.fmpp | 2 + .../apache/calcite/sql/parser/SqlParserTest.java | 46 ++ piglet/src/main/javacc/PigletParser.jj | 1 - server/src/main/codegen/config.fmpp| 2 + 6 files changed, 66 insertions(+), 6 deletions(-) diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index cd5a36d..dc9f513 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -124,6 +124,7 @@ data: { "GOTO" "GRANTED" "HIERARCHY" +"IGNORE" "IMMEDIATE" "IMMEDIATELY" "IMPLEMENTATION" @@ -210,6 +211,7 @@ data: { "RELATIVE" "REPEATABLE" "REPLACE" +"RESPECT" "RESTART" "RESTRICT" "RETURNED_CARDINALITY" diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index cd49717..f9af1f0 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -1894,7 +1894,7 @@ SqlNode TableRef2(boolean lateral) : tableRef = unnestOp.createCall(s.end(this), args.toArray()); } | -[ LOOKAHEAD(1) { lateral = true; } ] +[ { lateral = true; } ] { s = span(); } tableRef = TableFunctionCall(s.pos()) @@ -2597,7 +2597,17 @@ SqlMatchRecognize MatchRecognize(SqlNode tableRef) : s1.end(var), var); } | -[ LOOKAHEAD(1) ] var = SimpleIdentifier() { +// This "LOOKAHEAD({true})" is a workaround for Babel. +// Because of babel parser uses option "LOOKAHEAD=2" globally, +// JavaCC generates something like "LOOKAHEAD(2, [] SimpleIdentifier())" +// here. But the correct LOOKAHEAD should be +// "LOOKAHEAD(2, [ LOOKAHEAD(2, SimpleIdentifier()) ] +// SimpleIdentifier())" which have the syntactic lookahead for considered. +// +// Overall LOOKAHEAD({true}) is even better as this is the last branch in the +// choice. +LOOKAHEAD({true}) +[ LOOKAHEAD(2, SimpleIdentifier()) ] var = SimpleIdentifier() { after = SqlMatchRecognize.SKIP_TO_LAST.createCall( s1.end(var), var); } @@ -3423,7 +3433,6 @@ SqlNode AtomicRowExpression() : } { ( -LOOKAHEAD(1) e = Literal() | e = DynamicParam() @@ -5221,7 +5230,7 @@ List JsonNameAndValue() : } { [ -LOOKAHEAD(1) +LOOKAHEAD(2, JsonName()) { kvMode = true; } ] e = JsonName() { @@ -5664,7 +5673,7 @@ SqlNode NamedFunctionCall() : call = createCall(qualifiedName, s.end(this), funcType, quantifier, args); } [ -LOOKAHEAD(1) call = nullTreatment(call) +LOOKAHEAD(2) call = nullTreatment(call) ] [ call = withinGroup(call) diff --git a/core/src/test/codegen/config.fmpp b/core/src/test/codegen/config.fmpp index 230b280..7c24366 100644 --- a/core/src/test/codegen/config.fmpp +++ b/core/src/test/codegen/config.fmpp @@ -128,6 +128,7 @@ data: { "GOTO" "GRANTED" "HIERARCHY" +"IGNORE" "IMMEDIATE" "IMMEDIATELY" "IMPLEMENTATION" @@ -214,6 +215,7 @@ data: { "RELATIVE" "REPEATABLE" "REPLACE" +"RESPECT" "RESTART"
[calcite] branch master updated: [CALCITE-3010] In SQL parser, move JsonValueExpression into Expression
This is an automated email from the ASF dual-hosted git repository. hongze 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 02eb106 [CALCITE-3010] In SQL parser, move JsonValueExpression into Expression 02eb106 is described below commit 02eb106bcd1b0fdb1d0be06d117a94eddc9f3fce Author: Hongze Zhang AuthorDate: Fri Apr 19 23:40:12 2019 +0800 [CALCITE-3010] In SQL parser, move JsonValueExpression into Expression * SqlJsonValueExpressionOperator is now a postfix operator; * Remove SqlStdOperatorTable.JSON_STRUCTURED_VALUE_EXPRESSION; * Remove SqlStdOperatorTable.JSON_API_COMMON_SYNTAX_WITHOUT_PATH; * When "FORMAT JSON" is implicit, a call to SqlJsonValueExpressionOperator is added and validated during sql-to-rel process; * Correct JSON_DEPTH's return type. --- core/src/main/codegen/templates/Parser.jj | 145 +++-- .../calcite/adapter/enumerable/RexImpTable.java| 6 - .../org/apache/calcite/runtime/SqlFunctions.java | 34 ++--- .../sql/fun/SqlJsonApiCommonSyntaxOperator.java| 30 + .../sql/fun/SqlJsonArrayAggAggFunction.java| 7 +- .../calcite/sql/fun/SqlJsonArrayFunction.java | 5 +- .../calcite/sql/fun/SqlJsonDepthFunction.java | 4 +- .../calcite/sql/fun/SqlJsonKeysFunction.java | 20 +-- .../calcite/sql/fun/SqlJsonLengthFunction.java | 21 +-- .../sql/fun/SqlJsonObjectAggAggFunction.java | 12 +- .../calcite/sql/fun/SqlJsonObjectFunction.java | 16 ++- .../sql/fun/SqlJsonValueExpressionOperator.java| 39 ++ .../calcite/sql/fun/SqlStdOperatorTable.java | 15 +-- .../org/apache/calcite/sql/type/InferTypes.java| 14 ++ .../calcite/sql2rel/StandardConvertletTable.java | 80 +++- .../src/main/java/org/apache/calcite/util/Bug.java | 5 + .../org/apache/calcite/util/BuiltInMethod.java | 4 - .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 13 ++ .../apache/calcite/sql/parser/SqlParserTest.java | 97 -- .../apache/calcite/sql/test/SqlAdvisorTest.java| 1 + .../calcite/sql/test/SqlOperatorBaseTest.java | 42 +++--- .../apache/calcite/test/SqlJsonFunctionsTest.java | 15 +-- .../apache/calcite/test/SqlToRelConverterTest.java | 40 ++ .../org/apache/calcite/test/SqlValidatorTest.java | 29 - .../apache/calcite/test/SqlToRelConverterTest.xml | 101 -- core/src/test/resources/sql/agg.iq | 123 + 26 files changed, 493 insertions(+), 425 deletions(-) diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 77ecacb..cd49717 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -3090,6 +3090,7 @@ List Expression2(ExprContext exprContext) : { Expression2b(exprContext, list) ( +LOOKAHEAD(2) ( LOOKAHEAD(2) ( @@ -4882,20 +4883,10 @@ SqlNode BuiltinFunctionCall() : | node = JsonValueFunctionCall() { return node; } | -node = JsonKeysFunctionCall() { return node; } -| -node = JsonPrettyFunctionCall() { return node; } -| node = JsonQueryFunctionCall() { return node; } | node = JsonObjectFunctionCall() { return node; } | -node = JsonTypeFunctionCall() { return node; } -| -node = JsonDepthFunctionCall() { return node; } -| -node = JsonLengthFunctionCall() { return node; } -| node = JsonObjectAggFunctionCall() { return node; } | node = JsonArrayFunctionCall() { return node; } @@ -4912,7 +4903,7 @@ SqlJsonEncoding JsonRepresentation() : [ // Encoding is currently ignored. - +LOOKAHEAD(2) ( { return SqlJsonEncoding.UTF8; } | @@ -4956,30 +4947,6 @@ SqlDataTypeSpec JsonOutputClause() : } } -SqlNode JsonValueExpression(boolean implicitFormatJson) : -{ -SqlNode e; -List args = new ArrayList(); -Span span; -} -{ -e = Expression(ExprContext.ACCEPT_NON_QUERY) { -args.add(e); -span = Span.of(e); -} -[ -JsonInputClause() { -return SqlStdOperatorTable.JSON_VALUE_EXPRESSION.createCall(span.end(this), args); -} -] -{ -if (implicitFormatJson) { -return SqlStdOperatorTable.JSON_VALUE_EXPRESSION.createCall(span.end(this), args); -} -return SqlStdOperatorTable.JSON_STRUCTURED_VALUE_EXPRESSION.createCall(span.end(this), args); -} -} - SqlNode JsonPathSpec() : { SqlNode e; @@ -4995,17 +4962,15 @@ SqlNode JsonApiCommonSyntax(boolean acceptNonPath) : SqlNode e; List args = new ArrayList(); Span span; -SqlOperator op; } { -e = JsonValueExpression
[calcite] branch master updated: [CALCITE-2343] PushProjector with OVER expression causes infinite loop (Chunwei Lei)
This is an automated email from the ASF dual-hosted git repository. hongze 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 b03cdc4 [CALCITE-2343] PushProjector with OVER expression causes infinite loop (Chunwei Lei) b03cdc4 is described below commit b03cdc486cf5c7232bbc6fa9b5f02f564e9601c3 Author: Chunwei Lei AuthorDate: Sun Apr 14 10:27:36 2019 +0800 [CALCITE-2343] PushProjector with OVER expression causes infinite loop (Chunwei Lei) Also, remove unnecessary cast to RexNode in PushProjector.java. Close apache/calcite#1162 --- .../rel/rules/ProjectJoinTransposeRule.java| 3 +- .../apache/calcite/rel/rules/PushProjector.java| 4 +- .../org/apache/calcite/test/RelOptRulesTest.java | 34 + .../org/apache/calcite/test/RelOptRulesTest.xml| 81 ++ 4 files changed, 119 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java index 34dee11..52d22cc 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java @@ -25,6 +25,7 @@ import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.rel.core.SemiJoin; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rex.RexNode; +import org.apache.calcite.rex.RexOver; import org.apache.calcite.tools.RelBuilderFactory; import java.util.ArrayList; @@ -38,7 +39,7 @@ import java.util.List; */ public class ProjectJoinTransposeRule extends RelOptRule { public static final ProjectJoinTransposeRule INSTANCE = - new ProjectJoinTransposeRule(expr -> true, + new ProjectJoinTransposeRule(expr -> !(expr instanceof RexOver), RelFactories.LOGICAL_BUILDER); //~ Instance fields diff --git a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java index e34a4a8..376651e 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java @@ -514,7 +514,7 @@ public class PushProjector { final RelDataTypeField destField = destFields.get(refIdx - offset); newProjects.add( Pair.of( - (RexNode) rexBuilder.makeInputRef( + rexBuilder.makeInputRef( destField.getType(), refIdx - offset), destField.getName())); } @@ -629,7 +629,7 @@ public class PushProjector { for (Ord field : Ord.zip(childFields)) { projects.add( Pair.of( -(RexNode) rexBuilder.makeInputRef( +rexBuilder.makeInputRef( field.e.getType(), field.i), field.e.getName())); } } diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java index bf3eb8e..5c7a18e 100644 --- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java @@ -1435,6 +1435,40 @@ public class RelOptRulesTest extends RelOptTestBase { sql(sql).withRule(ProjectJoinTransposeRule.INSTANCE).check(); } + /** Test case for + * https://issues.apache.org/jira/browse/CALCITE-2343";>[CALCITE-2343] + * Should not push over whose columns are all from left child past join since + * join will affect row count.. */ + @Test public void testPushProjectWithOverPastJoin1() { +checkPlanning(ProjectJoinTransposeRule.INSTANCE, +"select e.sal + b.comm,\n" ++ "count(e.empno) over (partition by e.deptno)\n" ++ "from emp e join bonus b\n" ++ "on e.ename = b.ename and e.deptno = 10"); + } + + /** As {@link #testPushProjectWithOverPastJoin1()}; + * should not push over whose columns are all from right child past join since + * join will affect row count. */ + @Test public void testPushProjectWithOverPastJoin2() { +checkPlanning(ProjectJoinTransposeRule.INSTANCE, +"select e.sal + b.comm,\n" ++ "count(b.sal) over (partition by b.job)\n" ++ "from emp e join bonus b\n" ++ "on e.ename = b.ename and e.deptno = 10"); + } + + /** As {@link #testPushProjectWithOverPastJoin2()}; + * should not push over past join but should push the operands of over past + * join. */ + @Test public void testPushProjectWithOverPastJoin3() { +checkPlanning(ProjectJoinTransposeRule.INSTANCE, +&
[calcite] branch master updated: [CALCITE-2990] Fix document misspelling in RelInput (Shuming Li)
This is an automated email from the ASF dual-hosted git repository. hongze 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 af97f55 [CALCITE-2990] Fix document misspelling in RelInput (Shuming Li) af97f55 is described below commit af97f55f1fcbb3cf6005393dffd91eb345c04b6f Author: ShuMingLi AuthorDate: Thu Apr 11 17:12:03 2019 +0800 [CALCITE-2990] Fix document misspelling in RelInput (Shuming Li) Close apache/calcite#1154 --- core/src/main/java/org/apache/calcite/rel/RelInput.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/rel/RelInput.java b/core/src/main/java/org/apache/calcite/rel/RelInput.java index 6179c04..a619bae 100644 --- a/core/src/main/java/org/apache/calcite/rel/RelInput.java +++ b/core/src/main/java/org/apache/calcite/rel/RelInput.java @@ -62,7 +62,7 @@ public interface RelInput { Object get(String tag); /** - * Returns a {@code float} value. Throws if wrong type. + * Returns a {@code string} value. Throws if wrong type. */ String getString(String tag);
[calcite] branch master updated (7b1feec -> 16f518b)
This is an automated email from the ASF dual-hosted git repository. hongze pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. discard 7b1feec [CALCITE-2847] Optimize global LOOKAHEAD for SQL parsers new 16f518b [CALCITE-2847] Optimize global LOOKAHEAD for SQL parsers 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 (7b1feec) \ N -- N -- N refs/heads/master (16f518b) 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 3315 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/codegen/templates/Parser.jj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[calcite] branch master updated: [CALCITE-2847] Optimize global LOOKAHEAD for SQL parsers
This is an automated email from the ASF dual-hosted git repository. hongze 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 7b1feec [CALCITE-2847] Optimize global LOOKAHEAD for SQL parsers 7b1feec is described below commit 7b1feec6640c625a6e6f2fdefd0a905c150e9192 Author: hongzezhang AuthorDate: Thu Feb 14 16:22:18 2019 +0800 [CALCITE-2847] Optimize global LOOKAHEAD for SQL parsers --- .../org/apache/calcite/test/BabelParserTest.java | 59 +++ core/pom.xml | 4 +- core/src/main/codegen/templates/Parser.jj | 196 - .../apache/calcite/sql/parser/SqlParserTest.java | 151 .../apache/calcite/sql/test/SqlAdvisorTest.java| 15 +- .../apache/calcite/test/SqlValidatorMatchTest.java | 2 +- .../org/apache/calcite/test/SqlValidatorTest.java | 2 +- core/src/test/resources/sql/lateral.iq | 30 ++-- piglet/pom.xml | 2 +- piglet/src/main/javacc/PigletParser.jj | 6 +- server/pom.xml | 2 +- server/src/main/codegen/includes/parserImpls.ftl | 2 +- server/src/test/resources/sql/schema.iq| 4 +- 13 files changed, 278 insertions(+), 197 deletions(-) diff --git a/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java b/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java index 896a96e..8e3d312 100644 --- a/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java +++ b/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java @@ -19,13 +19,17 @@ package org.apache.calcite.test; import org.apache.calcite.sql.parser.SqlAbstractParserImpl; import org.apache.calcite.sql.parser.SqlParserImplFactory; import org.apache.calcite.sql.parser.SqlParserTest; +import org.apache.calcite.sql.parser.SqlParserUtil; import org.apache.calcite.sql.parser.babel.SqlBabelParserImpl; +import com.google.common.base.Throwables; + import org.junit.Ignore; import org.junit.Test; import java.util.Arrays; import java.util.Locale; +import java.util.Objects; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -140,6 +144,61 @@ public class BabelParserTest extends SqlParserTest { + "ORDER BY `DESC`, `DESC` DESC"; sql(sql).ok(expected); } + + /** + * This is a failure test making sure the LOOKAHEAD for WHEN clause is 2 in Babel, where + * in core parser this number is 1. + * + * @see SqlParserTest#testCaseExpression() + * @see https://issues.apache.org/jira/browse/CALCITE-2847";>[CALCITE-2847] + * Optimize global LOOKAHEAD for SQL parsers + */ + @Test public void testCaseExpressionBabel() { +checkFails( +"case x when 2, 4 then 3 ^when^ then 5 else 4 end", +"(?s)Encountered \"when then\" at .*"); + } + + /** + * Babel parser's global LOOKAHEAD is larger than the core parser's, this causes different + * parse error message between these two parser types. Here we define a looser error checker + * for Babel to reuse failure testing codes from {@link SqlParserTest}. + * + * Test cases just written in this file is still checked by {@link SqlParserTest}'s checker. + */ + @Override protected Tester getTester() { +return new TesterImpl() { + + @Override protected void checkEx(String expectedMsgPattern, + SqlParserUtil.StringAndPos sap, Throwable thrown) { +if (thrownByBabelTest(thrown)) { + super.checkEx(expectedMsgPattern, sap, thrown); +} else { + checkExNotNull(sap, thrown); +} + } + + private boolean thrownByBabelTest(Throwable ex) { +Throwable rootCause = Throwables.getRootCause(ex); +StackTraceElement[] stackTrace = rootCause.getStackTrace(); +for (StackTraceElement stackTraceElement : stackTrace) { + String className = stackTraceElement.getClassName(); + if (Objects.equals(className, BabelParserTest.class.getName())) { +return true; + } +} +return false; + } + + private void checkExNotNull(SqlParserUtil.StringAndPos sap, Throwable thrown) { +if (thrown == null) { + throw new AssertionError("Expected query to throw exception, " + + "but it did not; query [" + sap.sql + + "]"); +} + } +}; + } } // End BabelParserTest.java diff --git a/core/pom.xml b/core/pom.xml index a38234c..a8fbb69 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -306,7 +306,7 @@ limitations under the License. **/Parser.jj - 2 + 1 false @@
[calcite] branch master updated: [CALCITE-2892] Add the JSON_KEYS function (xuqianjin)
This is an automated email from the ASF dual-hosted git repository. hongze 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 80dc5bc [CALCITE-2892] Add the JSON_KEYS function (xuqianjin) 80dc5bc is described below commit 80dc5bcb3efa9c72573c4cc5b02f512d34c20d13 Author: XuQianJin-Stars AuthorDate: Thu Mar 7 00:34:42 2019 +0800 [CALCITE-2892] Add the JSON_KEYS function (xuqianjin) Close apache/calcite#1086 --- babel/src/main/codegen/config.fmpp | 125 +++-- core/src/main/codegen/config.fmpp | 3 +- core/src/main/codegen/templates/Parser.jj | 30 - .../calcite/adapter/enumerable/RexImpTable.java| 2 + .../apache/calcite/runtime/CalciteResource.java| 3 + .../org/apache/calcite/runtime/SqlFunctions.java | 29 + .../calcite/sql/fun/SqlJsonDepthFunction.java | 6 - ...DepthFunction.java => SqlJsonKeysFunction.java} | 33 ++ .../calcite/sql/fun/SqlJsonLengthFunction.java | 8 -- .../calcite/sql/fun/SqlJsonPrettyFunction.java | 6 - .../calcite/sql/fun/SqlJsonTypeFunction.java | 6 - .../calcite/sql/fun/SqlStdOperatorTable.java | 2 + .../org/apache/calcite/util/BuiltInMethod.java | 1 + .../calcite/runtime/CalciteResource.properties | 1 + core/src/test/codegen/config.fmpp | 3 +- .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 31 +++-- .../apache/calcite/sql/parser/SqlParserTest.java | 9 ++ .../calcite/sql/test/SqlOperatorBaseTest.java | 50 + .../java/org/apache/calcite/test/JdbcTest.java | 12 ++ .../apache/calcite/test/SqlJsonFunctionsTest.java | 56 +++-- .../org/apache/calcite/test/SqlValidatorTest.java | 6 + server/src/main/codegen/config.fmpp| 3 +- site/_docs/reference.md| 23 +++- 23 files changed, 307 insertions(+), 141 deletions(-) diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index 5439d14..cd5a36d 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -139,10 +139,11 @@ data: { "ISOLATION" "JAVA" "JSON" -"JSON_TYPE" "JSON_DEPTH" +"JSON_KEYS" "JSON_LENGTH" "JSON_PRETTY" +"JSON_TYPE" "K" "KEY" "KEY_MEMBER" @@ -365,7 +366,7 @@ data: { # "ANY", "ARE", "ARRAY", -# # "ARRAY_AGG", # not a keyword in Calcite +# "ARRAY_AGG", # not a keyword in Calcite "ARRAY_MAX_CARDINALITY", "AS", "ASC", @@ -384,7 +385,7 @@ data: { "BIGINT", "BINARY", "BIT", -# # "BIT_LENGTH", # not a keyword in Calcite +# "BIT_LENGTH", # not a keyword in Calcite "BLOB", "BOOLEAN", "BOTH", @@ -449,12 +450,12 @@ data: { "DATA", # "DATE", "DAY", -# # "DAYS", # not a keyword in Calcite +# "DAYS", # not a keyword in Calcite "DEALLOCATE", "DEC", "DECIMAL", "DECLARE", -# # "DEFAULT", +# "DEFAULT", "DEFERRABLE", "DEFERRED", # "DEFINE", @@ -464,42 +465,42 @@ data: { "DEREF", "DESC", # "DESCRIBE", # must be reserved - "DESCRIPTOR", - "DETERMINISTIC", - "DIAGNOSTICS", - "DISALLOW", - "DISCONNECT", +"DESCRIPTOR", +"DETERMINISTIC", +"DIAGNOSTICS", +"DISALLOW", +"DISCONNECT", # "DISTINCT", -# # "DO", # not a keyword in Calcite - "DOMAIN", - "DOUBLE", +# "DO", # not a keyword in Calcite +"DOMAIN", +"DOUBLE", # "DROP", # probably must be reserved - "DYNAMIC", - "EACH", - "ELEMENT", - "ELSE", -# # "ELSEIF", # not a keyword in Calcite - "EMPTY", - "END", -# # "END-EXEC", # not a keyword in Calcite, and contains '-' - "END_FRAME", - "END_PARTITION", - "EQUALS", - "ESCAPE", - "EVER
[calcite] branch master updated (a231418 -> b6d663c)
This is an automated email from the ASF dual-hosted git repository. hongze pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. discard a231418 Site: update content of "Not implemented" since JSON_LENGH has already been added new b6d663c Site: Update content of "Not implemented" since JSON_LENGH has already been added 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 (a231418) \ N -- N -- N refs/heads/master (b6d663c) 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 3302 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: Site: update content of "Not implemented" since JSON_LENGH has already been added
This is an automated email from the ASF dual-hosted git repository. hongze 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 a231418 Site: update content of "Not implemented" since JSON_LENGH has already been added a231418 is described below commit a231418f62901dfeb1270686b6d1d8a5c7be7318 Author: Hongze Zhang AuthorDate: Sat Mar 30 13:41:01 2019 +0800 Site: update content of "Not implemented" since JSON_LENGH has already been added --- site/_docs/reference.md | 1 - 1 file changed, 1 deletion(-) diff --git a/site/_docs/reference.md b/site/_docs/reference.md index c1f6861..895a968 100644 --- a/site/_docs/reference.md +++ b/site/_docs/reference.md @@ -2108,7 +2108,6 @@ Result Not implemented: -* JSON_LENGTH * JSON_INSERT * JSON_SET * JSON_REPLACE
[calcite] branch master updated: [CALCITE-2927] The Javadoc and implement of RuleQueue.computeImportance() is inconsistent (Meng Wang)
This is an automated email from the ASF dual-hosted git repository. hongze 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 3124a85 [CALCITE-2927] The Javadoc and implement of RuleQueue.computeImportance() is inconsistent (Meng Wang) 3124a85 is described below commit 3124a85b93ff2f1b79484c7bd4cc41835d4f1920 Author: wangzzu AuthorDate: Mon Mar 18 09:57:44 2019 +0800 [CALCITE-2927] The Javadoc and implement of RuleQueue.computeImportance() is inconsistent (Meng Wang) Close apache/calcite# --- core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java b/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java index ab025e3..25135f0 100644 --- a/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java +++ b/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java @@ -356,7 +356,7 @@ class RuleQueue { * * * the root {@link RelSubset} has an importance of 1 - * the importance of any other subset is the sum of its importance to + * the importance of any other subset is the max of its importance to * its parents * The importance of children is pro-rated according to the cost of the * children. Consider a node which has a cost of 3, and children with costs @@ -368,7 +368,7 @@ class RuleQueue { * * The formula for the importance I of node n is: * - * In = Sumparents p of n{Ip . + * In = Maxparents p of n{Ip . * W n, p} * * where Wn, p, the weight of n within its parent p, is
[calcite] branch master updated: [CALCITE-2808] Add the JSON_LENGTH function (xuqianjin)
This is an automated email from the ASF dual-hosted git repository. hongze 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 2d33c57 [CALCITE-2808] Add the JSON_LENGTH function (xuqianjin) 2d33c57 is described below commit 2d33c57bff41b6ea473f8f60505a10b196ea79d7 Author: XuQianJin-Stars AuthorDate: Tue Mar 5 18:35:24 2019 +0800 [CALCITE-2808] Add the JSON_LENGTH function (xuqianjin) Close apache/calcite#1070 --- babel/src/main/codegen/config.fmpp | 5 +- core/src/main/codegen/config.fmpp | 1 + core/src/main/codegen/templates/Parser.jj | 50 .../calcite/adapter/enumerable/RexImpTable.java| 7 ++- .../apache/calcite/runtime/.SqlFunctions.java.swp | Bin 0 -> 16384 bytes .../apache/calcite/runtime/CalciteResource.java| 14 +++-- .../org/apache/calcite/runtime/SqlFunctions.java | 62 ++-- .../sql/fun/SqlJsonApiCommonSyntaxOperator.java| 34 --- .../calcite/sql/fun/SqlJsonLengthFunction.java | 65 + .../calcite/sql/fun/SqlStdOperatorTable.java | 7 ++- .../org/apache/calcite/util/BuiltInMethod.java | 3 + .../calcite/runtime/CalciteResource.properties | 6 +- core/src/test/codegen/config.fmpp | 1 + .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 9 +++ .../apache/calcite/sql/parser/SqlParserTest.java | 11 .../calcite/sql/test/SqlOperatorBaseTest.java | 54 - .../java/org/apache/calcite/test/JdbcTest.java | 25 +--- .../apache/calcite/test/SqlJsonFunctionsTest.java | 36 .../org/apache/calcite/test/SqlValidatorTest.java | 9 +++ server/src/main/codegen/config.fmpp| 1 + site/_docs/reference.md| 21 +++ 21 files changed, 378 insertions(+), 43 deletions(-) diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index dab4251..5439d14 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -141,6 +141,8 @@ data: { "JSON" "JSON_TYPE" "JSON_DEPTH" +"JSON_LENGTH" +"JSON_PRETTY" "K" "KEY" "KEY_MEMBER" @@ -555,9 +557,6 @@ data: { "JSON_ARRAYAGG", "JSON_EXISTS", "JSON_VALUE", -"JSON_TYPE", -"JSON_DEPTH" -"JSON_PRETTY", "JSON_OBJECT", "JSON_OBJECTAGG", "JSON_QUERY", diff --git a/core/src/main/codegen/config.fmpp b/core/src/main/codegen/config.fmpp index c8f9ec8..7b3fca2 100644 --- a/core/src/main/codegen/config.fmpp +++ b/core/src/main/codegen/config.fmpp @@ -161,6 +161,7 @@ data: { "JSON" "JSON_TYPE" "JSON_DEPTH" +"JSON_LENGTH" "JSON_PRETTY" "K" "KEY" diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 98e3f1b..5dfa66e 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -4864,6 +4864,8 @@ SqlNode BuiltinFunctionCall() : | node = JsonDepthFunctionCall() { return node; } | +node = JsonLengthFunctionCall() { return node; } +| node = JsonObjectAggFunctionCall() { return node; } | node = JsonArrayFunctionCall() { return node; } @@ -4958,21 +4960,32 @@ SqlNode JsonPathSpec() : } } -SqlNode JsonApiCommonSyntax() : +SqlNode JsonApiCommonSyntax(boolean acceptNonPath) : { SqlNode e; List args = new ArrayList(); Span span; +SqlOperator op; } { e = JsonValueExpression(true) { args.add(e); span = Span.of(e); } - -e = Expression(ExprContext.ACCEPT_NON_QUERY) { -args.add(e); -} +( + +e = Expression(ExprContext.ACCEPT_NON_QUERY) { +op = SqlStdOperatorTable.JSON_API_COMMON_SYNTAX; +args.add(e); +} +| +{ +if (!acceptNonPath) { + throw new ParseException(RESOURCE.jsonPathMustBeSpecified().str()); +} +op = SqlStdOperatorTable.JSON_API_COMMON_SYNTAX_WITHOUT_PATH; +} +) [ e = JsonValueExpression(false) { args.add(e); @@ -4991,9 +5004,8 @@ SqlNode JsonApiCommonSyntax() : )* ] { -return SqlStdOperatorTable.JSON_API_COMMON_SYNTAX.createCall(span.end(this), args); +return op.createCall(span.end(this), args); } - } SqlJsonExistsErrorBehavior JsonExistsErrorBehavior() : @@ -5019,
[calcite] branch master updated: [CALCITE-2785] In EnumerableAggregate, wrong result produced if there are sorted aggregates and non-sorted aggregates at the same time
This is an automated email from the ASF dual-hosted git repository. hongze 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 f992e6c [CALCITE-2785] In EnumerableAggregate, wrong result produced if there are sorted aggregates and non-sorted aggregates at the same time f992e6c is described below commit f992e6c8fbc3712c6bd70096fb6b05da448b2cab Author: hongzezhang AuthorDate: Thu Feb 28 11:38:42 2019 +0800 [CALCITE-2785] In EnumerableAggregate, wrong result produced if there are sorted aggregates and non-sorted aggregates at the same time Rename SequencedAdderAggregateLambdaFactory to BasicAggregateLambdaFactory; Rename OrderedAggregateLambdaFactory to LazyAggregateLambdaFactory; Add BasicLazyAccumulator. --- ...ctory.java => BasicAggregateLambdaFactory.java} | 6 +-- .../adapter/enumerable/BasicLazyAccumulator.java | 45 ++ .../adapter/enumerable/EnumerableAggregate.java| 18 ++--- ...actory.java => LazyAggregateLambdaFactory.java} | 40 +++ .../calcite/adapter/enumerable/SourceSorter.java | 17 +--- .../org/apache/calcite/util/BuiltInMethod.java | 10 +++-- core/src/test/resources/sql/agg.iq | 21 ++ 7 files changed, 124 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/SequencedAdderAggregateLambdaFactory.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/BasicAggregateLambdaFactory.java similarity index 94% rename from core/src/main/java/org/apache/calcite/adapter/enumerable/SequencedAdderAggregateLambdaFactory.java rename to core/src/main/java/org/apache/calcite/adapter/enumerable/BasicAggregateLambdaFactory.java index 4b4577c..ee67523 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/SequencedAdderAggregateLambdaFactory.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/BasicAggregateLambdaFactory.java @@ -31,13 +31,13 @@ import java.util.List; * @param Type of the enumerable output result * @param Type of the group-by key */ -public class SequencedAdderAggregateLambdaFactory +public class BasicAggregateLambdaFactory implements AggregateLambdaFactory { private final Function0 accumulatorInitializer; private final Function2 accumulatorAdderDecorator; - public SequencedAdderAggregateLambdaFactory( + public BasicAggregateLambdaFactory( Function0 accumulatorInitializer, List> accumulatorAdders) { this.accumulatorInitializer = accumulatorInitializer; @@ -85,4 +85,4 @@ public class SequencedAdderAggregateLambdaFactoryhttp://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.adapter.enumerable; + +import org.apache.calcite.linq4j.function.Function2; + +/** + * Performs accumulation against a pre-collected list of input sources, + * used with {@link LazyAggregateLambdaFactory}. + * + * @param Type of the accumulator + * @param Type of the enumerable input source + */ +public class BasicLazyAccumulator +implements LazyAggregateLambdaFactory.LazyAccumulator { + + private final Function2 accumulatorAdder; + + public BasicLazyAccumulator(Function2 accumulatorAdder) { +this.accumulatorAdder = accumulatorAdder; + } + + @Override public void accumulate(Iterable sourceIterable, TAccumulate accumulator) { +TAccumulate accumulator1 = accumulator; +for (TSource tSource : sourceIterable) { + accumulator1 = accumulatorAdder.apply(accumulator1, tSource); +} + } +} + +// End BasicLazyAccumulator.java 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 3130bd0..aa33685 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 @@ -485,11 +485,11 @@ public class EnumerableAggregate extends Aggregate implements EnumerableRel { * * * {@code hasOrderedCall == true} means there is at least one aggregate - * call including sort spec. We use {@link OrderedAggregateLambdaFactory} + * call including sort spec. We use {@link LazyAggregateLambdaFactory} * implementation to implement sorted aggregates for that. * * {@code hasOrderedCall == false} indicates to use - * {@link SequencedAdderAggregateLambdaFactory} to implement a non-sort + * {@link BasicAggregateLambdaFa
[calcite] branch master updated: [CALCITE-2891] Alias suggester failed to suggest name based on original name incrementally (Haisheng Yuan)
This is an automated email from the ASF dual-hosted git repository. hongze 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 92562a0 [CALCITE-2891] Alias suggester failed to suggest name based on original name incrementally (Haisheng Yuan) 92562a0 is described below commit 92562a0f213fc1edc66e25f9c88e15bacb9085df Author: Haisheng Yuan AuthorDate: Mon Mar 4 23:06:44 2019 -0600 [CALCITE-2891] Alias suggester failed to suggest name based on original name incrementally (Haisheng Yuan) Close apache/calcite#1085 --- .../java/org/apache/calcite/tools/RelBuilder.java | 3 ++- .../org/apache/calcite/test/RelBuilderTest.java| 29 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java index 9dfba8b..ccb987c 100644 --- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java +++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java @@ -1207,6 +1207,7 @@ public class RelBuilder { for (int i = 0; i < fieldNameList.size(); ++i) { final RexNode node = nodeList.get(i); String name = fieldNameList.get(i); + String originalName = name; Field field; if (name == null || uniqueNameList.contains(name)) { int j = 0; @@ -1214,7 +1215,7 @@ public class RelBuilder { j = i; } do { - name = SqlValidatorUtil.F_SUGGESTER.apply(name, j, j++); + name = SqlValidatorUtil.F_SUGGESTER.apply(originalName, j, j++); } while (uniqueNameList.contains(name)); fieldNameList.set(i, name); } diff --git a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java index 635c1d7..fa5a150 100644 --- a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java @@ -1535,11 +1535,38 @@ public class RelBuilderTest { .build(); final String expected = "" + "LogicalFilter(condition=[>($1, $2)])\n" -+ " LogicalProject($f1=[20], $f12=[10], DEPTNO=[$7])\n" ++ " LogicalProject($f1=[20], $f2=[10], DEPTNO=[$7])\n" + "LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); } + /** + * Tests that project field name aliases are suggested incrementally. + */ + @Test public void testAliasSuggester() { +final RelBuilder builder = RelBuilder.create(config().build()); +RelNode root = builder.scan("EMP") +.project(builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0), +builder.field(0)) +.build(); +final String expected = "" ++ "LogicalProject(EMPNO=[$0], EMPNO0=[$0], EMPNO1=[$0], " ++ "EMPNO2=[$0], EMPNO3=[$0], EMPNO4=[$0], EMPNO5=[$0], " ++ "EMPNO6=[$0], EMPNO7=[$0], EMPNO8=[$0], EMPNO9=[$0], EMPNO10=[$0])\n" ++ " LogicalTableScan(table=[[scott, EMP]])\n"; +assertThat(root, hasTree(expected)); + } + @Test public void testAliasAggregate() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root =
[calcite] branch master updated (7c905ff -> 6c9557f)
This is an automated email from the ASF dual-hosted git repository. hongze pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. discard 7c905ff [CALCITE-2881] Add the JSON_PRETTY function (Ritesh Kapoor) new 6c9557f [CALCITE-2881] Add the JSON_PRETTY function (Ritesh Kapoor) 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 (7c905ff) \ N -- N -- N refs/heads/master (6c9557f) 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 3242 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/runtime/SqlFunctions.java | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-)
[calcite] branch master updated: [CALCITE-2881] Add the JSON_PRETTY function (Ritesh Kapoor)
This is an automated email from the ASF dual-hosted git repository. hongze 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 7c905ff [CALCITE-2881] Add the JSON_PRETTY function (Ritesh Kapoor) 7c905ff is described below commit 7c905ff3263bcc6cec826789305f1be9fba0962e Author: Ritesh Kapoor AuthorDate: Thu Feb 28 15:04:33 2019 +0530 [CALCITE-2881] Add the JSON_PRETTY function (Ritesh Kapoor) Also refactor SqlJsonFunctionsTest a little to better generate invocation descriptions. Close apache/calcite#1075 --- babel/src/main/codegen/config.fmpp | 3 + core/src/main/codegen/config.fmpp | 1 + core/src/main/codegen/templates/Parser.jj | 19 + .../calcite/adapter/enumerable/RexImpTable.java| 2 + .../apache/calcite/runtime/CalciteResource.java| 3 + .../org/apache/calcite/runtime/SqlFunctions.java | 12 ++- .../calcite/sql/fun/SqlJsonPrettyFunction.java | 68 .../calcite/sql/fun/SqlStdOperatorTable.java | 3 + .../org/apache/calcite/util/BuiltInMethod.java | 6 ++ .../calcite/runtime/CalciteResource.properties | 1 + core/src/test/codegen/config.fmpp | 1 + .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 7 ++ .../apache/calcite/sql/parser/SqlParserTest.java | 7 ++ .../calcite/sql/test/SqlOperatorBaseTest.java | 9 ++ .../java/org/apache/calcite/test/JdbcTest.java | 12 +++ .../apache/calcite/test/SqlJsonFunctionsTest.java | 95 -- .../org/apache/calcite/test/SqlValidatorTest.java | 11 ++- server/src/main/codegen/config.fmpp| 1 + site/_docs/reference.md| 2 + 19 files changed, 216 insertions(+), 47 deletions(-) diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index de1efb7..dab4251 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -555,6 +555,9 @@ data: { "JSON_ARRAYAGG", "JSON_EXISTS", "JSON_VALUE", +"JSON_TYPE", +"JSON_DEPTH" +"JSON_PRETTY", "JSON_OBJECT", "JSON_OBJECTAGG", "JSON_QUERY", diff --git a/core/src/main/codegen/config.fmpp b/core/src/main/codegen/config.fmpp index a28294a..c8f9ec8 100644 --- a/core/src/main/codegen/config.fmpp +++ b/core/src/main/codegen/config.fmpp @@ -161,6 +161,7 @@ data: { "JSON" "JSON_TYPE" "JSON_DEPTH" +"JSON_PRETTY" "K" "KEY" "KEY_MEMBER" diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 9bdae0d..56a3a7f 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -4823,6 +4823,8 @@ SqlNode BuiltinFunctionCall() : | node = JsonValueFunctionCall() { return node; } | +node = JsonPrettyFunctionCall() { return node; } +| node = JsonQueryFunctionCall() { return node; } | node = JsonObjectFunctionCall() { return node; } @@ -5072,6 +5074,22 @@ SqlCall JsonValueFunctionCall() : } } +SqlCall JsonPrettyFunctionCall() : +{ +final SqlNode[] args = new SqlNode[1]; +SqlNode e; +final Span span; +} +{ + { span = span(); } + e = JsonValueExpression(true) { +args[0] = e; +} + { +return SqlStdOperatorTable.JSON_PRETTY.createCall(span.end(this), args); +} +} + List JsonQueryEmptyOrErrorBehavior() : { final List list = new ArrayList(); @@ -6355,6 +6373,7 @@ SqlPostfixOperator PostfixRowOperator() : | < JSON_ARRAYAGG: "JSON_ARRAYAGG"> | < JSON_EXISTS: "JSON_EXISTS" > | < JSON_VALUE: "JSON_VALUE" > +| < JSON_PRETTY: "JSON_PRETTY" > | < JSON_OBJECT: "JSON_OBJECT"> | < JSON_TYPE: "JSON_TYPE"> | < JSON_DEPTH: "JSON_DEPTH"> 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 e44af2b..dcab895 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 @@ -167,6 +167,7 @@ import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_DEPTH; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_EXISTS; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECT; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON
[calcite] branch master updated: Following [CALCITE-2864], remove a redundant file generated by test
This is an automated email from the ASF dual-hosted git repository. hongze 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 a2e9f82 Following [CALCITE-2864], remove a redundant file generated by test a2e9f82 is described below commit a2e9f82f10355be40a7348707d2659270f06dda0 Author: Hongze Zhang AuthorDate: Thu Feb 28 12:10:41 2019 +0800 Following [CALCITE-2864], remove a redundant file generated by test --- core/custom-schema-model.json | 15 --- 1 file changed, 15 deletions(-) diff --git a/core/custom-schema-model.json b/core/custom-schema-model.json deleted file mode 100644 index bde460d..000 --- a/core/custom-schema-model.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - version: '1.0', - defaultSchema: 'adhoc', - schemas: [ -{ - name: 'empty' -}, -{ - name: 'adhoc', - type: 'custom', - factory: 'org.apache.calcite.test.JdbcTest$MySchemaFactory', - operand: {'tableName': 'ELVIS'} -} - ] -}
[calcite] branch master updated (5ada462 -> 82ab280)
This is an automated email from the ASF dual-hosted git repository. hongze pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git. discard 5ada462 [CALCITE-2787] Json aggregate calls with different null clause get incorrectly merged during converting from SQL to relational algebra new 82ab280 [CALCITE-2787] JSON aggregate calls with different null clause get incorrectly merged during converting from SQL to relational algebra 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 (5ada462) \ N -- N -- N refs/heads/master (82ab280) 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 3234 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-2787] Json aggregate calls with different null clause get incorrectly merged during converting from SQL to relational algebra
This is an automated email from the ASF dual-hosted git repository. hongze 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 5ada462 [CALCITE-2787] Json aggregate calls with different null clause get incorrectly merged during converting from SQL to relational algebra 5ada462 is described below commit 5ada462e6f792deee7185ad2df8ec58380061d59 Author: Hongze Zhang AuthorDate: Fri Feb 22 22:32:24 2019 +0800 [CALCITE-2787] Json aggregate calls with different null clause get incorrectly merged during converting from SQL to relational algebra --- .../calcite/adapter/enumerable/RexImpTable.java| 13 +++- .../org/apache/calcite/runtime/SqlFunctions.java | 3 +- .../sql/fun/SqlJsonArrayAggAggFunction.java| 11 +--- .../sql/fun/SqlJsonObjectAggAggFunction.java | 11 +--- .../calcite/sql/fun/SqlStdOperatorTable.java | 6 +- .../apache/calcite/test/SqlToRelConverterTest.xml | 10 +-- core/src/test/resources/sql/agg.iq | 77 +- 7 files changed, 100 insertions(+), 31 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 a8112d2..e44af2b 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 @@ -44,6 +44,7 @@ import org.apache.calcite.schema.ImplementableFunction; import org.apache.calcite.schema.impl.AggregateFunctionImpl; import org.apache.calcite.sql.SqlAggFunction; import org.apache.calcite.sql.SqlBinaryOperator; +import org.apache.calcite.sql.SqlJsonConstructorNullClause; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlJsonArrayAggAggFunction; import org.apache.calcite.sql.fun.SqlJsonObjectAggAggFunction; @@ -452,13 +453,19 @@ public class RexImpTable { defineMethod(JSON_VALUE_ANY, BuiltInMethod.JSON_VALUE_ANY.method, NullPolicy.NONE); defineMethod(JSON_QUERY, BuiltInMethod.JSON_QUERY.method, NullPolicy.NONE); defineMethod(JSON_OBJECT, BuiltInMethod.JSON_OBJECT.method, NullPolicy.NONE); +defineMethod(JSON_ARRAY, BuiltInMethod.JSON_ARRAY.method, NullPolicy.NONE); defineMethod(JSON_TYPE, BuiltInMethod.JSON_TYPE.method, NullPolicy.NONE); defineMethod(JSON_DEPTH, BuiltInMethod.JSON_DEPTH.method, NullPolicy.NONE); -aggMap.put(JSON_OBJECTAGG, + aggMap.put(JSON_OBJECTAGG.with(SqlJsonConstructorNullClause.ABSENT_ON_NULL), JsonObjectAggImplementor .supplierFor(BuiltInMethod.JSON_OBJECTAGG_ADD.method)); -defineMethod(JSON_ARRAY, BuiltInMethod.JSON_ARRAY.method, NullPolicy.NONE); -aggMap.put(JSON_ARRAYAGG, +aggMap.put(JSON_OBJECTAGG.with(SqlJsonConstructorNullClause.NULL_ON_NULL), +JsonObjectAggImplementor +.supplierFor(BuiltInMethod.JSON_OBJECTAGG_ADD.method)); +aggMap.put(JSON_ARRAYAGG.with(SqlJsonConstructorNullClause.ABSENT_ON_NULL), +JsonArrayAggImplementor +.supplierFor(BuiltInMethod.JSON_ARRAYAGG_ADD.method)); +aggMap.put(JSON_ARRAYAGG.with(SqlJsonConstructorNullClause.NULL_ON_NULL), JsonArrayAggImplementor .supplierFor(BuiltInMethod.JSON_ARRAYAGG_ADD.method)); defineImplementor(IS_JSON_VALUE, NullPolicy.NONE, 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 2c35aba..fed1d97 100644 --- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java +++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java @@ -73,7 +73,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; import java.util.Queue; import java.util.Set; import java.util.TimeZone; @@ -2487,7 +2486,7 @@ public class SqlFunctions { errorBehavior.toString()).ex(); } } else { - return !Objects.isNull(context.pathReturned); + return context.pathReturned != null; } } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java index 0569bea..6fcbc3f 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayAggAggFunction.java @@ -34,7 +34,6 @@ import org.apache.calcite.sql.validate.SqlValidatorImpl; import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.util.Optionality; -import java.util.Locale; import java.util.Objects; /** @@ -43,9 +42,9 @@ import java.util.Objects; public class SqlJsonArrayAggAggFunction extends SqlAggFunction { private final
[calcite] branch master updated: [CALCITE-2791] Add the JSON_TYPE function (xuqianjin)
This is an automated email from the ASF dual-hosted git repository. hongze 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 5101703 [CALCITE-2791] Add the JSON_TYPE function (xuqianjin) 5101703 is described below commit 5101703c3bb7e051766f9dc932534a0a7acba0c5 Author: xuqianjin AuthorDate: Sat Feb 23 00:44:49 2019 +0800 [CALCITE-2791] Add the JSON_TYPE function (xuqianjin) Close apache/calcite#1013 --- babel/src/main/codegen/config.fmpp | 1 + core/src/main/codegen/config.fmpp | 1 + core/src/main/codegen/templates/Parser.jj | 19 ++ .../calcite/adapter/enumerable/RexImpTable.java| 2 + .../apache/calcite/runtime/CalciteResource.java| 3 + .../org/apache/calcite/runtime/SqlFunctions.java | 36 +++ .../calcite/sql/fun/SqlJsonTypeFunction.java | 69 ++ .../calcite/sql/fun/SqlStdOperatorTable.java | 2 + .../org/apache/calcite/util/BuiltInMethod.java | 1 + .../calcite/runtime/CalciteResource.properties | 1 + core/src/test/codegen/config.fmpp | 1 + .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 8 +++ .../apache/calcite/sql/parser/SqlParserTest.java | 10 .../calcite/sql/test/SqlOperatorBaseTest.java | 24 .../java/org/apache/calcite/test/JdbcTest.java | 12 .../apache/calcite/test/SqlJsonFunctionsTest.java | 23 +++- .../org/apache/calcite/test/SqlValidatorTest.java | 8 +++ server/src/main/codegen/config.fmpp| 1 + site/_docs/reference.md| 24 19 files changed, 245 insertions(+), 1 deletion(-) diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index 2fa6061..f8f4a0b 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -139,6 +139,7 @@ data: { "ISOLATION" "JAVA" "JSON" +"JSON_TYPE" "K" "KEY" "KEY_MEMBER" diff --git a/core/src/main/codegen/config.fmpp b/core/src/main/codegen/config.fmpp index d7d5066..4021ab1 100644 --- a/core/src/main/codegen/config.fmpp +++ b/core/src/main/codegen/config.fmpp @@ -159,6 +159,7 @@ data: { "ISOLATION" "JAVA" "JSON" +"JSON_TYPE" "K" "KEY" "KEY_MEMBER" diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 6cecc56..a546495 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -4827,6 +4827,8 @@ SqlNode BuiltinFunctionCall() : | node = JsonObjectFunctionCall() { return node; } | +node = JsonTypeFunctionCall() { return node; } +| node = JsonObjectAggFunctionCall() { return node; } | node = JsonArrayFunctionCall() { return node; } @@ -5246,6 +5248,22 @@ SqlCall JsonObjectFunctionCall() : } } +SqlCall JsonTypeFunctionCall() : +{ +final SqlNode[] args = new SqlNode[1]; +SqlNode e; +final Span span; +} +{ + { span = span(); } + e = JsonValueExpression(true) { +args[0] = e; +} + { +return SqlStdOperatorTable.JSON_TYPE.createCall(span.end(this), args); +} +} + SqlCall JsonObjectAggFunctionCall() : { final SqlNode[] args = new SqlNode[2]; @@ -6274,6 +6292,7 @@ SqlPostfixOperator PostfixRowOperator() : | < JSON_EXISTS: "JSON_EXISTS" > | < JSON_VALUE: "JSON_VALUE" > | < JSON_OBJECT: "JSON_OBJECT"> +| < JSON_TYPE: "JSON_TYPE"> | < JSON_OBJECTAGG: "JSON_OBJECTAGG"> | < JSON_QUERY: "JSON_QUERY" > | < K: "K" > 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 910bebe..6059d5e 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 @@ -167,6 +167,7 @@ import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECT; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECTAGG; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_QUERY; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_STRUCTURED_VALUE_EXPRESSION; +import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_TYPE; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_VALUE_ANY; import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_VALUE_EXPRESSION; import stati