From 9ff03e27052f2995cc3bbe5023cb3cc2b83222e5 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 7 Apr 2019 17:49:19 +0800 Subject: [PATCH] for #2084, refactor insert g4, simplify insertValuesClause --- .../impl/dml/insert/InsertColumnsExtractor.java | 6 +++--- .../core/parse/antlr/extractor/util/RuleName.java | 2 -- .../src/main/antlr4/imports/mysql/DMLStatement.g4 | 10 +++++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/dml/insert/InsertColumnsExtractor.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/dml/insert/InsertColumnsExtractor.java index af23727818b6c..4e6f644902223 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/dml/insert/InsertColumnsExtractor.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/dml/insert/InsertColumnsExtractor.java @@ -40,9 +40,9 @@ public final class InsertColumnsExtractor implements OptionalSQLSegmentExtractor @Override public Optional extract(final ParserRuleContext ancestorNode) { - Optional insertColumnsClause = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.INSERT_COLUMNS_CLAUSE); - return insertColumnsClause.isPresent() - ? Optional.of(new InsertColumnsSegment(insertColumnsClause.get().getStart().getStartIndex(), extractColumns(insertColumnsClause.get()))) + Optional insertValuesClause = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.INSERT_VALUES_CLAUSE); + return insertValuesClause.isPresent() + ? Optional.of(new InsertColumnsSegment(insertValuesClause.get().getStart().getStartIndex(), extractColumns(insertValuesClause.get()))) : Optional.absent(); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java index 3622e60493a35..862506ceaa798 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java @@ -73,8 +73,6 @@ public enum RuleName { MODIFY_COL_PROPERTIES("ModifyColProperties"), - INSERT_COLUMNS_CLAUSE("InsertColumnsClause"), - INSERT_VALUES_CLAUSE("InsertValuesClause"), INSERT_ON_DUPLICATE_KEY_CLAUSE("InsertOnDuplicateKeyClause"), diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4 index 9611a98eb6b0d..741572a73d4ae 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4 @@ -20,7 +20,7 @@ grammar DMLStatement; import Symbol, Keyword, Literals, BaseRule; insert - : INSERT insertSpecification_ INTO? tableName partitionNames_? (insertColumnsClause | setAssignmentsClause) insertOnDuplicateKeyClause? + : INSERT insertSpecification_ INTO? tableName partitionNames_? (insertValuesClause | setAssignmentsClause | insertSelectClause) insertOnDuplicateKeyClause? ; insertSpecification_ @@ -31,12 +31,12 @@ partitionNames_ : PARTITION identifier_ (COMMA_ identifier_)* ; -insertColumnsClause - : columnNames? (insertValuesClause | select) +insertValuesClause + : columnNames? (VALUES | VALUE) assignmentValues (COMMA_ assignmentValues)* ; -insertValuesClause - : (VALUES | VALUE) assignmentValues (COMMA_ assignmentValues)* +insertSelectClause + : columnNames? select ; insertOnDuplicateKeyClause