From 1b5046ce43de542d59f704ab5a029664e2dc18b6 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 5 Jan 2023 15:54:13 +0000 Subject: [PATCH] Extend ThingConstraint.has to return attribute identity variables --- java/pattern/constraint/ThingConstraint.java | 3 ++- java/query/test/TypeQLQueryTest.java | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/java/pattern/constraint/ThingConstraint.java b/java/pattern/constraint/ThingConstraint.java index 2b5e51cf8..11d1b19b7 100644 --- a/java/pattern/constraint/ThingConstraint.java +++ b/java/pattern/constraint/ThingConstraint.java @@ -41,6 +41,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static com.vaticle.typedb.common.collection.Collections.list; import static com.vaticle.typedb.common.collection.Collections.pair; @@ -436,7 +437,7 @@ private Has(@Nullable TypeVariable type, ThingVariable attribute) { @Override public Set variables() { - return set(attribute); + return attribute.variables().collect(Collectors.toSet()); } @Override diff --git a/java/query/test/TypeQLQueryTest.java b/java/query/test/TypeQLQueryTest.java index d5696ba5b..97a56cf54 100644 --- a/java/query/test/TypeQLQueryTest.java +++ b/java/query/test/TypeQLQueryTest.java @@ -142,6 +142,14 @@ public void testMatchInsertWithValueVariable() { assertEquals("match\n?x = 2;\ninsert\n$a ?x isa prime;", query.toString()); } + @Test + public void testMatchInsertOwnershipWithValueVariable() { + TypeQLInsert query = match( + valvar("x").assign(Expr.constant(2)) + ).insert(var("p").has("prime", valvar("x"))); + assertEquals("match\n?x = 2;\ninsert\n$p has prime ?x;", query.toString()); + } + @Test public void testZeroToString() { assertEquals("match\n$x 0.0;", match(var("x").eq(0.0)).toString());