Skip to content

Commit

Permalink
Extend ThingConstraint.has to return attribute identity variables
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnangovindraj committed Jan 5, 2023
1 parent 25531fc commit 1b5046c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion java/pattern/constraint/ThingConstraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -436,7 +437,7 @@ private Has(@Nullable TypeVariable type, ThingVariable<?> attribute) {

@Override
public Set<BoundVariable> variables() {
return set(attribute);
return attribute.variables().collect(Collectors.toSet());
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions java/query/test/TypeQLQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 1b5046c

Please sign in to comment.