You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/06/11 13:34:08 UTC
[shardingsphere] branch master updated: Add LocalDataQueryResultRow (#18303)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 f2a4a68e030 Add LocalDataQueryResultRow (#18303)
f2a4a68e030 is described below
commit f2a4a68e030adc2ddd01617ecdde718895b47e34
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Jun 11 21:34:02 2022 +0800
Add LocalDataQueryResultRow (#18303)
---
.../merge/dal/ShardingDALResultMerger.java | 5 ++-
.../result/impl/local/LocalDataMergedResult.java | 11 +++--
.../result/impl/local/LocalDataQueryResultRow.java | 48 ++++++++++++++++++++++
.../impl/local/LocalDataMergedResultTest.java | 10 ++---
.../mysql/executor/ShowConnectionIdExecutor.java | 5 ++-
.../executor/ShowCurrentDatabaseExecutor.java | 5 ++-
.../mysql/executor/ShowCurrentUserExecutor.java | 3 +-
.../mysql/executor/ShowDatabasesExecutor.java | 16 +++-----
.../mysql/executor/ShowTransactionExecutor.java | 5 ++-
.../admin/mysql/executor/ShowVersionExecutor.java | 5 ++-
.../distsql/ral/QueryableRALBackendHandler.java | 5 ++-
.../distsql/ral/advanced/FormatSQLHandler.java | 6 +--
.../distsql/ral/advanced/ParseDistSQLHandler.java | 6 +--
.../text/distsql/ral/advanced/PreviewHandler.java | 8 ++--
.../ShowReadwriteSplittingHintStatusExecutor.java | 13 ++----
.../executor/ShowShardingHintStatusExecutor.java | 21 ++++------
.../queryable/CountInstanceRulesHandler.java | 9 +++-
.../ExportDatabaseConfigurationHandler.java | 8 ++--
.../common/queryable/ShowAuthorityRuleHandler.java | 14 +++----
.../ral/common/queryable/ShowInstanceHandler.java | 27 ++++--------
.../common/queryable/ShowInstanceModeHandler.java | 6 +--
...ShowReadwriteSplittingReadResourcesHandler.java | 19 ++++-----
.../common/queryable/ShowSQLParserRuleHandler.java | 14 +++----
.../common/queryable/ShowTableMetadataHandler.java | 18 ++++----
.../common/queryable/ShowTrafficRulesHandler.java | 21 ++++------
.../queryable/ShowTransactionRuleHandler.java | 13 +++---
.../ral/common/queryable/ShowVariableHandler.java | 22 +++++-----
.../DatabaseAdminQueryBackendHandlerTest.java | 6 +--
28 files changed, 183 insertions(+), 166 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
index 00fab483de1..b65533650ff 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
@@ -23,10 +23,11 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.engine.merger.ResultMerger;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import org.apache.shardingsphere.sharding.merge.dal.show.LogicTablesMergedResult;
import org.apache.shardingsphere.sharding.merge.dal.show.ShowCreateTableMergedResult;
import org.apache.shardingsphere.sharding.merge.dal.show.ShowIndexMergedResult;
@@ -58,7 +59,7 @@ public final class ShardingDALResultMerger implements ResultMerger {
SQLStatement dalStatement = sqlStatementContext.getSqlStatement();
String schemaName = sqlStatementContext.getTablesContext().getSchemaName().orElse(DatabaseTypeEngine.getDefaultSchemaName(sqlStatementContext.getDatabaseType(), database.getName()));
if (dalStatement instanceof MySQLShowDatabasesStatement) {
- return new LocalDataMergedResult(Collections.singleton(Collections.singletonList(databaseName)));
+ return new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow(databaseName)));
}
ShardingSphereSchema schema = database.getSchemas().get(schemaName);
if (dalStatement instanceof MySQLShowTablesStatement) {
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResult.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResult.java
index cc65acc56ab..220bfc6bc63 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResult.java
@@ -25,18 +25,17 @@ import java.sql.SQLFeatureNotSupportedException;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
/**
* Local data merged result.
*/
public final class LocalDataMergedResult implements MergedResult {
- private final Iterator<List<Object>> rows;
+ private final Iterator<LocalDataQueryResultRow> rows;
- private List<Object> currentRow;
+ private LocalDataQueryResultRow currentRow;
- public LocalDataMergedResult(final Collection<List<Object>> rows) {
+ public LocalDataMergedResult(final Collection<LocalDataQueryResultRow> rows) {
this.rows = rows.iterator();
}
@@ -51,12 +50,12 @@ public final class LocalDataMergedResult implements MergedResult {
@Override
public Object getValue(final int columnIndex, final Class<?> type) {
- return currentRow.get(columnIndex - 1);
+ return currentRow.getCell(columnIndex);
}
@Override
public Object getCalendarValue(final int columnIndex, final Class<?> type, final Calendar calendar) {
- return currentRow.get(columnIndex - 1);
+ return currentRow.getCell(columnIndex);
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataQueryResultRow.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataQueryResultRow.java
new file mode 100644
index 00000000000..b2a71fe1772
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataQueryResultRow.java
@@ -0,0 +1,48 @@
+/*
+ * 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.infra.merge.result.impl.local;
+
+import com.google.common.base.Preconditions;
+import lombok.RequiredArgsConstructor;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Local data query result row.
+ */
+@RequiredArgsConstructor
+public final class LocalDataQueryResultRow {
+
+ private final List<Object> data;
+
+ public LocalDataQueryResultRow(final Object... data) {
+ this.data = Arrays.asList(data);
+ }
+
+ /**
+ * Get data from cell.
+ *
+ * @param columnIndex column index
+ * @return data from cell
+ */
+ public Object getCell(final int columnIndex) {
+ Preconditions.checkArgument(columnIndex > 0 && columnIndex < data.size() + 1);
+ return data.get(columnIndex - 1);
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
index f749c11f60b..85056feb0b9 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
@@ -35,7 +35,7 @@ public final class LocalDataMergedResultTest {
@Test
public void assertNext() {
- List<Object> row = Collections.singletonList("value");
+ LocalDataQueryResultRow row = new LocalDataQueryResultRow("value");
LocalDataMergedResult actual = new LocalDataMergedResult(Collections.singletonList(row));
assertTrue(actual.next());
assertFalse(actual.next());
@@ -43,7 +43,7 @@ public final class LocalDataMergedResultTest {
@Test
public void assertGetValue() {
- List<Object> row = Collections.singletonList("value");
+ LocalDataQueryResultRow row = new LocalDataQueryResultRow("value");
LocalDataMergedResult actual = new LocalDataMergedResult(Collections.singletonList(row));
assertTrue(actual.next());
assertThat(actual.getValue(1, Object.class).toString(), is("value"));
@@ -51,7 +51,7 @@ public final class LocalDataMergedResultTest {
@Test
public void assertGetCalendarValue() {
- List<Object> row = Collections.singletonList(new Date(0L));
+ LocalDataQueryResultRow row = new LocalDataQueryResultRow(new Date(0L));
LocalDataMergedResult actual = new LocalDataMergedResult(Collections.singletonList(row));
assertTrue(actual.next());
assertThat(actual.getCalendarValue(1, Object.class, Calendar.getInstance()), is(new Date(0L)));
@@ -60,14 +60,14 @@ public final class LocalDataMergedResultTest {
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertGetInputStream() throws SQLException {
List<Object> row = Collections.singletonList("value");
- LocalDataMergedResult actual = new LocalDataMergedResult(Collections.singletonList(row));
+ LocalDataMergedResult actual = new LocalDataMergedResult(Collections.singletonList(new LocalDataQueryResultRow(row)));
actual.getInputStream(1, "Ascii");
}
@Test
public void assertWasNull() {
List<Object> row = Collections.singletonList("value");
- LocalDataMergedResult actual = new LocalDataMergedResult(Collections.singletonList(row));
+ LocalDataMergedResult actual = new LocalDataMergedResult(Collections.singletonList(new LocalDataQueryResultRow(row)));
assertTrue(actual.next());
assertFalse(actual.wasNull());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowConnectionIdExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowConnectionIdExecutor.java
index 891beff5cfe..486e1c5820f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowConnectionIdExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowConnectionIdExecutor.java
@@ -22,9 +22,10 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminQueryExecutor;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import java.sql.Types;
import java.util.Collections;
@@ -41,7 +42,7 @@ public final class ShowConnectionIdExecutor implements DatabaseAdminQueryExecuto
@Override
public void execute(final ConnectionSession connectionSession) {
- mergedResult = new LocalDataMergedResult(Collections.singleton(Collections.singletonList(connectionSession.getConnectionId())));
+ mergedResult = new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow(connectionSession.getConnectionId())));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java
index 7d3c25cdb4c..834ba989d44 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java
@@ -22,9 +22,10 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminQueryExecutor;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import java.sql.Types;
import java.util.Collections;
@@ -41,7 +42,7 @@ public final class ShowCurrentDatabaseExecutor implements DatabaseAdminQueryExec
@Override
public void execute(final ConnectionSession connectionSession) {
- mergedResult = new LocalDataMergedResult(Collections.singleton(Collections.singletonList(connectionSession.getDatabaseName())));
+ mergedResult = new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow(connectionSession.getDatabaseName())));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentUserExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentUserExecutor.java
index 9a31253312f..8097b1b6dd5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentUserExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentUserExecutor.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -54,7 +55,7 @@ public final class ShowCurrentUserExecutor implements DatabaseAdminQueryExecutor
Optional<Grantee> grantee = rules.stream().filter(each -> each instanceof AuthorityRule)
.map(each -> ((AuthorityRule) each).findUser(connectionSession.getGrantee())).filter(Optional::isPresent)
.map(Optional::get).map(ShardingSphereUser::getGrantee).findFirst();
- mergedResult = new LocalDataMergedResult(Collections.singleton(Collections.singletonList(grantee.isPresent() ? grantee.get().toString() : "")));
+ mergedResult = new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow(grantee.isPresent() ? grantee.get().toString() : "")));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java
index cf9199515aa..176c7cdc657 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java
@@ -24,11 +24,12 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminQueryExecutor;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
@@ -36,8 +37,8 @@ import java.sql.Types;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
-import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Show databases executor.
@@ -55,14 +56,9 @@ public final class ShowDatabasesExecutor implements DatabaseAdminQueryExecutor {
mergedResult = new LocalDataMergedResult(getDatabaseNames(connectionSession));
}
- private Collection<List<Object>> getDatabaseNames(final ConnectionSession connectionSession) {
- List<List<Object>> result = new LinkedList<>();
- for (String each : ProxyContext.getInstance().getAllDatabaseNames()) {
- if (checkLikePattern(each) && SQLCheckEngine.check(each, getRules(each), connectionSession.getGrantee())) {
- result.add(Collections.singletonList(each));
- }
- }
- return result;
+ private Collection<LocalDataQueryResultRow> getDatabaseNames(final ConnectionSession connectionSession) {
+ return ProxyContext.getInstance().getAllDatabaseNames().stream()
+ .filter(each -> checkLikePattern(each) && SQLCheckEngine.check(each, getRules(each), connectionSession.getGrantee())).map(LocalDataQueryResultRow::new).collect(Collectors.toList());
}
private boolean checkLikePattern(final String databaseName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTransactionExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTransactionExecutor.java
index 2d2c40f8bde..1db57f2d55e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTransactionExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTransactionExecutor.java
@@ -23,9 +23,10 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminQueryExecutor;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import java.sql.Types;
import java.util.Collections;
@@ -48,7 +49,7 @@ public final class ShowTransactionExecutor implements DatabaseAdminQueryExecutor
@Override
public void execute(final ConnectionSession connectionSession) {
String row = functionName.equals(TRANSACTION_ISOLATION) ? "REPEATABLE-READ" : "0";
- mergedResult = new LocalDataMergedResult(Collections.singleton(Collections.singletonList(row)));
+ mergedResult = new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow(row)));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java
index d4822ee44ee..75b56387a92 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java
@@ -23,9 +23,10 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminQueryExecutor;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import java.sql.Types;
import java.util.Collections;
@@ -42,7 +43,7 @@ public final class ShowVersionExecutor implements DatabaseAdminQueryExecutor {
@Override
public void execute(final ConnectionSession connectionSession) {
- mergedResult = new LocalDataMergedResult(Collections.singleton(Collections.singletonList(MySQLServerInfo.getServerVersion(connectionSession.getDatabaseName()))));
+ mergedResult = new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow(MySQLServerInfo.getServerVersion(connectionSession.getDatabaseName()))));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/QueryableRALBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/QueryableRALBackendHandler.java
index 456db00ac1f..f613b54a7eb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/QueryableRALBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/QueryableRALBackendHandler.java
@@ -19,6 +19,8 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral;
import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
@@ -27,7 +29,6 @@ import org.apache.shardingsphere.proxy.backend.response.data.impl.TextQueryRespo
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import java.sql.SQLException;
import java.sql.Types;
@@ -78,5 +79,5 @@ public abstract class QueryableRALBackendHandler<E extends RALStatement> extends
protected abstract Collection<String> getColumnNames();
- protected abstract Collection<List<Object>> getRows(ContextManager contextManager) throws SQLException;
+ protected abstract Collection<LocalDataQueryResultRow> getRows(ContextManager contextManager) throws SQLException;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/FormatSQLHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/FormatSQLHandler.java
index 790a2cc8f1a..6b732cbf1eb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/FormatSQLHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/FormatSQLHandler.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.ral.advanced;
import org.apache.shardingsphere.distsql.parser.statement.ral.advanced.FormatStatement;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
@@ -29,7 +30,6 @@ import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Properties;
/**
@@ -45,10 +45,10 @@ public final class FormatSQLHandler extends QueryableRALBackendHandler<FormatSta
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) throws SQLException {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) throws SQLException {
String sql = getSqlStatement().getSql();
String databaseType = getConnectionSession().getDatabaseType().getType();
- return Collections.singleton(Collections.singletonList(formatSQL(sql, databaseType)));
+ return Collections.singleton(new LocalDataQueryResultRow(formatSQL(sql, databaseType)));
}
private Object formatSQL(final String sql, final String databaseType) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLHandler.java
index 325c384b177..3341f2618e5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLHandler.java
@@ -22,6 +22,7 @@ import com.google.common.base.Strings;
import com.google.gson.Gson;
import org.apache.shardingsphere.distsql.parser.statement.ral.advanced.ParseStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -32,7 +33,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Optional;
/**
@@ -50,9 +50,9 @@ public final class ParseDistSQLHandler extends QueryableRALBackendHandler<ParseS
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
SQLStatement parsedSqlStatement = parseSQL(contextManager);
- return Collections.singleton(Arrays.asList(parsedSqlStatement.getClass().getSimpleName(), new Gson().toJson(parsedSqlStatement)));
+ return Collections.singleton(new LocalDataQueryResultRow(parsedSqlStatement.getClass().getSimpleName(), new Gson().toJson(parsedSqlStatement)));
}
private SQLStatement parseSQL(final ContextManager contextManager) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java
index b6b853f2b5d..ae43bc80c16 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java
@@ -47,6 +47,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.Statemen
import org.apache.shardingsphere.infra.federation.executor.FederationContext;
import org.apache.shardingsphere.infra.federation.executor.FederationExecutor;
import org.apache.shardingsphere.infra.federation.executor.FederationExecutorFactory;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -68,7 +69,6 @@ import java.sql.Statement;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -89,7 +89,7 @@ public final class PreviewHandler extends QueryableRALBackendHandler<PreviewStat
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) throws SQLException {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) throws SQLException {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
String databaseName = getDatabaseName();
String databaseType = DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getMetaData().getDatabases().get(databaseName).getProtocolType());
@@ -123,8 +123,8 @@ public final class PreviewHandler extends QueryableRALBackendHandler<PreviewStat
((CursorDefinitionAware) sqlStatementContext).setUpCursorDefinition(cursorStatementContext);
}
- private List<Object> buildRow(final ExecutionUnit unit) {
- return Arrays.asList(unit.getDataSourceName(), unit.getSqlUnit().getSql());
+ private LocalDataQueryResultRow buildRow(final ExecutionUnit unit) {
+ return new LocalDataQueryResultRow(unit.getDataSourceName(), unit.getSqlUnit().getSql());
}
private Collection<ExecutionUnit> getFederationExecutionUnits(final LogicSQL logicSQL, final String databaseName, final MetaDataContexts metaDataContexts) throws SQLException {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowReadwriteSplittingHintStatusExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowReadwriteSplittingHintStatusExecutor.java
index 7c28801762f..cdaafebe3a5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowReadwriteSplittingHintStatusExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowReadwriteSplittingHintStatusExecutor.java
@@ -20,10 +20,11 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.exe
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.HintSourceType;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.hint.ShowReadwriteSplittingHintStatusStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import java.sql.Types;
import java.util.ArrayList;
@@ -45,13 +46,7 @@ public final class ShowReadwriteSplittingHintStatusExecutor extends AbstractHint
@Override
protected MergedResult createMergedResult() {
- List<Object> row = createRow(HintManager.isWriteRouteOnly() ? HintSourceType.WRITE.getValue() : HintSourceType.AUTO.getValue());
- return new LocalDataMergedResult(Collections.singletonList(row));
- }
-
- private List<Object> createRow(final String source) {
- List<Object> result = new ArrayList<>(1);
- result.add(source);
- return result;
+ LocalDataQueryResultRow row = new LocalDataQueryResultRow(HintManager.isWriteRouteOnly() ? HintSourceType.WRITE.getValue() : HintSourceType.AUTO.getValue());
+ return new LocalDataMergedResult(Collections.singleton(row));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java
index ceda985cbc6..9863d7ab996 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java
@@ -21,6 +21,8 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.RuleNotExistedException;
@@ -29,7 +31,6 @@ import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.HintShardingType;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.result.ShowShardingHintStatusResult;
import org.apache.shardingsphere.sharding.distsql.parser.statement.hint.ShowShardingHintStatusStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import java.sql.Types;
import java.util.ArrayList;
@@ -38,6 +39,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* Show sharding hint status executor.
@@ -90,19 +92,12 @@ public final class ShowShardingHintStatusExecutor extends AbstractHintQueryExecu
}
private MergedResult convertToMergedResult(final Collection<ShowShardingHintStatusResult> showShardingHintStatusResults) {
- Collection<List<Object>> values = new ArrayList<>(showShardingHintStatusResults.size());
- for (ShowShardingHintStatusResult each : showShardingHintStatusResults) {
- values.add(createRow(each));
- }
- return new LocalDataMergedResult(values);
+ return new LocalDataMergedResult(showShardingHintStatusResults.stream().map(this::createRow).collect(Collectors.toList()));
}
- private List<Object> createRow(final ShowShardingHintStatusResult showShardingHintStatusResult) {
- List<Object> result = new ArrayList<>(3);
- result.add(showShardingHintStatusResult.getLogicTable());
- result.add(String.join(",", showShardingHintStatusResult.getDatabaseShardingValues()));
- result.add(String.join(",", showShardingHintStatusResult.getTableShardingValues()));
- result.add(String.valueOf(HintManager.isDatabaseShardingOnly() ? HintShardingType.DATABASES_ONLY : HintShardingType.DATABASES_TABLES).toLowerCase());
- return result;
+ private LocalDataQueryResultRow createRow(final ShowShardingHintStatusResult showShardingHintStatusResult) {
+ return new LocalDataQueryResultRow(showShardingHintStatusResult.getLogicTable(),
+ String.join(",", showShardingHintStatusResult.getDatabaseShardingValues()), String.join(",", showShardingHintStatusResult.getTableShardingValues()),
+ String.valueOf(HintManager.isDatabaseShardingOnly() ? HintShardingType.DATABASES_ONLY : HintShardingType.DATABASES_TABLES).toLowerCase());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java
index 18f0254f554..c7ca0df6e73 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.C
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -73,10 +74,14 @@ public final class CountInstanceRulesHandler extends QueryableRALBackendHandler<
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) throws SQLException {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) throws SQLException {
Map<String, List<Object>> dataMap = new LinkedHashMap<>();
ProxyContext.getInstance().getAllDatabaseNames().forEach(each -> addSchemaData(dataMap, ProxyContext.getInstance().getDatabase(each)));
- return dataMap.values();
+ Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+ for (List<Object> each : dataMap.values()) {
+ result.add(new LocalDataQueryResultRow(each));
+ }
+ return result;
}
private void addSchemaData(final Map<String, List<Object>> dataMap, final ShardingSphereDatabase database) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java
index 5b682cf00f6..451661a95b6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
import org.apache.shardingsphere.infra.exception.DatabaseNotExistedException;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -48,7 +49,6 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -103,7 +103,7 @@ public final class ExportDatabaseConfigurationHandler extends QueryableRALBacken
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
String databaseName = getDatabaseName();
ShardingSphereDatabase database = ProxyContext.getInstance().getDatabase(databaseName);
StringBuilder result = new StringBuilder();
@@ -111,7 +111,7 @@ public final class ExportDatabaseConfigurationHandler extends QueryableRALBacken
getDataSourcesConfig(database, result);
getRuleConfigurations(database.getRuleMetaData().getConfigurations(), result);
if (!getSqlStatement().getFilePath().isPresent()) {
- return Collections.singleton(Collections.singletonList(result.toString()));
+ return Collections.singleton(new LocalDataQueryResultRow(result.toString()));
}
File outFile = new File(getSqlStatement().getFilePath().get());
if (!outFile.exists()) {
@@ -123,7 +123,7 @@ public final class ExportDatabaseConfigurationHandler extends QueryableRALBacken
} catch (final IOException ex) {
throw new ShardingSphereException(ex);
}
- return Collections.singleton(Collections.singletonList(String.format("Successfully exported to:'%s'", getSqlStatement().getFilePath().get())));
+ return Collections.singleton(new LocalDataQueryResultRow(String.format("Successfully exported to:'%s'", getSqlStatement().getFilePath().get())));
}
private void getDataSourcesConfig(final ShardingSphereDatabase database, final StringBuilder result) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowAuthorityRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowAuthorityRuleHandler.java
index ad52431b494..82e16b5e847 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowAuthorityRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowAuthorityRuleHandler.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.queryabl
import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowAuthorityRuleStatement;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
@@ -26,8 +27,6 @@ import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBack
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -48,17 +47,14 @@ public final class ShowAuthorityRuleHandler extends QueryableRALBackendHandler<S
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
Optional<AuthorityRuleConfiguration> authorityRuleConfig = ProxyContext.getInstance().getContextManager()
.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().findRuleConfigurations(AuthorityRuleConfiguration.class).stream().findFirst();
return authorityRuleConfig.isPresent() ? Collections.singleton(getRow(authorityRuleConfig.get())) : Collections.emptyList();
}
- private List<Object> getRow(final AuthorityRuleConfiguration authorityRuleConfig) {
- List<Object> result = new LinkedList<>();
- result.add(authorityRuleConfig.getUsers().stream().map(each -> each.getGrantee().toString()).collect(Collectors.joining("; ")));
- result.add(authorityRuleConfig.getProvider().getType());
- result.add(authorityRuleConfig.getProvider().getProps().size() == 0 ? "" : authorityRuleConfig.getProvider().getProps());
- return result;
+ private LocalDataQueryResultRow getRow(final AuthorityRuleConfiguration authorityRuleConfig) {
+ return new LocalDataQueryResultRow(authorityRuleConfig.getUsers().stream().map(each -> each.getGrantee().toString()).collect(Collectors.joining("; ")),
+ authorityRuleConfig.getProvider().getType(), authorityRuleConfig.getProvider().getProps().size() == 0 ? "" : authorityRuleConfig.getProvider().getProps());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java
index fb81f9a6c60..f63e1376677 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java
@@ -20,16 +20,14 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.queryabl
import com.google.common.base.Joiner;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowInstanceStatement;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -58,29 +56,20 @@ public final class ShowInstanceHandler extends QueryableRALBackendHandler<ShowIn
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
- return buildInstanceRows(contextManager);
- }
-
- private Collection<List<Object>> buildInstanceRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
String modeType = contextManager.getInstanceContext().getModeConfiguration().getType();
if ("Memory".equalsIgnoreCase(modeType) || "Standalone".equalsIgnoreCase(modeType)) {
return Collections.singletonList(buildRow(contextManager.getInstanceContext().getInstance(), modeType));
}
Collection<ComputeNodeInstance> instances = contextManager.getInstanceContext().getComputeNodeInstances().stream()
.filter(each -> InstanceType.PROXY.equals(each.getInstanceDefinition().getInstanceType())).collect(Collectors.toList());
- return instances.isEmpty() ? Collections.emptyList()
- : instances.stream().filter(Objects::nonNull).map(each -> buildRow(each, modeType)).collect(Collectors.toList());
- }
-
- private List<Object> buildRow(final ComputeNodeInstance instance, final String modeType) {
- return buildRow(instance.getInstanceDefinition(), instance.getState().getCurrentState().name(), modeType, instance.getLabels(), Joiner.on(",").join(instance.getXaRecoveryIds()));
+ return instances.isEmpty() ? Collections.emptyList() : instances.stream().filter(Objects::nonNull).map(each -> buildRow(each, modeType)).collect(Collectors.toList());
}
- private List<Object> buildRow(final InstanceDefinition instanceDefinition, final String status, final String modeType, final Collection<String> instanceLabels, final String xaRecoveryId) {
- String host = instanceDefinition.getIp();
- String port = instanceDefinition.getUniqueSign();
- String labels = null == instanceLabels ? "" : String.join(",", instanceLabels);
- return new LinkedList<>(Arrays.asList(instanceDefinition.getInstanceId(), host, port, status, modeType, labels, null == xaRecoveryId ? "" : xaRecoveryId));
+ private LocalDataQueryResultRow buildRow(final ComputeNodeInstance instance, final String modeType) {
+ String labels = null == instance.getLabels() ? "" : String.join(",", instance.getLabels());
+ String xaRecoveryIds = Joiner.on(",").join(instance.getXaRecoveryIds());
+ return new LocalDataQueryResultRow(instance.getInstanceDefinition().getInstanceId(),
+ instance.getInstanceDefinition().getIp(), instance.getInstanceDefinition().getUniqueSign(), instance.getState().getCurrentState().name(), modeType, labels, xaRecoveryIds);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceModeHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceModeHandler.java
index 5aa1a07a0bf..a70c9669a71 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceModeHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceModeHandler.java
@@ -21,6 +21,7 @@ import com.google.gson.Gson;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowInstanceModeStatement;
import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
@@ -28,7 +29,6 @@ import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBack
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
/**
* Show instance mode handler.
@@ -51,7 +51,7 @@ public final class ShowInstanceModeHandler extends QueryableRALBackendHandler<Sh
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
InstanceContext instanceContext = ProxyContext.getInstance().getContextManager().getInstanceContext();
PersistRepositoryConfiguration repositoryConfig = instanceContext.getModeConfiguration().getRepository();
String instanceId = instanceContext.getInstance().getInstanceDefinition().getInstanceId();
@@ -59,6 +59,6 @@ public final class ShowInstanceModeHandler extends QueryableRALBackendHandler<Sh
String repositoryType = null == repositoryConfig ? "" : repositoryConfig.getType();
String props = null == repositoryConfig || null == repositoryConfig.getProps() ? "" : new Gson().toJson(repositoryConfig.getProps());
String overwrite = String.valueOf(instanceContext.getModeConfiguration().isOverwrite());
- return Collections.singleton(Arrays.asList(instanceId, modeType, repositoryType, props, overwrite));
+ return Collections.singleton(new LocalDataQueryResultRow(instanceId, modeType, repositoryType, props, overwrite));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
index 700635dea7f..e2c89e73a3e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
import org.apache.shardingsphere.infra.distsql.constant.ExportableItemConstants;
import org.apache.shardingsphere.infra.exception.DatabaseNotExistedException;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule;
@@ -43,7 +44,6 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
@@ -65,7 +65,7 @@ public final class ShowReadwriteSplittingReadResourcesHandler extends QueryableR
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
String databaseName = getDatabaseName();
MetaDataContexts metaDataContexts = contextManager.getMetaDataContexts();
ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabases().get(databaseName);
@@ -110,7 +110,7 @@ public final class ShowReadwriteSplittingReadResourcesHandler extends QueryableR
return result;
}
- private Collection<List<Object>> buildRows(final Collection<String> readResources, final Map<String, StorageNodeDataSource> persistentReadResources) {
+ private Collection<LocalDataQueryResultRow> buildRows(final Collection<String> readResources, final Map<String, StorageNodeDataSource> persistentReadResources) {
Map<String, Map<String, StorageNodeDataSource>> persistentReadResourceGroup = persistentReadResources.entrySet().stream()
.collect(Collectors.groupingBy(each -> each.getValue().getStatus().toUpperCase(), Collectors.toMap(Entry::getKey, Entry::getValue)));
Map<String, StorageNodeDataSource> disabledReadResources = persistentReadResourceGroup.getOrDefault(StorageNodeStatus.DISABLED.name(), Collections.emptyMap());
@@ -118,20 +118,19 @@ public final class ShowReadwriteSplittingReadResourcesHandler extends QueryableR
readResources.removeIf(disabledReadResources::containsKey);
readResources.addAll(enabledReadResources.keySet());
readResources.addAll(disabledReadResources.keySet());
- return readResources.stream().map(each -> buildRow(each, disabledReadResources.get(each))).collect(Collectors.toCollection(LinkedList::new));
+ return readResources.stream().map(each -> buildRow(each, disabledReadResources.get(each))).collect(Collectors.toList());
}
private LinkedList<String> deconstructString(final String str) {
return new LinkedList<>(Arrays.asList(str.split(",")));
}
- private List<Object> buildRow(final String resource, final StorageNodeDataSource storageNodeDataSource) {
+ private LocalDataQueryResultRow buildRow(final String resource, final StorageNodeDataSource storageNodeDataSource) {
if (null == storageNodeDataSource) {
- return Arrays.asList(resource, StorageNodeStatus.ENABLED.name().toLowerCase(), "0");
- } else {
- long replicationDelayMilliseconds = storageNodeDataSource.getReplicationDelayMilliseconds();
- String status = StorageNodeStatus.valueOf(storageNodeDataSource.getStatus().toUpperCase()).name().toLowerCase();
- return Arrays.asList(resource, status, Long.toString(replicationDelayMilliseconds));
+ return new LocalDataQueryResultRow(resource, StorageNodeStatus.ENABLED.name().toLowerCase(), "0");
}
+ long replicationDelayMilliseconds = storageNodeDataSource.getReplicationDelayMilliseconds();
+ String status = StorageNodeStatus.valueOf(storageNodeDataSource.getStatus().toUpperCase()).name().toLowerCase();
+ return new LocalDataQueryResultRow(resource, status, Long.toString(replicationDelayMilliseconds));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowSQLParserRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowSQLParserRuleHandler.java
index b468e3f2fc0..5b488ba0d82 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowSQLParserRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowSQLParserRuleHandler.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.queryabl
import com.google.gson.Gson;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowSQLParserRuleStatement;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -27,8 +28,6 @@ import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBack
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Optional;
/**
@@ -50,17 +49,14 @@ public final class ShowSQLParserRuleHandler extends QueryableRALBackendHandler<S
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
Optional<SQLParserRuleConfiguration> sqlParserRuleConfig = ProxyContext.getInstance().getContextManager()
.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().findRuleConfigurations(SQLParserRuleConfiguration.class).stream().findAny();
return sqlParserRuleConfig.isPresent() ? Collections.singleton(getRow(sqlParserRuleConfig.get())) : Collections.emptyList();
}
- private List<Object> getRow(final SQLParserRuleConfiguration sqlParserRuleConfig) {
- List<Object> result = new LinkedList<>();
- result.add(String.valueOf(sqlParserRuleConfig.isSqlCommentParseEnabled()));
- result.add(GSON.toJson(sqlParserRuleConfig.getParseTreeCache()));
- result.add(GSON.toJson(sqlParserRuleConfig.getSqlStatementCache()));
- return result;
+ private LocalDataQueryResultRow getRow(final SQLParserRuleConfiguration sqlParserRuleConfig) {
+ return new LocalDataQueryResultRow(
+ String.valueOf(sqlParserRuleConfig.isSqlCommentParseEnabled()), GSON.toJson(sqlParserRuleConfig.getParseTreeCache()), GSON.toJson(sqlParserRuleConfig.getSqlStatementCache()));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java
index c2e1dfd297b..e9b9fe50c1c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowTableMetadataStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.exception.DatabaseNotExistedException;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereIndex;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -28,11 +29,9 @@ import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
-import java.util.List;
import java.util.stream.Collectors;
/**
@@ -54,7 +53,7 @@ public final class ShowTableMetadataHandler extends QueryableRALBackendHandler<S
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
String databaseName = getDatabaseName();
String defaultSchema = DatabaseTypeEngine.getDefaultSchemaName(getConnectionSession().getDatabaseType(), getConnectionSession().getDatabaseName());
ShardingSphereSchema schema = ProxyContext.getInstance().getDatabase(databaseName).getSchemas().get(defaultSchema);
@@ -73,18 +72,17 @@ public final class ShowTableMetadataHandler extends QueryableRALBackendHandler<S
return result;
}
- private Collection<List<Object>> buildTableRows(final String databaseName, final ShardingSphereSchema schema, final String tableName) {
- Collection<List<Object>> result = new LinkedList<>();
- Collection<List<Object>> columnRows = schema.getAllColumnNames(tableName).stream().map(each -> buildRow(databaseName, tableName, "COLUMN", each))
- .collect(Collectors.toList());
- Collection<List<Object>> indexRows = schema.getTables().get(tableName).getIndexes().values().stream().map(ShardingSphereIndex::getName)
+ private Collection<LocalDataQueryResultRow> buildTableRows(final String databaseName, final ShardingSphereSchema schema, final String tableName) {
+ Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+ Collection<LocalDataQueryResultRow> columnRows = schema.getAllColumnNames(tableName).stream().map(each -> buildRow(databaseName, tableName, "COLUMN", each)).collect(Collectors.toList());
+ Collection<LocalDataQueryResultRow> indexRows = schema.getTables().get(tableName).getIndexes().values().stream().map(ShardingSphereIndex::getName)
.map(each -> buildRow(databaseName, tableName, "INDEX", each)).collect(Collectors.toList());
result.addAll(columnRows);
result.addAll(indexRows);
return result;
}
- private List<Object> buildRow(final String databaseName, final String tableName, final String type, final String name) {
- return new ArrayList<>(Arrays.asList(databaseName, tableName, type, name));
+ private LocalDataQueryResultRow buildRow(final String databaseName, final String tableName, final String type, final String name) {
+ return new LocalDataQueryResultRow(databaseName, tableName, type, name);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandler.java
index 6a418f71050..517ea2a71fe 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandler.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.queryabl
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowTrafficRulesStatement;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.properties.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -30,7 +31,6 @@ import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -58,10 +58,10 @@ public final class ShowTrafficRulesHandler extends QueryableRALBackendHandler<Sh
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
Optional<TrafficRuleConfiguration> config = ProxyContext.getInstance().getContextManager().getMetaDataContexts()
.getMetaData().getGlobalRuleMetaData().findRuleConfigurations(TrafficRuleConfiguration.class).stream().findAny();
- Collection<List<Object>> result = new LinkedList<>();
+ Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Optional<String> ruleName = Optional.ofNullable(getSqlStatement().getRuleName());
config.ifPresent(optional -> {
Map<String, ShardingSphereAlgorithmConfiguration> trafficAlgorithms = optional.getTrafficAlgorithms();
@@ -72,15 +72,10 @@ public final class ShowTrafficRulesHandler extends QueryableRALBackendHandler<Sh
return result;
}
- private List<Object> buildRow(final TrafficStrategyConfiguration strategy, final ShardingSphereAlgorithmConfiguration trafficAlgorithm,
- final ShardingSphereAlgorithmConfiguration loadBalancer) {
- List<Object> result = new LinkedList<>();
- result.add(strategy.getName());
- result.add(String.join(",", strategy.getLabels()));
- result.add(null != trafficAlgorithm ? trafficAlgorithm.getType() : "");
- result.add(null != trafficAlgorithm ? PropertiesConverter.convert(trafficAlgorithm.getProps()) : "");
- result.add(null != loadBalancer ? loadBalancer.getType() : "");
- result.add(null != loadBalancer ? PropertiesConverter.convert(loadBalancer.getProps()) : "");
- return result;
+ private LocalDataQueryResultRow buildRow(final TrafficStrategyConfiguration strategy,
+ final ShardingSphereAlgorithmConfiguration trafficAlgorithm, final ShardingSphereAlgorithmConfiguration loadBalancer) {
+ return new LocalDataQueryResultRow(strategy.getName(), String.join(",", strategy.getLabels()), null != trafficAlgorithm ? trafficAlgorithm.getType() : "",
+ null != trafficAlgorithm ? PropertiesConverter.convert(trafficAlgorithm.getProps()) : "", null != loadBalancer ? loadBalancer.getType() : "",
+ null != loadBalancer ? PropertiesConverter.convert(loadBalancer.getProps()) : "");
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTransactionRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTransactionRuleHandler.java
index 927158c6b2a..487e267f70b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTransactionRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTransactionRuleHandler.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.queryabl
import com.google.gson.Gson;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowTransactionRuleStatement;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
@@ -28,8 +29,6 @@ import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Optional;
/**
@@ -50,16 +49,14 @@ public final class ShowTransactionRuleHandler extends QueryableRALBackendHandler
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
Optional<TransactionRuleConfiguration> ruleConfig = ProxyContext.getInstance().getContextManager()
.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().findRuleConfigurations(TransactionRuleConfiguration.class).stream().findAny();
if (!ruleConfig.isPresent()) {
return Collections.emptyList();
}
- List<Object> row = new LinkedList<>();
- row.add(ruleConfig.get().getDefaultType());
- row.add(null == ruleConfig.get().getProviderType() ? "" : ruleConfig.get().getProviderType());
- row.add(null == ruleConfig.get().getProps() ? "" : new Gson().toJson(ruleConfig.get().getProps()));
- return Collections.singleton(row);
+ return Collections.singleton(new LocalDataQueryResultRow(
+ ruleConfig.get().getDefaultType(), null == ruleConfig.get().getProviderType() ? "" : ruleConfig.get().getProviderType(),
+ null == ruleConfig.get().getProps() ? "" : new Gson().toJson(ruleConfig.get().getProps())));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableHandler.java
index f72cb103763..b417cf94529 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableHandler.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowVariableStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
@@ -50,7 +51,7 @@ public final class ShowVariableHandler extends QueryableRALBackendHandler<ShowVa
}
@Override
- protected Collection<List<Object>> getRows(final ContextManager contextManager) {
+ protected Collection<LocalDataQueryResultRow> getRows(final ContextManager contextManager) {
if (hasSpecifiedKey()) {
return buildSpecifiedRow(contextManager, getSqlStatement().getName());
} else {
@@ -62,26 +63,27 @@ public final class ShowVariableHandler extends QueryableRALBackendHandler<ShowVa
return !Strings.isNullOrEmpty(getSqlStatement().getName());
}
- private Collection<List<Object>> buildAllVariableRows(final ContextManager contextManager) {
- List<List<Object>> result = new LinkedList<>();
+ private Collection<LocalDataQueryResultRow> buildAllVariableRows(final ContextManager contextManager) {
+ List<LocalDataQueryResultRow> result = new LinkedList<>();
ConfigurationProperties props = contextManager.getMetaDataContexts().getMetaData().getProps();
ConfigurationPropertyKey.getKeyNames().forEach(each -> {
String propertyValue = props.getValue(ConfigurationPropertyKey.valueOf(each)).toString();
- result.add(Arrays.asList(each.toLowerCase(), propertyValue));
+ result.add(new LocalDataQueryResultRow(each.toLowerCase(), propertyValue));
});
- result.add(Arrays.asList(VariableEnum.AGENT_PLUGINS_ENABLED.name().toLowerCase(), SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.TRUE.toString())));
+ result.add(new LocalDataQueryResultRow(
+ VariableEnum.AGENT_PLUGINS_ENABLED.name().toLowerCase(), SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.TRUE.toString())));
if (getConnectionSession().getBackendConnection() instanceof JDBCBackendConnection) {
- result.add(Arrays.asList(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(), ((JDBCBackendConnection) getConnectionSession().getBackendConnection()).getConnectionSize()));
+ result.add(new LocalDataQueryResultRow(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(), ((JDBCBackendConnection) getConnectionSession().getBackendConnection()).getConnectionSize()));
}
- result.add(Arrays.asList(VariableEnum.TRANSACTION_TYPE.name().toLowerCase(), getConnectionSession().getTransactionStatus().getTransactionType().name()));
+ result.add(new LocalDataQueryResultRow(VariableEnum.TRANSACTION_TYPE.name().toLowerCase(), getConnectionSession().getTransactionStatus().getTransactionType().name()));
return result;
}
- private Collection<List<Object>> buildSpecifiedRow(final ContextManager contextManager, final String key) {
+ private Collection<LocalDataQueryResultRow> buildSpecifiedRow(final ContextManager contextManager, final String key) {
if (isConfigurationKey(key)) {
- return Collections.singletonList(Arrays.asList(key.toLowerCase(), getConfigurationValue(contextManager, key)));
+ return Collections.singletonList(new LocalDataQueryResultRow(key.toLowerCase(), getConfigurationValue(contextManager, key)));
} else {
- return Collections.singletonList(Arrays.asList(key.toLowerCase(), getSpecialValue(key)));
+ return Collections.singletonList(new LocalDataQueryResultRow(key.toLowerCase(), getSpecialValue(key)));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandlerTest.java
index 57cc493d778..55d6d03d595 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandlerTest.java
@@ -22,6 +22,8 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -33,12 +35,10 @@ import org.apache.shardingsphere.proxy.backend.response.header.query.QueryRespon
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor.SelectTableExecutor;
import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import org.junit.Before;
import org.junit.Test;
import java.sql.SQLException;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
@@ -64,7 +64,7 @@ public final class DatabaseAdminQueryBackendHandlerTest extends ProxyContextRest
ConnectionSession connectionSession = mock(ConnectionSession.class);
when(connectionSession.getDatabaseName()).thenReturn("db");
SelectTableExecutor executor = mock(SelectTableExecutor.class, RETURNS_DEEP_STUBS);
- MergedResult mergedResult = new LocalDataMergedResult(Collections.singleton(Arrays.asList("demo_ds_0", "demo_ds_1")));
+ MergedResult mergedResult = new LocalDataMergedResult(Collections.singleton(new LocalDataQueryResultRow("demo_ds_0", "demo_ds_1")));
when(executor.getMergedResult()).thenReturn(mergedResult);
when(executor.getQueryResultMetaData().getColumnCount()).thenReturn(1);
handler = new DatabaseAdminQueryBackendHandler(connectionSession, executor);