Skip to content

Commit ecfbfc5

Browse files
Support TypeQL Fetch queries (#189)
## What is the goal of this PR? We implement 'TypeQL Fetch' query protocols, plus refactor the existing protocols around 'Match' queries to use the new 'Get' query terminology. This is a major change to the protocol, so we update the protocol version to `3`. ## What are the changes implemented in this PR? * Implement 'fetch' query API * Implement 'fetch' response type: ReadableConceptTree * We don't expect to expose this type to the user, instead translating it to JSON * This type primarily lets use re-use message definitions for Concepts * Refactor existing 'Match' query into 'Get' query terminology * Update protocol VERSION to 3
1 parent 657dd96 commit ecfbfc5

File tree

4 files changed

+75
-32
lines changed

4 files changed

+75
-32
lines changed

proto/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ proto_library(
8484
":answer-proto",
8585
":logic-proto",
8686
":options-proto",
87+
":concept-proto",
8788
],
8889
)
8990

proto/answer.proto

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,44 @@ message ConceptMapGroup {
4949
repeated ConceptMap concept_maps = 2;
5050
}
5151

52-
message Numeric {
53-
oneof value {
54-
sint64 long_value = 1;
55-
double double_value = 2;
56-
bool nan = 3;
57-
}
52+
message ValueGroup {
53+
Concept owner = 1;
54+
optional Value value = 2;
5855
}
5956

60-
message NumericGroup {
61-
Concept owner = 1;
62-
Numeric number = 2;
57+
message ReadableConceptTree {
58+
59+
Node.Map root = 1;
60+
61+
message Node {
62+
oneof node {
63+
Map map = 1;
64+
List list = 2;
65+
ReadableConcept readable_concept = 3;
66+
}
67+
68+
message Map {
69+
map<string, Node> map = 1;
70+
}
71+
72+
message List {
73+
repeated Node list = 1;
74+
}
75+
76+
message ReadableConcept {
77+
oneof readable_concept {
78+
EntityType entity_type = 1;
79+
RelationType relation_type = 2;
80+
AttributeType attribute_type = 3;
81+
82+
RoleType role_type = 4;
83+
84+
Attribute attribute = 5;
85+
86+
Value value = 6;
87+
88+
ThingType.Root thing_type_root = 7;
89+
}
90+
}
91+
}
6392
}

proto/query.proto

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ option java_outer_classname = "QueryProto";
2323
import "proto/answer.proto";
2424
import "proto/logic.proto";
2525
import "proto/options.proto";
26+
import "proto/concept.proto";
2627

2728
package typedb.protocol;
2829

@@ -33,38 +34,40 @@ message QueryManager {
3334
oneof req {
3435
Define.Req define_req = 100;
3536
Undefine.Req undefine_req = 101;
36-
Match.Req match_req = 102;
37-
MatchAggregate.Req match_aggregate_req = 103;
38-
MatchGroup.Req match_group_req = 104;
39-
MatchGroupAggregate.Req match_group_aggregate_req = 105;
40-
Insert.Req insert_req = 106;
41-
Delete.Req delete_req = 107;
42-
Update.Req update_req = 108;
43-
Explain.Req explain_req = 109;
37+
Get.Req get_req = 102;
38+
GetAggregate.Req get_aggregate_req = 103;
39+
GetGroup.Req get_group_req = 104;
40+
GetGroupAggregate.Req get_group_aggregate_req = 105;
41+
Fetch.Req fetch_req = 106;
42+
Insert.Req insert_req = 107;
43+
Delete.Req delete_req = 108;
44+
Update.Req update_req = 109;
45+
Explain.Req explain_req = 110;
4446
}
4547
}
4648

4749
message Res {
4850
oneof res {
4951
Define.Res define_res = 100;
5052
Undefine.Res undefine_res = 101;
51-
MatchAggregate.Res match_aggregate_res = 102;
53+
GetAggregate.Res get_aggregate_res = 102;
5254
Delete.Res delete_res = 104;
5355
}
5456
}
5557

5658
message ResPart {
5759
oneof res {
58-
Match.ResPart match_res_part = 100;
59-
MatchGroup.ResPart match_group_res_part = 101;
60-
MatchGroupAggregate.ResPart match_group_aggregate_res_part = 102;
61-
Insert.ResPart insert_res_part = 103;
62-
Update.ResPart update_res_part = 104;
63-
Explain.ResPart explain_res_part = 105;
60+
Get.ResPart get_res_part = 100;
61+
GetGroup.ResPart get_group_res_part = 101;
62+
GetGroupAggregate.ResPart get_group_aggregate_res_part = 102;
63+
Fetch.ResPart fetch_res_part = 103;
64+
Insert.ResPart insert_res_part = 104;
65+
Update.ResPart update_res_part = 105;
66+
Explain.ResPart explain_res_part = 106;
6467
}
6568
}
6669

67-
message Match {
70+
message Get {
6871
message Req {
6972
string query = 1;
7073
}
@@ -73,17 +76,17 @@ message QueryManager {
7376
}
7477
}
7578

76-
message MatchAggregate {
79+
message GetAggregate {
7780
message Req {
7881
string query = 1;
7982
}
8083

8184
message Res {
82-
Numeric answer = 1;
85+
optional Value answer = 1;
8386
}
8487
}
8588

86-
message MatchGroup {
89+
message GetGroup {
8790
message Req {
8891
string query = 1;
8992
}
@@ -93,13 +96,23 @@ message QueryManager {
9396
}
9497
}
9598

96-
message MatchGroupAggregate {
99+
message GetGroupAggregate {
97100
message Req {
98101
string query = 1;
99102
}
100103

101104
message ResPart {
102-
repeated NumericGroup answers = 1;
105+
repeated ValueGroup answers = 1;
106+
}
107+
}
108+
109+
message Fetch {
110+
message Req {
111+
string query = 1;
112+
}
113+
114+
message ResPart {
115+
repeated ReadableConceptTree answers = 1;
103116
}
104117
}
105118

proto/version.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ option java_generic_services = true;
2424
package typedb.protocol;
2525

2626
enum Version {
27-
reserved 1; // add past version numbers into the reserved range
27+
reserved 1, 2; // add past version numbers into the reserved range
2828
UNSPECIFIED = 0;
29-
VERSION = 2;
29+
VERSION = 3;
3030
}

0 commit comments

Comments
 (0)