You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/29 07:27:08 UTC
[shardingsphere] branch master updated: fix `sctl:query` (#6502)
This is an automated email from the ASF dual-hosted git repository.
zhyee 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 8390217 fix `sctl:query` (#6502)
8390217 is described below
commit 8390217b39933783e4a19601e166ffbae1e53a4d
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Wed Jul 29 15:26:57 2020 +0800
fix `sctl:query` (#6502)
* Create parser binder and statements
* license
* fix `sctl:query`
* check style
---
.../explain/ShardingCTLExplainBackendHandler.java | 3 +-
.../ShardingCTLExplainBackendHandlerTest.java | 62 ++++++++++++++++++++++
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
index 2d6ad02..b62b4ad 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
@@ -57,7 +57,8 @@ public final class ShardingCTLExplainBackendHandler implements TextProtocolBacke
return new ErrorResponse(new InvalidShardingCTLFormatException(sql));
}
SchemaContext schema = backendConnection.getSchema();
- StatementExecutorWrapper statementExecutorWrapper = new StatementExecutorWrapper(schema, schema.getRuntimeContext().getSqlParserEngine().parse(sql, false));
+ StatementExecutorWrapper statementExecutorWrapper =
+ new StatementExecutorWrapper(schema, schema.getRuntimeContext().getSqlParserEngine().parse(explainStatement.get().getSql(), false));
executionUnits = statementExecutorWrapper.execute(explainStatement.get().getSql()).getExecutionUnits().iterator();
queryHeaders = new ArrayList<>(2);
queryHeaders.add(new QueryHeader("", "", "datasource_name", "", 255, Types.CHAR, 0, false, false, false, false));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
new file mode 100644
index 0000000..a011048
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
@@ -0,0 +1,62 @@
+package org.apache.shardingsphere.proxy.backend.text.sctl.explain;
+
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.kernel.context.SchemaContext;
+import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
+import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.sql.parser.SQLParserEngine;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/*
+ * 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.
+ */
+
+public class ShardingCTLExplainBackendHandlerTest {
+
+ private ShardingCTLExplainBackendHandler handler;
+
+ @Before
+ public void setUp() {
+ BackendConnection connection = mock(BackendConnection.class);
+ when(connection.getSchema()).thenReturn(createSchemaContext());
+ handler = new ShardingCTLExplainBackendHandler("sctl:explain select 1", connection);
+ }
+
+ private SchemaContext createSchemaContext() {
+ RuntimeContext runtimeContext = new RuntimeContext(null, null, new SQLParserEngine("MySQL"), null);
+ ShardingSphereSchema schema = new ShardingSphereSchema(new MySQLDatabaseType(), Collections.emptyList(),
+ Collections.emptyList(), Collections.singletonMap("ds0", mock(DataSource.class)), null);
+ return new SchemaContext("c1", schema, runtimeContext);
+ }
+
+ @Test
+ public void assertQueryData() {
+ handler.execute();
+ assertTrue(handler.next());
+ assertThat(handler.getQueryData().getData().get(1), is("select 1"));
+ }
+}