Skip to content

Commit

Permalink
for #2084, refactor insert g4, simplify insertValuesClause
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Apr 7, 2019
1 parent c594265 commit 9ff03e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public final class InsertColumnsExtractor implements OptionalSQLSegmentExtractor

@Override
public Optional<InsertColumnsSegment> extract(final ParserRuleContext ancestorNode) {
Optional<ParserRuleContext> insertColumnsClause = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.INSERT_COLUMNS_CLAUSE);
return insertColumnsClause.isPresent()
? Optional.of(new InsertColumnsSegment(insertColumnsClause.get().getStart().getStartIndex(), extractColumns(insertColumnsClause.get())))
Optional<ParserRuleContext> insertValuesClause = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.INSERT_VALUES_CLAUSE);
return insertValuesClause.isPresent()
? Optional.of(new InsertColumnsSegment(insertValuesClause.get().getStart().getStartIndex(), extractColumns(insertValuesClause.get())))
: Optional.<InsertColumnsSegment>absent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand All @@ -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
Expand Down

0 comments on commit 9ff03e2

Please sign in to comment.