You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/09/05 11:28:32 UTC
(shardingsphere) branch master updated: Upgrade Apache Calcite to 1.42.0 (#39734)
This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new c008f7cd002 Upgrade Apache Calcite to 1.42.0 (#39734)
c008f7cd002 is described below
commit c008f7cd002101838e8a6c7c3097270e9787d29c
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Sep 5 19:28:26 2026 +0800
Upgrade Apache Calcite to 1.42.0 (#39734)
---
distribution/proxy/src/main/release-docs/LICENSE | 27 +++---
.../rel/converter/SQLFederationRelConverter.java | 95 +++++++++++++++++++++-
pom.xml | 20 +++--
3 files changed, 121 insertions(+), 21 deletions(-)
diff --git a/distribution/proxy/src/main/release-docs/LICENSE b/distribution/proxy/src/main/release-docs/LICENSE
index 11f31e7cc6e..f9f55451f13 100644
--- a/distribution/proxy/src/main/release-docs/LICENSE
+++ b/distribution/proxy/src/main/release-docs/LICENSE
@@ -215,13 +215,13 @@ Apache 2.0 licenses
The following components are provided under the Apache License. See project link for details.
The text of each license is the standard Apache 2.0 license.
- accessors-smart 2.4.9: https://www.minidev.net/, Apache 2.0
+ accessors-smart 2.6.0: https://www.minidev.net/, Apache 2.0
aggdesigner-algorithm 6.1: Apache 2.0
audience-annotations 0.12.0: https://github.com/apache/yetus, Apache 2.0
- avatica-core 1.26.0: https://calcite.apache.org/avatica, Apache 2.0
+ avatica-core 1.28.0: https://calcite.apache.org/avatica, Apache 2.0
caffeine 2.9.3: https://github.com/ben-manes/caffeine, Apache 2.0
- calcite-core 1.40.0: https://calcite.apache.org, Apache 2.0
- calcite-linq4j 1.40.0: https://calcite.apache.org, Apache 2.0
+ calcite-core 1.42.0: https://calcite.apache.org, Apache 2.0
+ calcite-linq4j 1.42.0: https://calcite.apache.org, Apache 2.0
commons-codec 1.16.0: https://github.com/apache/commons-codec, Apache 2.0
commons-exec 1.3: https://github.com/apache/commons-exec, Apache 2.0
commons-io 2.20.0: https://github.com/apache/commons-io, Apache 2.0
@@ -247,13 +247,13 @@ The text of each license is the standard Apache 2.0 license.
grpc-stub 1.75.0: https://github.com/grpc/grpc-java, Apache 2.0
grpc-util 1.75.0: https://github.com/grpc/grpc-java, Apache 2.0
gson 2.10.1: https://github.com/google/gson, Apache 2.0
- guava 33.4.6-jre: https://github.com/google/guava, Apache 2.0
+ guava 33.4.8-jre: https://github.com/google/guava, Apache 2.0
HikariCP 4.0.3: https://github.com/brettwooldridge/HikariCP, Apache 2.0
- jackson-annotations 2.16.1: http://github.com/FasterXML/jackson, Apache 2.0
- jackson-core 2.16.1: http://github.com/FasterXML/jackson, Apache 2.0
- jackson-databind 2.16.1: http://github.com/FasterXML/jackson, Apache 2.0
- jackson-datatype-jdk8 2.16.1: http://github.com/FasterXML/jackson-modules-java8, Apache 2.0
- jackson-datatype-jsr310 2.16.1: http://github.com/FasterXML/jackson, Apache 2.0
+ jackson-annotations 2.18.6: http://github.com/FasterXML/jackson, Apache 2.0
+ jackson-core 2.18.6: http://github.com/FasterXML/jackson, Apache 2.0
+ jackson-databind 2.18.6: http://github.com/FasterXML/jackson, Apache 2.0
+ jackson-datatype-jdk8 2.18.6: http://github.com/FasterXML/jackson-modules-java8, Apache 2.0
+ jackson-datatype-jsr310 2.18.6: http://github.com/FasterXML/jackson, Apache 2.0
javassist 3.29.2-GA: https://www.javassist.org/, Apache 2.0
jcl-over-slf4j 2.0.17: https://github.com/qos-ch/slf4j, Apache 2.0
jctools-core 4.0.5: https://github.com/JCTools/JCTools, Apache 2.0
@@ -261,8 +261,9 @@ The text of each license is the standard Apache 2.0 license.
jetcd-common 0.7.7: https://github.com/etcd-io/jetcd, Apache 2.0
jetcd-core 0.7.7: https://github.com/etcd-io/jetcd, Apache 2.0
jetcd-grpc 0.7.7: https://github.com/etcd-io/jetcd, Apache 2.0
- json-path 2.9.0: https://github.com/jayway/JsonPath, Apache 2.0
- json-smart 2.4.10: https://www.minidev.net/, Apache 2.0
+ joou-java-6 0.9.5: https://github.com/jOOQ/jOOU, Apache 2.0
+ json-path 2.10.0: https://github.com/jayway/JsonPath, Apache 2.0
+ json-smart 2.6.0: https://www.minidev.net/, Apache 2.0
json-simple 1.1.1: https://code.google.com/archive/p/json-simple/, Apache 2.0
jspecify 1.0.0: https://jspecify.dev/, Apache 2.0
listenablefuture 1.0: https://github.com/google/guava, Apache 2.0
@@ -323,7 +324,7 @@ The following components are provided under a BSD license. See project link for
The text of each license is also included at licenses/LICENSE-[project].txt.
antlr4-runtime 4.13.2: https://github.com/antlr/antlr4, BSD-3-Clause
- asm 9.3: https://github.com/llbit/ow2-asm, BSD-3-Clause
+ asm 9.7.1: https://github.com/llbit/ow2-asm, BSD-3-Clause
commons-compiler 3.1.12: https://github.com/janino-compiler/janino, BSD-3-Clause
janino 3.1.12: https://github.com/janino-compiler/janino, BSD-3-Clause
opengauss-jdbc 3.1.0-og: https://gitee.com/opengauss/openGauss-connector-jdbc, BSD-2-Clause
diff --git a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/rel/converter/SQLFederationRelConverter.java b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/rel/converter/SQLFederationRelConverter.java
index bcf240cf8a4..70b1909f909 100644
--- a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/rel/converter/SQLFederationRelConverter.java
+++ b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/rel/converter/SQLFederationRelConverter.java
@@ -26,16 +26,29 @@ import org.apache.calcite.prepare.CalciteCatalogReader;
import org.apache.calcite.rel.RelRoot;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeFamily;
import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.fun.SqlBetweenOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.type.SqlTypeUtil;
import org.apache.calcite.sql.util.SqlOperatorTables;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql.validate.SqlValidatorUtil;
+import org.apache.calcite.sql2rel.SqlRexContext;
+import org.apache.calcite.sql2rel.SqlRexConvertlet;
import org.apache.calcite.sql2rel.SqlToRelConverter;
import org.apache.calcite.sql2rel.SqlToRelConverter.Config;
import org.apache.calcite.sql2rel.StandardConvertletTable;
+import org.apache.calcite.util.Util;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.sqlfederation.compiler.context.CompilerContext;
@@ -43,7 +56,9 @@ import org.apache.shardingsphere.sqlfederation.compiler.metadata.catalog.SQLFede
import org.apache.shardingsphere.sqlfederation.compiler.metadata.view.ShardingSphereViewExpander;
import org.apache.shardingsphere.sqlfederation.compiler.planner.builder.SQLFederationPlannerBuilder;
import org.apache.shardingsphere.sqlfederation.compiler.sql.type.SQLFederationDataTypeFactory;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -86,7 +101,85 @@ public final class SQLFederationRelConverter {
: (rowType, queryString, schemaPath, viewPath) -> null;
// TODO remove withRemoveSortInSubQuery when calcite can expand view which contains order by correctly
Config converterConfig = SqlToRelConverter.config().withTrimUnusedFields(true).withRemoveSortInSubQuery(false);
- return new SqlToRelConverter(expander, validator, catalogReader, cluster, StandardConvertletTable.INSTANCE, converterConfig);
+ return new SqlToRelConverter(expander, validator, catalogReader, cluster, SQLFederationRelConverter::getConvertlet, converterConfig);
+ }
+
+ private static @Nullable SqlRexConvertlet getConvertlet(final SqlCall call) {
+ if (call.getKind().belongsTo(SqlKind.ORDER_COMPARISON)) {
+ return SQLFederationRelConverter::convertOrderComparison;
+ }
+ return call.getOperator() instanceof SqlBetweenOperator ? SQLFederationRelConverter::convertBetween : StandardConvertletTable.INSTANCE.get(call);
+ }
+
+ private static RexNode convertOrderComparison(final SqlRexContext context, final SqlCall call) {
+ RexBuilder rexBuilder = context.getRexBuilder();
+ List<RexNode> operands = convertOperands(context, call);
+ return rexBuilder.makeCall(call.getParserPosition(), rexBuilder.deriveReturnType(call.getOperator(), operands), call.getOperator(), operands);
+ }
+
+ private static RexNode convertBetween(final SqlRexContext context, final SqlCall call) {
+ List<RexNode> operands = convertOperands(context, call);
+ RexNode value = operands.get(SqlBetweenOperator.VALUE_OPERAND);
+ RexNode lower = operands.get(SqlBetweenOperator.LOWER_OPERAND);
+ RexNode upper = operands.get(SqlBetweenOperator.UPPER_OPERAND);
+ RexBuilder rexBuilder = context.getRexBuilder();
+ RexNode firstRange = rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.AND,
+ rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.GREATER_THAN_OR_EQUAL, value, lower),
+ rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.LESS_THAN_OR_EQUAL, value, upper));
+ SqlBetweenOperator operator = (SqlBetweenOperator) call.getOperator();
+ RexNode result;
+ switch (operator.flag) {
+ case ASYMMETRIC:
+ result = firstRange;
+ break;
+ case SYMMETRIC:
+ RexNode secondRange = rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.AND,
+ rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.GREATER_THAN_OR_EQUAL, value, upper),
+ rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.LESS_THAN_OR_EQUAL, value, lower));
+ result = rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.OR, firstRange, secondRange);
+ break;
+ default:
+ throw Util.unexpected(operator.flag);
+ }
+ return operator.isNegated() ? rexBuilder.makeCall(call.getParserPosition(), SqlStdOperatorTable.NOT, result) : result;
+ }
+
+ private static List<RexNode> convertOperands(final SqlRexContext context, final SqlCall call) {
+ RexBuilder rexBuilder = context.getRexBuilder();
+ List<RexNode> result = new ArrayList<>(call.operandCount());
+ for (SqlNode each : call.getOperandList()) {
+ result.add(context.convertExpression(each));
+ }
+ List<RelDataType> operandTypes = context.getValidator().getValidatedOperandTypes(call);
+ if (null != operandTypes) {
+ for (int i = 0; i < result.size(); i++) {
+ result.set(i, rexBuilder.ensureType(call.getParserPosition(), operandTypes.get(i), result.get(i), true));
+ }
+ }
+ RelDataType consistentType = getConsistentType(context, RexUtil.types(result));
+ if (null != consistentType) {
+ result.replaceAll(each -> rexBuilder.ensureType(call.getParserPosition(), consistentType, each, true));
+ }
+ return result;
+ }
+
+ private static @Nullable RelDataType getConsistentType(final SqlRexContext context, final List<RelDataType> types) {
+ if (SqlTypeUtil.areSameFamily(types)) {
+ return null;
+ }
+ List<RelDataType> nonCharacterTypes = new ArrayList<>(types.size());
+ for (RelDataType each : types) {
+ if (SqlTypeFamily.CHARACTER != each.getFamily()) {
+ nonCharacterTypes.add(each);
+ }
+ }
+ if (nonCharacterTypes.size() < types.size()) {
+ RelDataTypeFamily family = nonCharacterTypes.get(0).getFamily();
+ if (SqlTypeFamily.INTEGER == family || SqlTypeFamily.NUMERIC == family) {
+ nonCharacterTypes.add(context.getTypeFactory().createSqlType(SqlTypeName.BIGINT));
+ }
+ }
+ return context.getTypeFactory().leastRestrictive(nonCharacterTypes);
}
private RelOptCluster createRelOptCluster(final RelDataTypeFactory typeFactory, final Convention convention) {
diff --git a/pom.xml b/pom.xml
index e9c2fd59148..27bccca5cfe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,11 +73,12 @@
<sonar.exclusions>**/autogen/**/*</sonar.exclusions>
<!-- 3rd party library versions -->
- <guava.version>33.4.6-jre</guava.version>
+ <guava.version>33.4.8-jre</guava.version>
<checker-qual.version>3.39.0</checker-qual.version>
<error_prone_annotations.version>2.22.0</error_prone_annotations.version>
<java-util.version>4.103.0</java-util.version>
- <calcite.version>1.40.0</calcite.version>
+ <calcite.version>1.42.0</calcite.version>
+ <joou.version>0.9.5</joou.version>
<commons-lang3.version>3.18.0</commons-lang3.version>
<commons-codec.version>1.16.0</commons-codec.version>
@@ -92,11 +93,11 @@
<antlr4.version>4.13.2</antlr4.version>
<snakeyaml.version>2.2</snakeyaml.version>
<gson.version>2.10.1</gson.version>
- <jackson.version>2.16.1</jackson.version>
- <json-path.version>2.9.0</json-path.version>
- <json-smart.version>2.4.10</json-smart.version>
- <accessors-smart.version>2.4.9</accessors-smart.version>
- <asm.version>9.3</asm.version>
+ <jackson.version>2.18.6</jackson.version>
+ <json-path.version>2.10.0</json-path.version>
+ <json-smart.version>2.6.0</json-smart.version>
+ <accessors-smart.version>2.6.0</accessors-smart.version>
+ <asm.version>9.7.1</asm.version>
<groovy.version>4.0.22</groovy.version>
<freemarker.version>2.3.31</freemarker.version>
<bytebuddy.version>1.18.8</bytebuddy.version>
@@ -421,6 +422,11 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.jooq</groupId>
+ <artifactId>joou-java-6</artifactId>
+ <version>${joou.version}</version>
+ </dependency>
<dependency>
<groupId>org.bouncycastle</groupId>