Skip to content

Commit

Permalink
Merge pull request #8292 from orientechnologies/letExpressionFix_new
Browse files Browse the repository at this point in the history
Fix for let expression mentioned in issue #8283
  • Loading branch information
luigidellaquila authored May 25, 2018
2 parents 19e584f + 7b3b5d3 commit db2fc50
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.core.sql.functions.OIndexableSQLFunction;
import com.orientechnologies.orient.core.sql.functions.OSQLFunction;
import com.orientechnologies.orient.core.sql.functions.graph.OSQLFunctionMove;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -339,14 +340,30 @@ private OProjectionItem createProjection(OFunctionCall newFunct, OIdentifier ali
}

public boolean isEarlyCalculated() {

if (isTraverseFunction())
return false;

for (OExpression param : params) {
if (!param.isEarlyCalculated()) {
return false;
}
}

return true;
}

private boolean isTraverseFunction() {
if (name == null) {
return false;
}
OSQLFunction function = OSQLEngine.getInstance().getFunction(name.value);
if (function instanceof OSQLFunctionMove) {
return true;
}
return false;
}

public AggregationContext getAggregationContext(OCommandContext ctx) {
OSQLFunction function = OSQLEngine.getInstance().getFunction(name.getStringValue());
function.config(this.params.toArray());
Expand All @@ -355,6 +372,7 @@ public AggregationContext getAggregationContext(OCommandContext ctx) {
return result;
}

@Override
public OFunctionCall copy() {
OFunctionCall result = new OFunctionCall(-1);
result.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.OEdgeToVertexIterable;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import org.junit.AfterClass;
import org.junit.Assert;
Expand Down Expand Up @@ -2089,6 +2092,43 @@ public void testLet7() {
result.close();
}

@Test
public void testLetWithTraverseFunction() {
String vertexClassName = "testLetWithTraverseFunction";
String edgeClassName = "testLetWithTraverseFunctioEdge";

OClass vertexClass = db.createVertexClass(vertexClassName);

OVertex doc1 = db.newVertex(vertexClass);
doc1.setProperty("name", "A");
doc1.save();

OVertex doc2 = db.newVertex(vertexClass);
doc2.setProperty("name", "B");
doc2.save();
ORID doc2Id = doc2.getIdentity();

OClass edgeClass = db.createEdgeClass(edgeClassName);

db.newEdge(doc1, doc2, edgeClass);
String queryString = "SELECT $x, name FROM " + vertexClassName + " let $x = out(\"" + edgeClassName + "\")";
OResultSet resultSet = db.query(queryString);
int counter = 0;
while (resultSet.hasNext()) {
OResult result = resultSet.next();
OEdgeToVertexIterable edge = result.getProperty("$x");
Iterator<OVertex> iter = edge.iterator();
while (iter.hasNext()) {
OVertex toVertex = iter.next();
if (doc2Id.equals(toVertex.getIdentity())) {
++counter;
}
}
}
Assert.assertEquals(1, counter);
resultSet.close();
}

@Test
public void testUnwind1() {
String className = "testUnwind1";
Expand Down

0 comments on commit db2fc50

Please sign in to comment.