Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit aaaeed9

Browse files
Support generalised annotations and uniqueness (#293)
## What is the goal of this PR? We update the Typedb Protocol and TypeQL to the latest versions, which support the uniqueness annotation and generalised `Type` APIs. These generalised APIs allow querying by a set of annotations, rather than just boolean = `true|false`. For example, the API: `AttributeType.get_owners(onlyKey: boolean)`, has become: `AttributeType.get_owners(annotations: Set["Annotation"])` All usages of boolean flags to indicate key-ness should be replaced by a set of `ThingType.AnnotationEnum.KEY`. The new `@unique` annotation is available as `ThingType.AnnotationEnum.KEY`, and also usable within the APIs that accept annotations. ## What are the changes implemented in this PR? * Update dependencies to include generalised annotations in the language and protocol. We also pull the `behaviour` repository to include tests for generalised annotations * We reflect the changes to the behaviour test steps in the implementation of BDD steps, in particular with extensions for generalised annotations * Update Concept API methods to remove the `*_key` boolean and replace it with a set of flags from `ThingType.Annotation` Related protocol changes: typedb/typedb-protocol#182 and typedb/typedb-protocol@de4f5b4 Related core changes: typedb/typedb#6775 , typedb/typedb@e24cfa9 , and typedb/typedb@b16cdb0
1 parent 756beb7 commit aaaeed9

File tree

18 files changed

+267
-195
lines changed

18 files changed

+267
-195
lines changed

dependencies/vaticle/artifacts.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def vaticle_typedb_artifacts():
2929
artifact_name = "typedb-server-{platform}-{version}.{ext}",
3030
tag_source = deployment["artifact.release"],
3131
commit_source = deployment["artifact.snapshot"],
32-
commit = "c36d4deeb6a7f9b53dced92002e57c1df9963f7a",
32+
commit = "0f43f6654dff206d168711d90785d12df4c98b5e",
3333
)
3434

3535
def vaticle_typedb_cluster_artifacts():
@@ -39,5 +39,5 @@ def vaticle_typedb_cluster_artifacts():
3939
artifact_name = "typedb-cluster-all-{platform}-{version}.{ext}",
4040
tag_source = deployment_private["artifact.release"],
4141
commit_source = deployment_private["artifact.snapshot"],
42-
commit = "230757ad05e2b1a8cf78a3cb67d90d759de64a19",
42+
commit = "9b70d31b54ed0162ce5df6ac4ab6180229bd7cb9",
4343
)

dependencies/vaticle/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ def vaticle_typedb_behaviour():
3939
git_repository(
4040
name = "vaticle_typedb_behaviour",
4141
remote = "https://github.com/vaticle/typedb-behaviour",
42-
commit = "fbba9fc19042460760b852b765d356c9b3f4ebf0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
42+
commit = "aa675d9052046b1a4ffd45f444854d8735028702" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
4343
)

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
## Dependencies
3737

38-
typedb-protocol==2.17.0
38+
typedb-protocol==2.18.0.dev0
3939
grpcio>=1.43.0,<2
40-
protobuf>=3.15.5,<4
40+
protobuf>=3.15.6,<4
41+
parse==1.18.0

tests/behaviour/concept/thing/thing_steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ def step_impl(context: Context, var1: str, var2: str):
8585
@step("attribute {var1:Var} get keys contain: {var2:Var}")
8686
@step("relation {var1:Var} get keys contain: {var2:Var}")
8787
def step_impl(context: Context, var1: str, var2: str):
88-
assert_that(context.get(var1).as_remote(context.tx()).get_has(only_key=True), has_item(context.get(var2).as_attribute()))
88+
assert_that(context.get(var1).as_remote(context.tx()).get_has(annotations={Annotations.KEY}), has_item(context.get(var2).as_attribute()))
8989

9090

9191
@step("entity {var1:Var} get keys do not contain: {var2:Var}")
9292
@step("attribute {var1:Var} get keys do not contain: {var2:Var}")
9393
@step("relation {var1:Var} get keys do not contain: {var2:Var}")
9494
def step_impl(context: Context, var1: str, var2: str):
95-
assert_that(context.get(var1).as_remote(context.tx()).get_has(only_key=True), not_(has_item(context.get(var2).as_attribute())))
95+
assert_that(context.get(var1).as_remote(context.tx()).get_has(annotations={Annotations.KEY}), not_(has_item(context.get(var2).as_attribute())))
9696

9797

9898
@step("entity {var1:Var} get attributes contain: {var2:Var}")

tests/behaviour/concept/type/attributetype/attribute_type_steps.py

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -113,74 +113,82 @@ def step_impl(context: Context, type_label: str, value_type):
113113
assert_that(attribute_type.as_remote(context.tx()).get_regex(), is_(None))
114114

115115

116-
@step("attribute({type_label}) get key owners contain")
117-
def step_impl(context: Context, type_label: str):
116+
def attribute_get_owners_with_annotations_contain(context: Context, type_label: str, annotations: Set["Annotation"]):
118117
owner_labels = [parse_label(s) for s in parse_list(context.table)]
119118
attribute_type = context.tx().concepts().get_attribute_type(type_label)
120-
actuals = list(map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners(only_key=True)))
119+
actuals = list(
120+
map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners(annotations=annotations)))
121121
for owner_label in owner_labels:
122122
assert_that(actuals, has_item(owner_label))
123123

124124

125-
@step("attribute({type_label}) get key owners do not contain")
126-
def step_impl(context: Context, type_label: str):
127-
owner_labels = [parse_label(s) for s in parse_list(context.table)]
128-
attribute_type = context.tx().concepts().get_attribute_type(type_label)
129-
actuals = list(map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners(only_key=True)))
130-
for owner_label in owner_labels:
131-
assert_that(actuals, not_(has_item(owner_label)))
125+
@step("attribute({type_label}) get owners, with annotations: {annotations:Annotations}; contain")
126+
def step_impl(context: Context, type_label: str, annotations: Set["Annotation"]):
127+
attribute_get_owners_with_annotations_contain(context, type_label, annotations)
132128

133-
@step("attribute({type_label}) get key owners explicit contain")
129+
130+
@step("attribute({type_label}) get owners contain")
134131
def step_impl(context: Context, type_label: str):
135-
owner_labels = [parse_label(s) for s in parse_list(context.table)]
136-
attribute_type = context.tx().concepts().get_attribute_type(type_label)
137-
actuals = list(
138-
map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners_explicit(only_key=True)))
139-
for owner_label in owner_labels:
140-
assert_that(actuals, has_item(owner_label))
132+
attribute_get_owners_with_annotations_contain(context, type_label, set())
141133

142134

143-
@step("attribute({type_label}) get key owners explicit do not contain")
144-
def step_impl(context: Context, type_label: str):
135+
def attribute_get_owners_with_annotations_do_not_contain(context: Context, type_label: str,
136+
annotations: Set["Annotation"]):
145137
owner_labels = [parse_label(s) for s in parse_list(context.table)]
146138
attribute_type = context.tx().concepts().get_attribute_type(type_label)
147139
actuals = list(
148-
map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners_explicit(only_key=True)))
140+
map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners(annotations=annotations)))
149141
for owner_label in owner_labels:
150142
assert_that(actuals, not_(has_item(owner_label)))
151143

152144

153-
@step("attribute({type_label}) get attribute owners contain")
145+
@step("attribute({type_label}) get owners, with annotations: {annotations:Annotations}; do not contain")
146+
def step_impl(context: Context, type_label: str, annotations: Set["Annotation"]):
147+
attribute_get_owners_with_annotations_do_not_contain(context, type_label, annotations)
148+
149+
150+
@step("attribute({type_label}) get owners do not contain")
154151
def step_impl(context: Context, type_label: str):
152+
attribute_get_owners_with_annotations_do_not_contain(context, type_label, set())
153+
154+
155+
def attribute_get_owners_explicit_with_annotations_contain(context: Context, type_label: str,
156+
annotations: Set["Annotation"]):
155157
owner_labels = [parse_label(s) for s in parse_list(context.table)]
156158
attribute_type = context.tx().concepts().get_attribute_type(type_label)
157-
actuals = list(map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners(only_key=False)))
159+
actuals = list(
160+
map(lambda tt: tt.get_label(),
161+
attribute_type.as_remote(context.tx()).get_owners_explicit(annotations=annotations)))
158162
for owner_label in owner_labels:
159163
assert_that(actuals, has_item(owner_label))
160164

161165

162-
@step("attribute({type_label}) get attribute owners do not contain")
166+
@step("attribute({type_label}) get owners explicit, with annotations: {annotations:Annotations}; contain")
167+
def step_impl(context: Context, type_label: str, annotations: Set["Annotation"]):
168+
attribute_get_owners_explicit_with_annotations_contain(context, type_label, annotations)
169+
170+
171+
@step("attribute({type_label}) get owners explicit contain")
163172
def step_impl(context: Context, type_label: str):
173+
attribute_get_owners_explicit_with_annotations_contain(context, type_label, set())
174+
175+
176+
def attribute_get_owners_explicit_with_annotations_do_not_contain(context: Context, type_label: str,
177+
annotations: Set["Annotation"]):
164178
owner_labels = [parse_label(s) for s in parse_list(context.table)]
165179
attribute_type = context.tx().concepts().get_attribute_type(type_label)
166-
actuals = list(map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners(only_key=False)))
180+
actuals = list(
181+
map(lambda tt: tt.get_label(),
182+
attribute_type.as_remote(context.tx()).get_owners_explicit(annotations=annotations)))
167183
for owner_label in owner_labels:
168184
assert_that(actuals, not_(has_item(owner_label)))
169185

170186

171-
@step("attribute({type_label}) get attribute owners explicit contain")
172-
def step_impl(context: Context, type_label: str):
173-
owner_labels = [parse_label(s) for s in parse_list(context.table)]
174-
attribute_type = context.tx().concepts().get_attribute_type(type_label)
175-
actuals = list(map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners_explicit(only_key=False)))
176-
for owner_label in owner_labels:
177-
assert_that(actuals, has_item(owner_label))
187+
@step("attribute({type_label}) get owners explicit, with annotations: {annotations:Annotations}; do not contain")
188+
def step_impl(context: Context, type_label: str, annotations: Set["Annotation"]):
189+
attribute_get_owners_explicit_with_annotations_do_not_contain(context, type_label, annotations)
178190

179191

180-
@step("attribute({type_label}) get attribute owners explicit do not contain")
192+
@step("attribute({type_label}) get owners explicit do not contain")
181193
def step_impl(context: Context, type_label: str):
182-
owner_labels = [parse_label(s) for s in parse_list(context.table)]
183-
attribute_type = context.tx().concepts().get_attribute_type(type_label)
184-
actuals = list(map(lambda tt: tt.get_label(), attribute_type.as_remote(context.tx()).get_owners_explicit(only_key=False)))
185-
for owner_label in owner_labels:
186-
assert_that(actuals, not_(has_item(owner_label)))
194+
attribute_get_owners_explicit_with_annotations_do_not_contain(context, type_label, set())

0 commit comments

Comments
 (0)