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 e4428d6 support mysql create and drop view refresh meta data (#7853)
e4428d6 is described below
commit e4428d6a4fb312a4579e8320e4e019b5d05dc5cc
Author: DuanZhengqiang <[email protected]>
AuthorDate: Tue Oct 20 14:04:06 2020 +0800
support mysql create and drop view refresh meta data (#7853)
* support create and drop view refresh meta data
* support function and procedure all databases route
---
.../engine/type/ShardingRouteEngineFactory.java | 5 +-
.../ddl/ShardingDDLStatementValidator.java | 19 +++++++
.../ShardingCreateFunctionStatementValidator.java | 6 ++-
.../ShardingCreateProcedureStatementValidator.java | 6 ++-
...ardingCreateFunctionStatementValidatorTest.java | 24 +++++++++
...rdingCreateProcedureStatementValidatorTest.java | 24 +++++++++
.../infra/binder/SQLStatementContextFactory.java | 7 ++-
.../statement/ddl/AlterViewStatementContext.java | 14 ++++--
...tContext.java => DropViewStatementContext.java} | 18 ++-----
.../refresh/MetaDataRefreshStrategyFactory.java | 6 +++
...CreateViewStatementMetaDataRefreshStrategy.java | 58 ++++++++++++++++++++++
.../DropViewStatementMetaDataRefreshStrategy.java | 48 ++++++++++++++++++
...teViewStatementMetaDataRefreshStrategyTest.java | 55 ++++++++++++++++++++
...opViewStatementMetaDataRefreshStrategyTest.java | 56 +++++++++++++++++++++
.../src/main/antlr4/imports/mysql/BaseRule.g4 | 4 ++
.../src/main/antlr4/imports/mysql/DDLStatement.g4 | 2 +-
.../sql/parser/mysql/visitor/MySQLVisitor.java | 21 ++++++++
.../parser/mysql/visitor/impl/MySQLDDLVisitor.java | 7 ++-
.../common/statement/ddl/AlterViewStatement.java | 7 +++
.../common/statement/ddl/CreateViewStatement.java | 7 +++
.../common/statement/ddl/DropViewStatement.java | 8 +++
21 files changed, 380 insertions(+), 22 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
index 4abc2c9..d11afc8 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
@@ -110,11 +110,14 @@ public final class ShardingRouteEngineFactory {
SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
boolean functionStatement = sqlStatement instanceof
CreateFunctionStatement || sqlStatement instanceof AlterFunctionStatement ||
sqlStatement instanceof DropFunctionStatement;
boolean procedureStatement = sqlStatement instanceof
CreateProcedureStatement || sqlStatement instanceof AlterProcedureStatement ||
sqlStatement instanceof DropProcedureStatement;
+ if (functionStatement || procedureStatement) {
+ return new ShardingDatabaseBroadcastRoutingEngine();
+ }
boolean viewStatement = sqlStatement instanceof CreateViewStatement ||
sqlStatement instanceof AlterViewStatement || sqlStatement instanceof
DropViewStatement;
boolean tableStatement = sqlStatement instanceof CreateTableStatement
|| sqlStatement instanceof AlterTableStatement || sqlStatement instanceof
DropTableStatement;
Collection<String> tableNames =
sqlStatementContext.getTablesContext().getTableNames();
boolean modifyTableWithoutShardingRule = tableStatement &&
!tableNames.isEmpty() && !shardingRule.tableRuleExists(tableNames);
- if (functionStatement || procedureStatement || viewStatement ||
modifyTableWithoutShardingRule) {
+ if (viewStatement || modifyTableWithoutShardingRule) {
return new ShardingUnconfiguredTablesRoutingEngine(tableNames,
schemaMetaData.getUnconfiguredSchemaMetaDataMap(), sqlStatement);
}
return new
ShardingTableBroadcastRoutingEngine(schemaMetaData.getConfiguredSchemaMetaData(),
sqlStatementContext);
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
index 3ba66b0..8067253 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDDLStatementValidator.java
@@ -19,12 +19,14 @@ package
org.apache.shardingsphere.sharding.route.engine.validator.ddl;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import
org.apache.shardingsphere.sharding.route.engine.exception.NoSuchTableException;
import
org.apache.shardingsphere.sharding.route.engine.exception.TableExistsException;
import
org.apache.shardingsphere.sharding.route.engine.validator.ShardingStatementValidator;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
import java.util.Collection;
+import java.util.Map;
/**
* Sharding ddl statement validator.
@@ -47,6 +49,23 @@ public abstract class ShardingDDLStatementValidator<T
extends DDLStatement> impl
}
/**
+ * Validate table exist.
+ *
+ * @param metaData meta data
+ * @param tables tables
+ */
+ protected void validateTableExist(final ShardingSphereMetaData metaData,
final Collection<SimpleTableSegment> tables) {
+ for (SimpleTableSegment each : tables) {
+ String tableName = each.getTableName().getIdentifier().getValue();
+ for (Map.Entry<String, Collection<String>> entry :
metaData.getSchemaMetaData().getUnconfiguredSchemaMetaDataMap().entrySet()) {
+ if (!entry.getValue().contains(tableName)) {
+ throw new NoSuchTableException(entry.getKey(), tableName);
+ }
+ }
+ }
+ }
+
+ /**
* Validate table not exist.
*
* @param metaData meta data
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
index ec2dfe9..6596101 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java
@@ -24,9 +24,11 @@ import
org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDL
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.routine.RoutineBodySegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateFunctionStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateFunctionStatementHandler;
+import java.util.Collection;
import java.util.List;
import java.util.Optional;
@@ -41,7 +43,9 @@ public final class ShardingCreateFunctionStatementValidator
extends ShardingDDLS
Optional<RoutineBodySegment> routineBodySegment =
CreateFunctionStatementHandler.getRoutineBodySegment(sqlStatementContext.getSqlStatement());
routineBodySegment.ifPresent(routineBody -> {
TableExtractor extractor = new TableExtractor();
- validateShardingTable(metaData,
extractor.extractExistTableFromRoutineBody(routineBody));
+ Collection<SimpleTableSegment> existTables =
extractor.extractExistTableFromRoutineBody(routineBody);
+ validateShardingTable(metaData, existTables);
+ validateTableExist(metaData, existTables);
validateTableNotExist(metaData,
extractor.extractNotExistTableFromRoutineBody(routineBody));
});
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
index 2af986c..b522e99 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java
@@ -24,9 +24,11 @@ import
org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDL
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.routine.RoutineBodySegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateProcedureStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateProcedureStatementHandler;
+import java.util.Collection;
import java.util.List;
import java.util.Optional;
@@ -42,7 +44,9 @@ public final class ShardingCreateProcedureStatementValidator
extends ShardingDDL
routineBodySegment.ifPresent(routineBody -> {
TableExtractor extractor = new TableExtractor();
validateTableNotExist(metaData,
extractor.extractNotExistTableFromRoutineBody(routineBody));
- validateShardingTable(metaData,
extractor.extractExistTableFromRoutineBody(routineBody));
+ Collection<SimpleTableSegment> existTables =
extractor.extractExistTableFromRoutineBody(routineBody);
+ validateShardingTable(metaData, existTables);
+ validateTableExist(metaData, existTables);
});
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java
index d5ab0eb..fe705ce 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
import
org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
+import
org.apache.shardingsphere.sharding.route.engine.exception.NoSuchTableException;
import
org.apache.shardingsphere.sharding.route.engine.exception.TableExistsException;
import
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingCreateFunctionStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -99,6 +100,29 @@ public final class
ShardingCreateFunctionStatementValidatorTest {
new
ShardingCreateFunctionStatementValidator().preValidate(shardingRule,
sqlStatementContext, Collections.emptyList(), metaData);
}
+ @Test(expected = NoSuchTableException.class)
+ public void assertValidateCreateFunctionWithNoSuchTableForMySQL() {
+ MySQLSelectStatement selectStatement = new MySQLSelectStatement();
+ selectStatement.setFrom(new SimpleTableSegment(0, 0, new
IdentifierValue("t_order")));
+ ValidStatementSegment validStatementSegment = new
ValidStatementSegment(0, 0);
+ validStatementSegment.setSqlStatement(selectStatement);
+ RoutineBodySegment routineBody = new RoutineBodySegment(0, 0);
+ routineBody.getValidStatements().add(validStatementSegment);
+ MySQLCreateFunctionStatement sqlStatement = new
MySQLCreateFunctionStatement();
+ sqlStatement.setRoutineBody(routineBody);
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ LogicSchemaMetaData logicSchemaMetaData =
mock(LogicSchemaMetaData.class);
+ PhysicalSchemaMetaData schemaMetaData =
mock(PhysicalSchemaMetaData.class);
+ when(metaData.getSchemaMetaData()).thenReturn(logicSchemaMetaData);
+
when(logicSchemaMetaData.getConfiguredSchemaMetaData()).thenReturn(schemaMetaData);
+
when(schemaMetaData.getAllTableNames()).thenReturn(Collections.emptyList());
+ Map<String, Collection<String>> unconfiguredSchemaMetaDataMap = new
HashMap<>(1, 1);
+ unconfiguredSchemaMetaDataMap.put("ds_0", Collections.emptyList());
+
when(logicSchemaMetaData.getUnconfiguredSchemaMetaDataMap()).thenReturn(unconfiguredSchemaMetaDataMap);
+ SQLStatementContext<CreateFunctionStatement> sqlStatementContext = new
CommonSQLStatementContext<>(sqlStatement);
+ new
ShardingCreateFunctionStatementValidator().preValidate(shardingRule,
sqlStatementContext, Collections.emptyList(), metaData);
+ }
+
@Test(expected = TableExistsException.class)
public void assertValidateCreateFunctionWithTableExistsForMySQL() {
MySQLCreateTableStatement createTableStatement = new
MySQLCreateTableStatement();
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java
index 9d66196..ec5dddb 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
import
org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
+import
org.apache.shardingsphere.sharding.route.engine.exception.NoSuchTableException;
import
org.apache.shardingsphere.sharding.route.engine.exception.TableExistsException;
import
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingCreateProcedureStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -99,6 +100,29 @@ public final class
ShardingCreateProcedureStatementValidatorTest {
new
ShardingCreateProcedureStatementValidator().preValidate(shardingRule,
sqlStatementContext, Collections.emptyList(), metaData);
}
+ @Test(expected = NoSuchTableException.class)
+ public void assertValidateCreateProcedureWithNoSuchTableForMySQL() {
+ MySQLSelectStatement selectStatement = new MySQLSelectStatement();
+ selectStatement.setFrom(new SimpleTableSegment(0, 0, new
IdentifierValue("t_order")));
+ ValidStatementSegment validStatementSegment = new
ValidStatementSegment(0, 0);
+ validStatementSegment.setSqlStatement(selectStatement);
+ RoutineBodySegment routineBody = new RoutineBodySegment(0, 0);
+ routineBody.getValidStatements().add(validStatementSegment);
+ MySQLCreateProcedureStatement sqlStatement = new
MySQLCreateProcedureStatement();
+ sqlStatement.setRoutineBody(routineBody);
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ LogicSchemaMetaData logicSchemaMetaData =
mock(LogicSchemaMetaData.class);
+ PhysicalSchemaMetaData schemaMetaData =
mock(PhysicalSchemaMetaData.class);
+ when(metaData.getSchemaMetaData()).thenReturn(logicSchemaMetaData);
+
when(logicSchemaMetaData.getConfiguredSchemaMetaData()).thenReturn(schemaMetaData);
+
when(schemaMetaData.getAllTableNames()).thenReturn(Collections.emptyList());
+ Map<String, Collection<String>> unconfiguredSchemaMetaDataMap = new
HashMap<>(1, 1);
+ unconfiguredSchemaMetaDataMap.put("ds_0", Collections.emptyList());
+
when(logicSchemaMetaData.getUnconfiguredSchemaMetaDataMap()).thenReturn(unconfiguredSchemaMetaDataMap);
+ SQLStatementContext<CreateProcedureStatement> sqlStatementContext =
new CommonSQLStatementContext<>(sqlStatement);
+ new
ShardingCreateProcedureStatementValidator().preValidate(shardingRule,
sqlStatementContext, Collections.emptyList(), metaData);
+ }
+
@Test(expected = TableExistsException.class)
public void assertValidateCreateProcedureWithTableExistsForMySQL() {
MySQLCreateTableStatement createTableStatement = new
MySQLCreateTableStatement();
diff --git
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
index ca1392f..473a852 100644
---
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
+++
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.binder;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dal.DescribeStatementContext;
@@ -39,12 +38,14 @@ import
org.apache.shardingsphere.infra.binder.statement.ddl.CreateTableStatement
import
org.apache.shardingsphere.infra.binder.statement.ddl.CreateViewStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.DropIndexStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.DropTableStatementContext;
+import
org.apache.shardingsphere.infra.binder.statement.ddl.DropViewStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.TruncateStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.CallStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.DeleteStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
+import
org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DCLStatement;
@@ -61,6 +62,7 @@ import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewS
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.TruncateStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.CallStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
@@ -159,6 +161,9 @@ public final class SQLStatementContextFactory {
if (sqlStatement instanceof AlterViewStatement) {
return new AlterViewStatementContext((AlterViewStatement)
sqlStatement);
}
+ if (sqlStatement instanceof DropViewStatement) {
+ return new DropViewStatementContext((DropViewStatement)
sqlStatement);
+ }
return new CommonSQLStatementContext<>(sqlStatement);
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterViewStatementContext.java
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterViewStatementContext.java
index 43be81d..c1633c0 100644
---
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterViewStatementContext.java
+++
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterViewStatementContext.java
@@ -21,10 +21,13 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterViewStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterViewStatementHandler;
+import java.util.Collection;
+import java.util.LinkedList;
import java.util.Optional;
/**
@@ -37,9 +40,14 @@ public final class AlterViewStatementContext extends
CommonSQLStatementContext<A
public AlterViewStatementContext(final AlterViewStatement sqlStatement) {
super(sqlStatement);
+ Collection<SimpleTableSegment> tables = new LinkedList<>();
+ tables.add(sqlStatement.getView());
Optional<SelectStatement> selectStatement =
AlterViewStatementHandler.getSelectStatement(sqlStatement);
- TableExtractor extractor = new TableExtractor();
- selectStatement.ifPresent(extractor::extractTablesFromSelect);
- tablesContext = new TablesContext(extractor.getRewriteTables());
+ selectStatement.ifPresent(select -> {
+ TableExtractor extractor = new TableExtractor();
+ extractor.extractTablesFromSelect(select);
+ tables.addAll(extractor.getRewriteTables());
+ });
+ tablesContext = new TablesContext(tables);
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterViewStatementContext.java
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/DropViewStatementContext.java
similarity index 59%
copy from
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterViewStatementContext.java
copy to
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/DropViewStatementContext.java
index 43be81d..f10f62e 100644
---
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/AlterViewStatementContext.java
+++
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/DropViewStatementContext.java
@@ -20,26 +20,18 @@ package
org.apache.shardingsphere.infra.binder.statement.ddl;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
-import
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterViewStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterViewStatementHandler;
-
-import java.util.Optional;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
/**
- * Alter view statement context.
+ * Drop view statement context.
*/
@Getter
-public final class AlterViewStatementContext extends
CommonSQLStatementContext<AlterViewStatement> {
+public final class DropViewStatementContext extends
CommonSQLStatementContext<DropViewStatement> {
private final TablesContext tablesContext;
- public AlterViewStatementContext(final AlterViewStatement sqlStatement) {
+ public DropViewStatementContext(final DropViewStatement sqlStatement) {
super(sqlStatement);
- Optional<SelectStatement> selectStatement =
AlterViewStatementHandler.getSelectStatement(sqlStatement);
- TableExtractor extractor = new TableExtractor();
- selectStatement.ifPresent(extractor::extractTablesFromSelect);
- tablesContext = new TablesContext(extractor.getRewriteTables());
+ tablesContext = new TablesContext(sqlStatement.getViews());
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/MetaDataRefreshStrategyFactory.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/MetaDataRefreshStrategyFactory.java
index 218002c..7f193ee 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/MetaDataRefreshStrategyFactory.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/MetaDataRefreshStrategyFactory.java
@@ -22,14 +22,18 @@ import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.infra.metadata.refresh.impl.AlterTableStatementMetaDataRefreshStrategy;
import
org.apache.shardingsphere.infra.metadata.refresh.impl.CreateIndexStatementMetaDataRefreshStrategy;
import
org.apache.shardingsphere.infra.metadata.refresh.impl.CreateTableStatementMetaDataRefreshStrategy;
+import
org.apache.shardingsphere.infra.metadata.refresh.impl.CreateViewStatementMetaDataRefreshStrategy;
import
org.apache.shardingsphere.infra.metadata.refresh.impl.DropIndexStatementMetaDataRefreshStrategy;
import
org.apache.shardingsphere.infra.metadata.refresh.impl.DropTableStatementMetaDataRefreshStrategy;
+import
org.apache.shardingsphere.infra.metadata.refresh.impl.DropViewStatementMetaDataRefreshStrategy;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
import java.util.HashMap;
import java.util.Map;
@@ -50,6 +54,8 @@ public final class MetaDataRefreshStrategyFactory {
REGISTRY.put(DropTableStatement.class, new
DropTableStatementMetaDataRefreshStrategy());
REGISTRY.put(CreateIndexStatement.class, new
CreateIndexStatementMetaDataRefreshStrategy());
REGISTRY.put(DropIndexStatement.class, new
DropIndexStatementMetaDataRefreshStrategy());
+ REGISTRY.put(CreateViewStatement.class, new
CreateViewStatementMetaDataRefreshStrategy());
+ REGISTRY.put(DropViewStatement.class, new
DropViewStatementMetaDataRefreshStrategy());
}
/**
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/impl/CreateViewStatementMetaDataRefreshStrategy.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/impl/CreateViewStatementMetaDataRefreshStrategy.java
new file mode 100644
index 0000000..a75e0ab
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/impl/CreateViewStatementMetaDataRefreshStrategy.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.refresh.impl;
+
+import com.google.common.collect.Lists;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import
org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
+import
org.apache.shardingsphere.infra.metadata.refresh.MetaDataRefreshStrategy;
+import
org.apache.shardingsphere.infra.metadata.refresh.TableMetaDataLoaderCallback;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * Create view statement meta data refresh strategy.
+ */
+public final class CreateViewStatementMetaDataRefreshStrategy implements
MetaDataRefreshStrategy<CreateViewStatement> {
+
+ @Override
+ public void refreshMetaData(final ShardingSphereMetaData metaData, final
DatabaseType databaseType, final Collection<String> routeDataSourceNames,
+ final CreateViewStatement sqlStatement, final
TableMetaDataLoaderCallback callback) throws SQLException {
+ String viewName =
sqlStatement.getView().getTableName().getIdentifier().getValue();
+ refreshUnconfiguredMetaData(metaData, routeDataSourceNames, viewName);
+ metaData.getSchemaMetaData().getSchemaMetaData().put(viewName, new
PhysicalTableMetaData());
+ }
+
+ private void refreshUnconfiguredMetaData(final ShardingSphereMetaData
metaData, final Collection<String> routeDataSourceNames, final String viewName)
{
+ for (String each : routeDataSourceNames) {
+ refreshUnconfiguredMetaData(metaData, viewName, each);
+ }
+ }
+
+ private void refreshUnconfiguredMetaData(final ShardingSphereMetaData
metaData, final String viewName, final String dataSourceName) {
+ Collection<String> schemaMetaData =
metaData.getSchemaMetaData().getUnconfiguredSchemaMetaDataMap().get(dataSourceName);
+ if (null == schemaMetaData) {
+
metaData.getSchemaMetaData().getUnconfiguredSchemaMetaDataMap().put(dataSourceName,
Lists.newArrayList(viewName));
+ } else {
+ schemaMetaData.add(viewName);
+ }
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/impl/DropViewStatementMetaDataRefreshStrategy.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/impl/DropViewStatementMetaDataRefreshStrategy.java
new file mode 100644
index 0000000..2e735ac
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/refresh/impl/DropViewStatementMetaDataRefreshStrategy.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.refresh.impl;
+
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import
org.apache.shardingsphere.infra.metadata.refresh.MetaDataRefreshStrategy;
+import
org.apache.shardingsphere.infra.metadata.refresh.TableMetaDataLoaderCallback;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
+
+import java.util.Collection;
+
+/**
+ * Drop view statement meta data refresh strategy.
+ */
+public final class DropViewStatementMetaDataRefreshStrategy implements
MetaDataRefreshStrategy<DropViewStatement> {
+
+ @Override
+ public void refreshMetaData(final ShardingSphereMetaData metaData, final
DatabaseType databaseType, final Collection<String> routeDataSourceNames,
+ final DropViewStatement sqlStatement, final
TableMetaDataLoaderCallback callback) {
+ sqlStatement.getViews().forEach(each -> removeMetaData(metaData,
each.getTableName().getIdentifier().getValue(), routeDataSourceNames));
+ }
+
+ private void removeMetaData(final ShardingSphereMetaData metaData, final
String viewName, final Collection<String> routeDataSourceNames) {
+ for (String each : routeDataSourceNames) {
+ Collection<String> schemaMetaData =
metaData.getSchemaMetaData().getUnconfiguredSchemaMetaDataMap().get(each);
+ if (null != schemaMetaData) {
+ schemaMetaData.remove(viewName);
+ }
+ }
+ metaData.getSchemaMetaData().getSchemaMetaData().remove(viewName);
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/impl/CreateViewStatementMetaDataRefreshStrategyTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/impl/CreateViewStatementMetaDataRefreshStrategyTest.java
new file mode 100644
index 0000000..fa3a5d7
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/impl/CreateViewStatementMetaDataRefreshStrategyTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.refresh.impl;
+
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import
org.apache.shardingsphere.infra.metadata.refresh.AbstractMetaDataRefreshStrategyTest;
+import
org.apache.shardingsphere.infra.metadata.refresh.MetaDataRefreshStrategy;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateViewStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateViewStatement;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.junit.Assert.assertTrue;
+
+public final class CreateViewStatementMetaDataRefreshStrategyTest extends
AbstractMetaDataRefreshStrategyTest {
+
+ @Test
+ public void refreshMetaDataWithUnConfiguredForMySQL() throws SQLException {
+ refreshMetaDataWithUnConfigured(new MySQLCreateViewStatement());
+ }
+
+ @Test
+ public void refreshMetaDataWithUnConfiguredForPostgreSQL() throws
SQLException {
+ refreshMetaDataWithUnConfigured(new PostgreSQLCreateViewStatement());
+ }
+
+ private void refreshMetaDataWithUnConfigured(final CreateViewStatement
createViewStatement) throws SQLException {
+ createViewStatement.setView(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_item_0"))));
+ MetaDataRefreshStrategy<CreateViewStatement> metaDataRefreshStrategy =
new CreateViewStatementMetaDataRefreshStrategy();
+ metaDataRefreshStrategy.refreshMetaData(getMetaData(), new
MySQLDatabaseType(), Collections.singletonList("t_order_item"),
createViewStatement, tableName -> Optional.empty());
+
assertTrue(getMetaData().getSchemaMetaData().getUnconfiguredSchemaMetaDataMap().get("t_order_item").contains("t_order_item_0"));
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/impl/DropViewStatementMetaDataRefreshStrategyTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/impl/DropViewStatementMetaDataRefreshStrategyTest.java
new file mode 100644
index 0000000..44e150f6
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/impl/DropViewStatementMetaDataRefreshStrategyTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.refresh.impl;
+
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import
org.apache.shardingsphere.infra.metadata.refresh.AbstractMetaDataRefreshStrategyTest;
+import
org.apache.shardingsphere.infra.metadata.refresh.MetaDataRefreshStrategy;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLDropViewStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropViewStatement;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.mock;
+
+public final class DropViewStatementMetaDataRefreshStrategyTest extends
AbstractMetaDataRefreshStrategyTest {
+
+ @Test
+ public void refreshMetaDataWithUnConfiguredForMySQL() throws SQLException {
+ refreshMetaDataWithUnConfigured(new MySQLDropViewStatement());
+ }
+
+ @Test
+ public void refreshMetaDataWithUnConfiguredForPostgreSQL() throws
SQLException {
+ refreshMetaDataWithUnConfigured(new PostgreSQLDropViewStatement());
+ }
+
+ private void refreshMetaDataWithUnConfigured(final DropViewStatement
dropViewStatement) throws SQLException {
+ MetaDataRefreshStrategy<DropViewStatement> metaDataRefreshStrategy =
new DropViewStatementMetaDataRefreshStrategy();
+ dropViewStatement.getViews().add(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_item"))));
+ metaDataRefreshStrategy.refreshMetaData(getMetaData(),
mock(DatabaseType.class), Collections.singletonList("t_order_item"),
dropViewStatement, tableName -> Optional.empty());
+
assertFalse(getMetaData().getSchemaMetaData().getUnconfiguredSchemaMetaDataMap().get("t_order_item").contains("t_order_item"));
+ }
+}
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
index d095973..1bb9df0 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
@@ -242,6 +242,10 @@ name
tableNames
: LP_? tableName (COMMA_ tableName)* RP_?
;
+
+viewNames
+ : viewName (COMMA_ viewName)*
+ ;
columnNames
: LP_? columnName (COMMA_ columnName)* RP_?
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
index 0515336..44a0684 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
@@ -227,7 +227,7 @@ alterView
;
dropView
- : DROP VIEW existClause? viewName (COMMA_ viewName)* (RESTRICT | CASCADE)?
+ : DROP VIEW existClause? viewNames (RESTRICT | CASCADE)?
;
createTablespaceInnodb
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
index 350eb3b..418cf6e 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java
@@ -66,6 +66,8 @@ import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.Substri
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TableNameContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TableNamesContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UnreservedWordContext;
+import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ViewNameContext;
+import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ViewNamesContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WeightStringFunctionContext;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WindowFunctionContext;
import
org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
@@ -243,6 +245,16 @@ public abstract class MySQLVisitor extends
MySQLStatementBaseVisitor<ASTNode> {
}
@Override
+ public final ASTNode visitViewName(final ViewNameContext ctx) {
+ SimpleTableSegment result = new SimpleTableSegment(new
TableNameSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
(IdentifierValue) visit(ctx.identifier())));
+ OwnerContext owner = ctx.owner();
+ if (null != owner) {
+ result.setOwner(new OwnerSegment(owner.getStart().getStartIndex(),
owner.getStop().getStopIndex(), (IdentifierValue) visit(owner.identifier())));
+ }
+ return result;
+ }
+
+ @Override
public final ASTNode visitColumnName(final ColumnNameContext ctx) {
ColumnSegment result = new
ColumnSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
(IdentifierValue) visit(ctx.name()));
OwnerContext owner = ctx.owner();
@@ -267,6 +279,15 @@ public abstract class MySQLVisitor extends
MySQLStatementBaseVisitor<ASTNode> {
}
@Override
+ public final ASTNode visitViewNames(final ViewNamesContext ctx) {
+ CollectionValue<SimpleTableSegment> result = new CollectionValue<>();
+ for (ViewNameContext each : ctx.viewName()) {
+ result.getValue().add((SimpleTableSegment) visit(each));
+ }
+ return result;
+ }
+
+ @Override
public final ASTNode visitColumnNames(final ColumnNamesContext ctx) {
CollectionValue<ColumnSegment> result = new CollectionValue<>();
for (ColumnNameContext each : ctx.columnName()) {
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java
index 103d82a..0a83f85 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDDLVisitor.java
@@ -156,6 +156,7 @@ public final class MySQLDDLVisitor extends MySQLVisitor
implements DDLVisitor {
@Override
public ASTNode visitCreateView(final CreateViewContext ctx) {
MySQLCreateViewStatement result = new MySQLCreateViewStatement();
+ result.setView((SimpleTableSegment) visit(ctx.viewName()));
result.setSelect((MySQLSelectStatement) visit(ctx.select()));
return result;
}
@@ -163,13 +164,17 @@ public final class MySQLDDLVisitor extends MySQLVisitor
implements DDLVisitor {
@Override
public ASTNode visitAlterView(final AlterViewContext ctx) {
MySQLAlterViewStatement result = new MySQLAlterViewStatement();
+ result.setView((SimpleTableSegment) visit(ctx.viewName()));
result.setSelect((MySQLSelectStatement) visit(ctx.select()));
return result;
}
+ @SuppressWarnings("unchecked")
@Override
public ASTNode visitDropView(final DropViewContext ctx) {
- return new MySQLDropViewStatement();
+ MySQLDropViewStatement result = new MySQLDropViewStatement();
+ result.getViews().addAll(((CollectionValue<SimpleTableSegment>)
visit(ctx.viewNames())).getValue());
+ return result;
}
@Override
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterViewStatement.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterViewStatement.java
index 691dc46..ffcaac8 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterViewStatement.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterViewStatement.java
@@ -17,10 +17,17 @@
package org.apache.shardingsphere.sql.parser.sql.common.statement.ddl;
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
/**
* Alter view statement.
*/
+@Getter
+@Setter
public abstract class AlterViewStatement extends AbstractSQLStatement
implements DDLStatement {
+
+ private SimpleTableSegment view;
}
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/CreateViewStatement.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/CreateViewStatement.java
index 2a5dbe7..2128ee6 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/CreateViewStatement.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/CreateViewStatement.java
@@ -17,10 +17,17 @@
package org.apache.shardingsphere.sql.parser.sql.common.statement.ddl;
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
/**
* Create view statement.
*/
+@Getter
+@Setter
public abstract class CreateViewStatement extends AbstractSQLStatement
implements DDLStatement {
+
+ private SimpleTableSegment view;
}
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/DropViewStatement.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/DropViewStatement.java
index e80b8d3..1d893f3 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/DropViewStatement.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/DropViewStatement.java
@@ -17,10 +17,18 @@
package org.apache.shardingsphere.sql.parser.sql.common.statement.ddl;
+import lombok.Getter;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import java.util.Collection;
+import java.util.LinkedList;
+
/**
* Drop view statement.
*/
+@Getter
public abstract class DropViewStatement extends AbstractSQLStatement
implements DDLStatement {
+
+ private final Collection<SimpleTableSegment> views = new LinkedList<>();
}