This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 6217483a45e Refactor ColumnProjection.columnBoundInfo as final (#33610)
6217483a45e is described below
commit 6217483a45e06183771cbdef6216c145a8c56d75
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Nov 10 23:43:39 2024 +0800
Refactor ColumnProjection.columnBoundInfo as final (#33610)
* Refactor ColumnProjection.columnBoundInfo as final
* Refactor ColumnProjection.columnBoundInfo as final
---
.../projection/EncryptProjectionTokenGenerator.java | 6 ++----
.../EncryptSelectProjectionSupportedCheckerTest.java | 16 ++++++++--------
.../encrypt/merge/dql/EncryptMergedResultTest.java | 18 ++++++++----------
.../select/projection/engine/ProjectionEngine.java | 6 ++----
.../select/projection/impl/ColumnProjection.java | 13 ++++++++-----
.../select/projection/impl/ColumnProjectionTest.java | 16 ++++++++--------
6 files changed, 36 insertions(+), 39 deletions(-)
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGenerator.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGenerator.java
index 36f25e0d232..035b6fa259a 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGenerator.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGenerator.java
@@ -141,10 +141,8 @@ public final class EncryptProjectionTokenGenerator {
private ColumnProjection buildColumnProjection(final
ColumnProjectionSegment segment) {
IdentifierValue owner =
segment.getColumn().getOwner().map(OwnerSegment::getIdentifier).orElse(null);
- ColumnProjection result = new ColumnProjection(owner,
segment.getColumn().getIdentifier(), segment.getAliasName().isPresent() ?
segment.getAlias().orElse(null) : null, databaseType,
- segment.getColumn().getLeftParentheses().orElse(null),
segment.getColumn().getRightParentheses().orElse(null));
- result.setColumnBoundInfo(segment.getColumn().getColumnBoundInfo());
- return result;
+ return new ColumnProjection(owner,
segment.getColumn().getIdentifier(), segment.getAliasName().isPresent() ?
segment.getAlias().orElse(null) : null, databaseType,
+ segment.getColumn().getLeftParentheses().orElse(null),
segment.getColumn().getRightParentheses().orElse(null),
segment.getColumn().getColumnBoundInfo());
}
private Collection<Projection> generateProjections(final EncryptColumn
encryptColumn, final ColumnProjection columnProjection,
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java
index af8131f0eb8..4c7677653cb 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java
@@ -58,16 +58,16 @@ class EncryptSelectProjectionSupportedCheckerTest {
when(sqlStatementContext.getSqlStatement().getCombine().isPresent()).thenReturn(true);
CombineSegment combineSegment = mock(CombineSegment.class,
RETURNS_DEEP_STUBS);
when(sqlStatementContext.getSqlStatement().getCombine().get()).thenReturn(combineSegment);
- ColumnProjection orderIdColumn = new ColumnProjection("o", "order_id",
null, new MySQLDatabaseType());
- orderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("t_order"),
new IdentifierValue("order_id")));
- ColumnProjection userIdColumn = new ColumnProjection("o", "user_id",
null, new MySQLDatabaseType());
- userIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("t_order"),
new IdentifierValue("user_id")));
+ ColumnProjection orderIdColumn = new ColumnProjection(new
IdentifierValue("o"), new IdentifierValue("order_id"), null, new
MySQLDatabaseType(),
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("t_order"),
new IdentifierValue("order_id")));
+ ColumnProjection userIdColumn = new ColumnProjection(new
IdentifierValue("o"), new IdentifierValue("user_id"), null, new
MySQLDatabaseType(),
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("t_order"),
new IdentifierValue("user_id")));
SelectStatementContext leftSelectStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(leftSelectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Arrays.asList(orderIdColumn,
userIdColumn));
- ColumnProjection merchantIdColumn = new ColumnProjection("m",
"merchant_id", null, new MySQLDatabaseType());
- merchantIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new
IdentifierValue("t_merchant"), new IdentifierValue("merchant_id")));
- ColumnProjection merchantNameColumn = new ColumnProjection("m",
"merchant_name", null, new MySQLDatabaseType());
- merchantNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new
IdentifierValue("t_merchant"), new IdentifierValue("merchant_name")));
+ ColumnProjection merchantIdColumn = new ColumnProjection(new
IdentifierValue("m"), new IdentifierValue("merchant_id"), null, new
MySQLDatabaseType(),
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new
IdentifierValue("t_merchant"), new IdentifierValue("merchant_id")));
+ ColumnProjection merchantNameColumn = new ColumnProjection(new
IdentifierValue("m"), new IdentifierValue("merchant_name"), null, new
MySQLDatabaseType(),
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new
IdentifierValue("t_merchant"), new IdentifierValue("merchant_name")));
SelectStatementContext rightSelectStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(rightSelectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Arrays.asList(merchantIdColumn,
merchantNameColumn));
Map<Integer, SelectStatementContext> subqueryContexts = new
LinkedHashMap<>(2, 1F);
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java
index b4af5ca3457..2858dac0e90 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java
@@ -91,8 +91,8 @@ class EncryptMergedResultTest {
@Test
void assertGetValueWithoutEncryptTable() throws SQLException {
- ColumnProjection columnProjection = new ColumnProjection("bar_tbl",
"foo_col", "foo_alias", databaseType);
- columnProjection.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue("foo_col")));
+ ColumnProjection columnProjection = new ColumnProjection(new
IdentifierValue("bar_tbl"), new IdentifierValue("foo_col"), new
IdentifierValue("foo_alias"), databaseType,
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue("foo_col")));
when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection));
EncryptRule rule = mockRule(mock(EncryptAlgorithm.class));
when(database.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(rule)));
@@ -102,8 +102,8 @@ class EncryptMergedResultTest {
@Test
void assertGetValueWithoutEncryptColumn() throws SQLException {
- ColumnProjection columnProjection = new ColumnProjection("foo_tbl",
"bar_col", "bar_alias", databaseType);
- columnProjection.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue("bar_col")));
+ ColumnProjection columnProjection = new ColumnProjection(new
IdentifierValue("foo_tbl"), new IdentifierValue("bar_col"), new
IdentifierValue("bar_alias"), databaseType,
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue("bar_col")));
when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection));
EncryptRule rule = mockRule(mock(EncryptAlgorithm.class));
when(database.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(rule)));
@@ -113,9 +113,8 @@ class EncryptMergedResultTest {
@Test
void assertGetValueWithEncryptColumn() throws SQLException {
- ColumnProjection columnProjection = new ColumnProjection("foo_tbl",
"foo_col", "foo_alias", databaseType);
- columnProjection.setColumnBoundInfo(new ColumnSegmentBoundInfo(
- new IdentifierValue("foo_db"), new
IdentifierValue("foo_schema"), new IdentifierValue("foo_tbl"), new
IdentifierValue("foo_col")));
+ ColumnProjection columnProjection = new ColumnProjection(new
IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new
IdentifierValue("foo_alias"), databaseType,
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new
IdentifierValue("foo_tbl"), new IdentifierValue("foo_col")));
when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection));
when(selectStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_schema"));
EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class);
@@ -132,9 +131,8 @@ class EncryptMergedResultTest {
@Test
void assertGetValueFailed() throws SQLException {
- ColumnProjection columnProjection = new ColumnProjection("foo_tbl",
"foo_col", "foo_alias", databaseType);
- columnProjection.setColumnBoundInfo(new ColumnSegmentBoundInfo(
- new IdentifierValue("foo_db"), new
IdentifierValue("foo_schema"), new IdentifierValue("foo_tbl"), new
IdentifierValue("foo_col")));
+ ColumnProjection columnProjection = new ColumnProjection(new
IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new
IdentifierValue("foo_alias"), databaseType,
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new
IdentifierValue("foo_tbl"), new IdentifierValue("foo_col")));
when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection));
when(selectStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_schema"));
EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class);
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionEngine.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionEngine.java
index 46a24422a41..7edd0674707 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionEngine.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionEngine.java
@@ -108,10 +108,8 @@ public final class ProjectionEngine {
private ColumnProjection createProjection(final ColumnProjectionSegment
projectionSegment) {
IdentifierValue owner =
projectionSegment.getColumn().getOwner().isPresent() ?
projectionSegment.getColumn().getOwner().get().getIdentifier() : null;
IdentifierValue alias = projectionSegment.getAliasName().isPresent() ?
projectionSegment.getAlias().orElse(null) : null;
- ColumnProjection result = new ColumnProjection(owner,
projectionSegment.getColumn().getIdentifier(), alias, databaseType,
projectionSegment.getColumn().getLeftParentheses().orElse(null),
-
projectionSegment.getColumn().getRightParentheses().orElse(null));
-
result.setColumnBoundInfo(projectionSegment.getColumn().getColumnBoundInfo());
- return result;
+ return new ColumnProjection(owner,
projectionSegment.getColumn().getIdentifier(), alias, databaseType,
+
projectionSegment.getColumn().getLeftParentheses().orElse(null),
projectionSegment.getColumn().getRightParentheses().orElse(null),
projectionSegment.getColumn().getColumnBoundInfo());
}
private ExpressionProjection createProjection(final
ExpressionProjectionSegment projectionSegment) {
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 dc53d030945..1100bce1984 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
@@ -21,7 +21,6 @@ import com.google.common.base.Strings;
import lombok.EqualsAndHashCode;
import lombok.Getter;
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.ProjectionIdentifierExtractEngine;
@@ -39,7 +38,6 @@ import java.util.Optional;
*/
@RequiredArgsConstructor
@Getter
-@Setter
@EqualsAndHashCode(exclude = "columnBoundInfo")
@ToString
public final class ColumnProjection implements Projection {
@@ -56,15 +54,20 @@ public final class ColumnProjection implements Projection {
private final ParenthesesSegment rightParentheses;
- private ColumnSegmentBoundInfo columnBoundInfo;
+ private final ColumnSegmentBoundInfo columnBoundInfo;
public ColumnProjection(final String owner, final String name, final
String alias, final DatabaseType databaseType) {
this(null == owner ? null : new IdentifierValue(owner,
QuoteCharacter.NONE), new IdentifierValue(name, QuoteCharacter.NONE),
- null == alias ? null : new IdentifierValue(alias,
QuoteCharacter.NONE), databaseType, null, null);
+ null == alias ? null : new IdentifierValue(alias,
QuoteCharacter.NONE), databaseType, null, null, null);
}
public ColumnProjection(final IdentifierValue owner, final IdentifierValue
name, final IdentifierValue alias, final DatabaseType databaseType) {
- this(owner, name, alias, databaseType, null, null);
+ this(owner, name, alias, databaseType, null, null, null);
+ }
+
+ public ColumnProjection(final IdentifierValue owner, final IdentifierValue
name, final IdentifierValue alias, final DatabaseType databaseType,
+ final ParenthesesSegment leftParentheses, final
ParenthesesSegment rightParentheses) {
+ this(owner, name, alias, databaseType, leftParentheses,
rightParentheses, null);
}
/**
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java
index 6e5193671b3..0b84d3971e6 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java
@@ -45,15 +45,15 @@ class ColumnProjectionTest {
@Test
void assertGetOriginalTableWithEmptyOriginalTableAndWithOwner() {
- ColumnProjection projection = new ColumnProjection("owner", "name",
"alias", databaseType);
- projection.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue("")));
+ ColumnProjection projection = new ColumnProjection(new
IdentifierValue("owner"), new IdentifierValue("name"), new
IdentifierValue("alias"), databaseType,
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue("")));
assertThat(projection.getOriginalTable(), is(new
IdentifierValue("owner")));
}
@Test
void assertGetOriginalTable() {
- ColumnProjection projection = new ColumnProjection("owner", "name",
"alias", databaseType);
- projection.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("tbl"), new
IdentifierValue("")));
+ ColumnProjection projection = new ColumnProjection(new
IdentifierValue("owner"), new IdentifierValue("name"), new
IdentifierValue("alias"), databaseType,
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("tbl"), new
IdentifierValue("")));
assertThat(projection.getOriginalTable(), is(new
IdentifierValue("tbl")));
}
@@ -64,15 +64,15 @@ class ColumnProjectionTest {
@Test
void assertGetOriginalColumnWithEmptyOriginalColumn() {
- ColumnProjection projection = new ColumnProjection(null, "name",
"alias", databaseType);
- projection.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue("")));
+ ColumnProjection projection = new ColumnProjection(null, new
IdentifierValue("name"), new IdentifierValue("alias"), databaseType,
+ null, null, new ColumnSegmentBoundInfo(new
IdentifierValue("")));
assertThat(projection.getOriginalColumn(), is(new
IdentifierValue("name")));
}
@Test
void assertGetOriginalColumn() {
- ColumnProjection projection = new ColumnProjection(null, "name",
"alias", databaseType);
- projection.setColumnBoundInfo(new ColumnSegmentBoundInfo(new
IdentifierValue("col")));
+ ColumnProjection projection = new ColumnProjection(null, new
IdentifierValue("name"), new IdentifierValue("alias"),
+ databaseType, null, null, new ColumnSegmentBoundInfo(new
IdentifierValue("col")));
assertThat(projection.getOriginalColumn(), is(new
IdentifierValue("col")));
}