You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/06/22 03:14:01 UTC
[shardingsphere] branch master updated: fix rewrite for 'order by'
(#6126)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 682672d fix rewrite for 'order by' (#6126)
682672d is described below
commit 682672db4950f31b0971055cc752eca909ad123d
Author: JingShang Lu <ji...@gmail.com>
AuthorDate: Mon Jun 22 11:13:46 2020 +0800
fix rewrite for 'order by' (#6126)
---
.../src/test/resources/sharding/select.xml | 12 ++++++++++++
.../segment/select/projection/engine/ProjectionEngine.java | 4 ++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/sharding/select.xml b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/sharding/select.xml
index bcf46f7..dd6a084 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/sharding/select.xml
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/sharding/select.xml
@@ -38,6 +38,18 @@
<output sql="SELECT * FROM t_account_0 WHERE amount = 1000" />
<output sql="SELECT * FROM t_account_1 WHERE amount = 1000" />
</rewrite-assertion>
+
+ <rewrite-assertion id="select_for_literals_with_table_prefix" db-type="MySQL">
+ <input sql="SELECT `t_account`.`account_id` FROM `t_account` order by `t_account`.`account_id` ASC" />
+ <output sql="SELECT `t_account_0`.`account_id` FROM `t_account_0` order by `t_account_0`.`account_id` ASC" />
+ <output sql="SELECT `t_account_1`.`account_id` FROM `t_account_1` order by `t_account_1`.`account_id` ASC" />
+ </rewrite-assertion>
+
+ <rewrite-assertion id="select_for_literals_no_quote_with_table_prefix" db-type="MySQL">
+ <input sql="SELECT t_account.account_id FROM t_account order by t_account.account_id ASC" />
+ <output sql="SELECT t_account_0.account_id FROM t_account_0 order by t_account_0.account_id ASC" />
+ <output sql="SELECT t_account_1.account_id FROM t_account_1 order by t_account_1.account_id ASC" />
+ </rewrite-assertion>
<rewrite-assertion id="select_binding_table_with_sharding_value_for_parameters">
<input sql="SELECT * FROM t_account o, t_account_detail i WHERE o.account_id=i.account_id AND o.account_id = ?" parameters="100" />
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/segment/select/projection/engine/ProjectionEngine.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/segment/select/projection/engine/ProjectionEngine.java
index db29aa0..b2e6dd51 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/segment/select/projection/engine/ProjectionEngine.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/segment/select/projection/engine/ProjectionEngine.java
@@ -88,8 +88,8 @@ public final class ProjectionEngine {
}
private ColumnProjection createProjection(final ColumnProjectionSegment projectionSegment) {
- String owner = projectionSegment.getColumn().getOwner().isPresent() ? projectionSegment.getColumn().getOwner().get().getIdentifier().getValue() : null;
- return new ColumnProjection(owner, projectionSegment.getColumn().getIdentifier().getValue(), projectionSegment.getAlias().orElse(null));
+ String owner = projectionSegment.getColumn().getOwner().isPresent() ? projectionSegment.getColumn().getOwner().get().getIdentifier().getValueWithQuoteCharacters() : null;
+ return new ColumnProjection(owner, projectionSegment.getColumn().getIdentifier().getValueWithQuoteCharacters(), projectionSegment.getAlias().orElse(null));
}
private ExpressionProjection createProjection(final ExpressionProjectionSegment projectionSegment) {