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 2021/06/30 03:26:58 UTC
[shardingsphere] branch master updated: Add Oracle SQL - ASSOCIATE
STATISTICS (#11000)
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 9652844 Add Oracle SQL - ASSOCIATE STATISTICS (#11000)
9652844 is described below
commit 96528441931ca6f32e9c66fc807cebfa94d8ab9e
Author: Liangda-w <66...@users.noreply.github.com>
AuthorDate: Wed Jun 30 05:26:31 2021 +0200
Add Oracle SQL - ASSOCIATE STATISTICS (#11000)
* Add Oracle SQL - ASSOCIATE STATISTICS
* Delete unused
* Add Oracle SQL - ASSOCIATE STATISTICS
* Delete unused
* Add Getter
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 44 ++++++++++---
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 37 +++++++++--
.../main/antlr4/imports/oracle/OracleKeyword.g4 | 24 +++++++
.../sql/parser/autogen/OracleStatement.g4 | 1 +
.../impl/OracleDDLStatementSQLVisitor.java | 23 +++++++
.../core/database/visitor/SQLVisitorRule.java | 2 +
.../sql/common/segment/ddl/index/IndexSegment.java | 18 +++++-
.../ddl/OracleAssociateStatisticsStatement.java | 46 +++++++++++++
.../asserts/segment/index/IndexAssert.java | 11 +++-
.../asserts/statement/ddl/DDLStatementAssert.java | 5 ++
.../statement/ddl/impl/AnalyzeStatementAssert.java | 2 +-
.../impl/AssociateStatisticsStatementAssert.java | 75 ++++++++++++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 5 ++
.../domain/segment/impl/index/ExpectedIndex.java | 10 +++
.../ddl/AssociateStatisticsStatementTestCase.java | 47 ++++++++++++++
.../resources/case/ddl/associate-statistics.xml | 40 ++++++++++++
.../sql/supported/ddl/associate-statistics.xml | 27 ++++++++
17 files changed, 401 insertions(+), 16 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
index fd71a52..b060070 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/BaseRule.g4
@@ -127,6 +127,26 @@ indexName
: (owner DOT_)? name
;
+statisticsTypeName
+ : (owner DOT_)? name
+ ;
+
+function
+ : (owner DOT_)? name
+ ;
+
+packageName
+ : (owner DOT_)? name
+ ;
+
+typeName
+ : (owner DOT_)? name
+ ;
+
+indexTypeName
+ : (owner DOT_)? name
+ ;
+
constraintName
: identifier
;
@@ -195,10 +215,6 @@ accessDriverType
: identifier
;
-type
- : identifier
- ;
-
varrayItem
: identifier
;
@@ -448,10 +464,6 @@ attributeName
: oracleId
;
-indexTypeName
- : IDENTIFIER_
- ;
-
simpleExprs
: simpleExpr (COMMA_ simpleExpr)*
;
@@ -731,3 +743,19 @@ unitName
procedureName
: identifier
;
+
+cpuCost
+ : INTEGER_
+ ;
+
+ioCost
+ : INTEGER_
+ ;
+
+networkCost
+ : INTEGER_
+ ;
+
+defaultSelectivity
+ : INTEGER_
+ ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
index 6b4cd62..74eab82 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
@@ -59,10 +59,6 @@ tablespaceClause
: TABLESPACE ignoredIdentifier
;
-domainIndexClause
- : indexTypeName
- ;
-
createSharingClause
: (SHARING EQ_ (METADATA | DATA | EXTENDED DATA | NONE))?
;
@@ -1813,3 +1809,36 @@ validationClauses
intoClause
: INTO tableName
;
+
+associateStatistics
+ : ASSOCIATE STATISTICS WITH (columnAssociation | functionAssociation) storageTableClause?
+ ;
+
+columnAssociation
+ : COLUMNS tableName DOT_ columnName (COMMA_ tableName DOT_ columnName)* usingStatisticsType
+ ;
+
+functionAssociation
+ : (FUNCTIONS function (COMMA_ function)*
+ | PACKAGES packageName (COMMA_ packageName)*
+ | TYPES typeName (COMMA_ typeName)*
+ | INDEXES indexName (COMMA_ indexName)*
+ | INDEXTYPES indexTypeName (COMMA_ indexTypeName)*)
+ (usingStatisticsType | defaultCostClause (COMMA_ defaultSelectivityClause)? | defaultSelectivityClause (COMMA_ defaultCostClause)?)
+ ;
+
+storageTableClause
+ : WITH (SYSTEM | USER) MANAGED STORAGE TABLES
+ ;
+
+usingStatisticsType
+ : USING (statisticsTypeName | NULL)
+ ;
+
+defaultCostClause
+ : DEFAULT COST LP_ cpuCost COMMA_ ioCost COMMA_ networkCost RP_
+ ;
+
+defaultSelectivityClause
+ : DEFAULT SELECTIVITY defaultSelectivity
+ ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
index be780a3..6ba3ec8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
@@ -535,6 +535,10 @@ INDEXTYPE
: I N D E X T Y P E
;
+INDEXTYPES
+ : I N D E X T Y P E S
+ ;
+
EXTERNAL
: E X T E R N A L
;
@@ -2023,6 +2027,10 @@ PACKAGE
: P A C K A G E
;
+PACKAGES
+ : P A C K A G E S
+ ;
+
USING_NLS_COMP
: U S I N G UL_ N L S UL_ C O M P
;
@@ -2202,3 +2210,19 @@ FAST
COMPLETE
: C O M P L E T E
;
+
+ASSOCIATE
+ : A S S O C I A T E
+ ;
+
+FUNCTIONS
+ : F U N C T I O N S
+ ;
+
+TYPES
+ : T Y P E S
+ ;
+
+SELECTIVITY
+ : S E L E C T I V I T Y
+ ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
index 888b9db..1e52fb0 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
@@ -52,5 +52,6 @@ execute
| alterSystem
| setConstraints
| analyze
+ | associateStatistics
) SEMI_?
;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java
index 4b835ac..261018c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDDLStatementSQLVisitor.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterS
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterSystemContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterTableContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AnalyzeContext;
+import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AssociateStatisticsContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnDefinitionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnOrVirtualDefinitionContext;
@@ -42,6 +43,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropCo
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropConstraintClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropIndexContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropTableContext;
+import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.IndexNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.InlineConstraintContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyColPropertiesContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyColumnSpecificationContext;
@@ -50,6 +52,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.Operat
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.OutOfLineConstraintContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.OutOfLineRefConstraintContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.RelationalPropertyContext;
+import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TableNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TruncateTableContext;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.CreateDefinitionSegment;
@@ -74,6 +77,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.Ora
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSystemStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterTableStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAnalyzeStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAssociateStatisticsStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropIndexStatement;
@@ -389,4 +393,23 @@ public final class OracleDDLStatementSQLVisitor extends OracleStatementSQLVisito
}
return result;
}
+
+ @Override
+ public ASTNode visitAssociateStatistics(final AssociateStatisticsContext ctx) {
+ OracleAssociateStatisticsStatement result = new OracleAssociateStatisticsStatement();
+ if (null != ctx.columnAssociation()) {
+ for (TableNameContext each: ctx.columnAssociation().tableName()) {
+ result.getTables().add((SimpleTableSegment) visit(each));
+ }
+ for (ColumnNameContext each: ctx.columnAssociation().columnName()) {
+ result.getColumns().add((ColumnSegment) visit(each));
+ }
+ }
+ if (null != ctx.functionAssociation()) {
+ for (IndexNameContext each: ctx.functionAssociation().indexName()) {
+ result.getIndexes().add((IndexSegment) visit(each));
+ }
+ }
+ return result;
+ }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
index 9edd8df..1ff6489 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
@@ -130,6 +130,8 @@ public enum SQLVisitorRule {
DROP_TABLESPACE("DropTablespace", SQLStatementType.DDL),
+ ASSOCIATE_STATISTICS("AssociateStatistics", SQLStatementType.DDL),
+
SET_CONSTRAINTS("SetConstraints", SQLStatementType.TCL),
SET_TRANSACTION("SetTransaction", SQLStatementType.TCL),
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
index d21943b..b14174f 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/index/IndexSegment.java
@@ -19,19 +19,33 @@ package org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import lombok.Setter;
import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerAvailable;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+
+import java.util.Optional;
/**
* Index segment.
*/
@RequiredArgsConstructor
@Getter
-public final class IndexSegment implements SQLSegment {
+@Setter
+public final class IndexSegment implements SQLSegment, OwnerAvailable {
private final int startIndex;
private final int stopIndex;
private final IdentifierValue identifier;
+
+ private OwnerSegment owner;
+
+ @Override
+ public Optional<OwnerSegment> getOwner() {
+ return Optional.ofNullable(owner);
+ }
+
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAssociateStatisticsStatement.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAssociateStatisticsStatement.java
new file mode 100644
index 0000000..273be59
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleAssociateStatisticsStatement.java
@@ -0,0 +1,46 @@
+/*
+ * 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.sql.parser.sql.dialect.statement.oracle.ddl;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Oracle associate statistics statement.
+ */
+@Getter
+@Setter
+@ToString
+public final class OracleAssociateStatisticsStatement extends AbstractSQLStatement implements DDLStatement, OracleStatement {
+
+ private List<IndexSegment> indexes = new LinkedList<>();
+
+ private List<SimpleTableSegment> tables = new LinkedList<>();
+
+ private List<ColumnSegment> columns = new LinkedList<>();
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java
index 675152e..bc4d379 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/index/IndexAssert.java
@@ -22,10 +22,13 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.SQLSegmentAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.owner.OwnerAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.value.IdentifierValueAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.index.ExpectedIndex;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/**
* Index assert.
@@ -34,7 +37,7 @@ import static org.junit.Assert.assertNotNull;
public final class IndexAssert {
/**
- * Assert actual column segment is correct with expected column.
+ * Assert actual index segment is correct with expected index.
*
* @param assertContext assert context
* @param actual actual index segment
@@ -43,6 +46,12 @@ public final class IndexAssert {
public static void assertIs(final SQLCaseAssertContext assertContext, final IndexSegment actual, final ExpectedIndex expected) {
assertNotNull(assertContext.getText("Index should exist."), expected);
IdentifierValueAssert.assertIs(assertContext, actual.getIdentifier(), expected, "Index");
+ if (null != expected.getOwner()) {
+ assertTrue(assertContext.getText("Actual owner should exist."), actual.getOwner().isPresent());
+ OwnerAssert.assertIs(assertContext, actual.getOwner().get(), expected.getOwner());
+ } else {
+ assertFalse(assertContext.getText("Actual owner should not exist."), actual.getOwner().isPresent());
+ }
SQLSegmentAssert.assertIs(assertContext, actual, expected);
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/DDLStatementAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/DDLStatementAssert.java
index b69bc21..e6e5886 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/DDLStatementAssert.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/DDLStatementAssert.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.TruncateSta
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSessionStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterSynonymStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAnalyzeStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAssociateStatisticsStatement;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.AlterIndexStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.AlterSessionStatementAssert;
@@ -38,6 +39,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.AlterSystemStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.AlterTableStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.AnalyzeStatementAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.AssociateStatisticsStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.CreateIndexStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.CreateTableStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.ddl.impl.DropIndexStatementAssert;
@@ -50,6 +52,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterSystemStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterTableStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AnalyzeStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AssociateStatisticsStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.CreateIndexStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.CreateTableStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.DropIndexStatementTestCase;
@@ -92,6 +95,8 @@ public final class DDLStatementAssert {
AlterSystemStatementAssert.assertIs(assertContext, (AlterSystemStatement) actual, (AlterSystemStatementTestCase) expected);
} else if (actual instanceof OracleAnalyzeStatement) {
AnalyzeStatementAssert.assertIs(assertContext, (OracleAnalyzeStatement) actual, (AnalyzeStatementTestCase) expected);
+ } else if (actual instanceof OracleAssociateStatisticsStatement) {
+ AssociateStatisticsStatementAssert.assertIs(assertContext, (OracleAssociateStatisticsStatement) actual, (AssociateStatisticsStatementTestCase) expected);
}
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AnalyzeStatementAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AnalyzeStatementAssert.java
index aac7a33..6ac5f4c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AnalyzeStatementAssert.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AnalyzeStatementAssert.java
@@ -32,7 +32,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
public final class AnalyzeStatementAssert {
/**
- * Assert truncate statement is correct with expected parser result.
+ * Assert analyze statement is correct with expected parser result.
*
* @param assertContext assert context
* @param actual actual analyze statement
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AssociateStatisticsStatementAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AssociateStatisticsStatementAssert.java
new file mode 100644
index 0000000..f9d639f
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/ddl/impl/AssociateStatisticsStatementAssert.java
@@ -0,0 +1,75 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.statement.ddl.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAssociateStatisticsStatement;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.column.ColumnAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.index.IndexAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.table.TableAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AssociateStatisticsStatementTestCase;
+
+/**
+ * Associate Statistics statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class AssociateStatisticsStatementAssert {
+
+ /**
+ * Assert associate statistics statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual associate statistics statement
+ * @param expected expected associate statistics statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final OracleAssociateStatisticsStatement actual, final AssociateStatisticsStatementTestCase expected) {
+ assertTables(assertContext, actual, expected);
+ assertColumns(assertContext, actual, expected);
+ assertIndexes(assertContext, actual, expected);
+ }
+
+ private static void assertTables(final SQLCaseAssertContext assertContext, final OracleAssociateStatisticsStatement actual, final AssociateStatisticsStatementTestCase expected) {
+ if (null != expected.getTables()) {
+ TableAssert.assertIs(assertContext, actual.getTables(), expected.getTables());
+ }
+ }
+
+ private static void assertColumns(final SQLCaseAssertContext assertContext, final OracleAssociateStatisticsStatement actual, final AssociateStatisticsStatementTestCase expected) {
+ if (null != expected.getColumns()) {
+ int count = 0;
+ for (ColumnSegment each : actual.getColumns()) {
+ ColumnAssert.assertIs(assertContext, each, expected.getColumns().get(count));
+ count++;
+ }
+ }
+ }
+
+ private static void assertIndexes(final SQLCaseAssertContext assertContext, final OracleAssociateStatisticsStatement actual, final AssociateStatisticsStatementTestCase expected) {
+ if (null != expected.getIndexes()) {
+ int count = 0;
+ for (IndexSegment each : actual.getIndexes()) {
+ IndexAssert.assertIs(assertContext, each, expected.getIndexes().get(count));
+ count++;
+ }
+ }
+ }
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index 01557b4..1e3c109 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -58,6 +58,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterSystemStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AlterTableStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AnalyzeStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.AssociateStatisticsStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.CreateDatabaseStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.CreateFunctionStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl.CreateIndexStatementTestCase;
@@ -346,6 +347,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "analyze")
private final List<AnalyzeStatementTestCase> analyzeTestCase = new LinkedList<>();
+
+ @XmlElement(name = "associate-statistics")
+ private final List<AssociateStatisticsStatementTestCase> associateStatisticsTestCase = new LinkedList<>();
@XmlElement(name = "add-resource")
private final List<AddResourceStatementTestCase> addResourceTestCase = new LinkedList<>();
@@ -506,6 +510,7 @@ public final class SQLParserTestCases {
putAll(alterSequenceTestCase, result);
putAll(dropSequenceTestCase, result);
putAll(analyzeTestCase, result);
+ putAll(associateStatisticsTestCase, result);
putAll(addResourceTestCase, result);
putAll(alterDataBaseDiscoveryRuleTestCase, result);
putAll(alterEncryptRuleTestCase, result);
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/index/ExpectedIndex.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/index/ExpectedIndex.java
index 241e9ec..aec81cd 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/index/ExpectedIndex.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/index/ExpectedIndex.java
@@ -17,10 +17,20 @@
package org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.index;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.AbstractExpectedIdentifierSQLSegment;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.table.ExpectedOwner;
+
+import javax.xml.bind.annotation.XmlElement;
/**
* Expected index.
*/
+@Getter
+@Setter
public final class ExpectedIndex extends AbstractExpectedIdentifierSQLSegment {
+
+ @XmlElement
+ private ExpectedOwner owner;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AssociateStatisticsStatementTestCase.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AssociateStatisticsStatementTestCase.java
new file mode 100644
index 0000000..546295e
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/ddl/AssociateStatisticsStatementTestCase.java
@@ -0,0 +1,47 @@
+/*
+ * 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.test.sql.parser.parameterized.jaxb.cases.domain.statement.ddl;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.column.ExpectedColumn;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.index.ExpectedIndex;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.table.ExpectedSimpleTable;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Associate Statistics statement test case.
+ */
+@Getter
+@Setter
+public final class AssociateStatisticsStatementTestCase extends SQLParserTestCase {
+
+ @XmlElement(name = "index")
+ private final List<ExpectedIndex> indexes = new LinkedList<>();
+
+ @XmlElement(name = "table")
+ private final List<ExpectedSimpleTable> tables = new LinkedList<>();
+
+ @XmlElement(name = "column")
+ private final List<ExpectedColumn> columns = new LinkedList<>();
+
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/associate-statistics.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/associate-statistics.xml
new file mode 100644
index 0000000..26af908
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/ddl/associate-statistics.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<sql-parser-test-cases>
+ <associate-statistics sql-case-id="associate_statistics_with_column">
+ <table name="employee" start-index="34" stop-index="41" />
+ <column name="age" start-index="43" stop-index="45" />
+ </associate-statistics>
+
+ <associate-statistics sql-case-id="associate_statistics_with_columns">
+ <table name="employee" start-index="34" stop-index="41" />
+ <column name="age" start-index="43" stop-index="45" />
+ <table name="employee" start-index="48" stop-index="55" />
+ <column name="salary" start-index="57" stop-index="62" />
+ </associate-statistics>
+
+ <associate-statistics sql-case-id="associate_statistics_with_index">
+ <index name="salary_index" start-index="34" stop-index="45" />
+ </associate-statistics>
+
+ <associate-statistics sql-case-id="associate_statistics_with_function" />
+ <associate-statistics sql-case-id="associate_statistics_with_package" />
+ <associate-statistics sql-case-id="associate_statistics_with_type" />
+ <associate-statistics sql-case-id="associate_statistics_with_indextype" />
+</sql-parser-test-cases>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/associate-statistics.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/associate-statistics.xml
new file mode 100644
index 0000000..0e1665f
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/ddl/associate-statistics.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<sql-cases>
+ <sql-case id="associate_statistics_with_column" value="ASSOCIATE STATISTICS WITH COLUMNS employee.age USING NULL" db-types="Oracle" />
+ <sql-case id="associate_statistics_with_columns" value="ASSOCIATE STATISTICS WITH COLUMNS employee.age, employee.salary USING stat" db-types="Oracle" />
+ <sql-case id="associate_statistics_with_index" value="ASSOCIATE STATISTICS WITH INDEXES salary_index DEFAULT COST (100,5,0)" db-types="Oracle" />
+ <sql-case id="associate_statistics_with_function" value="ASSOCIATE STATISTICS WITH FUNCTIONS myFunction USING stat_MyFunction" db-types="Oracle" />
+ <sql-case id="associate_statistics_with_package" value="ASSOCIATE STATISTICS WITH PACKAGES emp_mgmt DEFAULT SELECTIVITY 10" db-types="Oracle" />
+ <sql-case id="associate_statistics_with_type" value="ASSOCIATE STATISTICS WITH TYPES Example_typ DEFAULT SELECTIVITY 30, DEFAULT COST (100,5,0)" db-types="Oracle" />
+ <sql-case id="associate_statistics_with_indextype" value="ASSOCIATE STATISTICS WITH INDEXTYPES indtype USING stat_indtype WITH SYSTEM MANAGED STORAGE TABLES" db-types="Oracle" />
+</sql-cases>