Skip to content

Commit

Permalink
refactor: add support for multiple json or parameter in insert conten…
Browse files Browse the repository at this point in the history
…t in the query engine
  • Loading branch information
tglman committed Nov 27, 2023
1 parent a69005a commit 783da28
Show file tree
Hide file tree
Showing 5 changed files with 590 additions and 521 deletions.
6 changes: 4 additions & 2 deletions core/src/main/grammar/OrientSQL.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,8 @@ OInsertBody InsertBody():
OIdentifier lastIdentifier;
OExpression lastExpression;
List<OExpression> lastExpressionList;
OJson content;
OInputParameter inputParamater;
}
{
(
Expand Down Expand Up @@ -1915,9 +1917,9 @@ OInsertBody InsertBody():
|
( <CONTENT>
(
jjtThis.content = Json()
content = Json() { jjtThis.addContent(content);}
|
jjtThis.contentInputParam = InputParameter()
inputParamater = InputParameter() { jjtThis.addContentInputParam(inputParamater); }
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import com.orientechnologies.orient.core.sql.parser.OExecutionPlanCache;
import com.orientechnologies.orient.core.sql.parser.OExpression;
import com.orientechnologies.orient.core.sql.parser.OIdentifier;
import com.orientechnologies.orient.core.sql.parser.OInputParameter;
import com.orientechnologies.orient.core.sql.parser.OInsertBody;
import com.orientechnologies.orient.core.sql.parser.OInsertSetExpression;
import com.orientechnologies.orient.core.sql.parser.OJson;
import com.orientechnologies.orient.core.sql.parser.OUpdateItem;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -194,9 +196,13 @@ private void handleSetFields(
ctx,
profilingEnabled));
} else if (insertBody.getContent() != null) {
result.chain(new UpdateContentStep(insertBody.getContent(), ctx, profilingEnabled));
for (OJson json : insertBody.getContent()) {
result.chain(new UpdateContentStep(json, ctx, profilingEnabled));
}
} else if (insertBody.getContentInputParam() != null) {
result.chain(new UpdateContentStep(insertBody.getContentInputParam(), ctx, profilingEnabled));
for (OInputParameter inputParam : insertBody.getContentInputParam()) {
result.chain(new UpdateContentStep(inputParam, ctx, profilingEnabled));
}
} else if (insertBody.getSetExpressions() != null) {
List<OUpdateItem> items = new ArrayList<>();
for (OInsertSetExpression exp : insertBody.getSetExpressions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.orientechnologies.orient.core.sql.parser.OCluster;
import com.orientechnologies.orient.core.sql.parser.OIdentifier;
import com.orientechnologies.orient.core.sql.parser.OIndexIdentifier;
import com.orientechnologies.orient.core.sql.parser.OInputParameter;
import com.orientechnologies.orient.core.sql.parser.OInsertBody;
import com.orientechnologies.orient.core.sql.parser.OInsertSetExpression;
import com.orientechnologies.orient.core.sql.parser.OInsertStatement;
import com.orientechnologies.orient.core.sql.parser.OJson;
import com.orientechnologies.orient.core.sql.parser.OProjection;
import com.orientechnologies.orient.core.sql.parser.OSelectStatement;
import com.orientechnologies.orient.core.sql.parser.OUpdateItem;
Expand Down Expand Up @@ -105,9 +107,13 @@ private void handleSetFields(
ctx,
profilingEnabled));
} else if (insertBody.getContent() != null) {
result.chain(new UpdateContentStep(insertBody.getContent(), ctx, profilingEnabled));
for (OJson json : insertBody.getContent()) {
result.chain(new UpdateContentStep(json, ctx, profilingEnabled));
}
} else if (insertBody.getContentInputParam() != null) {
result.chain(new UpdateContentStep(insertBody.getContentInputParam(), ctx, profilingEnabled));
for (OInputParameter inputParam : insertBody.getContentInputParam()) {
result.chain(new UpdateContentStep(inputParam, ctx, profilingEnabled));
}
} else if (insertBody.getSetExpressions() != null) {
List<OUpdateItem> items = new ArrayList<>();
for (OInsertSetExpression exp : insertBody.getSetExpressions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

public class OInsertBody extends SimpleNode {

protected List<OIdentifier> identifierList;
protected List<List<OExpression>> valueExpressions;
protected List<OInsertSetExpression> setExpressions;
private List<OIdentifier> identifierList;
private List<List<OExpression>> valueExpressions;
private List<OInsertSetExpression> setExpressions;

protected OJson content;
protected OInputParameter contentInputParam;
private List<OJson> content;
private List<OInputParameter> contentInputParam;

public OInsertBody(int id) {
super(id);
Expand Down Expand Up @@ -71,12 +71,26 @@ public void toString(Map<Object, Object> params, StringBuilder builder) {
}
}

if (content != null) {
builder.append("CONTENT ");
content.toString(params, builder);
} else if (contentInputParam != null) {
if (content != null || contentInputParam != null) {
builder.append("CONTENT ");
contentInputParam.toString(params, builder);
boolean first = true;
if (content != null) {
for (OJson item : content) {
if (!first) {
builder.append(", ");
}
item.toString(params, builder);
first = false;
}
} else if (contentInputParam != null) {
for (OInputParameter item : contentInputParam) {
if (!first) {
builder.append(", ");
}
item.toString(params, builder);
first = false;
}
}
}
}

Expand Down Expand Up @@ -127,12 +141,26 @@ public void toGenericStatement(StringBuilder builder) {
}
}

if (content != null) {
if (content != null || contentInputParam != null) {
builder.append("CONTENT ");
content.toGenericStatement(builder);
} else if (contentInputParam != null) {
builder.append("CONTENT ");
contentInputParam.toGenericStatement(builder);
boolean first = true;
if (content != null) {
for (OJson item : content) {
if (!first) {
builder.append(", ");
}
item.toGenericStatement(builder);
first = false;
}
} else if (contentInputParam != null) {
for (OInputParameter item : contentInputParam) {
if (!first) {
builder.append(", ");
}
item.toGenericStatement(builder);
first = false;
}
}
}
}

Expand All @@ -152,8 +180,12 @@ public OInsertBody copy() {
setExpressions == null
? null
: setExpressions.stream().map(x -> x.copy()).collect(Collectors.toList());
result.content = content == null ? null : content.copy();
result.contentInputParam = contentInputParam == null ? null : contentInputParam.copy();
result.content =
content == null ? null : content.stream().map(x -> x.copy()).collect(Collectors.toList());
result.contentInputParam =
contentInputParam == null
? null
: contentInputParam.stream().map(x -> x.copy()).collect(Collectors.toList());
return result;
}

Expand Down Expand Up @@ -222,14 +254,28 @@ public void addInsertSetExpression(OInsertSetExpression exp) {
this.setExpressions.add(exp);
}

public OJson getContent() {
public List<OJson> getContent() {
return content;
}

public OInputParameter getContentInputParam() {
public List<OInputParameter> getContentInputParam() {
return contentInputParam;
}

public void addContentInputParam(OInputParameter par) {
if (contentInputParam == null) {
contentInputParam = new ArrayList<>();
}
contentInputParam.add(par);
}

public void addContent(OJson json) {
if (content == null) {
content = new ArrayList<>();
}
content.add(json);
}

public boolean isCacheable() {

if (this.valueExpressions != null) {
Expand All @@ -249,9 +295,14 @@ public boolean isCacheable() {
}
}

if (content != null && !content.isCacheable()) {
return false;
if (content != null) {
for (OJson item : content) {
if (!item.isCacheable()) {
return false;
}
}
}

return true;
}
}
Expand Down
Loading

0 comments on commit 783da28

Please sign in to comment.