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 61ec4356bca Add ProjectionIdentifierExtractEngine and 
DialectProjectionIdentifierExtractor (#32327)
61ec4356bca is described below

commit 61ec4356bca69c1f858b3bdb95d9490da5fed4a8
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jul 30 13:14:56 2024 +0800

    Add ProjectionIdentifierExtractEngine and 
DialectProjectionIdentifierExtractor (#32327)
    
    * Add ProjectionIdentifierExtractEngine and 
DialectProjectionIdentifierExtractor
    
    * Add ProjectionIdentifierExtractEngine and 
DialectProjectionIdentifierExtractor
---
 .../DialectProjectionIdentifierExtractor.java      | 53 +++-------------------
 ...java => ProjectionIdentifierExtractEngine.java} | 49 ++++++--------------
 .../OpenGaussProjectionIdentifierExtractor.java}   | 47 +++++++------------
 .../OracleProjectionIdentifierExtractor.java}      | 46 ++++++-------------
 .../PostgreSQLProjectionIdentifierExtractor.java}  | 47 +++++++------------
 .../projection/impl/AggregationProjection.java     |  8 ++--
 .../select/projection/impl/ColumnProjection.java   | 10 ++--
 .../projection/impl/ExpressionProjection.java      |  8 ++--
 .../select/projection/impl/SubqueryProjection.java |  6 +--
 .../binder/engine/util/SubqueryTableBindUtils.java | 11 ++---
 ....extractor.DialectProjectionIdentifierExtractor | 20 ++++++++
 ... => ProjectionIdentifierExtractEngineTest.java} | 22 ++++-----
 12 files changed, 118 insertions(+), 209 deletions(-)

diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/DialectProjectionIdentifierExtractor.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/DialectProjectionIdentifierExtractor.java
index 41e5502597d..73da997261c 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/DialectProjectionIdentifierExtractor.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/DialectProjectionIdentifierExtractor.java
@@ -17,22 +17,14 @@
 
 package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor;
 
-import lombok.RequiredArgsConstructor;
-import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.opengauss.type.OpenGaussDatabaseType;
-import org.apache.shardingsphere.infra.database.oracle.type.OracleDatabaseType;
-import 
org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
 
 /**
  * Dialect projection identifier extractor.
  */
-@RequiredArgsConstructor
-public final class DialectProjectionIdentifierExtractor {
-    
-    private final DatabaseType databaseType;
+public interface DialectProjectionIdentifierExtractor extends DatabaseTypedSPI 
{
     
     /**
      * Get identifier value.
@@ -40,18 +32,7 @@ public final class DialectProjectionIdentifierExtractor {
      * @param identifierValue identifier value
      * @return identifier value
      */
-    public String getIdentifierValue(final IdentifierValue identifierValue) {
-        if (QuoteCharacter.NONE != identifierValue.getQuoteCharacter()) {
-            return identifierValue.getValue();
-        }
-        if (databaseType instanceof PostgreSQLDatabaseType || databaseType 
instanceof OpenGaussDatabaseType) {
-            return identifierValue.getValue().toLowerCase();
-        }
-        if (databaseType instanceof OracleDatabaseType) {
-            return identifierValue.getValue().toUpperCase();
-        }
-        return identifierValue.getValue();
-    }
+    String getIdentifierValue(IdentifierValue identifierValue);
     
     /**
      * Get column name from function.
@@ -60,15 +41,7 @@ public final class DialectProjectionIdentifierExtractor {
      * @param functionExpression function expression
      * @return column name
      */
-    public String getColumnNameFromFunction(final String functionName, final 
String functionExpression) {
-        if (databaseType instanceof PostgreSQLDatabaseType || databaseType 
instanceof OpenGaussDatabaseType) {
-            return functionName.toLowerCase();
-        }
-        if (databaseType instanceof OracleDatabaseType) {
-            return functionExpression.replace(" ", "").toUpperCase();
-        }
-        return functionExpression;
-    }
+    String getColumnNameFromFunction(String functionName, String 
functionExpression);
     
     /**
      * Get column name from expression.
@@ -76,15 +49,7 @@ public final class DialectProjectionIdentifierExtractor {
      * @param expression expression
      * @return column name
      */
-    public String getColumnNameFromExpression(final String expression) {
-        if (databaseType instanceof PostgreSQLDatabaseType || databaseType 
instanceof OpenGaussDatabaseType) {
-            return "?column?";
-        }
-        if (databaseType instanceof OracleDatabaseType) {
-            return expression.replace(" ", "").toUpperCase();
-        }
-        return expression;
-    }
+    String getColumnNameFromExpression(String expression);
     
     /**
      * Get column name from subquery segment.
@@ -92,11 +57,5 @@ public final class DialectProjectionIdentifierExtractor {
      * @param subquerySegment subquery segment
      * @return column name
      */
-    public String getColumnNameFromSubquery(final SubqueryProjectionSegment 
subquerySegment) {
-        // TODO support postgresql subquery projection
-        if (databaseType instanceof OracleDatabaseType) {
-            return subquerySegment.getText().replace(" ", "").toUpperCase();
-        }
-        return subquerySegment.getText();
-    }
+    String getColumnNameFromSubquery(SubqueryProjectionSegment 
subquerySegment);
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/DialectProjectionIdentifierExtractor.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/ProjectionIdentifierExtractEngine.java
similarity index 58%
copy from 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/DialectProjectionIdentifierExtractor.java
copy to 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/ProjectionIdentifierExtractEngine.java
index 41e5502597d..422f43a9418 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/DialectProjectionIdentifierExtractor.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/ProjectionIdentifierExtractEngine.java
@@ -17,22 +17,25 @@
 
 package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor;
 
-import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.opengauss.type.OpenGaussDatabaseType;
-import org.apache.shardingsphere.infra.database.oracle.type.OracleDatabaseType;
-import 
org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
 
+import java.util.Optional;
+
 /**
- * Dialect projection identifier extractor.
+ * Projection identifier extract engine.
  */
-@RequiredArgsConstructor
-public final class DialectProjectionIdentifierExtractor {
+public final class ProjectionIdentifierExtractEngine {
+    
+    @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
+    private final Optional<DialectProjectionIdentifierExtractor> 
projectionIdentifierExtractor;
     
-    private final DatabaseType databaseType;
+    public ProjectionIdentifierExtractEngine(final DatabaseType databaseType) {
+        projectionIdentifierExtractor = 
DatabaseTypedSPILoader.findService(DialectProjectionIdentifierExtractor.class, 
databaseType);
+    }
     
     /**
      * Get identifier value.
@@ -44,13 +47,7 @@ public final class DialectProjectionIdentifierExtractor {
         if (QuoteCharacter.NONE != identifierValue.getQuoteCharacter()) {
             return identifierValue.getValue();
         }
-        if (databaseType instanceof PostgreSQLDatabaseType || databaseType 
instanceof OpenGaussDatabaseType) {
-            return identifierValue.getValue().toLowerCase();
-        }
-        if (databaseType instanceof OracleDatabaseType) {
-            return identifierValue.getValue().toUpperCase();
-        }
-        return identifierValue.getValue();
+        return projectionIdentifierExtractor.map(optional -> 
optional.getIdentifierValue(identifierValue)).orElseGet(identifierValue::getValue);
     }
     
     /**
@@ -61,13 +58,7 @@ public final class DialectProjectionIdentifierExtractor {
      * @return column name
      */
     public String getColumnNameFromFunction(final String functionName, final 
String functionExpression) {
-        if (databaseType instanceof PostgreSQLDatabaseType || databaseType 
instanceof OpenGaussDatabaseType) {
-            return functionName.toLowerCase();
-        }
-        if (databaseType instanceof OracleDatabaseType) {
-            return functionExpression.replace(" ", "").toUpperCase();
-        }
-        return functionExpression;
+        return projectionIdentifierExtractor.map(optional -> 
optional.getColumnNameFromFunction(functionName, 
functionExpression)).orElse(functionExpression);
     }
     
     /**
@@ -77,13 +68,7 @@ public final class DialectProjectionIdentifierExtractor {
      * @return column name
      */
     public String getColumnNameFromExpression(final String expression) {
-        if (databaseType instanceof PostgreSQLDatabaseType || databaseType 
instanceof OpenGaussDatabaseType) {
-            return "?column?";
-        }
-        if (databaseType instanceof OracleDatabaseType) {
-            return expression.replace(" ", "").toUpperCase();
-        }
-        return expression;
+        return projectionIdentifierExtractor.map(optional -> 
optional.getColumnNameFromExpression(expression)).orElse(expression);
     }
     
     /**
@@ -93,10 +78,6 @@ public final class DialectProjectionIdentifierExtractor {
      * @return column name
      */
     public String getColumnNameFromSubquery(final SubqueryProjectionSegment 
subquerySegment) {
-        // TODO support postgresql subquery projection
-        if (databaseType instanceof OracleDatabaseType) {
-            return subquerySegment.getText().replace(" ", "").toUpperCase();
-        }
-        return subquerySegment.getText();
+        return projectionIdentifierExtractor.map(optional -> 
optional.getColumnNameFromSubquery(subquerySegment)).orElseGet(subquerySegment::getText);
     }
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OpenGaussProjectionIdentifierExtractor.java
similarity index 52%
copy from 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
copy to 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OpenGaussProjectionIdentifierExtractor.java
index 2a4f938d16c..c5ec97785cf 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OpenGaussProjectionIdentifierExtractor.java
@@ -15,55 +15,40 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl;
+package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.dialect;
 
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
 
-import java.util.Optional;
-
 /**
- * Subquery projection.
+ * Projection identifier extractor for openGauss.
  */
-@RequiredArgsConstructor
-@Getter
-@EqualsAndHashCode
-@ToString
-public final class SubqueryProjection implements Projection {
-    
-    private final SubqueryProjectionSegment subquerySegment;
-    
-    private final Projection projection;
-    
-    private final IdentifierValue alias;
-    
-    private final DatabaseType databaseType;
+public final class OpenGaussProjectionIdentifierExtractor implements 
DialectProjectionIdentifierExtractor {
     
     @Override
-    public String getColumnName() {
-        return getColumnLabel();
+    public String getIdentifierValue(final IdentifierValue identifierValue) {
+        return identifierValue.getValue().toLowerCase();
     }
     
     @Override
-    public String getColumnLabel() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
-        return getAlias().isPresent() ? 
identifierExtractor.getIdentifierValue(getAlias().get()) : 
identifierExtractor.getColumnNameFromSubquery(subquerySegment);
+    public String getColumnNameFromFunction(final String functionName, final 
String functionExpression) {
+        return functionName.toLowerCase();
     }
     
     @Override
-    public Optional<IdentifierValue> getAlias() {
-        return Optional.ofNullable(alias);
+    public String getColumnNameFromExpression(final String expression) {
+        return "?column?";
     }
     
     @Override
-    public String getExpression() {
+    public String getColumnNameFromSubquery(final SubqueryProjectionSegment 
subquerySegment) {
+        // TODO support subquery projection
         return subquerySegment.getText();
     }
+    
+    @Override
+    public String getDatabaseType() {
+        return "openGauss";
+    }
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OracleProjectionIdentifierExtractor.java
similarity index 51%
copy from 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
copy to 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OracleProjectionIdentifierExtractor.java
index 2a4f938d16c..49195645c70 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/OracleProjectionIdentifierExtractor.java
@@ -15,55 +15,39 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl;
+package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.dialect;
 
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
 
-import java.util.Optional;
-
 /**
- * Subquery projection.
+ * Projection identifier extractor or Oracle.
  */
-@RequiredArgsConstructor
-@Getter
-@EqualsAndHashCode
-@ToString
-public final class SubqueryProjection implements Projection {
-    
-    private final SubqueryProjectionSegment subquerySegment;
-    
-    private final Projection projection;
+public final class OracleProjectionIdentifierExtractor implements 
DialectProjectionIdentifierExtractor {
     
-    private final IdentifierValue alias;
-    
-    private final DatabaseType databaseType;
+    @Override
+    public String getIdentifierValue(final IdentifierValue identifierValue) {
+        return identifierValue.getValue().toUpperCase();
+    }
     
     @Override
-    public String getColumnName() {
-        return getColumnLabel();
+    public String getColumnNameFromFunction(final String functionName, final 
String functionExpression) {
+        return functionExpression.replace(" ", "").toUpperCase();
     }
     
     @Override
-    public String getColumnLabel() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
-        return getAlias().isPresent() ? 
identifierExtractor.getIdentifierValue(getAlias().get()) : 
identifierExtractor.getColumnNameFromSubquery(subquerySegment);
+    public String getColumnNameFromExpression(final String expression) {
+        return expression.replace(" ", "").toUpperCase();
     }
     
     @Override
-    public Optional<IdentifierValue> getAlias() {
-        return Optional.ofNullable(alias);
+    public String getColumnNameFromSubquery(final SubqueryProjectionSegment 
subquerySegment) {
+        return subquerySegment.getText().replace(" ", "").toUpperCase();
     }
     
     @Override
-    public String getExpression() {
-        return subquerySegment.getText();
+    public String getDatabaseType() {
+        return "Oracle";
     }
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/PostgreSQLProjectionIdentifierExtractor.java
similarity index 52%
copy from 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
copy to 
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/PostgreSQLProjectionIdentifierExtractor.java
index 2a4f938d16c..720f7f0410b 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/extractor/dialect/PostgreSQLProjectionIdentifierExtractor.java
@@ -15,55 +15,40 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl;
+package 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.dialect;
 
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
 
-import java.util.Optional;
-
 /**
- * Subquery projection.
+ * Projection identifier extractor for PostgreSQL.
  */
-@RequiredArgsConstructor
-@Getter
-@EqualsAndHashCode
-@ToString
-public final class SubqueryProjection implements Projection {
-    
-    private final SubqueryProjectionSegment subquerySegment;
-    
-    private final Projection projection;
-    
-    private final IdentifierValue alias;
-    
-    private final DatabaseType databaseType;
+public final class PostgreSQLProjectionIdentifierExtractor implements 
DialectProjectionIdentifierExtractor {
     
     @Override
-    public String getColumnName() {
-        return getColumnLabel();
+    public String getIdentifierValue(final IdentifierValue identifierValue) {
+        return identifierValue.getValue().toLowerCase();
     }
     
     @Override
-    public String getColumnLabel() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
-        return getAlias().isPresent() ? 
identifierExtractor.getIdentifierValue(getAlias().get()) : 
identifierExtractor.getColumnNameFromSubquery(subquerySegment);
+    public String getColumnNameFromFunction(final String functionName, final 
String functionExpression) {
+        return functionName.toLowerCase();
     }
     
     @Override
-    public Optional<IdentifierValue> getAlias() {
-        return Optional.ofNullable(alias);
+    public String getColumnNameFromExpression(final String expression) {
+        return "?column?";
     }
     
     @Override
-    public String getExpression() {
+    public String getColumnNameFromSubquery(final SubqueryProjectionSegment 
subquerySegment) {
+        // TODO support subquery projection
         return subquerySegment.getText();
     }
+    
+    @Override
+    public String getDatabaseType() {
+        return "PostgreSQL";
+    }
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/AggregationProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/AggregationProjection.java
index 1e2796e427e..3034779f829 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/AggregationProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/AggregationProjection.java
@@ -24,7 +24,7 @@ import lombok.Setter;
 import lombok.ToString;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.DerivedColumn;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.ProjectionIdentifierExtractEngine;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.enums.AggregationType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
@@ -62,10 +62,10 @@ public class AggregationProjection implements Projection {
     
     @Override
     public String getColumnLabel() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
+        ProjectionIdentifierExtractEngine extractEngine = new 
ProjectionIdentifierExtractEngine(databaseType);
         return getAlias().isPresent() && 
!DerivedColumn.isDerivedColumnName(getAlias().get().getValueWithQuoteCharacters())
-                ? identifierExtractor.getIdentifierValue(getAlias().get())
-                : identifierExtractor.getColumnNameFromFunction(type.name(), 
expression);
+                ? extractEngine.getIdentifierValue(getAlias().get())
+                : extractEngine.getColumnNameFromFunction(type.name(), 
expression);
     }
     
     @Override
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjection.java
index 43d95f488ad..1f46f86b3e7 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjection.java
@@ -24,7 +24,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.Setter;
 import lombok.ToString;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.ProjectionIdentifierExtractEngine;
 import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType;
@@ -61,14 +61,14 @@ public final class ColumnProjection implements Projection {
     
     @Override
     public String getColumnName() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
-        return databaseType instanceof MySQLDatabaseType ? 
identifierExtractor.getIdentifierValue(name) : getColumnLabel();
+        ProjectionIdentifierExtractEngine extractEngine = new 
ProjectionIdentifierExtractEngine(databaseType);
+        return databaseType instanceof MySQLDatabaseType ? 
extractEngine.getIdentifierValue(name) : getColumnLabel();
     }
     
     @Override
     public String getColumnLabel() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
-        return getAlias().isPresent() ? 
identifierExtractor.getIdentifierValue(getAlias().get()) : 
identifierExtractor.getIdentifierValue(name);
+        ProjectionIdentifierExtractEngine extractEngine = new 
ProjectionIdentifierExtractEngine(databaseType);
+        return getAlias().isPresent() ? 
extractEngine.getIdentifierValue(getAlias().get()) : 
extractEngine.getIdentifierValue(name);
     }
     
     @Override
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ExpressionProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ExpressionProjection.java
index 2554d787c26..b932a9abbc4 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ExpressionProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ExpressionProjection.java
@@ -22,7 +22,7 @@ import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.ToString;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.ProjectionIdentifierExtractEngine;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
@@ -51,10 +51,8 @@ public final class ExpressionProjection implements 
Projection {
     
     @Override
     public String getColumnLabel() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
-        return getAlias().isPresent()
-                ? identifierExtractor.getIdentifierValue(getAlias().get())
-                : 
identifierExtractor.getColumnNameFromExpression(expressionSegment.getText());
+        ProjectionIdentifierExtractEngine extractEngine = new 
ProjectionIdentifierExtractEngine(databaseType);
+        return getAlias().isPresent() ? 
extractEngine.getIdentifierValue(getAlias().get()) : 
extractEngine.getColumnNameFromExpression(expressionSegment.getText());
     }
     
     @Override
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
index 2a4f938d16c..bb4e9908414 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/SubqueryProjection.java
@@ -22,7 +22,7 @@ import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.ToString;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.ProjectionIdentifierExtractEngine;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
@@ -53,8 +53,8 @@ public final class SubqueryProjection implements Projection {
     
     @Override
     public String getColumnLabel() {
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
-        return getAlias().isPresent() ? 
identifierExtractor.getIdentifierValue(getAlias().get()) : 
identifierExtractor.getColumnNameFromSubquery(subquerySegment);
+        ProjectionIdentifierExtractEngine extractEngine = new 
ProjectionIdentifierExtractEngine(databaseType);
+        return getAlias().isPresent() ? 
extractEngine.getIdentifierValue(getAlias().get()) : 
extractEngine.getColumnNameFromSubquery(subquerySegment);
     }
     
     @Override
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java
index 6b29f6cca07..74026fc4299 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.infra.binder.engine.util;
 import com.google.common.base.Strings;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.ProjectionIdentifierExtractEngine;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
@@ -95,13 +95,10 @@ public final class SubqueryTableBindUtils {
     }
     
     private static String getColumnNameFromExpression(final ExpressionSegment 
expressionSegment, final DatabaseType databaseType) {
-        String result;
-        DialectProjectionIdentifierExtractor identifierExtractor = new 
DialectProjectionIdentifierExtractor(databaseType);
+        ProjectionIdentifierExtractEngine extractEngine = new 
ProjectionIdentifierExtractEngine(databaseType);
         if (expressionSegment instanceof AliasAvailable && ((AliasAvailable) 
expressionSegment).getAlias().isPresent()) {
-            result = identifierExtractor.getIdentifierValue(((AliasAvailable) 
expressionSegment).getAlias().get());
-        } else {
-            result = 
identifierExtractor.getColumnNameFromExpression(expressionSegment.getText());
+            return extractEngine.getIdentifierValue(((AliasAvailable) 
expressionSegment).getAlias().get());
         }
-        return result;
+        return 
extractEngine.getColumnNameFromExpression(expressionSegment.getText());
     }
 }
diff --git 
a/infra/binder/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor
 
b/infra/binder/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor
new file mode 100644
index 00000000000..fcc962495e4
--- /dev/null
+++ 
b/infra/binder/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.dialect.OracleProjectionIdentifierExtractor
+org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.dialect.PostgreSQLProjectionIdentifierExtractor
+org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.dialect.OpenGaussProjectionIdentifierExtractor
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/DialectProjectionIdentifierExtractorTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
similarity index 51%
rename from 
infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/DialectProjectionIdentifierExtractorTest.java
rename to 
infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
index 85dbbc61948..e7ccb3eab58 100644
--- 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/DialectProjectionIdentifierExtractorTest.java
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/extractor/ProjectionIdentifierExtractEngineTest.java
@@ -17,7 +17,7 @@
 
 package 
org.apache.shardingsphere.infra.binder.engine.segment.select.projection.extractor;
 
-import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.DialectProjectionIdentifierExtractor;
+import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.extractor.ProjectionIdentifierExtractEngine;
 import 
org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -27,28 +27,28 @@ import org.junit.jupiter.api.Test;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 
-class DialectProjectionIdentifierExtractorTest {
+class ProjectionIdentifierExtractEngineTest {
     
     @Test
     void assertGetIdentifierValue() {
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "PostgreSQL")).getIdentifierValue(new IdentifierValue("Data", 
QuoteCharacter.QUOTE)),
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getIdentifierValue(new IdentifierValue("Data", 
QuoteCharacter.QUOTE)),
                 is("Data"));
         IdentifierValue identifierValue = new IdentifierValue("Data", 
QuoteCharacter.NONE);
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "PostgreSQL")).getIdentifierValue(identifierValue), is("data"));
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "openGauss")).getIdentifierValue(identifierValue), is("data"));
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "Oracle")).getIdentifierValue(identifierValue), is("DATA"));
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "MySQL")).getIdentifierValue(identifierValue), is("Data"));
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getIdentifierValue(identifierValue), is("data"));
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"openGauss")).getIdentifierValue(identifierValue), is("data"));
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"Oracle")).getIdentifierValue(identifierValue), is("DATA"));
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"MySQL")).getIdentifierValue(identifierValue), is("Data"));
     }
     
     @Test
     void assertGetColumnNameFromFunction() {
         String functionName = "Function";
         String functionExpression = "FunctionExpression";
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "PostgreSQL")).getColumnNameFromFunction(functionName, functionExpression), 
is("function"));
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "openGauss")).getColumnNameFromFunction(functionName, functionExpression), 
is("function"));
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "Oracle")).getColumnNameFromFunction(functionName, functionExpression),
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"PostgreSQL")).getColumnNameFromFunction(functionName, functionExpression), 
is("function"));
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"openGauss")).getColumnNameFromFunction(functionName, functionExpression), 
is("function"));
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"Oracle")).getColumnNameFromFunction(functionName, functionExpression),
                 is("FUNCTIONEXPRESSION"));
-        assertThat(new 
DialectProjectionIdentifierExtractor(TypedSPILoader.getService(DatabaseType.class,
 "MySQL")).getColumnNameFromFunction(functionName, functionExpression),
+        assertThat(new 
ProjectionIdentifierExtractEngine(TypedSPILoader.getService(DatabaseType.class, 
"MySQL")).getColumnNameFromFunction(functionName, functionExpression),
                 is("FunctionExpression"));
     }
 }


Reply via email to