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

sunnianjun 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 b07b2e79db6 Filter invisible column in shorthand expand and add more 
unit test (#27517)
b07b2e79db6 is described below

commit b07b2e79db68ba3011254d99b48d53525b24ee40
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Fri Jul 28 10:20:25 2023 +0800

    Filter invisible column in shorthand expand and add more unit test (#27517)
    
    * Filter invisible column in shorthand expand and add more unit test
    
    * fix unit test
    
    * fix unit test
    
    * fix integration test
---
 .../from/impl/SimpleTableSegmentBinder.java        |  20 ++--
 .../projection/ProjectionsSegmentBinder.java       |   6 +-
 .../impl/ShorthandProjectionSegmentBinder.java     |  14 ++-
 .../statement/dml/SelectStatementBinder.java       |   2 +-
 .../from/impl/JoinTableSegmentBinderTest.java      | 104 +++++++++++++++++++++
 .../from/impl/SimpleTableSegmentBinderTest.java    |  13 ++-
 .../from/impl/SubqueryTableSegmentBinderTest.java  |  93 ++++++++++++++++++
 .../impl/ShorthandProjectionSegmentBinderTest.java |  53 +++++++++++
 .../segment/dml/item/ColumnProjectionSegment.java  |   6 +-
 .../common/segment/dml/item/ProjectionSegment.java |   9 ++
 .../engine/scenario/EncryptSQLRewriterIT.java      |  43 +++++----
 .../rewrite/engine/scenario/MixSQLRewriterIT.java  |  49 ++++------
 .../engine/scenario/ShardingSQLRewriterIT.java     |  72 ++++++--------
 .../dml/select/select-projection.xml               |   4 +-
 14 files changed, 376 insertions(+), 112 deletions(-)

diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java
index c904ba9ff20..94d8c25207d 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java
@@ -25,7 +25,9 @@ import 
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.database.opengauss.OpenGaussDatabaseType;
 import 
org.apache.shardingsphere.infra.database.postgresql.PostgreSQLDatabaseType;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
@@ -34,6 +36,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sim
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.Map;
@@ -95,17 +98,20 @@ public final class SimpleTableSegmentBinder {
         return new 
IdentifierValue(DatabaseTypeEngine.getDefaultSchemaName(databaseType, 
defaultDatabaseName));
     }
     
-    private static TableSegmentBinderContext 
createSimpleTableBinderContext(final SimpleTableSegment segment, final 
ShardingSphereSchema schema, final IdentifierValue originalDatabase,
-                                                                            
final IdentifierValue originalSchema) {
-        Collection<String> columnNames = 
schema.getAllColumnNames(segment.getTableName().getIdentifier().getValue());
+    private static TableSegmentBinderContext 
createSimpleTableBinderContext(final SimpleTableSegment segment, final 
ShardingSphereSchema schema,
+                                                                            
final IdentifierValue originalDatabase, final IdentifierValue originalSchema) {
+        Collection<ShardingSphereColumn> columnNames =
+                
Optional.ofNullable(schema.getTable(segment.getTableName().getIdentifier().getValue())).map(ShardingSphereTable::getColumnValues).orElseGet(Collections::emptyList);
         Collection<ProjectionSegment> projectionSegments = new LinkedList<>();
-        for (String each : columnNames) {
-            ColumnSegment columnSegment = new ColumnSegment(0, 0, new 
IdentifierValue(each));
+        for (ShardingSphereColumn each : columnNames) {
+            ColumnSegment columnSegment = new ColumnSegment(0, 0, new 
IdentifierValue(each.getName()));
             columnSegment.setOriginalDatabase(originalDatabase);
             columnSegment.setOriginalSchema(originalSchema);
             
columnSegment.setOriginalTable(segment.getTableName().getIdentifier());
-            columnSegment.setOriginalColumn(new IdentifierValue(each));
-            projectionSegments.add(new ColumnProjectionSegment(columnSegment));
+            columnSegment.setOriginalColumn(new 
IdentifierValue(each.getName()));
+            ColumnProjectionSegment columnProjectionSegment = new 
ColumnProjectionSegment(columnSegment);
+            columnProjectionSegment.setVisible(each.isVisible());
+            projectionSegments.add(columnProjectionSegment);
         }
         return new TableSegmentBinderContext(projectionSegments);
     }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/ProjectionsSegmentBinder.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/ProjectionsSegmentBinder.java
index 1f3c3cda223..8b3ef7f81c3 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/ProjectionsSegmentBinder.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/ProjectionsSegmentBinder.java
@@ -22,7 +22,6 @@ import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderContext;
 import 
org.apache.shardingsphere.infra.binder.segment.projection.impl.ColumnProjectionSegmentBinder;
 import 
org.apache.shardingsphere.infra.binder.segment.projection.impl.ShorthandProjectionSegmentBinder;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -40,13 +39,10 @@ public final class ProjectionsSegmentBinder {
      * Bind projections segment with metadata.
      *
      * @param segment table segment
-     * @param metaData meta data
-     * @param defaultDatabaseName default database name
      * @param tableBinderContexts table binder contexts
      * @return bounded projections segment
      */
-    public static ProjectionsSegment bind(final ProjectionsSegment segment, 
final ShardingSphereMetaData metaData, final String defaultDatabaseName,
-                                          final Map<String, 
TableSegmentBinderContext> tableBinderContexts) {
+    public static ProjectionsSegment bind(final ProjectionsSegment segment, 
final Map<String, TableSegmentBinderContext> tableBinderContexts) {
         ProjectionsSegment result = new 
ProjectionsSegment(segment.getStartIndex(), segment.getStopIndex());
         result.setDistinctRow(segment.isDistinctRow());
         segment.getProjections().forEach(each -> 
result.getProjections().add(bind(each, tableBinderContexts)));
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
index 364b2808c8f..0e8b500eae7 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
@@ -20,8 +20,10 @@ package 
org.apache.shardingsphere.infra.binder.segment.projection.impl;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderContext;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
 
+import java.util.Collection;
 import java.util.Map;
 
 /**
@@ -40,11 +42,19 @@ public final class ShorthandProjectionSegmentBinder {
     public static ShorthandProjectionSegment bind(final 
ShorthandProjectionSegment segment, final Map<String, 
TableSegmentBinderContext> tableBinderContexts) {
         if (segment.getOwner().isPresent()) {
             TableSegmentBinderContext tableBinderContext = 
tableBinderContexts.get(segment.getOwner().get().getIdentifier().getValue());
-            
segment.getActualProjectionSegments().addAll(tableBinderContext.getProjectionSegments());
+            expandVisibleColumn(tableBinderContext.getProjectionSegments(), 
segment);
         } else {
             // TODO expand according to different database with multi tables
-            tableBinderContexts.values().forEach(each -> 
segment.getActualProjectionSegments().addAll(each.getProjectionSegments()));
+            tableBinderContexts.values().forEach(each -> 
expandVisibleColumn(each.getProjectionSegments(), segment));
         }
         return segment;
     }
+    
+    private static void expandVisibleColumn(final 
Collection<ProjectionSegment> projectionSegments, final 
ShorthandProjectionSegment shorthandProjectionSegment) {
+        for (ProjectionSegment each : projectionSegments) {
+            if (each.isVisible()) {
+                
shorthandProjectionSegment.getActualProjectionSegments().add(each);
+            }
+        }
+    }
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java
index 2f0a8f610e5..56062800549 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementBinder.java
@@ -38,7 +38,7 @@ public final class SelectStatementBinder implements 
SQLStatementBinder<SelectSta
         Map<String, TableSegmentBinderContext> tableBinderContexts = new 
CaseInsensitiveMap<>();
         sqlStatement.setFrom(TableSegmentBinder.bind(sqlStatement.getFrom(), 
metaData, defaultDatabaseName, sqlStatement.getDatabaseType(), 
tableBinderContexts));
         sqlStatement.getCombine().ifPresent(optional -> 
sqlStatement.setCombine(CombineSegmentBinder.bind(optional, metaData, 
defaultDatabaseName)));
-        
sqlStatement.setProjections(ProjectionsSegmentBinder.bind(sqlStatement.getProjections(),
 metaData, defaultDatabaseName, tableBinderContexts));
+        
sqlStatement.setProjections(ProjectionsSegmentBinder.bind(sqlStatement.getProjections(),
 tableBinderContexts));
         // TODO support other segment bind in select statement
         return sqlStatement;
     }
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinderTest.java
new file mode 100644
index 00000000000..169b78a9044
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinderTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.binder.segment.from.impl;
+
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
+import 
org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderContext;
+import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
+import org.apache.shardingsphere.infra.database.mysql.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
+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;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class JoinTableSegmentBinderTest {
+    
+    @Test
+    void assertBindWithAlias() {
+        JoinTableSegment joinTableSegment = mock(JoinTableSegment.class);
+        SimpleTableSegment leftTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order")));
+        leftTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("o")));
+        SimpleTableSegment rightTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order_item")));
+        rightTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("i")));
+        when(joinTableSegment.getLeft()).thenReturn(leftTable);
+        when(joinTableSegment.getRight()).thenReturn(rightTable);
+        ShardingSphereMetaData metaData = createMetaData();
+        Map<String, TableSegmentBinderContext> tableBinderContexts = new 
CaseInsensitiveMap<>();
+        JoinTableSegment actual = 
JoinTableSegmentBinder.bind(joinTableSegment, metaData, 
DefaultDatabase.LOGIC_NAME, new MySQLDatabaseType(), tableBinderContexts);
+        assertTrue(actual.getLeft() instanceof SimpleTableSegment);
+        assertThat(((SimpleTableSegment) 
actual.getLeft()).getTableName().getOriginalDatabase().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertThat(((SimpleTableSegment) 
actual.getLeft()).getTableName().getOriginalSchema().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertTrue(actual.getRight() instanceof SimpleTableSegment);
+        assertThat(((SimpleTableSegment) 
actual.getRight()).getTableName().getOriginalDatabase().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertThat(((SimpleTableSegment) 
actual.getRight()).getTableName().getOriginalSchema().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertTrue(tableBinderContexts.containsKey("o"));
+        assertTrue(tableBinderContexts.containsKey("i"));
+    }
+    
+    @Test
+    void assertBindWithoutAlias() {
+        JoinTableSegment joinTableSegment = mock(JoinTableSegment.class);
+        SimpleTableSegment leftTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order")));
+        SimpleTableSegment rightTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order_item")));
+        when(joinTableSegment.getLeft()).thenReturn(leftTable);
+        when(joinTableSegment.getRight()).thenReturn(rightTable);
+        ShardingSphereMetaData metaData = createMetaData();
+        Map<String, TableSegmentBinderContext> tableBinderContexts = new 
CaseInsensitiveMap<>();
+        JoinTableSegment actual = 
JoinTableSegmentBinder.bind(joinTableSegment, metaData, 
DefaultDatabase.LOGIC_NAME, new MySQLDatabaseType(), tableBinderContexts);
+        assertTrue(actual.getLeft() instanceof SimpleTableSegment);
+        assertThat(((SimpleTableSegment) 
actual.getLeft()).getTableName().getOriginalDatabase().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertThat(((SimpleTableSegment) 
actual.getLeft()).getTableName().getOriginalSchema().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertTrue(actual.getRight() instanceof SimpleTableSegment);
+        assertThat(((SimpleTableSegment) 
actual.getRight()).getTableName().getOriginalDatabase().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertThat(((SimpleTableSegment) 
actual.getRight()).getTableName().getOriginalSchema().getValue(), 
is(DefaultDatabase.LOGIC_NAME));
+        assertTrue(tableBinderContexts.containsKey("t_order"));
+        assertTrue(tableBinderContexts.containsKey("t_order_item"));
+    }
+    
+    private ShardingSphereMetaData createMetaData() {
+        ShardingSphereSchema schema = mock(ShardingSphereSchema.class, 
RETURNS_DEEP_STUBS);
+        
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
+                new ShardingSphereColumn("order_id", Types.INTEGER, true, 
false, false, true, false),
+                new ShardingSphereColumn("user_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.INTEGER, false, 
false, false, true, false)));
+        
when(schema.getTable("t_order_item").getColumnValues()).thenReturn(Arrays.asList(
+                new ShardingSphereColumn("item_id", Types.INTEGER, true, 
false, false, true, false),
+                new ShardingSphereColumn("order_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("user_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.INTEGER, false, 
false, false, true, false)));
+        ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, 
RETURNS_DEEP_STUBS);
+        
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+        return result;
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java
index 29565ea9201..f4d329dd7f4 100644
--- 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.infra.database.core.DefaultDatabase;
 import org.apache.shardingsphere.infra.database.mysql.MySQLDatabaseType;
 import 
org.apache.shardingsphere.infra.database.postgresql.PostgreSQLDatabaseType;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
@@ -31,6 +32,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Tab
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 import org.junit.jupiter.api.Test;
 
+import java.sql.Types;
 import java.util.Arrays;
 import java.util.Map;
 
@@ -131,9 +133,14 @@ class SimpleTableSegmentBinderTest {
     }
     
     private ShardingSphereMetaData createMetaData() {
-        ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
-        
when(schema.getAllColumnNames("t_order")).thenReturn(Arrays.asList("order_id", 
"user_id", "status"));
-        
when(schema.getAllColumnNames("pg_database")).thenReturn(Arrays.asList("datname",
 "datdba"));
+        ShardingSphereSchema schema = mock(ShardingSphereSchema.class, 
RETURNS_DEEP_STUBS);
+        
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
+                new ShardingSphereColumn("order_id", Types.INTEGER, true, 
false, false, true, false),
+                new ShardingSphereColumn("user_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.INTEGER, false, 
false, false, true, false)));
+        
when(schema.getTable("pg_database").getColumnValues()).thenReturn(Arrays.asList(
+                new ShardingSphereColumn("datname", Types.VARCHAR, false, 
false, false, true, false),
+                new ShardingSphereColumn("datdba", Types.VARCHAR, false, 
false, false, true, false)));
         ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, 
RETURNS_DEEP_STUBS);
         
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
         
when(result.getDatabase("sharding_db").getSchema("sharding_db")).thenReturn(schema);
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SubqueryTableSegmentBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SubqueryTableSegmentBinderTest.java
new file mode 100644
index 00000000000..7de2337816d
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SubqueryTableSegmentBinderTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.binder.segment.from.impl;
+
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
+import 
org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderContext;
+import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
+import org.apache.shardingsphere.infra.database.mysql.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class SubqueryTableSegmentBinderTest {
+    
+    @Test
+    void assertBindWithAlias() {
+        MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
+        when(selectStatement.getDatabaseType()).thenReturn(new 
MySQLDatabaseType());
+        when(selectStatement.getFrom()).thenReturn(new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order"))));
+        ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
+        projectionsSegment.getProjections().add(new 
ShorthandProjectionSegment(0, 0));
+        when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SubqueryTableSegment subqueryTableSegment = new 
SubqueryTableSegment(new SubquerySegment(0, 0, selectStatement));
+        subqueryTableSegment.setAlias(new AliasSegment(0, 0, new 
IdentifierValue("temp")));
+        ShardingSphereMetaData metaData = createMetaData();
+        Map<String, TableSegmentBinderContext> tableBinderContexts = new 
CaseInsensitiveMap<>();
+        SubqueryTableSegment actual = 
SubqueryTableSegmentBinder.bind(subqueryTableSegment, metaData, 
DefaultDatabase.LOGIC_NAME, tableBinderContexts);
+        assertTrue(actual.getAlias().isPresent());
+        assertTrue(tableBinderContexts.containsKey("temp"));
+    }
+    
+    @Test
+    void assertBindWithoutAlias() {
+        MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
+        when(selectStatement.getDatabaseType()).thenReturn(new 
MySQLDatabaseType());
+        when(selectStatement.getFrom()).thenReturn(new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order"))));
+        ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
+        projectionsSegment.getProjections().add(new 
ShorthandProjectionSegment(0, 0));
+        when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SubqueryTableSegment subqueryTableSegment = new 
SubqueryTableSegment(new SubquerySegment(0, 0, selectStatement));
+        ShardingSphereMetaData metaData = createMetaData();
+        Map<String, TableSegmentBinderContext> tableBinderContexts = new 
CaseInsensitiveMap<>();
+        SubqueryTableSegment actual = 
SubqueryTableSegmentBinder.bind(subqueryTableSegment, metaData, 
DefaultDatabase.LOGIC_NAME, tableBinderContexts);
+        assertFalse(actual.getAlias().isPresent());
+        assertTrue(tableBinderContexts.containsKey(""));
+    }
+    
+    private ShardingSphereMetaData createMetaData() {
+        ShardingSphereSchema schema = mock(ShardingSphereSchema.class, 
RETURNS_DEEP_STUBS);
+        
when(schema.getTable("t_order").getColumnValues()).thenReturn(Arrays.asList(
+                new ShardingSphereColumn("order_id", Types.INTEGER, true, 
false, false, true, false),
+                new ShardingSphereColumn("user_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.INTEGER, false, 
false, false, true, false)));
+        ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, 
RETURNS_DEEP_STUBS);
+        
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+        return result;
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinderTest.java
new file mode 100644
index 00000000000..811c84eccd9
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinderTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.binder.segment.projection.impl;
+
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
+import 
org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderContext;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class ShorthandProjectionSegmentBinderTest {
+    
+    @Test
+    void assertBindWithOwner() {
+        ShorthandProjectionSegment shorthandProjectionSegment = new 
ShorthandProjectionSegment(0, 0);
+        shorthandProjectionSegment.setOwner(new OwnerSegment(0, 0, new 
IdentifierValue("o")));
+        Map<String, TableSegmentBinderContext> tableBinderContexts = new 
CaseInsensitiveMap<>();
+        ColumnProjectionSegment invisibleColumn = new 
ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("status")));
+        invisibleColumn.setVisible(false);
+        tableBinderContexts.put("o", new 
TableSegmentBinderContext(Arrays.asList(new ColumnProjectionSegment(new 
ColumnSegment(0, 0, new IdentifierValue("order_id"))), invisibleColumn)));
+        ShorthandProjectionSegment actual = 
ShorthandProjectionSegmentBinder.bind(shorthandProjectionSegment, 
tableBinderContexts);
+        assertThat(actual.getActualProjectionSegments().size(), is(1));
+        ProjectionSegment visibleColumn = 
actual.getActualProjectionSegments().iterator().next();
+        assertThat(visibleColumn.getColumnLabel(), is("order_id"));
+        assertTrue(visibleColumn.isVisible());
+    }
+}
diff --git 
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ColumnProjectionSegment.java
 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ColumnProjectionSegment.java
index 13f4d54e5f1..e9fb6ef11ae 100644
--- 
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ColumnProjectionSegment.java
+++ 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ColumnProjectionSegment.java
@@ -29,14 +29,16 @@ import java.util.Optional;
 /**
  * Column projection segment.
  */
+@Setter
+@Getter
 public final class ColumnProjectionSegment implements ProjectionSegment, 
AliasAvailable {
     
-    @Getter
     private final ColumnSegment column;
     
-    @Setter
     private AliasSegment alias;
     
+    private boolean visible = true;
+    
     public ColumnProjectionSegment(final ColumnSegment columnSegment) {
         column = columnSegment;
     }
diff --git 
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ProjectionSegment.java
 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ProjectionSegment.java
index e424209d179..558d03d65a6 100644
--- 
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ProjectionSegment.java
+++ 
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ProjectionSegment.java
@@ -30,4 +30,13 @@ public interface ProjectionSegment extends SQLSegment {
      * @return column label
      */
     String getColumnLabel();
+    
+    /**
+     * Judge whether column is visible or not.
+     * 
+     * @return whether column is visible or not
+     */
+    default boolean isVisible() {
+        return true;
+    }
 }
diff --git 
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
 
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
index 620ad795fc5..b025093bb88 100644
--- 
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
+++ 
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.test.it.rewrite.engine.scenario;
 
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -41,6 +42,7 @@ import java.sql.Types;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
@@ -62,23 +64,30 @@ class EncryptSQLRewriterIT extends SQLRewriterIT {
     
     @Override
     protected Map<String, ShardingSphereSchema> mockSchemas(final String 
schemaName) {
-        ShardingSphereSchema result = mock(ShardingSphereSchema.class);
-        
when(result.getAllColumnNames("t_account")).thenReturn(Arrays.asList("account_id",
 "certificate_number", "password", "amount", "status"));
-        
when(result.getAllColumnNames("t_account_bak")).thenReturn(Arrays.asList("account_id",
 "certificate_number", "password", "amount", "status"));
-        
when(result.getAllColumnNames("t_account_detail")).thenReturn(Arrays.asList("account_id",
 "certificate_number", "password", "amount", "status"));
-        
when(result.getAllColumnNames("t_order")).thenReturn(Arrays.asList("ORDER_ID", 
"USER_ID", "CONTENT"));
-        
when(result.getVisibleColumnNames("t_account")).thenReturn(Arrays.asList("account_id",
 "certificate_number", "password", "amount"));
-        
when(result.getVisibleColumnNames("t_account_bak")).thenReturn(Arrays.asList("account_id",
 "certificate_number", "password", "amount"));
-        
when(result.getVisibleColumnNames("t_account_detail")).thenReturn(Arrays.asList("account_id",
 "certificate_number", "password", "amount"));
-        
when(result.getVisibleColumnNames("t_order")).thenReturn(Arrays.asList("ORDER_ID",
 "USER_ID", "CONTENT"));
-        when(result.getTable("t_account")).thenReturn(new 
ShardingSphereTable("t_account", Collections.emptyList(), 
Collections.emptyList(), Collections.emptyList()));
-        when(result.getTable("t_account_bak")).thenReturn(new 
ShardingSphereTable("t_account_bak", Collections.emptyList(), 
Collections.emptyList(), Collections.emptyList()));
-        when(result.getTable("t_account_detail")).thenReturn(new 
ShardingSphereTable("t_account_detail", Collections.emptyList(), 
Collections.emptyList(), Collections.emptyList()));
-        when(result.getTable("t_order")).thenReturn(new 
ShardingSphereTable("t_order", Collections.emptyList(), 
Collections.emptyList(), Collections.emptyList()));
-        when(result.containsTable("t_account")).thenReturn(true);
-        when(result.containsTable("t_account_bak")).thenReturn(true);
-        when(result.containsTable("t_account_detail")).thenReturn(true);
-        when(result.containsTable("t_order")).thenReturn(true);
+        Map<String, ShardingSphereTable> tables = new LinkedHashMap<>();
+        tables.put("t_account", new ShardingSphereTable("t_account", 
Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("certificate_number", Types.INTEGER, 
false, false, false, true, false),
+                new ShardingSphereColumn("password", Types.VARCHAR, false, 
false, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.emptyList(), 
Collections.emptyList()));
+        tables.put("t_account_bak", new ShardingSphereTable("t_account_bak", 
Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("certificate_number", Types.INTEGER, 
false, false, false, true, false),
+                new ShardingSphereColumn("password", Types.VARCHAR, false, 
false, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.emptyList(), 
Collections.emptyList()));
+        tables.put("t_account_detail", new 
ShardingSphereTable("t_account_detail", Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("certificate_number", Types.INTEGER, 
false, false, false, true, false),
+                new ShardingSphereColumn("password", Types.VARCHAR, false, 
false, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.emptyList(), 
Collections.emptyList()));
+        tables.put("t_order", new ShardingSphereTable("t_order", Arrays.asList(
+                new ShardingSphereColumn("ORDER_ID", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("USER_ID", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("CONTENT", Types.VARCHAR, false, 
false, false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        ShardingSphereSchema result = new ShardingSphereSchema(tables, 
Collections.emptyMap());
         return Collections.singletonMap(schemaName, result);
     }
     
diff --git 
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java
 
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java
index 36b06c173c1..7af438650bf 100644
--- 
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java
+++ 
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java
@@ -37,13 +37,10 @@ import java.sql.Types;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedList;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Objects;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 @SQLRewriterITSettings("scenario/mix/case")
 class MixSQLRewriterIT extends SQLRewriterIT {
     
@@ -55,24 +52,23 @@ class MixSQLRewriterIT extends SQLRewriterIT {
     
     @Override
     protected Map<String, ShardingSphereSchema> mockSchemas(final String 
schemaName) {
-        ShardingSphereSchema result = mock(ShardingSphereSchema.class);
-        when(result.getAllTableNames()).thenReturn(Arrays.asList("t_account", 
"t_account_bak", "t_account_detail"));
-        ShardingSphereTable accountTable = mock(ShardingSphereTable.class);
-        when(accountTable.getColumnValues()).thenReturn(createColumns());
-        
when(accountTable.getIndexValues()).thenReturn(Collections.singletonList(new 
ShardingSphereIndex("index_name")));
-        when(result.containsTable("t_account")).thenReturn(true);
-        when(result.containsTable("t_account_bak")).thenReturn(true);
-        when(result.containsTable("t_account_detail")).thenReturn(true);
-        ShardingSphereTable accountBakTable = mock(ShardingSphereTable.class);
-        when(accountBakTable.getColumnValues()).thenReturn(createColumns());
-        when(result.containsTable("t_account_bak")).thenReturn(true);
-        when(result.getTable("t_account")).thenReturn(accountTable);
-        when(result.getTable("t_account_bak")).thenReturn(accountBakTable);
-        
when(result.getTable("t_account_detail")).thenReturn(mock(ShardingSphereTable.class));
-        
when(result.getAllColumnNames("t_account")).thenReturn(Arrays.asList("account_id",
 "password", "amount", "status"));
-        
when(result.getAllColumnNames("t_account_bak")).thenReturn(Arrays.asList("account_id",
 "password", "amount", "status"));
-        
when(result.getVisibleColumnNames("t_account")).thenReturn(Arrays.asList("account_id",
 "password", "amount"));
-        
when(result.getVisibleColumnNames("t_account_bak")).thenReturn(Arrays.asList("account_id",
 "password", "amount"));
+        Map<String, ShardingSphereTable> tables = new LinkedHashMap<>();
+        tables.put("t_account", new ShardingSphereTable("t_account", 
Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, true, 
true, false, true, false),
+                new ShardingSphereColumn("password", Types.VARCHAR, false, 
false, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.singletonList(new 
ShardingSphereIndex("index_name")), Collections.emptyList()));
+        tables.put("t_account_bak", new ShardingSphereTable("t_account_bak", 
Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, true, 
true, false, true, false),
+                new ShardingSphereColumn("password", Types.VARCHAR, false, 
false, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.emptyList(), 
Collections.emptyList()));
+        tables.put("t_account_detail", new 
ShardingSphereTable("t_account_detail", Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("password", Types.VARCHAR, false, 
false, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.emptyList(), 
Collections.emptyList()));
+        ShardingSphereSchema result = new ShardingSphereSchema(tables, 
Collections.emptyMap());
         return Collections.singletonMap(schemaName, result);
     }
     
@@ -83,13 +79,4 @@ class MixSQLRewriterIT extends SQLRewriterIT {
     @Override
     protected void mockDataSource(final Map<String, DataSource> dataSources) {
     }
-    
-    private Collection<ShardingSphereColumn> createColumns() {
-        Collection<ShardingSphereColumn> result = new LinkedList<>();
-        result.add(new ShardingSphereColumn("account_id", Types.INTEGER, true, 
true, false, true, false));
-        result.add(mock(ShardingSphereColumn.class));
-        result.add(mock(ShardingSphereColumn.class));
-        result.add(mock(ShardingSphereColumn.class));
-        return result;
-    }
 }
diff --git 
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
 
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
index e9bac09c7a7..49b7368b5ca 100644
--- 
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
+++ 
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
@@ -36,18 +36,14 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 import java.sql.Types;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedList;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 @SQLRewriterITSettings("scenario/sharding/case")
 class ShardingSQLRewriterIT extends SQLRewriterIT {
     
@@ -68,46 +64,38 @@ class ShardingSQLRewriterIT extends SQLRewriterIT {
     
     @Override
     protected Map<String, ShardingSphereSchema> mockSchemas(final String 
schemaName) {
-        ShardingSphereSchema result = mock(ShardingSphereSchema.class);
-        when(result.getAllTableNames()).thenReturn(Arrays.asList("t_account", 
"t_account_detail"));
-        ShardingSphereTable accountTableMetaData = 
mock(ShardingSphereTable.class);
-        
when(accountTableMetaData.getColumnValues()).thenReturn(createColumnMetaDataMap());
-        
when(accountTableMetaData.getIndexValues()).thenReturn(Collections.singletonList(new
 ShardingSphereIndex("status_idx_exist")));
-        
when(accountTableMetaData.containsIndex("status_idx_exist")).thenReturn(true);
-        
when(accountTableMetaData.getPrimaryKeyColumns()).thenReturn(Collections.singletonList("account_id"));
-        when(result.containsTable("t_account")).thenReturn(true);
-        when(result.getTable("t_account")).thenReturn(accountTableMetaData);
-        
when(result.getTable("t_account_detail")).thenReturn(mock(ShardingSphereTable.class));
-        when(result.getAllColumnNames("t_account")).thenReturn(new 
ArrayList<>(Arrays.asList("account_id", "amount", "status")));
-        when(result.getAllColumnNames("t_user")).thenReturn(new 
ArrayList<>(Arrays.asList("id", "content")));
-        when(result.getAllColumnNames("t_user_extend")).thenReturn(new 
ArrayList<>(Arrays.asList("user_id", "content")));
-        when(result.getAllColumnNames("t_single")).thenReturn(new 
ArrayList<>(Collections.singletonList("id")));
-        when(result.getAllColumnNames("t_single_extend")).thenReturn(new 
ArrayList<>(Collections.singletonList("id")));
-        when(result.getVisibleColumnNames("t_account")).thenReturn(new 
ArrayList<>(Arrays.asList("account_id", "amount")));
-        when(result.getVisibleColumnNames("t_user")).thenReturn(new 
ArrayList<>(Arrays.asList("id", "content")));
-        when(result.getVisibleColumnNames("t_user_extend")).thenReturn(new 
ArrayList<>(Arrays.asList("user_id", "content")));
-        when(result.containsColumn("t_account", 
"account_id")).thenReturn(true);
-        when(result.containsTable("t_account")).thenReturn(true);
-        when(result.containsTable("t_account_detail")).thenReturn(true);
-        when(result.containsTable("t_user")).thenReturn(true);
-        when(result.containsTable("t_user_extend")).thenReturn(true);
-        when(result.containsTable("t_single")).thenReturn(true);
-        when(result.containsTable("t_single_extend")).thenReturn(true);
-        when(result.containsTable("t_config")).thenReturn(true);
-        when(result.containsTable("T_ROLE")).thenReturn(true);
-        when(result.containsTable("T_ROLE_ADMIN")).thenReturn(true);
-        when(result.containsTable("t_account_view")).thenReturn(true);
+        Map<String, ShardingSphereTable> tables = new LinkedHashMap<>();
+        tables.put("t_account", new ShardingSphereTable("t_account", 
Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, true, 
true, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.singletonList(new 
ShardingSphereIndex("status_idx_exist")),
+                Collections.emptyList()));
+        tables.put("t_account_detail", new 
ShardingSphereTable("t_account_detail", Arrays.asList(
+                new ShardingSphereColumn("account_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("amount", Types.DECIMAL, false, 
false, false, true, false),
+                new ShardingSphereColumn("status", Types.TINYINT, false, 
false, false, false, false)), Collections.emptyList(), 
Collections.emptyList()));
+        tables.put("t_user", new ShardingSphereTable("t_user", Arrays.asList(
+                new ShardingSphereColumn("id", Types.INTEGER, false, false, 
false, true, false),
+                new ShardingSphereColumn("content", Types.VARCHAR, false, 
false, false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        tables.put("t_user_extend", new ShardingSphereTable("t_user_extend", 
Arrays.asList(
+                new ShardingSphereColumn("user_id", Types.INTEGER, false, 
false, false, true, false),
+                new ShardingSphereColumn("content", Types.VARCHAR, false, 
false, false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        tables.put("t_single", new ShardingSphereTable("t_single", 
Collections.singletonList(
+                new ShardingSphereColumn("id", Types.INTEGER, false, false, 
false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        tables.put("t_single_extend", new 
ShardingSphereTable("t_single_extend", Collections.singletonList(
+                new ShardingSphereColumn("id", Types.INTEGER, false, false, 
false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        tables.put("t_config", new ShardingSphereTable("t_config", 
Collections.singletonList(
+                new ShardingSphereColumn("id", Types.INTEGER, false, false, 
false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        tables.put("T_ROLE", new ShardingSphereTable("T_ROLE", 
Collections.singletonList(
+                new ShardingSphereColumn("id", Types.INTEGER, false, false, 
false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        tables.put("T_ROLE_ADMIN", new ShardingSphereTable("T_ROLE_ADMIN", 
Collections.singletonList(
+                new ShardingSphereColumn("id", Types.INTEGER, false, false, 
false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        tables.put("t_account_view", new ShardingSphereTable("t_account_view", 
Collections.singletonList(
+                new ShardingSphereColumn("id", Types.INTEGER, false, false, 
false, true, false)), Collections.emptyList(), Collections.emptyList()));
+        ShardingSphereSchema result = new ShardingSphereSchema(tables, 
Collections.emptyMap());
         return Collections.singletonMap(schemaName, result);
     }
     
-    private Collection<ShardingSphereColumn> createColumnMetaDataMap() {
-        Collection<ShardingSphereColumn> result = new LinkedList<>();
-        result.add(new ShardingSphereColumn("account_id", Types.INTEGER, true, 
true, false, true, false));
-        result.add(mock(ShardingSphereColumn.class));
-        result.add(mock(ShardingSphereColumn.class));
-        return result;
-    }
-    
     @Override
     protected void mockDataSource(final Map<String, DataSource> dataSources) {
     }
diff --git 
a/test/it/rewriter/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-projection.xml
 
b/test/it/rewriter/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-projection.xml
index dd03c43cc7f..37f2f3bd669 100644
--- 
a/test/it/rewriter/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-projection.xml
+++ 
b/test/it/rewriter/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-projection.xml
@@ -29,8 +29,8 @@
     
     <rewrite-assertion 
id="select_with_sharding_qualified_shorthand_join_table" db-types="MySQL">
         <input sql="SELECT b.* FROM t_account a, t_account_detail b where 
a.password = b.password" />
-        <output sql="SELECT b.* FROM t_account_0 a, t_account_detail_0 b where 
a.assisted_query_password = b.assisted_query_password" />
-        <output sql="SELECT b.* FROM t_account_1 a, t_account_detail_1 b where 
a.assisted_query_password = b.assisted_query_password" />
+        <output sql="SELECT b.`account_id`, b.`cipher_password` AS `password`, 
b.`cipher_amount` AS `amount` FROM t_account_0 a, t_account_detail_0 b where 
a.assisted_query_password = b.assisted_query_password" />
+        <output sql="SELECT b.`account_id`, b.`cipher_password` AS `password`, 
b.`cipher_amount` AS `amount` FROM t_account_1 a, t_account_detail_1 b where 
a.assisted_query_password = b.assisted_query_password" />
     </rewrite-assertion>
     
     <rewrite-assertion id="select_with_encrypt_qualified_shorthand_join_table" 
db-types="MySQL">

Reply via email to