Add Support for Upsert Operation
This change allows users to execute upsert commands which
couples delete if found with insert. It locks the primary
keys before doing the search ensuring consistency.
Change-Id: I8999000331795a5949d621d2dd003903e057a521
Reviewed-on: https://asterix-gerrit.ics.uci.edu/477
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterix-lang-aql/src/main/javacc/AQL.jj b/asterix-lang-aql/src/main/javacc/AQL.jj
index 8f62f74..93e3f68 100644
--- a/asterix-lang-aql/src/main/javacc/AQL.jj
+++ b/asterix-lang-aql/src/main/javacc/AQL.jj
@@ -124,6 +124,7 @@
import org.apache.asterix.lang.common.statement.TypeDecl;
import org.apache.asterix.lang.common.statement.TypeDropStatement;
import org.apache.asterix.lang.common.statement.UpdateStatement;
+import org.apache.asterix.lang.common.statement.UpsertStatement;
import org.apache.asterix.lang.common.statement.WriteStatement;
import org.apache.asterix.lang.common.struct.Identifier;
import org.apache.asterix.lang.common.struct.QuantifiedPair;
@@ -884,12 +885,17 @@
{
Pair<Identifier,Identifier> nameComponents = null;
Query query;
+ boolean upsert = false;
}
{
- "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
+ ("insert"|"upsert"{ upsert = true; }) "into" <DATASET> nameComponents = QualifiedName() query = Query()
{
query.setTopLevel(true);
- return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
+ if(upsert){
+ return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
+ } else{
+ return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
+ }
}
}