This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 4197c2df7b6 Add DistSQLQueryExecuteEngine (#29881)
4197c2df7b6 is described below
commit 4197c2df7b640c8b66b0a215f824075a765e741a
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 27 23:56:35 2024 +0800
Add DistSQLQueryExecuteEngine (#29881)
* Add protocolType on protocolType
* Remove DistSQLExecutorDatabaseProtocolTypeAware
* Add DistSQLQueryExecuteEngine
* Add DistSQLQueryExecuteEngine
---
.../DistSQLExecutorDatabaseProtocolTypeAware.java | 33 ---------
...eEngine.java => DistSQLQueryExecuteEngine.java} | 18 +++--
.../type/ral/query/QueryableRALExecuteEngine.java | 80 ----------------------
.../distsql/handler/type/rul/RULExecuteEngine.java | 75 --------------------
.../distsql/ral/QueryableRALBackendHandler.java | 4 +-
.../handler/distsql/rql/RQLBackendHandler.java | 14 +++-
.../handler/distsql/rul/RULBackendHandler.java | 4 +-
7 files changed, 28 insertions(+), 200 deletions(-)
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorDatabaseProtocolTypeAware.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorDatabaseProtocolTypeAware.java
deleted file mode 100644
index 61dcf2f2a3c..00000000000
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorDatabaseProtocolTypeAware.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.distsql.handler.aware;
-
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-
-/**
- * DistSQL executor database protocol type Aware.
- */
-public interface DistSQLExecutorDatabaseProtocolTypeAware {
-
- /**
- * Set database protocol type.
- *
- * @param protocolType database protocol type
- */
- void setDatabaseProtocolType(DatabaseType protocolType);
-}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/RQLExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLQueryExecuteEngine.java
similarity index 86%
rename from
infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/RQLExecuteEngine.java
rename to
infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLQueryExecuteEngine.java
index e2b5078be6a..26978721428 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rql/RQLExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLQueryExecuteEngine.java
@@ -15,13 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.handler.type.rql;
+package org.apache.shardingsphere.distsql.handler.type;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
-import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor;
import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException;
@@ -38,10 +38,10 @@ import java.util.Collections;
import java.util.Optional;
/**
- * RQL execute engine.
+ * DistSQL query execute engine.
*/
@RequiredArgsConstructor
-public abstract class RQLExecuteEngine {
+public abstract class DistSQLQueryExecuteEngine {
private final DistSQLStatement sqlStatement;
@@ -57,22 +57,26 @@ public abstract class RQLExecuteEngine {
/**
* Execute query.
- *
+ *
* @throws SQLException SQL exception
*/
- @SuppressWarnings({"rawtypes", "unchecked"})
+ @SuppressWarnings({"unchecked", "rawtypes"})
public void executeQuery() throws SQLException {
DistSQLQueryExecutor<DistSQLStatement> executor =
TypedSPILoader.getService(DistSQLQueryExecutor.class, sqlStatement.getClass());
columnNames = executor.getColumnNames();
if (executor instanceof DistSQLExecutorDatabaseAware) {
((DistSQLExecutorDatabaseAware)
executor).setDatabase(getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement,
currentDatabaseName)));
}
+ if (executor instanceof DistSQLExecutorConnectionContextAware) {
+ ((DistSQLExecutorConnectionContextAware)
executor).setConnectionContext(getDistSQLConnectionContext());
+ }
if (executor instanceof DistSQLExecutorRuleAware) {
setRule((DistSQLExecutorRuleAware) executor);
}
if (null == rows) {
rows = executor.getRows(sqlStatement, contextManager);
}
+ rows = executor.getRows(sqlStatement, contextManager);
}
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -98,4 +102,6 @@ public abstract class RQLExecuteEngine {
}
protected abstract ShardingSphereDatabase getDatabase(String databaseName);
+
+ protected abstract DistSQLConnectionContext getDistSQLConnectionContext();
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java
deleted file mode 100644
index 91843be0f23..00000000000
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.distsql.handler.type.ral.query;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware;
-import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
-import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
-import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor;
-import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils;
-import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-
-import java.sql.SQLException;
-import java.util.Collection;
-
-/**
- * Queryable RAL execute engine.
- */
-@RequiredArgsConstructor
-public abstract class QueryableRALExecuteEngine {
-
- private final DistSQLStatement sqlStatement;
-
- private final String currentDatabaseName;
-
- private final ContextManager contextManager;
-
- @Getter
- private Collection<String> columnNames;
-
- @Getter
- private Collection<LocalDataQueryResultRow> rows;
-
- /**
- * Execute query.
- *
- * @throws SQLException SQL exception
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public void executeQuery() throws SQLException {
- DistSQLQueryExecutor executor =
TypedSPILoader.getService(DistSQLQueryExecutor.class, sqlStatement.getClass());
- rows = getRows(executor);
- columnNames = executor.getColumnNames();
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private Collection<LocalDataQueryResultRow> getRows(final
DistSQLQueryExecutor executor) throws SQLException {
- if (executor instanceof DistSQLExecutorDatabaseAware) {
- ((DistSQLExecutorDatabaseAware)
executor).setDatabase(getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement,
currentDatabaseName)));
- }
- if (executor instanceof DistSQLExecutorConnectionContextAware) {
- ((DistSQLExecutorConnectionContextAware)
executor).setConnectionContext(getDistSQLConnectionContext());
- }
- return executor.getRows(sqlStatement, contextManager);
- }
-
- protected abstract ShardingSphereDatabase getDatabase(String databaseName);
-
- protected abstract DistSQLConnectionContext getDistSQLConnectionContext();
-}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java
deleted file mode 100644
index 2c23e5af2ff..00000000000
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.distsql.handler.type.rul;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware;
-import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
-import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
-import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor;
-import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils;
-import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-
-import java.sql.SQLException;
-import java.util.Collection;
-
-/**
- * RUL execute engine.
- */
-@RequiredArgsConstructor
-public abstract class RULExecuteEngine {
-
- private final DistSQLStatement sqlStatement;
-
- private final String currentDatabaseName;
-
- private final ContextManager contextManager;
-
- @Getter
- private Collection<String> columnNames;
-
- @Getter
- private Collection<LocalDataQueryResultRow> rows;
-
- /**
- * Execute query.
- *
- * @throws SQLException SQL exception
- */
- @SuppressWarnings("unchecked")
- public void executeQuery() throws SQLException {
- DistSQLQueryExecutor<DistSQLStatement> executor =
TypedSPILoader.getService(DistSQLQueryExecutor.class, sqlStatement.getClass());
- columnNames = executor.getColumnNames();
- if (executor instanceof DistSQLExecutorDatabaseAware) {
- ((DistSQLExecutorDatabaseAware)
executor).setDatabase(getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement,
currentDatabaseName)));
- }
- if (executor instanceof DistSQLExecutorConnectionContextAware) {
- ((DistSQLExecutorConnectionContextAware)
executor).setConnectionContext(getDistSQLConnectionContext());
- }
- rows = executor.getRows(sqlStatement, contextManager);
- }
-
- protected abstract ShardingSphereDatabase getDatabase(String databaseName);
-
- protected abstract DistSQLConnectionContext getDistSQLConnectionContext();
-}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
index a65409e0586..201462d9567 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral;
import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
-import
org.apache.shardingsphere.distsql.handler.type.ral.query.QueryableRALExecuteEngine;
+import
org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecuteEngine;
import
org.apache.shardingsphere.distsql.statement.ral.queryable.QueryableRALStatement;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
/**
* Queryable RAL backend handler.
*/
-public final class QueryableRALBackendHandler extends
QueryableRALExecuteEngine implements DistSQLBackendHandler {
+public final class QueryableRALBackendHandler extends
DistSQLQueryExecuteEngine implements DistSQLBackendHandler {
private final ConnectionSession connectionSession;
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java
index c667078fb20..1bbb3d4e8cf 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/RQLBackendHandler.java
@@ -17,7 +17,8 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
-import org.apache.shardingsphere.distsql.handler.type.rql.RQLExecuteEngine;
+import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
+import
org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecuteEngine;
import org.apache.shardingsphere.distsql.statement.rql.RQLStatement;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
@@ -42,7 +43,9 @@ import java.util.stream.Collectors;
/**
* RQL backend handler.
*/
-public final class RQLBackendHandler extends RQLExecuteEngine implements
DistSQLBackendHandler {
+public final class RQLBackendHandler extends DistSQLQueryExecuteEngine
implements DistSQLBackendHandler {
+
+ private final ConnectionSession connectionSession;
private List<QueryHeader> queryHeaders;
@@ -50,6 +53,7 @@ public final class RQLBackendHandler extends RQLExecuteEngine
implements DistSQL
public RQLBackendHandler(final RQLStatement sqlStatement, final
ConnectionSession connectionSession) {
super(sqlStatement, connectionSession.getDatabaseName(),
ProxyContext.getInstance().getContextManager());
+ this.connectionSession = connectionSession;
}
@Override
@@ -86,4 +90,10 @@ public final class RQLBackendHandler extends
RQLExecuteEngine implements DistSQL
protected ShardingSphereDatabase getDatabase(final String databaseName) {
return ProxyContext.getInstance().getDatabase(databaseName);
}
+
+ @Override
+ protected DistSQLConnectionContext getDistSQLConnectionContext() {
+ return new
DistSQLConnectionContext(connectionSession.getConnectionContext(),
connectionSession.getDatabaseConnectionManager().getConnectionSize(),
+ connectionSession.getProtocolType(),
connectionSession.getDatabaseConnectionManager(),
connectionSession.getStatementManager());
+ }
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
index 82f8d590897..d35f8e9843e 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.rul;
import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
-import org.apache.shardingsphere.distsql.handler.type.rul.RULExecuteEngine;
+import
org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecuteEngine;
import org.apache.shardingsphere.distsql.statement.rul.RULStatement;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
/**
* RUL backend handler.
*/
-public final class RULBackendHandler extends RULExecuteEngine implements
DistSQLBackendHandler {
+public final class RULBackendHandler extends DistSQLQueryExecuteEngine
implements DistSQLBackendHandler {
private final ConnectionSession connectionSession;