Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query-expr clause to handle duplicate table keys #22983

Closed
Closed
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 @@ -20,6 +20,8 @@
import org.ballerinalang.model.clauses.DoClauseNode;
import org.ballerinalang.model.clauses.FromClauseNode;
import org.ballerinalang.model.clauses.LetClauseNode;
import org.ballerinalang.model.clauses.OnClauseNode;
import org.ballerinalang.model.clauses.OnConflictClauseNode;
import org.ballerinalang.model.clauses.SelectClauseNode;
import org.ballerinalang.model.clauses.WhereClauseNode;
import org.ballerinalang.model.tree.AnnotationAttachmentNode;
Expand Down Expand Up @@ -165,6 +167,8 @@
import org.wso2.ballerinalang.compiler.tree.clauses.BLangDoClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangFromClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangLetClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnConflictClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangWhereClause;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangAnnotAccessExpr;
Expand Down Expand Up @@ -731,10 +735,18 @@ public static LetClauseNode createLetClauseNode() {
return new BLangLetClause();
}

public static OnClauseNode createOnClauseNode() {
return new BLangOnClause();
}

public static SelectClauseNode createSelectClauseNode() {
return new BLangSelectClause();
}

public static OnConflictClauseNode createOnConflictClauseNode() {
return new BLangOnConflictClause();
}

public static DoClauseNode createDoClauseNode() {
return new BLangDoClause();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.ballerinalang.model.clauses;

import org.ballerinalang.model.tree.Node;
import org.ballerinalang.model.tree.expressions.ExpressionNode;

/**
* The interface with the APIs to implement the "on" clause.
*
* @since 1.3.0
*/
public interface OnClauseNode extends Node {

ExpressionNode getExpression();

void setExpression(ExpressionNode expression);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.ballerinalang.model.clauses;

import org.ballerinalang.model.tree.Node;
import org.ballerinalang.model.tree.expressions.ExpressionNode;

/**
* The interface with the APIs to implement the "on conflict" clause.
*
* @since 1.3.0
*/
public interface OnConflictClauseNode extends Node {

ExpressionNode getExpression();

void setExpression(ExpressionNode expression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public enum NodeKind {
WHERE,
DO,
LET_CLAUSE,
ON_CONFLICT,
ON,

/* Types */
ARRAY_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.ballerinalang.model.clauses.FromClauseNode;
import org.ballerinalang.model.clauses.LetClauseNode;
import org.ballerinalang.model.clauses.OnClauseNode;
import org.ballerinalang.model.clauses.OnConflictClauseNode;
import org.ballerinalang.model.clauses.SelectClauseNode;
import org.ballerinalang.model.clauses.WhereClauseNode;

Expand All @@ -34,10 +36,18 @@ public interface QueryExpressionNode extends ExpressionNode {

void addFromClauseNode(FromClauseNode fromClauseNode);

OnClauseNode getOnClauseNode();

void setOnClauseNode(OnClauseNode onClauseNode);

SelectClauseNode getSelectClauseNode();

void setSelectClauseNode(SelectClauseNode selectClauseNode);

OnConflictClauseNode getOnConflictClauseNode();

void setOnConflictClauseNode(OnConflictClauseNode onConflictClauseNode);

List<? extends WhereClauseNode> getWhereClauseNode();

void addWhereClauseNode(WhereClauseNode whereClauseNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
import org.wso2.ballerinalang.compiler.tree.clauses.BLangDoClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangFromClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangLetClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnConflictClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangWhereClause;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangAccessExpression;
Expand Down Expand Up @@ -281,8 +283,12 @@ public class BLangPackageBuilder {

private Stack<BLangLetClause> letClauseNodeStack = new Stack<>();

private Stack<BLangOnClause> onClauseNodeStack = new Stack<>();

private Stack<BLangSelectClause> selectClauseNodeStack = new Stack<>();

private Stack<BLangOnConflictClause> onConflictNodeStack = new Stack<>();

private Stack<BLangWhereClause> whereClauseNodeStack = new Stack<>();

private Stack<BLangDoClause> doClauseNodeStack = new Stack<>();
Expand Down Expand Up @@ -1924,11 +1930,17 @@ void createQueryExpr(DiagnosticPos pos, Set<Whitespace> ws) {
while (letClauseNodeStack.size() > 0) {
queryExpr.addLetClause(letClauseNodeStack.pop());
}
if (onClauseNodeStack.size() > 0) {
queryExpr.setOnClauseNode(onClauseNodeStack.pop());
}
queryExpr.setSelectClauseNode(selectClauseNodeStack.pop());
Collections.reverse(whereClauseNodeStack);
while (whereClauseNodeStack.size() > 0) {
queryExpr.addWhereClauseNode(whereClauseNodeStack.pop());
}
if (onConflictNodeStack.size() > 0) {
queryExpr.setOnConflictClauseNode(onConflictNodeStack.pop());
}
addExpressionNode(queryExpr);
}

Expand Down Expand Up @@ -2004,6 +2016,14 @@ private void addFromClause(DiagnosticPos pos, Set<Whitespace> ws,
fromClauseNodeStack.push(fromClause);
}

void createOnClause(DiagnosticPos pos, Set<Whitespace> ws) {
BLangOnClause onClause = (BLangOnClause) TreeBuilder.createOnClauseNode();
onClause.addWS(ws);
onClause.pos = pos;
onClause.expression = (BLangExpression) this.exprNodeStack.pop();
onClauseNodeStack.push(onClause);
}

void createSelectClause(DiagnosticPos pos, Set<Whitespace> ws) {
BLangSelectClause selectClause = (BLangSelectClause) TreeBuilder.createSelectClauseNode();
selectClause.addWS(ws);
Expand All @@ -2012,6 +2032,14 @@ void createSelectClause(DiagnosticPos pos, Set<Whitespace> ws) {
selectClauseNodeStack.push(selectClause);
}

void createOnConflictClause(DiagnosticPos pos, Set<Whitespace> ws) {
BLangOnConflictClause onConflictClause = (BLangOnConflictClause) TreeBuilder.createOnConflictClauseNode();
onConflictClause.addWS(ws);
onConflictClause.pos = pos;
onConflictClause.expression = (BLangExpression) this.exprNodeStack.pop();
onConflictNodeStack.push(onConflictClause);
}

void createWhereClause(DiagnosticPos pos, Set<Whitespace> ws) {
BLangWhereClause whereClause = (BLangWhereClause) TreeBuilder.createWhereClauseNode();
whereClause.addWS(ws);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,14 @@ public void exitWhereClause(BallerinaParser.WhereClauseContext ctx) {
this.pkgBuilder.createWhereClause(getCurrentPos(ctx), getWS(ctx));
}

@Override
public void exitOnClause(BallerinaParser.OnClauseContext ctx) {
if (isInErrorState) {
return;
}
this.pkgBuilder.createOnClause(getCurrentPos(ctx), getWS(ctx));
}

@Override
public void exitSelectClause(BallerinaParser.SelectClauseContext ctx) {
if (isInErrorState) {
Expand All @@ -2816,6 +2824,15 @@ public void exitSelectClause(BallerinaParser.SelectClauseContext ctx) {
this.pkgBuilder.createSelectClause(getCurrentPos(ctx), getWS(ctx));
}

@Override
public void exitOnConflictClause(BallerinaParser.OnConflictClauseContext ctx) {
if (isInErrorState) {
return;
}

this.pkgBuilder.createOnConflictClause(getCurrentPos(ctx), getWS(ctx));
}

@Override
public void exitDoClause(BallerinaParser.DoClauseContext ctx) {
if (isInErrorState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import org.wso2.ballerinalang.compiler.tree.clauses.BLangDoClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangFromClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangLetClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnConflictClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangWhereClause;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangAccessExpression;
Expand Down Expand Up @@ -1286,8 +1288,10 @@ public void visit(BLangQueryExpr source) {
source.cloneRef = clone;
clone.fromClauseList = cloneList(source.fromClauseList);
clone.letClausesList = cloneList(source.letClausesList);
clone.onClause = clone(source.onClause);
clone.selectClause = clone(source.selectClause);
clone.whereClauseList = cloneList(source.whereClauseList);
clone.onConflictClause = clone(source.onConflictClause);
}

@Override
Expand Down Expand Up @@ -1320,6 +1324,14 @@ private List<BLangLetVariable> cloneLetVarDeclarations (List<BLangLetVariable> l
return cloneDefs;
}

@Override
public void visit(BLangOnClause source) {

BLangOnClause clone = new BLangOnClause();
source.cloneRef = clone;
clone.expression = clone(source.expression);
}

@Override
public void visit(BLangSelectClause source) {

Expand All @@ -1328,6 +1340,14 @@ public void visit(BLangSelectClause source) {
clone.expression = clone(source.expression);
}

@Override
public void visit(BLangOnConflictClause source) {

BLangOnConflictClause clone = new BLangOnConflictClause();
source.cloneRef = clone;
clone.expression = clone(source.expression);
}

@Override
public void visit(BLangWhereClause source) {

Expand Down
Loading