diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java index c9e61df6520..74518a54c24 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OFunctionCall.java @@ -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; @@ -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()); @@ -355,6 +372,7 @@ public AggregationContext getAggregationContext(OCommandContext ctx) { return result; } + @Override public OFunctionCall copy() { OFunctionCall result = new OFunctionCall(-1); result.name = name; diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java index 9261a19af88..14318ec0385 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java @@ -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; @@ -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 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";