You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/08/17 00:48:35 UTC
[shardingsphere] branch master updated: Fix master branch ci exception caused by sql parser (#20224)
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 715b86ecdff Fix master branch ci exception caused by sql parser (#20224)
715b86ecdff is described below
commit 715b86ecdff0e0090e1454b5273b8c63360373a0
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Wed Aug 17 08:48:22 2022 +0800
Fix master branch ci exception caused by sql parser (#20224)
* Fix master branch ci exception caused by sql parser
* update grammar rule
---
.../parser/DatabaseDiscoveryDistSQLTest.java | 8 +++---
.../segment/from/impl/JoinTableConverter.java | 30 ++++++++++++++++++++--
.../datasource/AbstractDataSourcePreparer.java | 2 +-
.../main/antlr4/imports/opengauss/DMLStatement.g4 | 2 +-
.../main/antlr4/imports/postgresql/DMLStatement.g4 | 2 +-
5 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/DatabaseDiscoveryDistSQLTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/DatabaseDiscoveryDistSQLTest.java
index 8294028b3b3..75057e6aad3 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/DatabaseDiscoveryDistSQLTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/DatabaseDiscoveryDistSQLTest.java
@@ -63,7 +63,7 @@ public class DatabaseDiscoveryDistSQLTest {
assertThat(distSQLStatement.getRules().size(), is(1));
assertDiscoverySegment((DatabaseDiscoveryDefinitionSegment) distSQLStatement.getRules().iterator().next());
}
-
+
@Test
public void assertCreateDatabaseDiscoveryType() {
String sql = "CREATE DB_DISCOVERY TYPE primary_replica_ds_mgr(TYPE(NAME='mgr',PROPERTIES('group-name'='92504d5b'))),primary_replica_ds_mgr_2(TYPE(NAME='mgr'))";
@@ -71,7 +71,7 @@ public class DatabaseDiscoveryDistSQLTest {
assertThat(distSQLStatement.getProviders().size(), is(2));
assertAlgorithmSegment(distSQLStatement.getProviders().iterator());
}
-
+
@Test
public void assertAlterDatabaseDiscoveryType() {
String sql = "ALTER DB_DISCOVERY TYPE primary_replica_ds_mgr(TYPE(NAME='mgr',PROPERTIES('group-name'='92504d5b'))),primary_replica_ds_mgr_2(TYPE(NAME='mgr'))";
@@ -79,7 +79,7 @@ public class DatabaseDiscoveryDistSQLTest {
assertThat(distSQLStatement.getProviders().size(), is(2));
assertAlgorithmSegment(distSQLStatement.getProviders().iterator());
}
-
+
private void assertDiscoverySegment(final DatabaseDiscoveryDefinitionSegment discoverySegment) {
assertThat(discoverySegment.getName(), is("db_discovery_group_0"));
assertThat(discoverySegment.getDataSources(), is(Arrays.asList("ds_0", "ds_1")));
@@ -91,7 +91,7 @@ public class DatabaseDiscoveryDistSQLTest {
heartbeatProps.setProperty("keep-alive-cron", "0/5 * * * * ?");
assertThat(discoverySegment.getDiscoveryHeartbeat(), is(heartbeatProps));
}
-
+
private void assertAlgorithmSegment(final Iterator<DatabaseDiscoveryProviderAlgorithmSegment> iterator) {
DatabaseDiscoveryProviderAlgorithmSegment providerAlgorithmSegment = iterator.next();
Properties properties = new Properties();
diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/JoinTableConverter.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/JoinTableConverter.java
index 6c71dc90748..89e81cbdfc5 100644
--- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/JoinTableConverter.java
+++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/JoinTableConverter.java
@@ -35,6 +35,14 @@ import java.util.Optional;
*/
public final class JoinTableConverter implements SQLSegmentConverter<JoinTableSegment, SqlJoin> {
+ private static final String JOIN_TYPE_INNER = "INNER";
+
+ private static final String JOIN_TYPE_LEFT = "LEFT";
+
+ private static final String JOIN_TYPE_RIGHT = "RIGHT";
+
+ private static final String JOIN_TYPE_FULL = "FULL";
+
@Override
public Optional<SqlJoin> convert(final JoinTableSegment segment) {
SqlNode left = new TableConverter().convert(segment.getLeft()).orElseThrow(IllegalStateException::new);
@@ -42,7 +50,25 @@ public final class JoinTableConverter implements SQLSegmentConverter<JoinTableSe
Optional<SqlNode> condition = new ExpressionConverter().convert(segment.getCondition());
SqlLiteral conditionType = condition.isPresent() ? JoinConditionType.ON.symbol(SqlParserPos.ZERO) : JoinConditionType.NONE.symbol(SqlParserPos.ZERO);
return Optional.of(
- new SqlJoin(SqlParserPos.ZERO, left, SqlLiteral.createBoolean(false, SqlParserPos.ZERO), JoinType.valueOf(segment.getJoinType()).symbol(SqlParserPos.ZERO), right, conditionType,
- condition.orElse(null)));
+ new SqlJoin(SqlParserPos.ZERO, left, SqlLiteral.createBoolean(false, SqlParserPos.ZERO), convertJoinType(segment.getJoinType()), right, conditionType, condition.orElse(null)));
+ }
+
+ private SqlLiteral convertJoinType(final String joinType) {
+ if (null == joinType) {
+ return JoinType.COMMA.symbol(SqlParserPos.ZERO);
+ }
+ if (JOIN_TYPE_INNER.equals(joinType)) {
+ return JoinType.INNER.symbol(SqlParserPos.ZERO);
+ }
+ if (JOIN_TYPE_LEFT.equals(joinType)) {
+ return JoinType.LEFT.symbol(SqlParserPos.ZERO);
+ }
+ if (JOIN_TYPE_RIGHT.equals(joinType)) {
+ return JoinType.RIGHT.symbol(SqlParserPos.ZERO);
+ }
+ if (JOIN_TYPE_FULL.equals(joinType)) {
+ return JoinType.FULL.symbol(SqlParserPos.ZERO);
+ }
+ throw new UnsupportedOperationException("unsupported join type " + joinType);
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/prepare/datasource/AbstractDataSourcePreparer.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/prepare/datasource/AbstractDataSourcePreparer.java
index 8fe4bd03984..15cf5495073 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/prepare/datasource/AbstractDataSourcePreparer.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/prepare/datasource/AbstractDataSourcePreparer.java
@@ -115,7 +115,7 @@ public abstract class AbstractDataSourcePreparer implements DataSourcePreparer {
}
return PATTERN_CREATE_TABLE.matcher(createTableSQL).replaceFirst("CREATE TABLE IF NOT EXISTS ");
}
-
+
protected String getActualTable(final ShardingSphereDatabase database, final String tableName) {
DataNodes dataNodes = new DataNodes(database.getRuleMetaData().getRules());
Optional<DataNode> filteredDataNode = dataNodes.getDataNodes(tableName).stream()
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
index a53968ecdd6..68978ff8848 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
@@ -387,7 +387,7 @@ tableReference
joinedTable
: crossJoinType tableReference
| innerJoinType tableReference joinQual
- | outerJoinType tableReference
+ | outerJoinType tableReference joinQual
| naturalJoinType tableReference
;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
index 8a458c2cebd..490e74fb51c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
@@ -390,7 +390,7 @@ tableReference
joinedTable
: crossJoinType tableReference
| innerJoinType tableReference joinQual
- | outerJoinType tableReference
+ | outerJoinType tableReference joinQual
| naturalJoinType tableReference
;