You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/07/20 02:36:54 UTC

[shardingsphere] branch master updated: Add ProjectionUtils to handle column name and column label (#27304)

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

zhaojinchao 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 32adbeaab15 Add ProjectionUtils to handle column name and column label (#27304)
32adbeaab15 is described below

commit 32adbeaab157b04894d424d4fa5c32f00d4871b6
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Thu Jul 20 10:36:46 2023 +0800

    Add ProjectionUtils to handle column name and column label (#27304)
    
    * Add ProjectionUtils to handle column name and column label
    
    * Fix sonar issue in MySQLStatementVisitor
    
    * Add more unit test for AggregationProjection
    
    * fix unit test
    
    * Add getExpression in Projection to distinct with getColumnName
---
 .../encrypt/merge/dql/EncryptMergedResult.java     |  2 +-
 .../generator/EncryptProjectionTokenGenerator.java |  4 +-
 .../mask/merge/dql/MaskAlgorithmMetaData.java      |  2 +-
 .../generator/impl/ProjectionsTokenGenerator.java  |  2 +-
 .../token/ProjectionsTokenGeneratorTest.java       |  2 +-
 .../segment/select/projection/Projection.java      |  7 +++
 .../select/projection/ProjectionsContext.java      | 10 +--
 .../select/projection/engine/ProjectionEngine.java |  2 +-
 .../engine/ProjectionsContextEngine.java           |  2 +-
 .../impl/AggregationDistinctProjection.java        |  9 ---
 .../projection/impl/AggregationProjection.java     | 12 +++-
 .../select/projection/impl/ColumnProjection.java   | 32 +++++-----
 .../projection/impl/ParameterMarkerProjection.java |  5 ++
 .../projection/impl/ShorthandProjection.java       |  5 ++
 .../select/projection/util/ProjectionUtils.java    | 72 ++++++++++++++++++++++
 .../infra/binder/segment/table/TablesContext.java  |  8 +--
 .../statement/dml/SelectStatementContext.java      |  2 +-
 .../select/projection/ProjectionsContextTest.java  |  4 +-
 .../impl/AggregationDistinctProjectionTest.java    |  5 --
 .../projection/impl/AggregationProjectionTest.java | 62 ++++++++++++-------
 .../projection/impl/ShorthandProjectionTest.java   |  2 +-
 .../statement/dml/SelectStatementContextTest.java  |  5 +-
 .../resultset/ShardingSphereResultSetMetaData.java |  4 +-
 .../resultset/ShardingSphereResultSetUtils.java    |  2 +-
 .../resultset/SQLFederationResultSet.java          |  2 +-
 .../resultset/SQLFederationResultSetMetaData.java  |  2 +-
 .../header/query/QueryHeaderBuilderEngine.java     |  4 +-
 .../admin/executor/NoResourceShowExecutor.java     |  4 +-
 .../prepare/MySQLComStmtPrepareExecutor.java       |  4 +-
 29 files changed, 186 insertions(+), 92 deletions(-)

diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java
index bf02065f086..d4b231aeff6 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java
@@ -78,7 +78,7 @@ public final class EncryptMergedResult implements MergedResult {
     }
     
     private Optional<String> findTableName(final ColumnProjection columnProjection, final Map<String, String> columnTableNames) {
-        String tableName = columnTableNames.get(columnProjection.getColumnName());
+        String tableName = columnTableNames.get(columnProjection.getExpression());
         if (null != tableName) {
             return Optional.of(tableName);
         }
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGenerator.java
index 525cfd32680..75980dd3e31 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGenerator.java
@@ -91,7 +91,7 @@ public final class EncryptProjectionTokenGenerator implements CollectionSQLToken
             if (each instanceof ColumnProjectionSegment) {
                 ColumnProjectionSegment columnSegment = (ColumnProjectionSegment) each;
                 ColumnProjection columnProjection = buildColumnProjection(columnSegment);
-                String tableName = columnTableNames.get(columnProjection.getColumnName());
+                String tableName = columnTableNames.get(columnProjection.getExpression());
                 if (null == tableName) {
                     continue;
                 }
@@ -122,7 +122,7 @@ public final class EncryptProjectionTokenGenerator implements CollectionSQLToken
                                                           final SelectStatementContext selectStatementContext, final SubqueryType subqueryType, final Map<String, String> columnTableNames) {
         List<Projection> projections = new LinkedList<>();
         for (Projection each : actualColumns) {
-            String tableName = columnTableNames.get(each.getColumnName());
+            String tableName = columnTableNames.get(each.getExpression());
             Optional<EncryptTable> encryptTable = null == tableName ? Optional.empty() : encryptRule.findEncryptTable(tableName);
             if (!encryptTable.isPresent() || !encryptTable.get().isEncryptColumn(each.getColumnLabel()) || containsTableSubquery(selectStatementContext)) {
                 projections.add(each.getAlias().map(optional -> (Projection) new ColumnProjection(null, optional, null)).orElse(each));
diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java
index 5f8ecaaab7d..5c0757c2af4 100644
--- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java
+++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java
@@ -73,7 +73,7 @@ public final class MaskAlgorithmMetaData {
     }
     
     private Optional<String> findTableName(final ColumnProjection columnProjection, final Map<String, String> columnTableNames) {
-        String tableName = columnTableNames.get(columnProjection.getColumnName());
+        String tableName = columnTableNames.get(columnProjection.getExpression());
         if (null != tableName) {
             return Optional.of(tableName);
         }
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
index 20f5eb43223..377db5803e0 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
@@ -100,7 +100,7 @@ public final class ProjectionsTokenGenerator implements OptionalSQLTokenGenerato
         if (projection instanceof AggregationDistinctProjection) {
             return ((AggregationDistinctProjection) projection).getDistinctInnerExpression() + " AS " + projection.getAlias().get().getValue() + " ";
         }
-        return projection.getColumnName() + " AS " + projection.getAlias().get().getValue() + " ";
+        return projection.getExpression() + " AS " + projection.getAlias().get().getValue() + " ";
     }
     
     private String getDerivedProjectionTextFromColumnOrderByItemSegment(final DerivedProjection projection, final TableExtractor tableExtractor, final RouteUnit routeUnit,
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java
index e05c888d762..ae6e59337f0 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java
@@ -151,7 +151,7 @@ class ProjectionsTokenGeneratorTest {
         DerivedProjection result = mock(DerivedProjection.class);
         when(result.getDerivedProjectionSegment()).thenReturn(null);
         when(result.getAlias()).thenReturn(Optional.of(new IdentifierValue(TEST_OTHER_DERIVED_PROJECTION_ALIAS)));
-        when(result.getColumnName()).thenReturn(TEST_OTHER_DERIVED_PROJECTION_EXPRESSION);
+        when(result.getExpression()).thenReturn(TEST_OTHER_DERIVED_PROJECTION_EXPRESSION);
         return result;
     }
 }
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/Projection.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/Projection.java
index 80af9bcdf10..b53f4ec1811 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/Projection.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/Projection.java
@@ -40,6 +40,13 @@ public interface Projection {
      */
     String getColumnLabel();
     
+    /**
+     * Get expression.
+     *
+     * @return expression
+     */
+    String getExpression();
+    
     /**
      * Get alias.
      *
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java
index 152dd927a6a..523c7b27ac6 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java
@@ -113,10 +113,10 @@ public final class ProjectionsContext {
                 Optional<Projection> projection =
                         ((ShorthandProjection) each).getActualColumns().stream().filter(optional -> projectionName.equalsIgnoreCase(getOriginalColumnName(optional))).findFirst();
                 if (projection.isPresent()) {
-                    return projection.map(Projection::getColumnName);
+                    return projection.map(Projection::getExpression);
                 }
             }
-            if (projectionName.equalsIgnoreCase(SQLUtils.getExactlyValue(each.getColumnName()))) {
+            if (projectionName.equalsIgnoreCase(SQLUtils.getExactlyValue(each.getExpression()))) {
                 return each.getAlias().map(IdentifierValue::getValue);
             }
         }
@@ -124,7 +124,7 @@ public final class ProjectionsContext {
     }
     
     private String getOriginalColumnName(final Projection projection) {
-        return projection instanceof ColumnProjection ? ((ColumnProjection) projection).getOriginalName().getValue() : projection.getColumnName();
+        return projection instanceof ColumnProjection ? ((ColumnProjection) projection).getOriginalName().getValue() : projection.getExpression();
     }
     
     /**
@@ -136,7 +136,7 @@ public final class ProjectionsContext {
     public Optional<Integer> findProjectionIndex(final String projectionName) {
         int result = 1;
         for (Projection each : projections) {
-            if (projectionName.equalsIgnoreCase(SQLUtils.getExactlyValue(each.getColumnName()))) {
+            if (projectionName.equalsIgnoreCase(SQLUtils.getExactlyValue(each.getExpression()))) {
                 return Optional.of(result);
             }
             result++;
@@ -163,7 +163,7 @@ public final class ProjectionsContext {
     
     private boolean isContainsLastInsertIdProjection(final Collection<Projection> projections) {
         for (Projection each : projections) {
-            if (LAST_INSERT_ID_FUNCTION_EXPRESSION.equalsIgnoreCase(SQLUtils.getExactlyExpression(each.getColumnName()))) {
+            if (LAST_INSERT_ID_FUNCTION_EXPRESSION.equalsIgnoreCase(SQLUtils.getExactlyExpression(each.getExpression()))) {
                 return true;
             }
         }
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java
index 1424703ba4f..d318ba9bada 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java
@@ -219,7 +219,7 @@ public final class ProjectionEngine {
         Collection<Projection> remainingProjections = new LinkedList<>();
         for (Projection each : getOriginalProjections(joinTable, projectionSegment)) {
             Collection<Projection> actualProjections = getActualProjections(Collections.singletonList(each));
-            if (joinTable.getUsing().isEmpty() && !joinTable.isNatural() || null != owner && each.getColumnName().contains(owner.getValue())) {
+            if (joinTable.getUsing().isEmpty() && !joinTable.isNatural() || null != owner && each.getExpression().contains(owner.getValue())) {
                 result.addAll(actualProjections);
             } else {
                 remainingProjections.addAll(actualProjections);
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java
index 005d9ba713d..d5458b77e0c 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java
@@ -150,6 +150,6 @@ public final class ProjectionsContextEngine {
     }
     
     private boolean isSameQualifiedName(final Projection projection, final String text) {
-        return SQLUtils.getExactlyValue(text).equalsIgnoreCase(SQLUtils.getExactlyValue(projection.getColumnName()));
+        return SQLUtils.getExactlyValue(text).equalsIgnoreCase(SQLUtils.getExactlyValue(projection.getExpression()));
     }
 }
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjection.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjection.java
index db30990cfc8..7e1e42c2cd6 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjection.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjection.java
@@ -45,15 +45,6 @@ public final class AggregationDistinctProjection extends AggregationProjection {
         this.distinctInnerExpression = distinctInnerExpression;
     }
     
-    /**
-     * Get distinct column label.
-     *
-     * @return distinct column label
-     */
-    public String getDistinctColumnLabel() {
-        return getAlias().map(IdentifierValue::getValue).orElse(distinctInnerExpression);
-    }
-    
     @Override
     public Projection transformSubqueryProjection(final IdentifierValue subqueryTableAlias, final IdentifierValue originalOwner, final IdentifierValue originalName) {
         return getAlias().isPresent() ? new ColumnProjection(subqueryTableAlias, getAlias().get(), null)
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
index 5c955a28b3d..cd30988df9c 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
@@ -23,6 +23,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.Setter;
 import lombok.ToString;
 import org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.util.ProjectionUtils;
 import org.apache.shardingsphere.infra.database.spi.DatabaseType;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -54,13 +55,18 @@ public class AggregationProjection implements Projection {
     private int index = -1;
     
     @Override
-    public final String getColumnName() {
-        return type.name() + innerExpression;
+    public String getColumnName() {
+        return ProjectionUtils.getColumnNameFromFunction(type.name(), type.name() + innerExpression, databaseType);
     }
     
     @Override
     public String getColumnLabel() {
-        return getAlias().map(IdentifierValue::getValue).orElseGet(() -> databaseType.getDefaultSchema().isPresent() ? type.name().toLowerCase() : getColumnName());
+        return getAlias().isPresent() ? ProjectionUtils.getColumnLabelFromAlias(getAlias().get(), databaseType) : getColumnName();
+    }
+    
+    @Override
+    public String getExpression() {
+        return type.name() + innerExpression;
     }
     
     @Override
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ColumnProjection.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ColumnProjection.java
index b015744089a..b93debb2d42 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ColumnProjection.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ColumnProjection.java
@@ -53,24 +53,6 @@ public final class ColumnProjection implements Projection {
                 null == alias ? null : new IdentifierValue(alias, QuoteCharacter.NONE));
     }
     
-    /**
-     * Get column name.
-     * 
-     * @return column name
-     */
-    public IdentifierValue getName() {
-        return name;
-    }
-    
-    /**
-     * Get owner.
-     * 
-     * @return owner
-     */
-    public Optional<IdentifierValue> getOwner() {
-        return Optional.ofNullable(owner);
-    }
-    
     @Override
     public String getColumnName() {
         return null == owner ? name.getValue() : owner.getValue() + "." + name.getValue();
@@ -81,6 +63,11 @@ public final class ColumnProjection implements Projection {
         return getAlias().map(IdentifierValue::getValue).orElse(name.getValue());
     }
     
+    @Override
+    public String getExpression() {
+        return null == owner ? name.getValue() : owner.getValue() + "." + name.getValue();
+    }
+    
     @Override
     public Optional<IdentifierValue> getAlias() {
         return Optional.ofNullable(alias);
@@ -94,6 +81,15 @@ public final class ColumnProjection implements Projection {
         return result;
     }
     
+    /**
+     * Get owner.
+     *
+     * @return owner
+     */
+    public Optional<IdentifierValue> getOwner() {
+        return Optional.ofNullable(owner);
+    }
+    
     /**
      * Get original owner.
      *
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ParameterMarkerProjection.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ParameterMarkerProjection.java
index e855bcb1674..7bb8803f2d0 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ParameterMarkerProjection.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ParameterMarkerProjection.java
@@ -52,6 +52,11 @@ public final class ParameterMarkerProjection implements Projection {
         return getAlias().map(IdentifierValue::getValue).orElseGet(() -> String.valueOf(parameterMarkerIndex));
     }
     
+    @Override
+    public String getExpression() {
+        return String.valueOf(parameterMarkerIndex);
+    }
+    
     @Override
     public Optional<IdentifierValue> getAlias() {
         return Optional.ofNullable(alias);
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjection.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjection.java
index 339d1fd35c1..18e125046e0 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjection.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjection.java
@@ -51,6 +51,11 @@ public final class ShorthandProjection implements Projection {
         return "*";
     }
     
+    @Override
+    public String getExpression() {
+        return null == owner ? "*" : owner.getValue() + ".*";
+    }
+    
     @Override
     public Optional<IdentifierValue> getAlias() {
         return Optional.empty();
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/util/ProjectionUtils.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/util/ProjectionUtils.java
new file mode 100644
index 00000000000..9db7d17877b
--- /dev/null
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/util/ProjectionUtils.java
@@ -0,0 +1,72 @@
+/*
+ * 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.select.projection.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.database.opengauss.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.oracle.OracleDatabaseType;
+import org.apache.shardingsphere.infra.database.postgresql.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
+import org.apache.shardingsphere.infra.util.quote.QuoteCharacter;
+import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+
+/**
+ * Projection utility class.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ProjectionUtils {
+    
+    /**
+     * Get column label from alias.
+     * 
+     * @param alias alias
+     * @param databaseType database type
+     * @return column label
+     */
+    public static String getColumnLabelFromAlias(final IdentifierValue alias, final DatabaseType databaseType) {
+        if (QuoteCharacter.NONE != alias.getQuoteCharacter()) {
+            return alias.getValue();
+        }
+        if (databaseType instanceof PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType) {
+            return alias.getValue().toLowerCase();
+        }
+        if (databaseType instanceof OracleDatabaseType) {
+            return alias.getValue().toUpperCase();
+        }
+        return alias.getValue();
+    }
+    
+    /**
+     * Get column name from function.
+     * 
+     * @param functionName function name
+     * @param functionExpression function expression
+     * @param databaseType database type
+     * @return column name
+     */
+    public static String getColumnNameFromFunction(final String functionName, final String functionExpression, final DatabaseType databaseType) {
+        if (databaseType instanceof PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType) {
+            return functionName.toLowerCase();
+        }
+        if (databaseType instanceof OracleDatabaseType) {
+            return functionExpression.replace(" ", "").toUpperCase();
+        }
+        return functionExpression;
+    }
+}
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
index 557b1125c07..1d1f7f6a4c0 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
@@ -181,13 +181,13 @@ public final class TablesContext {
         }
         Map<String, String> result = new LinkedHashMap<>(columns.size(), 1F);
         for (ColumnProjection each : columns) {
-            if (ownerTableNames.containsKey(each.getColumnName())) {
+            if (ownerTableNames.containsKey(each.getExpression())) {
                 continue;
             }
             Collection<SubqueryTableContext> subqueryTableContexts = each.getOwner().map(optional -> subqueryTables.get(each.getOwner().get().getValue())).orElseGet(Collections::emptyList);
             for (SubqueryTableContext subqueryTableContext : subqueryTableContexts) {
                 if (subqueryTableContext.getColumnNames().contains(each.getName().getValue())) {
-                    result.put(each.getColumnName(), subqueryTableContext.getTableName());
+                    result.put(each.getExpression(), subqueryTableContext.getTableName());
                 }
             }
         }
@@ -207,7 +207,7 @@ public final class TablesContext {
         String tableName = simpleTableSegments.iterator().next().getTableName().getIdentifier().getValue();
         Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         for (ColumnProjection each : columns) {
-            result.putIfAbsent(each.getColumnName(), tableName);
+            result.putIfAbsent(each.getExpression(), tableName);
         }
         return result;
     }
@@ -227,7 +227,7 @@ public final class TablesContext {
         Map<String, Collection<String>> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         for (ColumnProjection each : columns) {
             if (each.getOwner().isPresent()) {
-                result.computeIfAbsent(each.getOwner().get().getValue(), unused -> new LinkedList<>()).add(each.getColumnName());
+                result.computeIfAbsent(each.getOwner().get().getValue(), unused -> new LinkedList<>()).add(each.getExpression());
             }
         }
         return result;
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index 70c59b55a64..46cb79eacfd 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -293,7 +293,7 @@ public final class SelectStatementContext extends CommonSQLStatementContext impl
         String rawName = SQLUtils.getExactlyValue(((TextOrderByItemSegment) orderByItem).getText());
         for (Projection each : projectionsContext.getProjections()) {
             Optional<String> result = each.getAlias().map(IdentifierValue::getValue);
-            if (SQLUtils.getExactlyExpression(rawName).equalsIgnoreCase(SQLUtils.getExactlyExpression(SQLUtils.getExactlyValue(each.getColumnName())))) {
+            if (SQLUtils.getExactlyExpression(rawName).equalsIgnoreCase(SQLUtils.getExactlyExpression(SQLUtils.getExactlyValue(each.getExpression())))) {
                 return result;
             }
             if (rawName.equalsIgnoreCase(result.orElse(null))) {
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContextTest.java
index d7e0a3543d3..2f45cc770f4 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContextTest.java
@@ -77,14 +77,14 @@ class ProjectionsContextTest {
     void assertFindAlias() {
         Projection projection = getColumnProjectionWithAlias();
         ProjectionsContext projectionsContext = new ProjectionsContext(0, 0, true, Collections.singleton(projection));
-        assertTrue(projectionsContext.findAlias(projection.getColumnName()).isPresent());
+        assertTrue(projectionsContext.findAlias(projection.getExpression()).isPresent());
     }
     
     @Test
     void assertFindProjectionIndex() {
         Projection projection = getColumnProjection();
         ProjectionsContext projectionsContext = new ProjectionsContext(0, 0, true, Collections.singleton(projection));
-        Optional<Integer> actual = projectionsContext.findProjectionIndex(projection.getColumnName());
+        Optional<Integer> actual = projectionsContext.findProjectionIndex(projection.getExpression());
         assertTrue(actual.isPresent());
         assertThat(actual.get(), is(1));
     }
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjectionTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjectionTest.java
index fe731e1edc2..5cb37a3280a 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjectionTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationDistinctProjectionTest.java
@@ -31,11 +31,6 @@ class AggregationDistinctProjectionTest {
     private final AggregationDistinctProjection aggregationDistinctProjection = new AggregationDistinctProjection(
             0, 0, AggregationType.COUNT, "(DISTINCT order_id)", new IdentifierValue("c"), "order_id", mock(DatabaseType.class));
     
-    @Test
-    void assertGetDistinctColumnLabel() {
-        assertThat(aggregationDistinctProjection.getDistinctColumnLabel(), is("c"));
-    }
-    
     @Test
     void assertGetDistinctColumnName() {
         assertThat(aggregationDistinctProjection.getDistinctInnerExpression(), is("order_id"));
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
index 6dca8fd0d49..d154f585dcb 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
@@ -18,8 +18,12 @@
 package org.apache.shardingsphere.infra.binder.segment.select.projection.impl;
 
 import org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
+import org.apache.shardingsphere.infra.database.mysql.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.database.opengauss.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.oracle.OracleDatabaseType;
+import org.apache.shardingsphere.infra.database.postgresql.PostgreSQLDatabaseType;
 import org.apache.shardingsphere.infra.database.spi.DatabaseType;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.infra.util.quote.QuoteCharacter;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 import org.junit.jupiter.api.Test;
@@ -34,40 +38,52 @@ import static org.mockito.Mockito.mock;
 class AggregationProjectionTest {
     
     @Test
-    void assertGetExpression() {
-        Projection projection = new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, mock(DatabaseType.class));
-        assertThat(projection.getColumnName(), is("COUNT( A.\"DIRECTION\" )"));
+    void assertGetColumnName() {
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, new MySQLDatabaseType()).getColumnName(), is("COUNT( A.\"DIRECTION\" )"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, new PostgreSQLDatabaseType()).getColumnName(), is("count"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, new OpenGaussDatabaseType()).getColumnName(), is("count"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( a.\"direction\" )", null, new OracleDatabaseType()).getColumnName(), is("COUNT(A.\"DIRECTION\")"));
     }
     
     @Test
-    void assertGetAlias() {
-        Projection projection = new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0"), mock(DatabaseType.class));
-        Optional<IdentifierValue> actual = projection.getAlias();
-        assertTrue(actual.isPresent());
-        assertThat(actual.get().getValue(), is("AVG_DERIVED_COUNT_0"));
+    void assertGetColumnLabelWithAliasNoQuote() {
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0"), new MySQLDatabaseType()).getColumnLabel(),
+                is("AVG_DERIVED_COUNT_0"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0"), new PostgreSQLDatabaseType()).getColumnLabel(),
+                is("avg_derived_count_0"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0"), new OpenGaussDatabaseType()).getColumnLabel(),
+                is("avg_derived_count_0"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("avg_derived_count_0"), new OracleDatabaseType()).getColumnLabel(),
+                is("AVG_DERIVED_COUNT_0"));
     }
     
     @Test
-    void assertGetColumnLabelWithAlias() {
-        Projection projection = new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0"), mock(DatabaseType.class));
-        assertThat(projection.getColumnLabel(), is("AVG_DERIVED_COUNT_0"));
+    void assertGetColumnLabelWithAliasAndQuote() {
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0", QuoteCharacter.BACK_QUOTE), new MySQLDatabaseType())
+                .getColumnLabel(), is("AVG_DERIVED_COUNT_0"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0", QuoteCharacter.QUOTE), new PostgreSQLDatabaseType())
+                .getColumnLabel(), is("AVG_DERIVED_COUNT_0"));
+        assertThat(
+                new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0", QuoteCharacter.QUOTE), new OpenGaussDatabaseType()).getColumnLabel(),
+                is("AVG_DERIVED_COUNT_0"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("avg_derived_count_0", QuoteCharacter.QUOTE), new OracleDatabaseType()).getColumnLabel(),
+                is("avg_derived_count_0"));
     }
     
     @Test
     void assertGetColumnLabelWithoutAlias() {
-        Projection projection = new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, mock(DatabaseType.class));
-        assertThat(projection.getColumnLabel(), is("COUNT( A.\"DIRECTION\" )"));
-    }
-    
-    @Test
-    void assertGetColumnLabelWithoutAliasForPostgreSQL() {
-        Projection projection = new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
-        assertThat(projection.getColumnLabel(), is("count"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, new MySQLDatabaseType()).getColumnLabel(), is("COUNT( A.\"DIRECTION\" )"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, new PostgreSQLDatabaseType()).getColumnLabel(), is("count"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, new OpenGaussDatabaseType()).getColumnLabel(), is("count"));
+        assertThat(new AggregationProjection(AggregationType.COUNT, "( a.\"direction\" )", null, new OracleDatabaseType()).getColumnLabel(), is("COUNT(A.\"DIRECTION\")"));
     }
     
     @Test
-    void assertGetColumnLabelWithoutAliasForOpenGauss() {
-        Projection projection = new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, TypedSPILoader.getService(DatabaseType.class, "openGauss"));
-        assertThat(projection.getColumnLabel(), is("count"));
+    void assertGetAlias() {
+        Projection projection = new AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", new IdentifierValue("AVG_DERIVED_COUNT_0"), mock(DatabaseType.class));
+        Optional<IdentifierValue> actual = projection.getAlias();
+        assertTrue(actual.isPresent());
+        assertThat(actual.get().getValue(), is("AVG_DERIVED_COUNT_0"));
+        assertThat(actual.get().getQuoteCharacter(), is(QuoteCharacter.NONE));
     }
 }
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjectionTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjectionTest.java
index 2d723308d68..7555bc427e8 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjectionTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/ShorthandProjectionTest.java
@@ -31,7 +31,7 @@ class ShorthandProjectionTest {
     
     @Test
     void assertGetExpression() {
-        assertThat(new ShorthandProjection(new IdentifierValue("owner"), Collections.emptyList()).getColumnName(), is("owner.*"));
+        assertThat(new ShorthandProjection(new IdentifierValue("owner"), Collections.emptyList()).getExpression(), is("owner.*"));
     }
     
     @Test
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContextTest.java
index e397634f65f..c7577a61377 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContextTest.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
 import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
 import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule;
+import org.apache.shardingsphere.infra.util.quote.QuoteCharacter;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.NullsOrderType;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection;
@@ -358,13 +359,13 @@ class SelectStatementContextTest {
     }
     
     private void assertSetIndexWhenAggregationProjectionsPresent(final SelectStatement selectStatement) {
-        final ShardingSphereDatabase database = mockDatabase();
         selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITHOUT_OWNER_ALIAS))));
         ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
         AggregationProjectionSegment aggregationProjectionSegment = new AggregationProjectionSegment(0, 0, AggregationType.MAX, "");
-        aggregationProjectionSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue("id")));
+        aggregationProjectionSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue("id", QuoteCharacter.QUOTE)));
         projectionsSegment.getProjections().add(aggregationProjectionSegment);
         selectStatement.setProjections(projectionsSegment);
+        ShardingSphereDatabase database = mockDatabase();
         SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
         selectStatementContext.setIndexes(Collections.singletonMap("id", 3));
         assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(3));
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java
index 0c2b5f15916..c91ac1df616 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java
@@ -102,7 +102,7 @@ public final class ShardingSphereResultSetMetaData extends WrapperAdapter implem
             checkColumnIndex(column);
             Projection projection = ((SelectStatementContext) sqlStatementContext).getProjectionsContext().getExpandProjections().get(column - 1);
             if (projection instanceof AggregationDistinctProjection) {
-                return DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getColumnName() : projection.getColumnLabel();
+                return DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getExpression() : projection.getColumnLabel();
             }
         }
         return resultSetMetaData.getColumnLabel(column);
@@ -117,7 +117,7 @@ public final class ShardingSphereResultSetMetaData extends WrapperAdapter implem
                 return ((ColumnProjection) projection).getName().getValue();
             }
             if (projection instanceof AggregationDistinctProjection) {
-                return DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getColumnName() : projection.getColumnLabel();
+                return DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getExpression() : projection.getColumnLabel();
             }
         }
         return resultSetMetaData.getColumnName(column);
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java
index 12c05237f84..02662aa8230 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetUtils.java
@@ -62,7 +62,7 @@ public final class ShardingSphereResultSetUtils {
         Map<String, Integer> result = new CaseInsensitiveMap<>(actualProjections.size(), 1F);
         for (int columnIndex = actualProjections.size(); columnIndex > 0; columnIndex--) {
             Projection projection = actualProjections.get(columnIndex - 1);
-            result.put(DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getColumnName() : projection.getColumnLabel(), columnIndex);
+            result.put(DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getExpression() : projection.getColumnLabel(), columnIndex);
         }
         return result;
     }
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
index 8cb815f610c..06ab874e1b0 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
@@ -98,7 +98,7 @@ public final class SQLFederationResultSet extends AbstractUnsupportedOperationRe
     
     private String getColumnLabel(final Projection projection, final DatabaseType databaseType) {
         if (projection instanceof AggregationDistinctProjection) {
-            return databaseType.getDefaultSchema().isPresent() ? ((AggregationDistinctProjection) projection).getType().name().toLowerCase() : projection.getColumnName();
+            return databaseType.getDefaultSchema().isPresent() ? ((AggregationDistinctProjection) projection).getType().name().toLowerCase() : projection.getExpression();
         }
         return projection.getColumnLabel();
     }
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSetMetaData.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSetMetaData.java
index c3cd0fb5a97..0472c59c3da 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSetMetaData.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSetMetaData.java
@@ -186,7 +186,7 @@ public final class SQLFederationResultSetMetaData extends WrapperAdapter impleme
         if (projection instanceof ColumnProjection) {
             Map<String, String> tableNamesByColumnProjection =
                     selectStatementContext.getTablesContext().findTableNamesByColumnProjection(Collections.singletonList((ColumnProjection) projection), schema);
-            return Optional.of(tableNamesByColumnProjection.get(projection.getColumnName()));
+            return Optional.of(tableNamesByColumnProjection.get(projection.getExpression()));
         }
         return Optional.empty();
     }
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java
index 58215ee9093..d0c21b73ef1 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java
@@ -22,10 +22,10 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.DerivedC
 import org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
 import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
 import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
+import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.infra.database.spi.DatabaseType;
 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
 
 import java.sql.SQLException;
 
@@ -71,7 +71,7 @@ public final class QueryHeaderBuilderEngine {
     
     private String getColumnLabel(final ProjectionsContext projectionsContext, final QueryResultMetaData queryResultMetaData, final int columnIndex) throws SQLException {
         Projection projection = projectionsContext.getExpandProjections().get(columnIndex - 1);
-        return DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getColumnName() : queryResultMetaData.getColumnLabel(columnIndex);
+        return DerivedColumn.isDerivedColumnName(projection.getColumnLabel()) ? projection.getExpression() : queryResultMetaData.getColumnLabel(columnIndex);
     }
     
     private String getColumnName(final ProjectionsContext projectionsContext, final QueryResultMetaData queryResultMetaData, final int columnIndex) throws SQLException {
diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/NoResourceShowExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/NoResourceShowExecutor.java
index 47ff4c2479e..0dcc4dc8842 100644
--- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/NoResourceShowExecutor.java
+++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/NoResourceShowExecutor.java
@@ -28,8 +28,8 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.ra
 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.memory.row.MemoryQueryResultDataRow;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
 import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
@@ -61,7 +61,7 @@ public final class NoResourceShowExecutor implements DatabaseAdminQueryExecutor
         TableSegment tableSegment = sqlStatement.getFrom();
         expressions = sqlStatement.getProjections().getProjections().stream().filter(each -> !(each instanceof ShorthandProjectionSegment))
                 .map(each -> new ProjectionEngine(null, Collections.emptyMap(), null).createProjection(tableSegment, each))
-                .filter(Optional::isPresent).map(each -> each.get().getAlias().isPresent() ? each.get().getAlias().get() : each.get().getColumnName()).collect(Collectors.toList());
+                .filter(Optional::isPresent).map(each -> each.get().getAlias().isPresent() ? each.get().getAlias().get() : each.get().getExpression()).collect(Collectors.toList());
         mergedResult = new TransparentMergedResult(getQueryResult());
     }
     
diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
index 00e8b6206b7..f305624c5b7 100644
--- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
+++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
@@ -34,8 +34,8 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.Projecti
 import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.spi.DatabaseType;
 import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
 import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -149,7 +149,7 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
         for (Projection each : projections) {
             // TODO Calculate column definition flag for other projection types
             if (each instanceof ColumnProjection && null != ((ColumnProjection) each).getOriginalName()) {
-                result.add(Optional.ofNullable(columnToTableMap.get(each.getColumnName())).map(schema::getTable)
+                result.add(Optional.ofNullable(columnToTableMap.get(each.getExpression())).map(schema::getTable)
                         .map(table -> table.getColumns().get(((ColumnProjection) each).getOriginalName().getValue()))
                         .map(column -> createMySQLColumnDefinition41Packet(characterSet, calculateColumnDefinitionFlag(column), MySQLBinaryColumnType.valueOfJDBCType(column.getDataType())))
                         .orElseGet(() -> createMySQLColumnDefinition41Packet(characterSet, 0, MySQLBinaryColumnType.VAR_STRING)));