This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new fbd1c280ef4 Refactor ProjectionUtils.getIdentifierValue() (#32324)
fbd1c280ef4 is described below
commit fbd1c280ef4bcd845cced162ad1df88969b6b790
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jul 30 09:03:36 2024 +0800
Refactor ProjectionUtils.getIdentifierValue() (#32324)
* Refactor ProjectionUtils.getIdentifierValue()
* Refactor ProjectionUtils.getIdentifierValue()
---
.../projection/impl/AggregationProjection.java | 2 +-
.../select/projection/impl/ColumnProjection.java | 4 ++--
.../projection/impl/ExpressionProjection.java | 2 +-
.../select/projection/impl/SubqueryProjection.java | 2 +-
.../select/projection/util/ProjectionUtils.java | 23 ++++------------------
.../binder/engine/util/SubqueryTableBindUtils.java | 2 +-
.../projection/util/ProjectionUtilsTest.java | 15 +++++++-------
7 files changed, 17 insertions(+), 33 deletions(-)
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 a3a60dc97dd..e236d67f143 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
@@ -62,7 +62,7 @@ public class AggregationProjection implements Projection {
@Override
public String getColumnLabel() {
- return getAlias().isPresent() &&
!DerivedColumn.isDerivedColumnName(getAlias().get().getValueWithQuoteCharacters())
? ProjectionUtils.getColumnLabelFromAlias(getAlias().get(), databaseType)
+ return getAlias().isPresent() &&
!DerivedColumn.isDerivedColumnName(getAlias().get().getValueWithQuoteCharacters())
? ProjectionUtils.getIdentifierValue(getAlias().get(), databaseType)
: ProjectionUtils.getColumnNameFromFunction(type.name(),
expression, databaseType);
}
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 66aa0ddc5aa..54ad62a1a3c 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
@@ -61,12 +61,12 @@ public final class ColumnProjection implements Projection {
@Override
public String getColumnName() {
- return databaseType instanceof MySQLDatabaseType ?
ProjectionUtils.getColumnNameFromColumn(name, databaseType) : getColumnLabel();
+ return databaseType instanceof MySQLDatabaseType ?
ProjectionUtils.getIdentifierValue(name, databaseType) : getColumnLabel();
}
@Override
public String getColumnLabel() {
- return getAlias().isPresent() ?
ProjectionUtils.getColumnLabelFromAlias(getAlias().get(), databaseType) :
ProjectionUtils.getColumnNameFromColumn(name, databaseType);
+ return getAlias().isPresent() ?
ProjectionUtils.getIdentifierValue(getAlias().get(), databaseType) :
ProjectionUtils.getIdentifierValue(name, databaseType);
}
@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 04e2b512336..87febb332b5 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
@@ -51,7 +51,7 @@ public final class ExpressionProjection implements Projection
{
@Override
public String getColumnLabel() {
- return getAlias().isPresent() ?
ProjectionUtils.getColumnLabelFromAlias(getAlias().get(), databaseType)
+ return getAlias().isPresent() ?
ProjectionUtils.getIdentifierValue(getAlias().get(), databaseType)
:
ProjectionUtils.getColumnNameFromExpression(expressionSegment.getText(),
databaseType);
}
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 2746dcbc9a4..1a89e8878f4 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
@@ -53,7 +53,7 @@ public final class SubqueryProjection implements Projection {
@Override
public String getColumnLabel() {
- return getAlias().isPresent() ?
ProjectionUtils.getColumnLabelFromAlias(getAlias().get(), databaseType) :
ProjectionUtils.getColumnNameFromSubquery(subquerySegment, databaseType);
+ return getAlias().isPresent() ?
ProjectionUtils.getIdentifierValue(getAlias().get(), databaseType) :
ProjectionUtils.getColumnNameFromSubquery(subquerySegment, databaseType);
}
@Override
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/util/ProjectionUtils.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/util/ProjectionUtils.java
index 8f06135cee4..59630e294f8 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/util/ProjectionUtils.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/util/ProjectionUtils.java
@@ -34,17 +34,13 @@ import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.Iden
public final class ProjectionUtils {
/**
- * Get column label from alias.
+ * Get identifier value.
*
- * @param alias alias
+ * @param identifierValue identifier value
* @param databaseType database type
- * @return column label
+ * @return identifier value
*/
- public static String getColumnLabelFromAlias(final IdentifierValue alias,
final DatabaseType databaseType) {
- return getIdentifierValueByDatabaseType(alias, databaseType);
- }
-
- private static String getIdentifierValueByDatabaseType(final
IdentifierValue identifierValue, final DatabaseType databaseType) {
+ public static String getIdentifierValue(final IdentifierValue
identifierValue, final DatabaseType databaseType) {
if (QuoteCharacter.NONE != identifierValue.getQuoteCharacter()) {
return identifierValue.getValue();
}
@@ -57,17 +53,6 @@ public final class ProjectionUtils {
return identifierValue.getValue();
}
- /**
- * Get column name from column.
- *
- * @param columnName column name
- * @param databaseType database type
- * @return column name
- */
- public static String getColumnNameFromColumn(final IdentifierValue
columnName, final DatabaseType databaseType) {
- return getIdentifierValueByDatabaseType(columnName, databaseType);
- }
-
/**
* Get column name from function.
*
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 306ca9f83c6..5afb4d5da87 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
@@ -97,7 +97,7 @@ public final class SubqueryTableBindUtils {
private static String getColumnNameFromExpression(final ExpressionSegment
expressionSegment, final DatabaseType databaseType) {
String result;
if (expressionSegment instanceof AliasAvailable && ((AliasAvailable)
expressionSegment).getAlias().isPresent()) {
- result = ProjectionUtils.getColumnLabelFromAlias(((AliasAvailable)
expressionSegment).getAlias().get(), databaseType);
+ result = ProjectionUtils.getIdentifierValue(((AliasAvailable)
expressionSegment).getAlias().get(), databaseType);
} else {
result =
ProjectionUtils.getColumnNameFromExpression(expressionSegment.getText(),
databaseType);
}
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/util/ProjectionUtilsTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/util/ProjectionUtilsTest.java
index d314e4d0d25..b8591a1bcda 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/util/ProjectionUtilsTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/select/projection/util/ProjectionUtilsTest.java
@@ -30,15 +30,14 @@ import static org.hamcrest.Matchers.is;
class ProjectionUtilsTest {
- private final IdentifierValue alias = new IdentifierValue("Data",
QuoteCharacter.NONE);
-
@Test
- void assertGetColumnLabelFromAlias() {
- assertThat(ProjectionUtils.getColumnLabelFromAlias(new
IdentifierValue("Data", QuoteCharacter.QUOTE), new PostgreSQLDatabaseType()),
is("Data"));
- assertThat(ProjectionUtils.getColumnLabelFromAlias(alias,
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")), is("data"));
- assertThat(ProjectionUtils.getColumnLabelFromAlias(alias,
TypedSPILoader.getService(DatabaseType.class, "openGauss")), is("data"));
- assertThat(ProjectionUtils.getColumnLabelFromAlias(alias,
TypedSPILoader.getService(DatabaseType.class, "Oracle")), is("DATA"));
- assertThat(ProjectionUtils.getColumnLabelFromAlias(alias,
TypedSPILoader.getService(DatabaseType.class, "MySQL")), is("Data"));
+ void assertGetIdentifierValue() {
+ assertThat(ProjectionUtils.getIdentifierValue(new
IdentifierValue("Data", QuoteCharacter.QUOTE), new PostgreSQLDatabaseType()),
is("Data"));
+ IdentifierValue identifierValue = new IdentifierValue("Data",
QuoteCharacter.NONE);
+ assertThat(ProjectionUtils.getIdentifierValue(identifierValue,
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")), is("data"));
+ assertThat(ProjectionUtils.getIdentifierValue(identifierValue,
TypedSPILoader.getService(DatabaseType.class, "openGauss")), is("data"));
+ assertThat(ProjectionUtils.getIdentifierValue(identifierValue,
TypedSPILoader.getService(DatabaseType.class, "Oracle")), is("DATA"));
+ assertThat(ProjectionUtils.getIdentifierValue(identifierValue,
TypedSPILoader.getService(DatabaseType.class, "MySQL")), is("Data"));
}
@Test