Unverified Commit c34e1787 authored by Pontus Melke's avatar Pontus Melke Committed by GitHub
Browse files

Merge pull request #11793 from systay/3.4-udf-semantic-bug

Fix problems with UDF typing not working
parents b6799414 1c1391bc
No related merge requests found
Showing with 29 additions and 7 deletions
+29 -7
......@@ -26,7 +26,6 @@ import org.neo4j.cypher.internal.util.v3_4.InputPosition
import org.neo4j.cypher.internal.v3_4.expressions.Expression.SemanticContext
import org.neo4j.cypher.internal.v3_4.expressions.{CoerceTo, Expression, FunctionInvocation}
import org.neo4j.cypher.internal.v3_4.functions.UserDefinedFunctionInvocation
import org.neo4j.cypher.internal.util.v3_4.symbols._
object ResolvedFunctionInvocation {
......@@ -89,12 +88,7 @@ case class ResolvedFunctionInvocation(qualifiedName: QualifiedName,
SemanticExpressionCheck.check(SemanticContext.Results, arg) chain
SemanticExpressionCheck.expectType(field.typ.covariant, arg)
}.foldLeft(success)(_ chain _) chain
// If we get a List<Any> as the output type, that can be an artifact of
// Lost type information if the UDF function was using annotations and was compiled
// we cannot specify the type wrongly in this case.
SemanticExpressionCheck.when(signature.outputType != CTList(CTAny)) {
SemanticExpressionCheck.specifyType(signature.outputType, this)
}
SemanticExpressionCheck.specifyType(signature.outputType.covariant, this)
} else {
val msg = (if (signature.inputSignature.isEmpty) "arguments"
else if (signature.inputSignature.size == 1) s"argument of type ${signature.inputSignature.head.typ.toNeoTypeString}"
......
......@@ -27,6 +27,8 @@ import java.util
import org.neo4j.internal.kernel.api.procs.Neo4jTypes
import org.neo4j.kernel.impl.util.ValueUtils
import scala.collection.JavaConverters._
class FunctionCallSupportAcceptanceTest extends ProcedureCallAcceptanceTest {
test("should return correctly typed map result (even if converting to and from scala representation internally)") {
......@@ -111,4 +113,30 @@ class FunctionCallSupportAcceptanceTest extends ProcedureCallAcceptanceTest {
returned should equal(4)
}
test("should be able to use function returning list with list comprehension") {
val value = new util.ArrayList[Integer]()
value.add(1)
value.add(2)
registerUserFunction(ValueUtils.of(value), Neo4jTypes.NTAny)
val result = graph.execute("RETURN [x in my.first.value() | x + 1] as y")
result.hasNext shouldBe true
result.next.get("y").asInstanceOf[util.List[_]].asScala should equal(List(2, 3))
}
test("should be able to use function returning list with ANY") {
val value = new util.ArrayList[Integer]()
value.add(1)
value.add(2)
registerUserFunction(ValueUtils.of(value), Neo4jTypes.NTAny)
val result = graph.execute("RETURN ANY(x in my.first.value() WHERE x = 2) as u")
result.hasNext shouldBe true
result.next.get("u") should equal(true)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment