This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 e1f3ee72df4 Minor refactor for AbstractSQLBuilder (#33525)
e1f3ee72df4 is described below
commit e1f3ee72df4325f369f07455ca16b6ac7406af39
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Nov 4 11:18:55 2024 +0800
Minor refactor for AbstractSQLBuilder (#33525)
---
.../infra/rewrite/sql/impl/AbstractSQLBuilder.java | 27 ++++++++++++++--------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git
a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
index f5f409756bc..6e9331148ae 100644
---
a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
+++
b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.rewrite.sql.impl;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.rewrite.sql.SQLBuilder;
+import
org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Attachable;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import
org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Substitutable;
import
org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.ComposableSQLToken;
@@ -47,20 +48,28 @@ public abstract class AbstractSQLBuilder implements
SQLBuilder {
result.append(sql, 0, sqlTokens.get(0).getStartIndex());
Optional<SQLToken> previousToken = Optional.empty();
for (SQLToken each : sqlTokens) {
- if (each.getStartIndex() <
previousToken.map(SQLToken::getStopIndex).orElse(0)) {
- continue;
+ if (isContainsAttachableToken(each, previousToken.orElse(null))
+ || each.getStartIndex() >
previousToken.map(SQLToken::getStopIndex).orElse(0)) {
+ appendRewriteSQL(each, result);
+ previousToken = Optional.of(each);
}
- if (each instanceof ComposableSQLToken) {
- result.append(getComposableSQLTokenText((ComposableSQLToken)
each));
- } else {
- result.append(getSQLTokenText(each));
- }
- result.append(getConjunctionText(each));
- previousToken = Optional.of(each);
}
return result.toString();
}
+ private boolean isContainsAttachableToken(final SQLToken sqlToken, final
SQLToken previousToken) {
+ return sqlToken instanceof Attachable || previousToken instanceof
Attachable;
+ }
+
+ private void appendRewriteSQL(final SQLToken sqlToken, final StringBuilder
builder) {
+ if (sqlToken instanceof ComposableSQLToken) {
+ builder.append(getComposableSQLTokenText((ComposableSQLToken)
sqlToken));
+ } else {
+ builder.append(getSQLTokenText(sqlToken));
+ }
+ builder.append(getConjunctionText(sqlToken));
+ }
+
protected abstract String getSQLTokenText(SQLToken sqlToken);
private String getComposableSQLTokenText(final ComposableSQLToken
composableSQLToken) {