You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by hu...@apache.org on 2026/06/25 11:04:55 UTC
(shardingsphere) branch master updated: Minor refactor for StandardSQLFederationProcessor and SQLFederationExecutionPlan (#38921)
This is an automated email from the ASF dual-hosted git repository.
iamhucong 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 1c9e2803946 Minor refactor for StandardSQLFederationProcessor and SQLFederationExecutionPlan (#38921)
1c9e2803946 is described below
commit 1c9e2803946d56732ab0c8e574ad4b8b4c3e2ec9
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Thu Jun 25 19:04:48 2026 +0800
Minor refactor for StandardSQLFederationProcessor and SQLFederationExecutionPlan (#38921)
---
.../compiler/SQLFederationExecutionPlan.java | 21 ++++++++
.../compiler/SQLFederationExecutionPlanTest.java | 59 ++++++++++++++++++++++
.../impl/StandardSQLFederationProcessor.java | 8 ++-
.../impl/StandardSQLFederationProcessorTest.java | 19 +++----
4 files changed, 93 insertions(+), 14 deletions(-)
diff --git a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/SQLFederationExecutionPlan.java b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/SQLFederationExecutionPlan.java
index 28471d83390..a1a5c34b5c8 100644
--- a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/SQLFederationExecutionPlan.java
+++ b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/SQLFederationExecutionPlan.java
@@ -19,8 +19,15 @@ package org.apache.shardingsphere.sqlfederation.compiler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.calcite.adapter.enumerable.EnumerableInterpretable;
+import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.adapter.enumerable.EnumerableRel.Prefer;
+import org.apache.calcite.jdbc.CalcitePrepare.SparkHandler;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.runtime.Bindable;
+
+import java.util.Map;
/**
* SQL federation execution plan.
@@ -32,4 +39,18 @@ public final class SQLFederationExecutionPlan {
private final RelNode physicalPlan;
private final RelDataType resultColumnType;
+
+ /**
+ * Create bindable execution plan.
+ *
+ * @param physicalPlan physical plan
+ * @param internalParameters internal parameters
+ * @param spark spark handler
+ * @param prefer preferred Java row format
+ * @return bindable execution plan
+ */
+ @SuppressWarnings("unchecked")
+ public static synchronized Bindable<Object> toBindable(final RelNode physicalPlan, final Map<String, Object> internalParameters, final SparkHandler spark, final Prefer prefer) {
+ return EnumerableInterpretable.toBindable(internalParameters, spark, (EnumerableRel) physicalPlan, prefer);
+ }
}
diff --git a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/SQLFederationExecutionPlanTest.java b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/SQLFederationExecutionPlanTest.java
new file mode 100644
index 00000000000..34947c0d846
--- /dev/null
+++ b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/SQLFederationExecutionPlanTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sqlfederation.compiler;
+
+import org.apache.calcite.adapter.enumerable.EnumerableInterpretable;
+import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.adapter.enumerable.EnumerableRel.Prefer;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.runtime.Bindable;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+
+class SQLFederationExecutionPlanTest {
+
+ @Test
+ void assertCreateStandardExecutionPlan() {
+ RelNode physicalPlan = mock(RelNode.class);
+ RelDataType resultColumnType = mock(RelDataType.class);
+ SQLFederationExecutionPlan actual = new SQLFederationExecutionPlan(physicalPlan, resultColumnType);
+ assertThat(actual.getPhysicalPlan(), is(physicalPlan));
+ assertThat(actual.getResultColumnType(), is(resultColumnType));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void assertToBindable() {
+ EnumerableRel physicalPlan = mock(EnumerableRel.class);
+ Bindable<Object> expected = mock(Bindable.class);
+ Map<String, Object> internalParameters = Collections.emptyMap();
+ try (MockedStatic<EnumerableInterpretable> mockedInterpretable = mockStatic(EnumerableInterpretable.class)) {
+ mockedInterpretable.when(() -> EnumerableInterpretable.toBindable(internalParameters, null, physicalPlan, Prefer.ARRAY)).thenReturn(expected);
+ assertThat(SQLFederationExecutionPlan.toBindable(physicalPlan, internalParameters, null, Prefer.ARRAY), is(expected));
+ }
+ }
+}
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java
index 22d2c216308..039d6b08cfe 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java
@@ -19,8 +19,6 @@ package org.apache.shardingsphere.sqlfederation.engine.processor.impl;
import lombok.RequiredArgsConstructor;
import org.apache.calcite.adapter.enumerable.EnumerableConvention;
-import org.apache.calcite.adapter.enumerable.EnumerableInterpretable;
-import org.apache.calcite.adapter.enumerable.EnumerableRel;
import org.apache.calcite.adapter.enumerable.EnumerableRel.Prefer;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.calcite.plan.Convention;
@@ -127,11 +125,11 @@ public final class StandardSQLFederationProcessor implements SQLFederationProces
}
}
- @SuppressWarnings("unchecked")
@Override
public ResultSet executePlan(final DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine, final JDBCExecutorCallback<? extends ExecuteResult> queryCallback,
- final SQLFederationExecutionPlan executionPlan, final SQLFederationRelConverter converter, final SQLFederationContext federationContext, final SchemaPlus schemaPlus) {
- Bindable<Object> executablePlan = EnumerableInterpretable.toBindable(Collections.emptyMap(), null, (EnumerableRel) executionPlan.getPhysicalPlan(), Prefer.ARRAY);
+ final SQLFederationExecutionPlan executionPlan, final SQLFederationRelConverter converter,
+ final SQLFederationContext federationContext, final SchemaPlus schemaPlus) {
+ Bindable<Object> executablePlan = SQLFederationExecutionPlan.toBindable(executionPlan.getPhysicalPlan(), Collections.emptyMap(), null, Prefer.ARRAY);
Map<String, Object> params = createParameters(federationContext.getQueryContext().getParameters());
Enumerator<Object> enumerator = executablePlan.bind(new ExecutorBindContext(converter, params)).enumerator();
SelectStatementContext selectStatementContext = (SelectStatementContext) federationContext.getQueryContext().getSqlStatementContext();
diff --git a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessorTest.java b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessorTest.java
index d7b4afd9854..034b6b5ca7b 100644
--- a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessorTest.java
+++ b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessorTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.sqlfederation.engine.processor.impl;
import org.apache.calcite.adapter.enumerable.EnumerableConvention;
-import org.apache.calcite.adapter.enumerable.EnumerableInterpretable;
import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.adapter.enumerable.EnumerableRel.Prefer;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.calcite.runtime.Bindable;
@@ -61,11 +61,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
-import java.util.Map;
import java.util.Optional;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
@@ -211,7 +210,8 @@ class StandardSQLFederationProcessorTest {
processor.prepare(prepareEngine, callback, databaseName, schemaName, federationContext, compilerContext, rootSchema);
}
SQLFederationExecutionPlan executionPlan = mock(SQLFederationExecutionPlan.class);
- when(executionPlan.getPhysicalPlan()).thenReturn(mock(EnumerableRel.class));
+ EnumerableRel physicalPlan = mock(EnumerableRel.class);
+ when(executionPlan.getPhysicalPlan()).thenReturn(physicalPlan);
when(executionPlan.getResultColumnType()).thenReturn(mock(org.apache.calcite.rel.type.RelDataType.class));
SQLFederationRelConverter converter = mock(SQLFederationRelConverter.class);
Bindable<Object> bindable = mock(Bindable.class);
@@ -220,9 +220,9 @@ class StandardSQLFederationProcessorTest {
when(enumerable.enumerator()).thenReturn(enumerator);
when(bindable.bind(any())).thenReturn(enumerable);
try (
- MockedStatic<EnumerableInterpretable> ignoredInterpretable = mockStatic(EnumerableInterpretable.class);
+ MockedStatic<SQLFederationExecutionPlan> mockedExecutionPlan = mockStatic(SQLFederationExecutionPlan.class);
MockedStatic<DatabaseTypedSPILoader> mockedSpiLoader = mockStatic(DatabaseTypedSPILoader.class)) {
- ignoredInterpretable.when(() -> EnumerableInterpretable.toBindable(any(Map.class), any(), any(), any())).thenReturn(bindable);
+ mockedExecutionPlan.when(() -> SQLFederationExecutionPlan.toBindable(physicalPlan, Collections.emptyMap(), null, Prefer.ARRAY)).thenReturn(bindable);
mockedSpiLoader.when(() -> DatabaseTypedSPILoader
.getService(eq(DialectSQLFederationColumnTypeConverter.class), any(DatabaseType.class))).thenReturn(mock(DialectSQLFederationColumnTypeConverter.class));
ResultSet result = processor.executePlan(prepareEngine, callback, executionPlan, converter, federationContext, rootSchema);
@@ -251,7 +251,8 @@ class StandardSQLFederationProcessorTest {
processor.prepare(prepareEngine, callback, databaseName, schemaName, federationContext, compilerContext, rootSchema);
}
SQLFederationExecutionPlan executionPlan = mock(SQLFederationExecutionPlan.class);
- when(executionPlan.getPhysicalPlan()).thenReturn(mock(EnumerableRel.class));
+ EnumerableRel physicalPlan = mock(EnumerableRel.class);
+ when(executionPlan.getPhysicalPlan()).thenReturn(physicalPlan);
when(executionPlan.getResultColumnType()).thenReturn(mock(org.apache.calcite.rel.type.RelDataType.class));
SQLFederationRelConverter converter = mock(SQLFederationRelConverter.class);
Bindable<Object> bindable = mock(Bindable.class);
@@ -260,9 +261,9 @@ class StandardSQLFederationProcessorTest {
when(enumerable.enumerator()).thenReturn(enumerator);
when(bindable.bind(any())).thenReturn(enumerable);
try (
- MockedStatic<EnumerableInterpretable> ignoredInterpretable = mockStatic(EnumerableInterpretable.class);
+ MockedStatic<SQLFederationExecutionPlan> mockedExecutionPlan = mockStatic(SQLFederationExecutionPlan.class);
MockedStatic<DatabaseTypedSPILoader> mockedSpiLoader = mockStatic(DatabaseTypedSPILoader.class)) {
- ignoredInterpretable.when(() -> EnumerableInterpretable.toBindable(any(Map.class), any(), any(), any())).thenReturn(bindable);
+ mockedExecutionPlan.when(() -> SQLFederationExecutionPlan.toBindable(physicalPlan, Collections.emptyMap(), null, Prefer.ARRAY)).thenReturn(bindable);
mockedSpiLoader.when(() -> DatabaseTypedSPILoader
.getService(eq(DialectSQLFederationColumnTypeConverter.class), any(DatabaseType.class))).thenReturn(mock(DialectSQLFederationColumnTypeConverter.class));
ResultSet previewResult = processor.executePlan(prepareEngine, callback, executionPlan, converter, federationContext, rootSchema);