Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ baseSortName
: identifier
;

variableName
: identifier
;

constraintName
: identifier
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,44 @@ cteClause
: identifier (LP_ columnNames RP_)? AS subquery
;

merge
: MERGE intoClause usingClause
mergeWhen (mergeWhen)*
(RETURNING returnExprListClause (INTO variableListClause)?)?
;

intoClause
: INTO (tableName | viewName | subquery) (AS? alias)?
;

usingClause
: USING ((tableName | viewName) | subquery) (AS? alias)? ON predicate
;

mergeWhen
: mergeWhenMatched | mergeWhenNotMatched
;

mergeWhenMatched
: WHEN MATCHED (AND predicate)? THEN (UPDATE SET columnName EQ_ expr (COMMA_ (columnName EQ_ expr))* | DELETE )
;

mergeWhenNotMatched
: WHEN NOT MATCHED (AND predicate)? THEN INSERT columnNames? VALUES LP_ expr RP_
;

returnExpr
: expr (AS? alias)
;

returnExprListClause
: returnExpr (COMMA_ returnExpr)*
;

variableList
: LBT_ COLON_ RBT_ variableName
;

variableListClause
: variableList (COMMA_ variableList)*
;
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,18 @@ STARTING
: S T A R T I N G
;

MERGE
: M E R G E
;

RETURNING
: R E T U R N I N G
;

MATCHED
: M A T C H E D
;

PASSWORD
: P A S S W O R D
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ execute
| alterTrigger
| executeBlock
| createSequence
| merge
| createUser
| executeStmt
) SEMI_?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.TableReferencesContext;
import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.UpdateContext;
import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.WhereClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.MergeContext;
import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.IntoClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.UsingClauseContext;
import org.apache.shardingsphere.sql.parser.sql.common.enums.JoinType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
Expand Down Expand Up @@ -92,6 +95,7 @@
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.firebird.dml.FirebirdInsertStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.firebird.dml.FirebirdSelectStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.firebird.dml.FirebirdUpdateStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.firebird.dml.FirebirdMergeStatement;
import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitor;

import java.util.Collection;
Expand Down Expand Up @@ -479,4 +483,14 @@ public ASTNode visitGroupByClause(final GroupByClauseContext ctx) {
public ASTNode visitSubquery(final SubqueryContext ctx) {
return visit(ctx.combineClause());
}

@Override
public ASTNode visitMerge(final MergeContext ctx) {
FirebirdMergeStatement result = new FirebirdMergeStatement();
result.setTarget((TableSegment) visit(ctx.intoClause()));
result.setSource((TableSegment) visit(ctx.usingClause()));
// add mergeWhenNotMatched and mergeWhenMatched part
// add RETURNING part
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.firebird.dml;

import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.MergeStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.firebird.FirebirdStatement;

/**
* Firebird merge statement.
*/
public final class FirebirdMergeStatement extends MergeStatement implements FirebirdStatement {
}