This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 3f1cb47  Add ShowFilterSegment, refactor MySQL show columns SQL 
parser. (#13690)
3f1cb47 is described below

commit 3f1cb47a7416e84e4f1564da2f708f477fbdc30b
Author: Zonglei Dong <[email protected]>
AuthorDate: Fri Nov 19 07:51:23 2021 +0800

    Add ShowFilterSegment, refactor MySQL show columns SQL parser. (#13690)
    
    * add comment, fixes checkstyle problem.
    
    * add ShowFilterSegment, refactor MySQL show columns SQL parser.
    
    * add ShowFilterSegment test case, refactor MySQL show columns SQL parser.
    
    * fixes checkstyle, add class header license.
---
 .../ddl/ShardingDDLStatementValidator.java         |  1 +
 .../dal/ShowColumnsStatementContextTest.java       |  4 +-
 .../executor/AbstractDatabaseMetadataExecutor.java |  2 +
 .../src/main/antlr4/imports/mysql/DALStatement.g4  |  6 +--
 .../impl/MySQLDALStatementSQLVisitor.java          | 23 ++++++++-
 .../statement/impl/MySQLStatementSQLVisitor.java   |  3 +-
 .../sql/common/segment/dal/FromSchemaSegment.java  |  3 ++
 ...omSchemaSegment.java => ShowFilterSegment.java} | 34 +++++++++++--
 .../mysql/dal/MySQLShowColumnsStatement.java       | 12 +++++
 .../asserts/segment/show/ShowFilterAssert.java     | 55 ++++++++++++++++++++++
 .../dal/impl/ShowColumnsStatementAssert.java       | 12 +++++
 .../impl/from/ExpectedFromSchema.java}             | 19 +++-----
 .../impl/show/ExpectedShowFilter.java}             | 20 ++++----
 .../dal/ShowColumnsStatementTestCase.java          |  8 ++++
 .../src/main/resources/case/dal/show.xml           | 38 +++++++++++++++
 .../src/main/resources/sql/supported/dal/show.xml  |  4 ++
 16 files changed, 210 insertions(+), 34 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
index d2e44d7..7367a48 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
@@ -98,6 +98,7 @@ public abstract class ShardingDDLStatementValidator<T extends 
DDLStatement> impl
      *
      * @param schema ShardingSphere schema
      * @param index index
+     * @return whether schema contains index or not
      */
     protected boolean isSchemaContainsIndex(final ShardingSphereSchema schema, 
final IndexSegment index) {
         return schema.getAllTableNames().stream().anyMatch(each -> 
schema.get(each).getIndexes().containsKey(index.getIdentifier().getValue()));
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dal/ShowColumnsStatementContextTest.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dal/ShowColumnsStatementContextTest.java
index da93853..8140f25 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dal/ShowColumnsStatementContextTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dal/ShowColumnsStatementContextTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.binder.statement.dal;
 
 import 
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromSchemaSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -41,8 +42,9 @@ public final class ShowColumnsStatementContextTest {
     public void assertNewInstance() {
         MySQLShowColumnsStatement mySQLShowColumnsStatement = 
mock(MySQLShowColumnsStatement.class);
         String tableName = "tbl_1";
+        String schemaName = "sharding_db";
         SimpleTableSegment table = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue(tableName)));
-        FromSchemaSegment fromSchema = new FromSchemaSegment(0, 0);
+        FromSchemaSegment fromSchema = new FromSchemaSegment(0, 0, new 
SchemaSegment(0, 0, new IdentifierValue(schemaName)));
         when(mySQLShowColumnsStatement.getTable()).thenReturn(table);
         
when(mySQLShowColumnsStatement.getFromSchema()).thenReturn(Optional.of(fromSchema));
         ShowColumnsStatementContext actual = new 
ShowColumnsStatementContext(mySQLShowColumnsStatement);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java
index 312b26b..7c0ac10 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java
@@ -93,6 +93,8 @@ public abstract class AbstractDatabaseMetadataExecutor 
implements DatabaseAdminQ
     
     /**
      * Initialize the schema data.
+     *
+     * @param schemaName schema name
      */
     protected abstract void initSchemaData(String schemaName);
     
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
index 31c77f9..1677321 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
@@ -47,7 +47,7 @@ showTableStatus
     ;
 
 showColumns
-    : SHOW EXTENDED? FULL? COLUMNS fromTable fromSchema? (showColumnLike | 
showWhereClause)?
+    : SHOW EXTENDED? FULL? COLUMNS fromTable fromSchema? showFilter?
     ;
 
 showIndex
@@ -70,10 +70,6 @@ showLike
     : LIKE stringLiterals
     ;
 
-showColumnLike
-    : LIKE stringLiterals
-    ;
-
 showWhereClause
     : WHERE expr
     ;
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
index 80662ff..7dc463f 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
@@ -77,6 +77,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowDat
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEngineContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEnginesContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowErrorsContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFilterContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFunctionStatusContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowIndexContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowLikeContext;
@@ -105,6 +106,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UserVar
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.VariableContext;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromSchemaSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromTableSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowFilterSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowLikeSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
@@ -112,6 +114,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSe
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue;
@@ -489,7 +492,7 @@ public final class MySQLDALStatementSQLVisitor extends 
MySQLStatementSQLVisitor
     @Override
     public ASTNode visitUse(final UseContext ctx) {
         MySQLUseStatement result = new MySQLUseStatement();
-        result.setSchema(((IdentifierValue) 
visit(ctx.schemaName())).getValue());
+        result.setSchema(((SchemaSegment) 
visit(ctx.schemaName())).getIdentifier().getValue());
         return result;
     }
     
@@ -579,6 +582,22 @@ public final class MySQLDALStatementSQLVisitor extends 
MySQLStatementSQLVisitor
         if (null != ctx.fromSchema()) {
             result.setFromSchema((FromSchemaSegment) visit(ctx.fromSchema()));
         }
+        if (null != ctx.showFilter()) {
+            result.setFilter((ShowFilterSegment) visit(ctx.showFilter()));
+        }
+        result.setParameterCount(getCurrentParameterIndex());
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitShowFilter(final ShowFilterContext ctx) {
+        ShowFilterSegment result = new 
ShowFilterSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+        if (null != ctx.showLike()) {
+            result.setLike((ShowLikeSegment) visit(ctx.showLike()));
+        }
+        if (null != ctx.showWhereClause()) {
+            result.setWhere((WhereSegment) visit(ctx.showWhereClause()));
+        }
         return result;
     }
     
@@ -828,7 +847,7 @@ public final class MySQLDALStatementSQLVisitor extends 
MySQLStatementSQLVisitor
     
     @Override
     public ASTNode visitFromSchema(final FromSchemaContext ctx) {
-        return new FromSchemaSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex());
+        return new FromSchemaSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), (SchemaSegment) visit(ctx.schemaName()));
     }
     
     @Override
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index ec8b569..7ace0c0 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -180,6 +180,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegm
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeLengthSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.WindowSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.DeleteMultiTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
@@ -301,7 +302,7 @@ public abstract class MySQLStatementSQLVisitor extends 
MySQLStatementBaseVisitor
     
     @Override
     public final ASTNode visitSchemaName(final SchemaNameContext ctx) {
-        return visit(ctx.identifier());
+        return new SchemaSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
     }
     
     @Override
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/FromSchemaSegment.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/FromSchemaSegment.java
index 0e039bf..5959a36 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/FromSchemaSegment.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/FromSchemaSegment.java
@@ -20,6 +20,7 @@ package 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
 
 /**
  * From schema segment.
@@ -31,4 +32,6 @@ public final class FromSchemaSegment implements SQLSegment {
     private final int startIndex;
     
     private final int stopIndex;
+    
+    private final SchemaSegment schema;
 }
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/FromSchemaSegment.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/ShowFilterSegment.java
similarity index 61%
copy from 
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/FromSchemaSegment.java
copy to 
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/ShowFilterSegment.java
index 0e039bf..cf5c4e8 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/FromSchemaSegment.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dal/ShowFilterSegment.java
@@ -19,16 +19,44 @@ package 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal;
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
+import lombok.Setter;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
+
+import java.util.Optional;
 
 /**
- * From schema segment.
+ * Show filter segment.
  */
 @RequiredArgsConstructor
-@Getter
-public final class FromSchemaSegment implements SQLSegment {
+@Setter
+public final class ShowFilterSegment implements SQLSegment {
     
+    @Getter
     private final int startIndex;
     
+    @Getter
     private final int stopIndex;
+    
+    private ShowLikeSegment like;
+    
+    private WhereSegment where;
+    
+    /**
+     * Get like segment.
+     *
+     * @return like segment
+     */
+    public Optional<ShowLikeSegment> getLike() {
+        return Optional.ofNullable(like);
+    }
+    
+    /**
+     * Get where segment.
+     *
+     * @return where segment
+     */
+    public Optional<WhereSegment> getWhere() {
+        return Optional.ofNullable(where);
+    }
 }
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowColumnsStatement.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowColumnsStatement.java
index f6811ba..aef5be4 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowColumnsStatement.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowColumnsStatement.java
@@ -21,6 +21,7 @@ import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.FromSchemaSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowFilterSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
@@ -40,6 +41,8 @@ public final class MySQLShowColumnsStatement extends 
AbstractSQLStatement implem
     
     private FromSchemaSegment fromSchema;
     
+    private ShowFilterSegment filter;
+    
     /**
      * Get from schema.
      *
@@ -48,4 +51,13 @@ public final class MySQLShowColumnsStatement extends 
AbstractSQLStatement implem
     public Optional<FromSchemaSegment> getFromSchema() {
         return Optional.ofNullable(fromSchema);
     }
+    
+    /**
+     * Get filter segment.
+     *
+     * @return filter segment
+     */
+    public Optional<ShowFilterSegment> getFilter() {
+        return Optional.ofNullable(filter);
+    }
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/show/ShowFilterAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/show/ShowFilterAssert.java
new file mode 100644
index 0000000..864cc74
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/show/ShowFilterAssert.java
@@ -0,0 +1,55 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.segment.show;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.ShowFilterSegment;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.SQLSegmentAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.where.WhereClauseAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.show.ExpectedShowFilter;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Show filter assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowFilterAssert {
+    
+    /**
+     * Assert actual show filter segment is correct with expected schema.
+     *
+     * @param assertContext assert context
+     * @param actual actual show filter segment
+     * @param expected expected show filter
+     */
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final ShowFilterSegment actual, final ExpectedShowFilter expected) {
+        if (actual.getLike().isPresent()) {
+            assertThat(assertContext.getText("Show filter like segment pattern 
content assert error."),
+                    actual.getLike().get().getPattern(), 
is(expected.getLike().getPattern()));
+            SQLSegmentAssert.assertIs(assertContext, actual.getLike().get(), 
expected.getLike());
+        }
+        if (actual.getWhere().isPresent()) {
+            WhereClauseAssert.assertIs(assertContext, actual.getWhere().get(), 
expected.getWhere());
+        }
+        SQLSegmentAssert.assertIs(assertContext, actual, expected);
+    }
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowColumnsStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowColumnsStatementAssert.java
index ffdc633..5e1f4c9 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowColumnsStatementAssert.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowColumnsStatementAssert.java
@@ -21,6 +21,9 @@ import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowColumnsStatement;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.schema.SchemaAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.show.ShowFilterAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.table.TableAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowColumnsStatementTestCase;
 
 /**
@@ -37,5 +40,14 @@ public final class ShowColumnsStatementAssert {
      * @param expected expected show columns statement test case
      */
     public static void assertIs(final SQLCaseAssertContext assertContext, 
final MySQLShowColumnsStatement actual, final ShowColumnsStatementTestCase 
expected) {
+        if (null != actual.getTable()) {
+            TableAssert.assertIs(assertContext, actual.getTable(), 
expected.getTable());
+        }
+        if (actual.getFromSchema().isPresent()) {
+            SchemaAssert.assertIs(assertContext, 
actual.getFromSchema().get().getSchema(), expected.getSchema());
+        }
+        if (actual.getFilter().isPresent()) {
+            ShowFilterAssert.assertIs(assertContext, actual.getFilter().get(), 
expected.getFilter());
+        }
     }
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/from/ExpectedFromSchema.java
similarity index 71%
copy from 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
copy to 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/from/ExpectedFromSchema.java
index e3fe4da..05267cd 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/from/ExpectedFromSchema.java
@@ -15,22 +15,15 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal;
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.from;
 
-import lombok.Getter;
-import lombok.Setter;
-import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.table.ExpectedSimpleTable;
-import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-
-import javax.xml.bind.annotation.XmlElement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.AbstractExpectedSQLSegment;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.schema.ExpectedSchema;
 
 /**
- * Show columns statement test case.
+ * Expected from schema segment.
  */
-@Getter
-@Setter
-public final class ShowColumnsStatementTestCase extends SQLParserTestCase {
+public final class ExpectedFromSchema extends AbstractExpectedSQLSegment {
     
-    @XmlElement
-    private ExpectedSimpleTable table;
+    private ExpectedSchema schema;
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/show/ExpectedShowFilter.java
similarity index 67%
copy from 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
copy to 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/show/ExpectedShowFilter.java
index e3fe4da..6d6e421 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/show/ExpectedShowFilter.java
@@ -15,22 +15,24 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal;
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.show;
 
 import lombok.Getter;
-import lombok.Setter;
-import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.table.ExpectedSimpleTable;
-import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.AbstractExpectedSQLSegment;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.like.ExpectedLikeClause;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.where.ExpectedWhereClause;
 
 import javax.xml.bind.annotation.XmlElement;
 
 /**
- * Show columns statement test case.
+ * Expected show filter segment.
  */
 @Getter
-@Setter
-public final class ShowColumnsStatementTestCase extends SQLParserTestCase {
+public final class ExpectedShowFilter extends AbstractExpectedSQLSegment {
     
-    @XmlElement
-    private ExpectedSimpleTable table;
+    @XmlElement(name = "like")
+    private ExpectedLikeClause like;
+    
+    @XmlElement(name = "where")
+    private ExpectedWhereClause where;
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
index e3fe4da..93f7e60 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowColumnsStatementTestCase.java
@@ -19,6 +19,8 @@ package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domai
 
 import lombok.Getter;
 import lombok.Setter;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.schema.ExpectedSchema;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.show.ExpectedShowFilter;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.table.ExpectedSimpleTable;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
 
@@ -33,4 +35,10 @@ public final class ShowColumnsStatementTestCase extends 
SQLParserTestCase {
     
     @XmlElement
     private ExpectedSimpleTable table;
+    
+    @XmlElement
+    private ExpectedSchema schema;
+    
+    @XmlElement
+    private ExpectedShowFilter filter;
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
index 2bf868d..a32690e 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/show.xml
@@ -51,6 +51,44 @@
     <show-columns sql-case-id="show_columns_from_table">
         <table name="t_order" start-delimiter="`" end-delimiter="`" 
start-index="18" stop-index="26"/>
     </show-columns>
+
+    <show-columns sql-case-id="show_columns_from_table_with_owner">
+        <table name="t_order" start-delimiter="`" end-delimiter="`" 
start-index="18" stop-index="40">
+            <owner name="sharding_db" start-delimiter="`" end-delimiter="`" 
start-index="18" stop-index="30" />
+        </table>
+    </show-columns>
+
+    <show-columns sql-case-id="show_columns_with_schema">
+        <table name="t_order" start-delimiter="`" end-delimiter="`" 
start-index="18" stop-index="26"/>
+        <schema name="sharding_db" start-delimiter="`" end-delimiter="`" 
start-index="33" stop-index="45"/>
+    </show-columns>
+
+    <show-columns sql-case-id="show_columns_with_like_pattern">
+        <table name="t_order" start-delimiter="`" end-delimiter="`" 
start-index="18" stop-index="26"/>
+        <filter start-index="28" stop-index="41">
+            <like pattern="order_%" start-delimiter="'" end-delimiter="'" 
start-index="28" stop-index="41"/>
+        </filter>
+    </show-columns>
+
+    <show-columns sql-case-id="show_columns_with_where_expr" 
parameters="'order_id'">
+        <table name="t_order" start-delimiter="`" end-delimiter="`" 
start-index="18" stop-index="26"/>
+        <filter start-index="28" stop-index="42" literal-stop-index="51">
+            <where start-index="28" stop-index="42" literal-stop-index="51">
+                <expr>
+                    <binary-operation-expression start-index="34" 
stop-index="42" literal-stop-index="51">
+                        <left>
+                            <column name="field" start-index="34" 
stop-index="38" />
+                        </left>
+                        <operator>=</operator>
+                        <right>
+                            <literal-expression value="order_id" 
start-index="42" stop-index="51" />
+                            <parameter-marker-expression value="0" 
start-index="42" stop-index="42" />
+                        </right>
+                    </binary-operation-expression>
+                </expr>
+            </where>
+        </filter>
+    </show-columns>
     
     <show-create-table sql-case-id="show_create_table">
         <table name="t_order" start-delimiter="`" end-delimiter="`" 
start-index="18" stop-index="26"/>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
index bfc3de4..146c2e0 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/show.xml
@@ -25,6 +25,10 @@
     <sql-case id="show_index_with_database_back_quotes" value="SHOW INDEXES 
FROM t_order FROM `sharding_db`" db-types="MySQL" />
     <sql-case id="show_index_with_back_quotes" value="SHOW KEYS FROM 
`sharding_db`.`t_order`" db-types="MySQL" />
     <sql-case id="show_columns_from_table" value="SHOW COLUMNS FROM `t_order`" 
db-types="MySQL" />
+    <sql-case id="show_columns_from_table_with_owner" value="SHOW COLUMNS FROM 
`sharding_db`.`t_order`" db-types="MySQL" />
+    <sql-case id="show_columns_with_schema" value="SHOW COLUMNS FROM `t_order` 
FROM `sharding_db`" db-types="MySQL" />
+    <sql-case id="show_columns_with_like_pattern" value="SHOW COLUMNS FROM 
`t_order` LIKE 'order_%'" db-types="MySQL" />
+    <sql-case id="show_columns_with_where_expr" value="SHOW COLUMNS FROM 
`t_order` WHERE field = ?" db-types="MySQL" />
     <sql-case id="show_create_table" value="SHOW CREATE TABLE `t_order`" 
db-types="MySQL" />
     <sql-case id="show_create_trigger" value="SHOW CREATE TRIGGER `trigger1`" 
db-types="MySQL" />
     <sql-case id="show_create_user" value="SHOW CREATE USER `user1`" 
db-types="MySQL" />

Reply via email to