You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/08/26 06:55:11 UTC

[GitHub] [shardingsphere] RaigorJiang commented on a change in pull request #12011: Support information_schema.schemata query

RaigorJiang commented on a change in pull request #12011:
URL: https://github.com/apache/shardingsphere/pull/12011#discussion_r696343285



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLInformationSchemaExecutorFactory.java
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.proxy.backend.text.admin.mysql;
+
+import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminQueryExecutor;
+import org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.information.SelectSchemataExecutor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+
+/**
+ * Construct the information schema executor's factory.
+ */
+public final class MySQLInformationSchemaExecutorFactory {
+    
+    public static final String SCHEMATA = "schemata";
+    
+    /**
+     * Create executor.
+     *
+     * @param sqlStatement SQL statement
+     * @param sql SQL being executed
+     * @return executor
+     */
+    public static DatabaseAdminQueryExecutor newInstance(final SelectStatement sqlStatement, final String sql) {
+        String tableName = ((SimpleTableSegment) sqlStatement.getFrom()).getTableName().getIdentifier().getValue();
+        if (SCHEMATA.equalsIgnoreCase(tableName)) {
+            return new SelectSchemataExecutor(sqlStatement, sql);
+        }
+        throw new UnsupportedOperationException("unsupported table");

Review comment:
       It is better to prompt the tableName in error message.
   Because `information_schema` is mostly queried automatically by SQL client, user does not know which table is being queried.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org