[WIP] HIVE-29641: Upgrade Calcite to 1.42.0#6523
Draft
rubenada wants to merge 50 commits into
Draft
Conversation
1.40 [CALCITE-6961] Support LogicalRepeatUnion in RelShuttle + [CALCITE-6959] Support LogicalAsofJoin in RelShuttle Add visit(LogicalAsofJoin) and visit(LogicalRepeatUnion) to HiveRelShuttleImpl [CALCITE-5387] Type-mismatch on nullability in JoinPushTransitivePredicatesRule RelRule Adjust RexPermuteInputsShuttle constructor in HiveJoinConstraintsRule 1.41 [CALCITE-7029] Support DPhyp to handle various join types Add visitNodeAndFieldIndex in RexVisitor implementation (HiveCalciteUtil#ConstantFinder) 1.42 [CALCITE-7351] Make getMaxNumericScale() and getMaxNumericPrecision() final Adjust HiveTypeSystemImpl
…alues in RexLiteral: [CALCITE-2067] RexLiteral cannot represent accurately floating point values, including NaN, Infinity (1.38)
…alues in RexLiteral: [CALCITE-2067] RexLiteral cannot represent accurately floating point values, including NaN, Infinity (1.38)
[CALCITE-5639] RexSimplify should remove IS NOT NULL check when LIKE comparison is present (1.35) (actually more generic than just LIKE) [CALCITE-5769] Optimizing 'CAST(e AS t) IS NOT NULL' to 'e IS NOT NULL' (1.35) (actually more generic than just CAST)
… due to [CALCITE-4590] Incorrect query result with fixed-length string (1.39) Note: this Calcite fix only impacts predicates with OR/IN/SEARCH, and aligns these plans with single value condition ones (which already contained the padding, e.g. ql/src/test/results/clientpositive/perf/tpcds30tb/tez/cbo_query33.q.out)
[CALCITE-6417] Map value constructor and Array value constructor unparsed incorrectly for HiveSqlDialect (1.38)
… due to [CALCITE-4590] Incorrect query result with fixed-length string (1.39)
…alues in RexLiteral: [CALCITE-2067] RexLiteral cannot represent accurately floating point values, including NaN, Infinity (1.38)
[CALCITE-5639] RexSimplify should remove IS NOT NULL check when LIKE comparison is present (1.35) (actually more generic than just LIKE) [CALCITE-5769] Optimizing 'CAST(e AS t) IS NOT NULL' to 'e IS NOT NULL' (1.35) (actually more generic than just CAST)
… due to [CALCITE-4590] Incorrect query result with fixed-length string (1.39)
[CALCITE-5607] Serialize return type during RelJson.toJson(RexNode node) for SqlKind.MINUS (1.37)
…c issue on Jenkins (still tbd)
[CALCITE-7160] Simplify AND/OR with DISTINCT predicates to SEARCH (1.41)
[CALCITE-5639] RexSimplify should remove IS NOT NULL check when LIKE comparison is present (1.35) (actually more generic than just LIKE) [CALCITE-5769] Optimizing 'CAST(e AS t) IS NOT NULL' to 'e IS NOT NULL' (1.35)
[CALCITE-6417] Map value constructor and Array value constructor unparsed incorrectly for HiveSqlDialect (1.38)
…creating the filter RelNode. This is required to avoid this exception (new assertion introduced in 1.41 via [CALCITE-7070] FILTER_REDUCE_EXPRESSIONS crashes on expression BETWEEN ( NULL) AND X ) seen in TestMiniLlapLocalCliDriver subquery_null_agg when trying to create a Filter with NULL = NULL condition: java.lang.AssertionError: Comparison with NULL in pulledUpPredicates at org.apache.calcite.util.Litmus.lambda$static$0(Litmus.java:31) at org.apache.calcite.util.Litmus.check(Litmus.java:76) at org.apache.calcite.plan.RelOptPredicateList.<init>(RelOptPredicateList.java:128) ...
…y comparison RexCall create in HiveFunctionHelper), and avoid RexSimplify solution on CalcitePlanner (too many side effects)
…ntSnapshotMaterializationRule, use snapshotId -1 instead, and then switch it back in HivePushdownSnapshotFilterRule; this is required because an incorrect NULL comparison predicate would trigger a new assertion introduced in 1.41 (via [CALCITE-7070] FILTER_REDUCE_EXPRESSIONS crashes on expression BETWEEN ( NULL) AND X ): java.lang.AssertionError: Comparison with NULL in pulledUpPredicates at org.apache.calcite.util.Litmus.lambda$static$0(Litmus.java:31) at org.apache.calcite.util.Litmus.check(Litmus.java:76) at org.apache.calcite.plan.RelOptPredicateList.<init>(RelOptPredicateList.java:128)
…ge on HiveAugmentSnapshotMaterializationRule: generate $snapshotId <= -1 instead of $snapshotId <= null (which can lead to a Calcite error)
…doc generation: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.6.0:shade (default) on project hive-druid-handler: Error creating shaded jar: Problem shading JAR /../hive/druid-handler/target/hive-druid-handler-4.3.0-SNAPSHOT.jar entry org/apache/hive/druid/org/apache/calcite/runtime/SqlFunctions.class: org.apache.maven.plugin.MojoExecutionException: Error in ASM processing class org/apache/hive/druid/org/apache/calcite/runtime/SqlFunctions.class: Index 65536 out of bounds for length 334
…ing the expression SUBSTR(`value`, 5)
…d from RexSimplify for "non-safe" operations, e.g. division (if it could "hide" a runtime division by zero) or operations involving cast (only "lossless" casts can be simplified), via: [CALCITE-7145] RexSimplify should not simplify IS NULL(10/0) (1.42) [CALCITE-7296] RexSimplify should not simplify IS (NOT) NULL(CAST(10/0 AS BIGINT)) (1.42) [CALCITE-7032] Simplify 'NULL>ALL (ARRAY[1,2,NULL])' to 'NULL' (1.41)
[CALCITE-5639] RexSimplify should remove IS NOT NULL check when LIKE comparison is present (1.35) (actually more generic than just LIKE) [CALCITE-5769] Optimizing 'CAST(e AS t) IS NOT NULL' to 'e IS NOT NULL' (1.35)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Upgrade Calcite to 1.42.0.
Why are the changes needed?
Upgrade to latest Calcite version.
Does this PR introduce any user-facing change?
tbd
How was this patch tested?
tbd
Details
pom changes
Code adjustments due to Calcite breaking changes
Use non-deprecated version of RexBuilder#makeAbstractCast in HiveSqlSumAggFunction, RexNodeConverter, ASTConverter
AggCall construction adjustments in HiveAggregate and HiveSqlSumAggFunction
Add visitLambda and visitLambdaRef in RexVisitor implementation (HiveCalciteUtil#ConstantFinder)
Add visit(LogicalAsofJoin) and visit(LogicalRepeatUnion) to HiveRelShuttleImpl
Adjust RexPermuteInputsShuttle constructor in HiveJoinConstraintsRule
Add visitNodeAndFieldIndex in RexVisitor implementation (HiveCalciteUtil#ConstantFinder)
Adjust HiveTypeSystemImpl
Other code changes
_UTF-16LE'1'instead of simply'1') due to the modification inSqlImplemento#toSql(RexLiteral)via "[CALCITE-6006] RelToSqlConverter loses charset information" (introduced in 1.36)As a consequence of defining Calcite default charset system property, now
RexLiteral#appendAsJava(which already contained the literal charset vs default charset verification, added to SqlImplementor in CALCITE-6006 1.36), literals printed via this method (i.e. used to print the charset) don't do it any more, e.g._UTF-16LE'ten'=>'ten', which aligns them with the ones printed viaSqlImplemento#toSql(RexLiteral)This was also violated by materialization rules in HiveMaterializedViewRule, which used its own private static class HiveHepExtractRelNodeRule in a HepProgram as unionRewritingPullProgram. As a workaround, it is proposed to extend the MaterializedView rules (as HiveMaterializedViewRule), override the rewriteQuery
(where the UnionRewritingPullProgram is called), and unwrap the HepRelVertex tree ourselves (using (
HiveCalciteUtil.stripHepVertices) before calling the super.rewriteQuery.fieldsUsed.contains(aggregate.getGroupSet())but ratherfieldsUsed.intersects(aggregate.getGroupSet()).Also took the opportunity here to get rid of the unnecessary check aggregate.getIndicatorCount() > 0 which is always false (this method is deprecated and always returns zero)
java.lang.UnsupportedOperationException: Values with non-empty tuples are not supported. at org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.convert(ASTConverter.java:264). The reason is that RelBuilder#project_ contains the simplification (only applicable if config.simplifyValues is true): "If the expressions are all literals, and the input is a Values with N rows [...], replace with a Values with same tuple N times"; and with CALCITE-5717 that simplification was extended to not only "Values with N rows" but also "Aggregates with 1 row", and this case would lead to creating a non-empty HiveValues, which is not supported in our case. The easiest solution to prevent that from happening is disabling simplifyValues in HiveRelBuilder config.java.lang.AssertionError: Comparison with NULL in pulledUpPredicates, so in order to avoid that, a few classes needed to be adjusted. Firstly HiveFunctionHelper#getExpression must not create such expressions (seenNULL = NULLinTestMiniLlapLocalCliDriverwithsubquery_null_agg.q); secondly avoid incorrect comparison ($snapshotIdInputRef <= NULLseen inTestIcebergCliDriverwithmv_iceberg_orc.q) in HiveAugmentSnapshotMaterializationRule, use snapshotId -1 instead, and then switch it back in HivePushdownSnapshotFilterRule.