From 9a6a02230f699399abc61c47d5ebe47e3f6d3c2f Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 17:08:47 +0200 Subject: [PATCH 01/50] WIP: Flush out QueryStructure --- proto/query.proto | 1 + proto/structure.proto | 121 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 proto/structure.proto diff --git a/proto/query.proto b/proto/query.proto index efb9940..2eefc88 100644 --- a/proto/query.proto +++ b/proto/query.proto @@ -51,6 +51,7 @@ message Query { // TODO: network optimisation: replace types (== mostly constant strings) with a IDs, sending types in the header to rebuild on the client side repeated string column_variable_names = 1; Type query_type = 2; + QueryStructure query_structure = 3; } } } diff --git a/proto/structure.proto b/proto/structure.proto new file mode 100644 index 0000000..aa3c583 --- /dev/null +++ b/proto/structure.proto @@ -0,0 +1,121 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +syntax = "proto3"; + +import "proto/answer.proto"; +import "proto/options.proto"; +import "proto/concept.proto"; + +package typedb.protocol; + +message QueryStructure { + repeated QueryBranch branches = 1; + + message QueryBranch { + repeated QueryConstraint edges = 1; + } + + message QueryConstraint { + oneof edge { + // Thing + Isa isa = 1; + Has has = 2; + Links links = 3; + + // Type + Sub sub = 4; + Owns owns = 5; + Relates relates = 6; + Plays plays = 7; + + // Function + Comparison comparison = 8; + Expression expression = 9; + FunctionCall function_call = 10; + + // Special + Is is = 11; + IID iid = 12; + } + } + + // Vertices + message QueryVariable { + string name = 1; + } + + message QueryType { + oneof type { + QueryVariable variable = 1; + string label = 2; + } + } + + message QueryValue { + QueryVariable variable = 1; + Value constant = 2; + } + + // Edges + message Isa { + QueryVariable thing = 1; + QueryType type = 2; + }; + message Has { + QueryVariable owner = 1; + QueryVariable attribute = 2; + }; + message Links { + QueryVariable relation = 1; + QueryVariable player = 2; + QueryType role = 3; + }; + + // Type + message Sub { + QueryType subtype = 1; + QueryType supertype = 2; + }; + message Owns { + QueryType subtype = 1; + QueryType supertype = 2; + }; + message Relates { + QueryType relation = 1; + QueryType role = 2; + }; + message Plays { + QueryType player = 1; + QueryType role = 2; + }; + + // Function + message Comparison { + QueryValue lhs = 1; + QueryValue rhs = 2; + }; + + message Expression { + string text = 1; + QueryVariable assigned = 2; + repeated QueryVariable arguments = 3; // Treats constants as part of the text. + }; + message FunctionCall { + string name = 1; + repeated QueryVariable assigned = 2; + repeated QueryValue arguments = 3; // Include constants, since variables are schema-objects + }; + + // Special + message Is { + QueryVariable lhs = 1; + QueryVariable rhs = 2; + }; + + message IID { + QueryVariable var = 1; + string IID = 2; + }; +} \ No newline at end of file From 04fad54a6dfb0a9fda2dd5afe8595f192b4fcdc6 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 17:44:20 +0200 Subject: [PATCH 02/50] Add kind, links can have multiple role-players --- proto/structure.proto | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/proto/structure.proto b/proto/structure.proto index aa3c583..86bc7b0 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -25,19 +25,20 @@ message QueryStructure { Links links = 3; // Type - Sub sub = 4; - Owns owns = 5; - Relates relates = 6; - Plays plays = 7; + Kind kind = 4; + Sub sub = 5; + Owns owns = 6; + Relates relates = 7; + Plays plays = 8; // Function - Comparison comparison = 8; - Expression expression = 9; - FunctionCall function_call = 10; + Comparison comparison = 9; + Expression expression = 10; + FunctionCall function_call = 11; // Special - Is is = 11; - IID iid = 12; + Is is = 12; + IID iid = 13; } } @@ -63,29 +64,42 @@ message QueryStructure { QueryVariable thing = 1; QueryType type = 2; }; + message Has { QueryVariable owner = 1; QueryVariable attribute = 2; }; + message Links { QueryVariable relation = 1; - QueryVariable player = 2; - QueryType role = 3; + repeated RolePlayer roleplayers = 2; + message RolePlayer { + QueryVariable player = 1; + QueryType role = 2; + } }; // Type + message Kind { + protocol.ConceptDocument.Node.Leaf.Kind kind = 1; + QueryType type = 2; + } + message Sub { QueryType subtype = 1; QueryType supertype = 2; }; + message Owns { QueryType subtype = 1; QueryType supertype = 2; }; + message Relates { QueryType relation = 1; QueryType role = 2; }; + message Plays { QueryType player = 1; QueryType role = 2; @@ -102,6 +116,7 @@ message QueryStructure { QueryVariable assigned = 2; repeated QueryVariable arguments = 3; // Treats constants as part of the text. }; + message FunctionCall { string name = 1; repeated QueryVariable assigned = 2; @@ -116,6 +131,6 @@ message QueryStructure { message IID { QueryVariable var = 1; - string IID = 2; + bytes IID = 2; }; } \ No newline at end of file From 71bf044f3be0a467a13ce21aca2b30ec0b25afb4 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 17:45:32 +0200 Subject: [PATCH 03/50] Add query-structure into header & provenance into row --- proto/answer.proto | 1 + proto/query.proto | 1 + 2 files changed, 2 insertions(+) diff --git a/proto/answer.proto b/proto/answer.proto index e6bf5a9..a7d0082 100644 --- a/proto/answer.proto +++ b/proto/answer.proto @@ -10,6 +10,7 @@ package typedb.protocol; message ConceptRow { repeated RowEntry row = 1; + bytes provenance = 2; } message RowEntry { diff --git a/proto/query.proto b/proto/query.proto index 2eefc88..0d8a650 100644 --- a/proto/query.proto +++ b/proto/query.proto @@ -7,6 +7,7 @@ syntax = "proto3"; import "proto/answer.proto"; import "proto/options.proto"; import "proto/error.proto"; +import "structure.proto"; package typedb.protocol; From 7b606d8780b20f43f0b7b2d14f7a58c516ee8c9c Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 18:01:14 +0200 Subject: [PATCH 04/50] Update BUILD files --- grpc/java/BUILD | 1 + grpc/nodejs/BUILD | 1 + grpc/rust/BUILD | 1 + proto/BUILD | 9 +++++++++ 4 files changed, 12 insertions(+) diff --git a/grpc/java/BUILD b/grpc/java/BUILD index bce07da..149dced 100644 --- a/grpc/java/BUILD +++ b/grpc/java/BUILD @@ -21,6 +21,7 @@ java_grpc_library( "//proto:authentication-proto", "//proto:options-proto", "//proto:query-proto", + "//proto:structure-proto", "//proto:transaction-proto", "//proto:version-proto", ], diff --git a/grpc/nodejs/BUILD b/grpc/nodejs/BUILD index 75a7495..998b825 100644 --- a/grpc/nodejs/BUILD +++ b/grpc/nodejs/BUILD @@ -37,6 +37,7 @@ ts_grpc_compile( "//proto:authentication-proto", "//proto:options-proto", "//proto:query-proto", + "//proto:structure-proto", "//proto:transaction-proto", "//proto:version-proto", ] diff --git a/grpc/rust/BUILD b/grpc/rust/BUILD index 4340dd4..4f44713 100644 --- a/grpc/rust/BUILD +++ b/grpc/rust/BUILD @@ -24,6 +24,7 @@ rust_tonic_compile( "//proto:authentication-proto", "//proto:options-proto", "//proto:query-proto", + "//proto:structure-proto", "//proto:transaction-proto", "//proto:version-proto", ] diff --git a/proto/BUILD b/proto/BUILD index ab0af9d..af022ba 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -83,6 +83,15 @@ proto_library( ":concept-proto", ":error-proto", ":options-proto", + ":structure-proto" + ], +) +proto_library( + name = "structure-proto", + srcs = ["structure.proto"], + deps = [ + ":answer-proto", + ":concept-proto", ], ) From 97e193b721ec7c544fa5dee9dbcce189a23d582a Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 18:04:51 +0200 Subject: [PATCH 05/50] Fix build files --- proto/query.proto | 2 +- proto/structure.proto | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/proto/query.proto b/proto/query.proto index 0d8a650..7e5f07d 100644 --- a/proto/query.proto +++ b/proto/query.proto @@ -7,7 +7,7 @@ syntax = "proto3"; import "proto/answer.proto"; import "proto/options.proto"; import "proto/error.proto"; -import "structure.proto"; +import "proto/structure.proto"; package typedb.protocol; diff --git a/proto/structure.proto b/proto/structure.proto index 86bc7b0..fe1af09 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -5,7 +5,6 @@ syntax = "proto3"; import "proto/answer.proto"; -import "proto/options.proto"; import "proto/concept.proto"; package typedb.protocol; @@ -133,4 +132,4 @@ message QueryStructure { QueryVariable var = 1; bytes IID = 2; }; -} \ No newline at end of file +} From 2396babba05f0d12246cf536383cdfac146ef60e Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 18:38:13 +0200 Subject: [PATCH 06/50] Add constraint span --- proto/structure.proto | 198 ++++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 96 deletions(-) diff --git a/proto/structure.proto b/proto/structure.proto index fe1af09..2140474 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -16,31 +16,6 @@ message QueryStructure { repeated QueryConstraint edges = 1; } - message QueryConstraint { - oneof edge { - // Thing - Isa isa = 1; - Has has = 2; - Links links = 3; - - // Type - Kind kind = 4; - Sub sub = 5; - Owns owns = 6; - Relates relates = 7; - Plays plays = 8; - - // Function - Comparison comparison = 9; - Expression expression = 10; - FunctionCall function_call = 11; - - // Special - Is is = 12; - IID iid = 13; - } - } - // Vertices message QueryVariable { string name = 1; @@ -58,78 +33,109 @@ message QueryStructure { Value constant = 2; } - // Edges - message Isa { - QueryVariable thing = 1; - QueryType type = 2; - }; - - message Has { - QueryVariable owner = 1; - QueryVariable attribute = 2; - }; - - message Links { - QueryVariable relation = 1; - repeated RolePlayer roleplayers = 2; - message RolePlayer { - QueryVariable player = 1; - QueryType role = 2; + message QueryConstraint { + optional ConstraintSpan span = 1; + oneof edge { + // Thing + Isa isa = 2; + Has has = 3; + Links links = 4; + + // Type + Kind kind = 5; + Sub sub = 6; + Owns owns = 7; + Relates relates = 8; + Plays plays = 9; + + // Function + Comparison comparison = 10; + Expression expression = 11; + FunctionCall function_call = 12; + + // Special + Is is = 13; + IID iid = 14; } - }; - // Type - message Kind { - protocol.ConceptDocument.Node.Leaf.Kind kind = 1; - QueryType type = 2; - } + message ConstraintSpan { + uint64 begin = 1; + uint64 end = 2; + } - message Sub { - QueryType subtype = 1; - QueryType supertype = 2; - }; - - message Owns { - QueryType subtype = 1; - QueryType supertype = 2; - }; - - message Relates { - QueryType relation = 1; - QueryType role = 2; - }; - - message Plays { - QueryType player = 1; - QueryType role = 2; - }; - - // Function - message Comparison { - QueryValue lhs = 1; - QueryValue rhs = 2; - }; - - message Expression { - string text = 1; - QueryVariable assigned = 2; - repeated QueryVariable arguments = 3; // Treats constants as part of the text. - }; - - message FunctionCall { - string name = 1; - repeated QueryVariable assigned = 2; - repeated QueryValue arguments = 3; // Include constants, since variables are schema-objects - }; - - // Special - message Is { - QueryVariable lhs = 1; - QueryVariable rhs = 2; - }; - - message IID { - QueryVariable var = 1; - bytes IID = 2; - }; + // Edges + message Isa { + QueryVariable thing = 1; + QueryType type = 2; + }; + + message Has { + QueryVariable owner = 1; + QueryVariable attribute = 2; + }; + + message Links { + QueryVariable relation = 1; + repeated RolePlayer roleplayers = 2; + message RolePlayer { + QueryVariable player = 1; + QueryType role = 2; + } + }; + + // Type + message Kind { + protocol.ConceptDocument.Node.Leaf.Kind kind = 1; + QueryType type = 2; + } + + message Sub { + QueryType subtype = 1; + QueryType supertype = 2; + }; + + message Owns { + QueryType subtype = 1; + QueryType supertype = 2; + }; + + message Relates { + QueryType relation = 1; + QueryType role = 2; + }; + + message Plays { + QueryType player = 1; + QueryType role = 2; + }; + + // Function + message Comparison { + QueryValue lhs = 1; + QueryValue rhs = 2; + }; + + message Expression { + string text = 1; + QueryVariable assigned = 2; + repeated QueryVariable arguments = 3; // Treats constants as part of the text. + }; + + message FunctionCall { + string name = 1; + repeated QueryVariable assigned = 2; + repeated QueryValue arguments = 3; // Include constants, since variables are schema-objects + }; + + // Special + message Is { + QueryVariable lhs = 1; + QueryVariable rhs = 2; + }; + + message IID { + QueryVariable var = 1; + bytes IID = 2; + }; + } } From 9f9bd41ebf313d4ff17701a18d3e57e2dc190f80 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 18:51:24 +0200 Subject: [PATCH 07/50] Add exactness to Isa, Sub and other speculatively --- proto/structure.proto | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/proto/structure.proto b/proto/structure.proto index 2140474..d7681be 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -63,20 +63,32 @@ message QueryStructure { uint64 end = 2; } + message ConstraintExactness { + oneof exactness { + Exact exact = 1; + Subtypes subtypes = 2; + } + message Exact {} + message Subtypes {} + } + // Edges message Isa { QueryVariable thing = 1; QueryType type = 2; + ConstraintExactness exactness = 3; }; message Has { QueryVariable owner = 1; QueryVariable attribute = 2; + ConstraintExactness exactness = 3; }; message Links { QueryVariable relation = 1; repeated RolePlayer roleplayers = 2; + ConstraintExactness exactness = 3; message RolePlayer { QueryVariable player = 1; QueryType role = 2; @@ -92,21 +104,25 @@ message QueryStructure { message Sub { QueryType subtype = 1; QueryType supertype = 2; + ConstraintExactness exactness = 3; }; message Owns { QueryType subtype = 1; QueryType supertype = 2; + ConstraintExactness exactness = 3; }; message Relates { QueryType relation = 1; QueryType role = 2; + ConstraintExactness exactness = 3; }; message Plays { QueryType player = 1; QueryType role = 2; + ConstraintExactness exactness = 3; }; // Function From b10129f64e41383318d96577acbd2b32879ee671 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 19:05:26 +0200 Subject: [PATCH 08/50] Fix label to be a concept --- proto/structure.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/structure.proto b/proto/structure.proto index d7681be..b0eedff 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -24,7 +24,7 @@ message QueryStructure { message QueryType { oneof type { QueryVariable variable = 1; - string label = 2; + Concept label = 2; } } From 8b77d2af0c1fae224051ddb7172780584a4175a1 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 19:14:46 +0200 Subject: [PATCH 09/50] Fix value to be oneof --- proto/structure.proto | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proto/structure.proto b/proto/structure.proto index b0eedff..bc76b21 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -29,8 +29,10 @@ message QueryStructure { } message QueryValue { - QueryVariable variable = 1; - Value constant = 2; + oneof value { + QueryVariable variable = 1; + Value constant = 2; + } } message QueryConstraint { From 315168e2c0a7cc4cbf72d9e172d2156de86e1648 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 19:35:24 +0200 Subject: [PATCH 10/50] Fix owns field names --- proto/structure.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/structure.proto b/proto/structure.proto index bc76b21..8792e86 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -110,8 +110,8 @@ message QueryStructure { }; message Owns { - QueryType subtype = 1; - QueryType supertype = 2; + QueryType owner = 1; + QueryType attribute = 2; ConstraintExactness exactness = 3; }; From e7160bac950d6c097ec92bb35aebe5b77ef492e2 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 19:43:12 +0200 Subject: [PATCH 11/50] Make expression assigned repeated for future-proofing --- proto/structure.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/structure.proto b/proto/structure.proto index 8792e86..d01552d 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -135,7 +135,7 @@ message QueryStructure { message Expression { string text = 1; - QueryVariable assigned = 2; + repeated QueryVariable assigned = 2; repeated QueryVariable arguments = 3; // Treats constants as part of the text. }; From aee5da49a9547faa1a93b2770ee55cc9d8d86caa Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 20:22:06 +0200 Subject: [PATCH 12/50] Extend QueryVariable to possibly be unavailable --- proto/structure.proto | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/proto/structure.proto b/proto/structure.proto index d01552d..6d61ff0 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -18,7 +18,10 @@ message QueryStructure { // Vertices message QueryVariable { - string name = 1; + oneof variable { + string name = 1; + string unavailable = 2; + } } message QueryType { From 7de14792260f0095daa904321d59afbf44333e1e Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 12 May 2025 20:59:38 +0200 Subject: [PATCH 13/50] Some minor renaming --- proto/structure.proto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proto/structure.proto b/proto/structure.proto index 6d61ff0..4f48215 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -13,13 +13,13 @@ message QueryStructure { repeated QueryBranch branches = 1; message QueryBranch { - repeated QueryConstraint edges = 1; + repeated QueryConstraint constraints = 1; } // Vertices message QueryVariable { oneof variable { - string name = 1; + string named = 1; string unavailable = 2; } } @@ -40,7 +40,7 @@ message QueryStructure { message QueryConstraint { optional ConstraintSpan span = 1; - oneof edge { + oneof constraint { // Thing Isa isa = 2; Has has = 3; From 1d00ae0bfcea8944502d94e5d79af15c5bdaf462 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Tue, 13 May 2025 21:42:37 +0200 Subject: [PATCH 14/50] Add span for each role-player --- proto/answer.proto | 2 +- proto/structure.proto | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/proto/answer.proto b/proto/answer.proto index a7d0082..baacdfd 100644 --- a/proto/answer.proto +++ b/proto/answer.proto @@ -10,7 +10,7 @@ package typedb.protocol; message ConceptRow { repeated RowEntry row = 1; - bytes provenance = 2; + bytes involved_branches = 2; } message RowEntry { diff --git a/proto/structure.proto b/proto/structure.proto index 4f48215..d4628c5 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -39,7 +39,7 @@ message QueryStructure { } message QueryConstraint { - optional ConstraintSpan span = 1; + ConstraintSpan span = 1; oneof constraint { // Thing Isa isa = 2; @@ -95,8 +95,9 @@ message QueryStructure { repeated RolePlayer roleplayers = 2; ConstraintExactness exactness = 3; message RolePlayer { - QueryVariable player = 1; - QueryType role = 2; + ConstraintSpan span = 1; + QueryVariable player = 2; + QueryType role = 3; } }; From 0eaf9007c722b309991a1c06f383b2f860c4d418 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Tue, 13 May 2025 21:55:45 +0200 Subject: [PATCH 15/50] Flatten links roleplayers --- proto/structure.proto | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/proto/structure.proto b/proto/structure.proto index d4628c5..d5d9b45 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -92,13 +92,9 @@ message QueryStructure { message Links { QueryVariable relation = 1; - repeated RolePlayer roleplayers = 2; - ConstraintExactness exactness = 3; - message RolePlayer { - ConstraintSpan span = 1; - QueryVariable player = 2; - QueryType role = 3; - } + QueryVariable player = 2; + QueryType role = 3; + ConstraintExactness exactness = 4; }; // Type From 0a5eb800a129e631db3616f603710d180da3cc68 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Fri, 16 May 2025 15:17:15 +0200 Subject: [PATCH 16/50] Reflect naming --- proto/query.proto | 2 +- proto/structure.proto | 75 ++++++++++++++++++++----------------------- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/proto/query.proto b/proto/query.proto index 7e5f07d..384aedb 100644 --- a/proto/query.proto +++ b/proto/query.proto @@ -52,7 +52,7 @@ message Query { // TODO: network optimisation: replace types (== mostly constant strings) with a IDs, sending types in the header to rebuild on the client side repeated string column_variable_names = 1; Type query_type = 2; - QueryStructure query_structure = 3; + QueryStructure structure = 3; } } } diff --git a/proto/structure.proto b/proto/structure.proto index d5d9b45..819cce0 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -10,31 +10,24 @@ import "proto/concept.proto"; package typedb.protocol; message QueryStructure { - repeated QueryBranch branches = 1; + repeated QueryBlock branches = 1; - message QueryBranch { + message QueryBlock { repeated QueryConstraint constraints = 1; } // Vertices - message QueryVariable { - oneof variable { - string named = 1; - string unavailable = 2; - } - } - - message QueryType { - oneof type { + message QueryVertex { + oneof vertex { QueryVariable variable = 1; Concept label = 2; + Value value = 3; } - } - message QueryValue { - oneof value { - QueryVariable variable = 1; - Value constant = 2; + message QueryVariable { + string named = 1; + uint32 id = 2; + bool in_answer = 3; } } @@ -79,80 +72,80 @@ message QueryStructure { // Edges message Isa { - QueryVariable thing = 1; - QueryType type = 2; + QueryVertex thing = 1; + QueryVertex type = 2; ConstraintExactness exactness = 3; }; message Has { - QueryVariable owner = 1; - QueryVariable attribute = 2; + QueryVertex owner = 1; + QueryVertex attribute = 2; ConstraintExactness exactness = 3; }; message Links { - QueryVariable relation = 1; - QueryVariable player = 2; - QueryType role = 3; + QueryVertex relation = 1; + QueryVertex player = 2; + QueryVertex role = 3; ConstraintExactness exactness = 4; }; // Type message Kind { protocol.ConceptDocument.Node.Leaf.Kind kind = 1; - QueryType type = 2; + QueryVertex type = 2; } message Sub { - QueryType subtype = 1; - QueryType supertype = 2; + QueryVertex subtype = 1; + QueryVertex supertype = 2; ConstraintExactness exactness = 3; }; message Owns { - QueryType owner = 1; - QueryType attribute = 2; + QueryVertex owner = 1; + QueryVertex attribute = 2; ConstraintExactness exactness = 3; }; message Relates { - QueryType relation = 1; - QueryType role = 2; + QueryVertex relation = 1; + QueryVertex role = 2; ConstraintExactness exactness = 3; }; message Plays { - QueryType player = 1; - QueryType role = 2; + QueryVertex player = 1; + QueryVertex role = 2; ConstraintExactness exactness = 3; }; // Function message Comparison { - QueryValue lhs = 1; - QueryValue rhs = 2; + QueryVertex lhs = 1; + QueryVertex rhs = 2; }; message Expression { string text = 1; - repeated QueryVariable assigned = 2; - repeated QueryVariable arguments = 3; // Treats constants as part of the text. + repeated QueryVertex assigned = 2; + repeated QueryVertex arguments = 3; // Treats constants as part of the text. }; message FunctionCall { string name = 1; - repeated QueryVariable assigned = 2; - repeated QueryValue arguments = 3; // Include constants, since variables are schema-objects + repeated QueryVertex assigned = 2; + repeated QueryVertex arguments = 3; // Include constants, since variables are schema-objects }; // Special message Is { - QueryVariable lhs = 1; - QueryVariable rhs = 2; + QueryVertex lhs = 1; + QueryVertex rhs = 2; }; message IID { - QueryVariable var = 1; + QueryVertex var = 1; bytes IID = 2; }; } From b9127592a20b3cfdc0bd1c6756c5a4db19e19624 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Fri, 16 May 2025 15:45:38 +0200 Subject: [PATCH 17/50] Make labels only accept type --- proto/structure.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/structure.proto b/proto/structure.proto index 819cce0..60a6120 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -20,7 +20,7 @@ message QueryStructure { message QueryVertex { oneof vertex { QueryVariable variable = 1; - Concept label = 2; + Type label = 2; Value value = 3; } From 058627157adbbac59beb97eaa559cf842d811bbd Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 19 May 2025 12:21:43 +0200 Subject: [PATCH 18/50] Reflect renaming again --- proto/answer.proto | 2 +- proto/query.proto | 2 +- proto/structure.proto | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/proto/answer.proto b/proto/answer.proto index baacdfd..0ca455e 100644 --- a/proto/answer.proto +++ b/proto/answer.proto @@ -10,7 +10,7 @@ package typedb.protocol; message ConceptRow { repeated RowEntry row = 1; - bytes involved_branches = 2; + bytes involved_blocks = 2; } message RowEntry { diff --git a/proto/query.proto b/proto/query.proto index 384aedb..5f228ee 100644 --- a/proto/query.proto +++ b/proto/query.proto @@ -52,7 +52,7 @@ message Query { // TODO: network optimisation: replace types (== mostly constant strings) with a IDs, sending types in the header to rebuild on the client side repeated string column_variable_names = 1; Type query_type = 2; - QueryStructure structure = 3; + QueryStructure query = 3; } } } diff --git a/proto/structure.proto b/proto/structure.proto index 60a6120..8b1b4a1 100644 --- a/proto/structure.proto +++ b/proto/structure.proto @@ -10,12 +10,19 @@ import "proto/concept.proto"; package typedb.protocol; message QueryStructure { - repeated QueryBlock branches = 1; + repeated QueryBlock blocks = 1; + map variables = 2; + repeated uint32 outputs = 3; + message QueryBlock { repeated QueryConstraint constraints = 1; } + message VariableInfo { + string name = 1; + } + // Vertices message QueryVertex { oneof vertex { From cff738fd208a635c8463a89a5999b7e604eddf41 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Fri, 12 Sep 2025 12:33:40 +0200 Subject: [PATCH 19/50] Remove query structure from ConceptRowStream, making it currently unused --- proto/query.proto | 1 - 1 file changed, 1 deletion(-) diff --git a/proto/query.proto b/proto/query.proto index 5f228ee..c03ae8f 100644 --- a/proto/query.proto +++ b/proto/query.proto @@ -52,7 +52,6 @@ message Query { // TODO: network optimisation: replace types (== mostly constant strings) with a IDs, sending types in the header to rebuild on the client side repeated string column_variable_names = 1; Type query_type = 2; - QueryStructure query = 3; } } } From c8b975a9df3c5780be485eccb402661e02ddcb50 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Fri, 12 Sep 2025 22:29:20 +0200 Subject: [PATCH 20/50] Try filling in analyze proto --- grpc/java/BUILD | 3 +- grpc/nodejs/BUILD | 3 +- grpc/rust/BUILD | 3 +- proto/BUILD | 26 ++-- proto/analyze.proto | 122 +++++++++++++++++++ proto/{structure.proto => conjunction.proto} | 88 +++++-------- proto/query.proto | 1 - 7 files changed, 178 insertions(+), 68 deletions(-) create mode 100644 proto/analyze.proto rename proto/{structure.proto => conjunction.proto} (53%) diff --git a/grpc/java/BUILD b/grpc/java/BUILD index 149dced..66f77a1 100644 --- a/grpc/java/BUILD +++ b/grpc/java/BUILD @@ -21,8 +21,9 @@ java_grpc_library( "//proto:authentication-proto", "//proto:options-proto", "//proto:query-proto", - "//proto:structure-proto", "//proto:transaction-proto", + "//proto:analyze-proto", + "//proto:conjunction-proto", "//proto:version-proto", ], # TypeDB Core bundles JARs by maven coordinate, we can remove this when Core is rewritten in Rust diff --git a/grpc/nodejs/BUILD b/grpc/nodejs/BUILD index 998b825..fe57fbb 100644 --- a/grpc/nodejs/BUILD +++ b/grpc/nodejs/BUILD @@ -37,8 +37,9 @@ ts_grpc_compile( "//proto:authentication-proto", "//proto:options-proto", "//proto:query-proto", - "//proto:structure-proto", "//proto:transaction-proto", + "//proto:analyze-proto", + "//proto:conjunction-proto", "//proto:version-proto", ] ) diff --git a/grpc/rust/BUILD b/grpc/rust/BUILD index 4f44713..55f9340 100644 --- a/grpc/rust/BUILD +++ b/grpc/rust/BUILD @@ -24,8 +24,9 @@ rust_tonic_compile( "//proto:authentication-proto", "//proto:options-proto", "//proto:query-proto", - "//proto:structure-proto", "//proto:transaction-proto", + "//proto:analyze-proto", + "//proto:conjunction-proto", "//proto:version-proto", ] ) diff --git a/proto/BUILD b/proto/BUILD index af022ba..dd4e00f 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -83,15 +83,6 @@ proto_library( ":concept-proto", ":error-proto", ":options-proto", - ":structure-proto" - ], -) -proto_library( - name = "structure-proto", - srcs = ["structure.proto"], - deps = [ - ":answer-proto", - ":concept-proto", ], ) @@ -112,6 +103,23 @@ proto_library( ] ) +proto_library( + name = "analyze-proto", + srcs = ["analyze.proto"], + deps = [ + ":conjunction-proto", + ], +) + +proto_library( + name = "conjunction-proto", + srcs = ["conjunction.proto"], + deps = [ + ":answer-proto", + ":concept-proto", + ], +) + proto_library( name = "version-proto", srcs = ["version.proto"], diff --git a/proto/analyze.proto b/proto/analyze.proto new file mode 100644 index 0000000..fd8895f --- /dev/null +++ b/proto/analyze.proto @@ -0,0 +1,122 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +syntax = "proto3"; + +import "proto/conjunction.proto"; + +package typedb.protocol; + +message Analyze { + + message Req { + string query = 1; + } + + message Res { + PipelineStructure query = 1; + repeated FunctionStructure preamble = 2; + + message FunctionStructure { + PipelineStructure body = 1; + repeated uint32 arguments = 2; + oneof returns {// TODO: Does this need to be flattened up? + ReturnOpStream stream = 3; + ReturnOpSingle single = 4; + ReturnOpCheck check = 5; + ReturnOpReduce reduce = 6; + }; + + message ReturnOpStream { + repeated uint32 variables = 1; + } + message ReturnOpSingle { + string selector = 1; + repeated uint32 variables = 2; + } + message ReturnOpCheck {} + message ReturnOpReduce { + repeated Reducer reducer = 1; + } + } + + message PipelineStructure { + repeated ConjunctionStructure conjunctions = 1; + repeated PipelineStage stages = 2; + map variable_info = 3; + repeated uint32 outputs = 4; + + message VariableInfo { + string name = 1; + } + + message PipelineStage { + oneof stage { + Match match = 1; + Insert insert = 2; + Put put = 3; + Update update = 4; + Delete delete = 5; + Select select = 6; + Sort sort = 7; + Require require = 8; + Offset offset = 9; + Limit limit = 10; + Distinct distinct = 11; + Reduce reduce = 12; + } + + // They're all the same structure. Should we just use one? + message Match { + uint32 block = 1; + } + message Insert { + uint32 block = 1; + } + message Put { + uint32 block = 1; + } + message Update { + uint32 block = 1; + } + message Delete { + uint32 block = 1; + repeated uint32 deleted_variables = 2; + } + + message Select { + repeated uint32 variables = 1; + } + message Sort { + repeated uint32 variables = 1; + } + message Require { + repeated uint32 variables = 1; + } + + message Offset { + uint64 offset = 1; + } + message Limit { + uint64 limit = 1; + } + message Distinct {} + message Reduce { + repeated ReduceAssign reducers = 1; + repeated uint32 groupby = 2; + + message ReduceAssign { + uint32 assigned = 1; + Reducer reducer = 2; + } + } + } + } + + message Reducer { + string reducer = 1; + repeated uint32 variables = 2; + } + } +} diff --git a/proto/structure.proto b/proto/conjunction.proto similarity index 53% rename from proto/structure.proto rename to proto/conjunction.proto index 8b1b4a1..b27e0e5 100644 --- a/proto/structure.proto +++ b/proto/conjunction.proto @@ -9,36 +9,18 @@ import "proto/concept.proto"; package typedb.protocol; -message QueryStructure { - repeated QueryBlock blocks = 1; - map variables = 2; - repeated uint32 outputs = 3; +message ConjunctionStructure { + repeated Constraint constraints = 1; - - message QueryBlock { - repeated QueryConstraint constraints = 1; - } - - message VariableInfo { - string name = 1; - } - - // Vertices - message QueryVertex { + message StructureVertex { oneof vertex { - QueryVariable variable = 1; + uint32 variable = 1; Type label = 2; Value value = 3; } - - message QueryVariable { - string named = 1; - uint32 id = 2; - bool in_answer = 3; - } } - message QueryConstraint { + message Constraint { ConstraintSpan span = 1; oneof constraint { // Thing @@ -68,91 +50,87 @@ message QueryStructure { uint64 end = 2; } - message ConstraintExactness { - oneof exactness { - Exact exact = 1; - Subtypes subtypes = 2; - } - message Exact {} - message Subtypes {} + enum ConstraintExactness { + EXACT = 0; + SUBTYPES = 1; } // Edges message Isa { - QueryVertex thing = 1; - QueryVertex type = 2; + StructureVertex thing = 1; + StructureVertex type = 2; ConstraintExactness exactness = 3; }; message Has { - QueryVertex owner = 1; - QueryVertex attribute = 2; + StructureVertex owner = 1; + StructureVertex attribute = 2; ConstraintExactness exactness = 3; }; message Links { - QueryVertex relation = 1; - QueryVertex player = 2; - QueryVertex role = 3; + StructureVertex relation = 1; + StructureVertex player = 2; + StructureVertex role = 3; ConstraintExactness exactness = 4; }; // Type message Kind { protocol.ConceptDocument.Node.Leaf.Kind kind = 1; - QueryVertex type = 2; + StructureVertex type = 2; } message Sub { - QueryVertex subtype = 1; - QueryVertex supertype = 2; + StructureVertex subtype = 1; + StructureVertex supertype = 2; ConstraintExactness exactness = 3; }; message Owns { - QueryVertex owner = 1; - QueryVertex attribute = 2; + StructureVertex owner = 1; + StructureVertex attribute = 2; ConstraintExactness exactness = 3; }; message Relates { - QueryVertex relation = 1; - QueryVertex role = 2; + StructureVertex relation = 1; + StructureVertex role = 2; ConstraintExactness exactness = 3; }; message Plays { - QueryVertex player = 1; - QueryVertex role = 2; + StructureVertex player = 1; + StructureVertex role = 2; ConstraintExactness exactness = 3; }; // Function message Comparison { - QueryVertex lhs = 1; - QueryVertex rhs = 2; + StructureVertex lhs = 1; + StructureVertex rhs = 2; }; message Expression { string text = 1; - repeated QueryVertex assigned = 2; - repeated QueryVertex arguments = 3; // Treats constants as part of the text. + repeated StructureVertex assigned = 2; + repeated StructureVertex arguments = 3; // Treats constants as part of the text. }; message FunctionCall { string name = 1; - repeated QueryVertex assigned = 2; - repeated QueryVertex arguments = 3; // Include constants, since variables are schema-objects + repeated StructureVertex assigned = 2; + repeated StructureVertex arguments = 3; // Include constants, since variables are schema-objects }; // Special message Is { - QueryVertex lhs = 1; - QueryVertex rhs = 2; + StructureVertex lhs = 1; + StructureVertex rhs = 2; }; message IID { - QueryVertex var = 1; + StructureVertex var = 1; bytes IID = 2; }; } diff --git a/proto/query.proto b/proto/query.proto index c03ae8f..efb9940 100644 --- a/proto/query.proto +++ b/proto/query.proto @@ -7,7 +7,6 @@ syntax = "proto3"; import "proto/answer.proto"; import "proto/options.proto"; import "proto/error.proto"; -import "proto/structure.proto"; package typedb.protocol; From b197dc2bd8b8f0e7fab70a4123935963b2d55536 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 15 Sep 2025 11:21:34 +0200 Subject: [PATCH 21/50] Do I have to add it to the filegroup? --- proto/BUILD | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proto/BUILD b/proto/BUILD index dd4e00f..8f67fd5 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -131,9 +131,11 @@ proto_library( filegroup( name = "proto-raw-buffers", srcs = [ + "analyze.proto", "answer.proto", "concept.proto", "connection.proto", + "conjunction.proto", "options.proto", "query.proto", "transaction.proto", From 98ba00c798924401b380c968b4fca11e325faae9 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 15 Sep 2025 11:26:15 +0200 Subject: [PATCH 22/50] Rename Constraint to structureConstraint for consistency --- proto/conjunction.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index b27e0e5..20b55d5 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -10,7 +10,7 @@ import "proto/concept.proto"; package typedb.protocol; message ConjunctionStructure { - repeated Constraint constraints = 1; + repeated StructureConstraint constraints = 1; message StructureVertex { oneof vertex { @@ -20,7 +20,7 @@ message ConjunctionStructure { } } - message Constraint { + message StructureConstraint { ConstraintSpan span = 1; oneof constraint { // Thing From e7b96716e8b711f1c67373cff31aecf5479113fe Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 15 Sep 2025 14:54:37 +0200 Subject: [PATCH 23/50] And one for the build.rs --- grpc/rust/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grpc/rust/build.rs b/grpc/rust/build.rs index 3dbc768..2e2cda9 100644 --- a/grpc/rust/build.rs +++ b/grpc/rust/build.rs @@ -4,10 +4,12 @@ fn main() -> std::io::Result<()> { let protos = vec![ + "../../proto/analyze.proto", "../../proto/answer.proto", "../../proto/authentication.proto", "../../proto/concept.proto", "../../proto/connection.proto", + "../../proto/conjunction.proto", "../../proto/database.proto", "../../proto/error.proto", "../../proto/migration.proto", From e8f9bc373c3a9b97700d1a9d8041da15eed2a588 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 15 Sep 2025 23:17:58 +0200 Subject: [PATCH 24/50] Add constraint nested patterns + sort direction --- proto/analyze.proto | 13 ++++++++++--- proto/conjunction.proto | 43 ++++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index fd8895f..f1efdc0 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -88,13 +88,20 @@ message Analyze { message Select { repeated uint32 variables = 1; } - message Sort { - repeated uint32 variables = 1; + message Sort { + repeated SortVariable sort_variables = 1; + message SortVariable { + uint32 variable = 1; + SortDirection direction = 2; + enum SortDirection { + ASC = 0; + DESC = 1; + } + } } message Require { repeated uint32 variables = 1; } - message Offset { uint64 offset = 1; } diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 20b55d5..8148e89 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -23,26 +23,30 @@ message ConjunctionStructure { message StructureConstraint { ConstraintSpan span = 1; oneof constraint { + Disjunction disjunction = 2; + Negation negation = 3; + Optional optional = 4; + // Thing - Isa isa = 2; - Has has = 3; - Links links = 4; + Isa isa = 5; + Has has = 6; + Links links = 7; // Type - Kind kind = 5; - Sub sub = 6; - Owns owns = 7; - Relates relates = 8; - Plays plays = 9; + Kind kind = 8; + Sub sub = 9; + Owns owns = 10; + Relates relates = 11; + Plays plays = 12; // Function - Comparison comparison = 10; - Expression expression = 11; - FunctionCall function_call = 12; + Comparison comparison = 13; + Expression expression = 14; + FunctionCall function_call = 15; // Special - Is is = 13; - IID iid = 14; + Is is = 16; + IID iid = 17; } message ConstraintSpan { @@ -55,6 +59,19 @@ message ConjunctionStructure { SUBTYPES = 1; } + // Nested + message Disjunction { + repeated uint32 branches = 1; + } + + message Negation { + uint32 inner = 1; + } + + message Optional { + uint32 inner = 1; + } + // Edges message Isa { StructureVertex thing = 1; From 1a3bbeec9fed22beee04f11548402066813950e4 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 15 Sep 2025 23:23:05 +0200 Subject: [PATCH 25/50] Rename inner to conjunction --- proto/conjunction.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 8148e89..2119d78 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -65,11 +65,11 @@ message ConjunctionStructure { } message Negation { - uint32 inner = 1; + uint32 conjunction = 1; } message Optional { - uint32 inner = 1; + uint32 conjunction = 1; } // Edges From 90e977e8f033830f22609a557c9a3eb6a6c59c61 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 15 Sep 2025 23:25:05 +0200 Subject: [PATCH 26/50] Rename Disjunction -> or etc for consistency --- proto/conjunction.proto | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 2119d78..573d86c 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -23,9 +23,9 @@ message ConjunctionStructure { message StructureConstraint { ConstraintSpan span = 1; oneof constraint { - Disjunction disjunction = 2; - Negation negation = 3; - Optional optional = 4; + Or or = 2; + Not not = 3; + Try try = 4; // Thing Isa isa = 5; @@ -60,15 +60,15 @@ message ConjunctionStructure { } // Nested - message Disjunction { + message Or { repeated uint32 branches = 1; } - message Negation { + message Not { uint32 conjunction = 1; } - message Optional { + message Try { uint32 conjunction = 1; } From 373db612d1666ff9fe25e61c2f35e5acb4962504 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 22 Sep 2025 14:40:14 +0200 Subject: [PATCH 27/50] Make StructureVertex Label support unresolved labels --- proto/conjunction.proto | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 573d86c..4fd524e 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -15,9 +15,13 @@ message ConjunctionStructure { message StructureVertex { oneof vertex { uint32 variable = 1; - Type label = 2; + Label label = 2; Value value = 3; } + message Label { + Type resolved = 1; + string failedInference = 2; + } } message StructureConstraint { From 7b773606bf514ab6db0c053e7d77f17943da4df3 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 22 Sep 2025 14:46:35 +0200 Subject: [PATCH 28/50] Forgot oneoef --- proto/conjunction.proto | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 4fd524e..3c20c14 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -19,8 +19,10 @@ message ConjunctionStructure { Value value = 3; } message Label { - Type resolved = 1; - string failedInference = 2; + oneof label { + Type resolved = 1; + string failedInference = 2; + } } } From a2cd43a7c94457604c33fdb99d4760946dbb2365 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 11:17:05 +0200 Subject: [PATCH 29/50] Introduce Analyze req & res into transaction rpc --- proto/transaction.proto | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/proto/transaction.proto b/proto/transaction.proto index 4d37f23..b9f8de1 100644 --- a/proto/transaction.proto +++ b/proto/transaction.proto @@ -4,6 +4,7 @@ syntax = "proto3"; +import "proto/analyze.proto"; import "proto/error.proto"; import "proto/options.proto"; import "proto/query.proto"; @@ -33,6 +34,8 @@ message Transaction { Commit.Req commit_req = 6; Rollback.Req rollback_req = 7; Close.Req close_req = 8; + + Analyze.Req analyze_req = 9; } } @@ -43,6 +46,8 @@ message Transaction { Query.InitialRes query_initial_res = 3; Commit.Res commit_res = 5; Rollback.Res rollback_res = 6; + + Analyze.Res analyze_res = 9; } } From c9b4bf549607a4e42fdb1bbe2500f3a1eac46cda Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 15:19:06 +0200 Subject: [PATCH 30/50] Variables deserve their own message --- proto/analyze.proto | 22 +++++++++++----------- proto/conjunction.proto | 6 +++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index f1efdc0..d747e6d 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -20,7 +20,7 @@ message Analyze { message FunctionStructure { PipelineStructure body = 1; - repeated uint32 arguments = 2; + repeated ConjunctionStructure.Variable arguments = 2; oneof returns {// TODO: Does this need to be flattened up? ReturnOpStream stream = 3; ReturnOpSingle single = 4; @@ -29,11 +29,11 @@ message Analyze { }; message ReturnOpStream { - repeated uint32 variables = 1; + repeated ConjunctionStructure.Variable variables = 1; } message ReturnOpSingle { string selector = 1; - repeated uint32 variables = 2; + repeated ConjunctionStructure.Variable variables = 2; } message ReturnOpCheck {} message ReturnOpReduce { @@ -45,7 +45,7 @@ message Analyze { repeated ConjunctionStructure conjunctions = 1; repeated PipelineStage stages = 2; map variable_info = 3; - repeated uint32 outputs = 4; + repeated ConjunctionStructure.Variable outputs = 4; message VariableInfo { string name = 1; @@ -82,16 +82,16 @@ message Analyze { } message Delete { uint32 block = 1; - repeated uint32 deleted_variables = 2; + repeated ConjunctionStructure.Variable deleted_variables = 2; } message Select { - repeated uint32 variables = 1; + repeated ConjunctionStructure.Variable variables = 1; } message Sort { repeated SortVariable sort_variables = 1; message SortVariable { - uint32 variable = 1; + ConjunctionStructure.Variable variable = 1; SortDirection direction = 2; enum SortDirection { ASC = 0; @@ -100,7 +100,7 @@ message Analyze { } } message Require { - repeated uint32 variables = 1; + repeated ConjunctionStructure.Variable variables = 1; } message Offset { uint64 offset = 1; @@ -111,10 +111,10 @@ message Analyze { message Distinct {} message Reduce { repeated ReduceAssign reducers = 1; - repeated uint32 groupby = 2; + repeated ConjunctionStructure.Variable groupby = 2; message ReduceAssign { - uint32 assigned = 1; + ConjunctionStructure.Variable assigned = 1; Reducer reducer = 2; } } @@ -123,7 +123,7 @@ message Analyze { message Reducer { string reducer = 1; - repeated uint32 variables = 2; + repeated ConjunctionStructure.Variable variables = 2; } } } diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 3c20c14..39b3d9a 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -11,13 +11,17 @@ package typedb.protocol; message ConjunctionStructure { repeated StructureConstraint constraints = 1; + message Variable { + uint32 id = 1; + } message StructureVertex { oneof vertex { - uint32 variable = 1; + Variable variable = 1; Label label = 2; Value value = 3; } + message Label { oneof label { Type resolved = 1; From 3fb64f125695b33ff62b94da87788285cc8e40b5 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 16:17:22 +0200 Subject: [PATCH 31/50] Oopsies. I forgot about annotations --- proto/analyze.proto | 197 +++++++++++++++++++++++--------------------- 1 file changed, 102 insertions(+), 95 deletions(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index d747e6d..ef75584 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -15,115 +15,122 @@ message Analyze { } message Res { - PipelineStructure query = 1; - repeated FunctionStructure preamble = 2; - - message FunctionStructure { - PipelineStructure body = 1; - repeated ConjunctionStructure.Variable arguments = 2; - oneof returns {// TODO: Does this need to be flattened up? - ReturnOpStream stream = 3; - ReturnOpSingle single = 4; - ReturnOpCheck check = 5; - ReturnOpReduce reduce = 6; - }; - - message ReturnOpStream { - repeated ConjunctionStructure.Variable variables = 1; - } - message ReturnOpSingle { - string selector = 1; - repeated ConjunctionStructure.Variable variables = 2; - } - message ReturnOpCheck {} - message ReturnOpReduce { - repeated Reducer reducer = 1; - } - } + message QueryStructure { + PipelineStructure query = 1; + repeated FunctionStructure preamble = 2; - message PipelineStructure { - repeated ConjunctionStructure conjunctions = 1; - repeated PipelineStage stages = 2; - map variable_info = 3; - repeated ConjunctionStructure.Variable outputs = 4; + message FunctionStructure { + PipelineStructure body = 1; + repeated ConjunctionStructure.Variable arguments = 2; + oneof returns {// TODO: Does this need to be flattened up? + ReturnOpStream stream = 3; + ReturnOpSingle single = 4; + ReturnOpCheck check = 5; + ReturnOpReduce reduce = 6; + }; - message VariableInfo { - string name = 1; - } - - message PipelineStage { - oneof stage { - Match match = 1; - Insert insert = 2; - Put put = 3; - Update update = 4; - Delete delete = 5; - Select select = 6; - Sort sort = 7; - Require require = 8; - Offset offset = 9; - Limit limit = 10; - Distinct distinct = 11; - Reduce reduce = 12; - } - - // They're all the same structure. Should we just use one? - message Match { - uint32 block = 1; - } - message Insert { - uint32 block = 1; - } - message Put { - uint32 block = 1; + message ReturnOpStream { + repeated ConjunctionStructure.Variable variables = 1; } - message Update { - uint32 block = 1; + message ReturnOpSingle { + string selector = 1; + repeated ConjunctionStructure.Variable variables = 2; } - message Delete { - uint32 block = 1; - repeated ConjunctionStructure.Variable deleted_variables = 2; + message ReturnOpCheck {} + message ReturnOpReduce { + repeated Reducer reducer = 1; } + } - message Select { - repeated ConjunctionStructure.Variable variables = 1; + message PipelineStructure { + repeated ConjunctionStructure conjunctions = 1; + repeated PipelineStage stages = 2; + map variable_info = 3; + repeated ConjunctionStructure.Variable outputs = 4; + + message VariableInfo { + string name = 1; } - message Sort { - repeated SortVariable sort_variables = 1; - message SortVariable { - ConjunctionStructure.Variable variable = 1; - SortDirection direction = 2; - enum SortDirection { - ASC = 0; - DESC = 1; + + message PipelineStage { + oneof stage { + Match match = 1; + Insert insert = 2; + Put put = 3; + Update update = 4; + Delete delete = 5; + Select select = 6; + Sort sort = 7; + Require require = 8; + Offset offset = 9; + Limit limit = 10; + Distinct distinct = 11; + Reduce reduce = 12; + } + + // They're all the same structure. Should we just use one? + message Match { + uint32 block = 1; + } + message Insert { + uint32 block = 1; + } + message Put { + uint32 block = 1; + } + message Update { + uint32 block = 1; + } + message Delete { + uint32 block = 1; + repeated ConjunctionStructure.Variable deleted_variables = 2; + } + + message Select { + repeated ConjunctionStructure.Variable variables = 1; + } + message Sort { + repeated SortVariable sort_variables = 1; + message SortVariable { + ConjunctionStructure.Variable variable = 1; + SortDirection direction = 2; + enum SortDirection { + ASC = 0; + DESC = 1; + } } } - } - message Require { - repeated ConjunctionStructure.Variable variables = 1; - } - message Offset { - uint64 offset = 1; - } - message Limit { - uint64 limit = 1; - } - message Distinct {} - message Reduce { - repeated ReduceAssign reducers = 1; - repeated ConjunctionStructure.Variable groupby = 2; - - message ReduceAssign { - ConjunctionStructure.Variable assigned = 1; - Reducer reducer = 2; + message Require { + repeated ConjunctionStructure.Variable variables = 1; + } + message Offset { + uint64 offset = 1; + } + message Limit { + uint64 limit = 1; + } + message Distinct {} + message Reduce { + repeated ReduceAssign reducers = 1; + repeated ConjunctionStructure.Variable groupby = 2; + + message ReduceAssign { + ConjunctionStructure.Variable assigned = 1; + Reducer reducer = 2; + } } } } + + message Reducer { + string reducer = 1; + repeated ConjunctionStructure.Variable variables = 2; + } } - message Reducer { - string reducer = 1; - repeated ConjunctionStructure.Variable variables = 2; + message QueryAnnotations { + // TODO } } + } From f59677eba61d37d60d744c09da3b7b31ed347906 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 16:28:07 +0200 Subject: [PATCH 32/50] Forgot the fields in res --- proto/analyze.proto | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proto/analyze.proto b/proto/analyze.proto index ef75584..fb0f50e 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -15,6 +15,9 @@ message Analyze { } message Res { + QueryStructure structure = 1; + QueryAnnotations annotations = 2; + message QueryStructure { PipelineStructure query = 1; repeated FunctionStructure preamble = 2; From ec84d804cc5d023a63a36467fdbddf6174c038c9 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 17:19:26 +0200 Subject: [PATCH 33/50] Make return reducer field plural --- proto/analyze.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index fb0f50e..536464f 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -41,7 +41,7 @@ message Analyze { } message ReturnOpCheck {} message ReturnOpReduce { - repeated Reducer reducer = 1; + repeated Reducer reducers = 1; } } From e1851764e2507a3d12a2c9094c5666ab43821de0 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 18:49:41 +0200 Subject: [PATCH 34/50] Add kind & label constraints; comparator --- proto/conjunction.proto | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 39b3d9a..50a0156 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -48,15 +48,18 @@ message ConjunctionStructure { Owns owns = 10; Relates relates = 11; Plays plays = 12; + Value value = 13; + Label label = 14; + // Function - Comparison comparison = 13; - Expression expression = 14; - FunctionCall function_call = 15; + Comparison comparison = 15; + Expression expression = 16; + FunctionCall function_call = 17; // Special - Is is = 16; - IID iid = 17; + Is is = 18; + IID iid = 19; } message ConstraintSpan { @@ -132,10 +135,31 @@ message ConjunctionStructure { ConstraintExactness exactness = 3; }; + message Label { + StructureVertex type = 1; + string label = 2; + } + + message Value { + StructureVertex type = 1; + ValueType value_type = 2; + } + // Function message Comparison { StructureVertex lhs = 1; StructureVertex rhs = 2; + Comparator comparator = 3; + enum Comparator { + EQUAL = 0; + NOT_EQUAL = 1; + LESS = 2; + GREATER = 3; + LESS_OR_EQUAL =4; + GREATER_OR_EQUAL = 5; + LIKE = 6; + CONTAINS = 7; + } }; message Expression { From 574bc32a3f5f85207acd79078a70f85890b79776 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 19:00:51 +0200 Subject: [PATCH 35/50] Rename Value(Constraint)::type -> attribute_type --- proto/conjunction.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 50a0156..3af7e7e 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -141,7 +141,7 @@ message ConjunctionStructure { } message Value { - StructureVertex type = 1; + StructureVertex attribute_type = 1; ValueType value_type = 2; } From 9fba4c5c8105594053ab6b5fea01117e144b7de6 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Wed, 24 Sep 2025 19:25:49 +0200 Subject: [PATCH 36/50] Rename Iid field: var -> concenpt --- proto/conjunction.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index 3af7e7e..d378d6e 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -181,7 +181,7 @@ message ConjunctionStructure { }; message IID { - StructureVertex var = 1; + StructureVertex concept = 1; bytes IID = 2; }; } From daa9860d1acfff61a17d8762397e72a20aa6af8d Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 29 Sep 2025 12:43:31 +0200 Subject: [PATCH 37/50] Fix build --- proto/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/proto/BUILD b/proto/BUILD index 8f67fd5..d43ba7b 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -95,6 +95,7 @@ proto_library( name = "transaction-proto", srcs = ["transaction.proto"], deps = [ + ":analyze-proto", ":answer-proto", ":concept-proto", ":error-proto", From a3cd5d50e3e89086a5db69864f2f5899a5b92442 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 29 Sep 2025 14:26:01 +0200 Subject: [PATCH 38/50] WIP: Add conjunction annotations; next fetch --- proto/BUILD | 1 + proto/analyze.proto | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/proto/BUILD b/proto/BUILD index d43ba7b..2e22a0f 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -109,6 +109,7 @@ proto_library( srcs = ["analyze.proto"], deps = [ ":conjunction-proto", + ":concept-proto", ], ) diff --git a/proto/analyze.proto b/proto/analyze.proto index 536464f..5d71525 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -5,6 +5,7 @@ syntax = "proto3"; import "proto/conjunction.proto"; +import "concept.proto"; package typedb.protocol; @@ -132,8 +133,18 @@ message Analyze { } message QueryAnnotations { - // TODO + // TODO: All of this could be absorbed into Conjunction + PipelineAnnotations query = 1; + repeated PipelineAnnotations preamble = 2; + message PipelineAnnotations { + repeated ConjunctionAnnotations conjunctions = 1; + message ConjunctionAnnotations { + map annotations = 1; + message VariableAnnotations { + repeated Type annotation = 1; + } + } + } } } - } From 6729f15fbeab33416e74086debd76489846de02c Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 29 Sep 2025 14:41:56 +0200 Subject: [PATCH 39/50] Add fetch annotations --- proto/analyze.proto | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index 5d71525..3d9bcf1 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -5,7 +5,7 @@ syntax = "proto3"; import "proto/conjunction.proto"; -import "concept.proto"; +import "proto/concept.proto"; package typedb.protocol; @@ -136,6 +136,8 @@ message Analyze { // TODO: All of this could be absorbed into Conjunction PipelineAnnotations query = 1; repeated PipelineAnnotations preamble = 2; + FetchAnnotations fetch = 3; + message PipelineAnnotations { repeated ConjunctionAnnotations conjunctions = 1; message ConjunctionAnnotations { @@ -145,6 +147,20 @@ message Analyze { } } } + + message FetchAnnotations { + oneof node { + Object object = 1; + FetchAnnotations list = 2; + Leaf leaf = 3; + } + message Object { + map annotations = 1; + } + message Leaf { + repeated Type annotation = 1; + } + } } } } From f731396c3f0ca1f1b11cdab9e9bd99ab4a9fcc97 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 2 Oct 2025 14:44:13 +0200 Subject: [PATCH 40/50] Add function annotations & update --- proto/analyze.proto | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index 3d9bcf1..faf4e61 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -138,13 +138,16 @@ message Analyze { repeated PipelineAnnotations preamble = 2; FetchAnnotations fetch = 3; + message FunctionAnnotations { + repeated VariableAnnotations arguments = 1; + repeated VariableAnnotations returns = 2; + PipelineAnnotations body = 3; + } + message PipelineAnnotations { repeated ConjunctionAnnotations conjunctions = 1; message ConjunctionAnnotations { - map annotations = 1; - message VariableAnnotations { - repeated Type annotation = 1; - } + map variable_annotations = 1; } } @@ -158,7 +161,18 @@ message Analyze { map annotations = 1; } message Leaf { - repeated Type annotation = 1; + repeated ValueType annotations = 1; + } + } + + message VariableAnnotations { + oneof annotations { + ConceptVariableAnnotations concept_annotations = 1; + ValueType value_annotations = 2; + + } + message ConceptVariableAnnotations { + repeated Type annotations = 1; } } } From a3e548fc8f9bf53c46dd18568fc319d46e4b4614 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 2 Oct 2025 14:58:02 +0200 Subject: [PATCH 41/50] Add returns_stream to function annotations --- proto/analyze.proto | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index faf4e61..c65d801 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -141,7 +141,8 @@ message Analyze { message FunctionAnnotations { repeated VariableAnnotations arguments = 1; repeated VariableAnnotations returns = 2; - PipelineAnnotations body = 3; + bool returns_stream = 3; + PipelineAnnotations body = 4; } message PipelineAnnotations { From 9f0f3888eb6a19251dc578b458e233e8bd1a4c67 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 2 Oct 2025 15:15:32 +0200 Subject: [PATCH 42/50] Fix function annotations --- proto/analyze.proto | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index c65d801..b0a6ff8 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -133,9 +133,8 @@ message Analyze { } message QueryAnnotations { - // TODO: All of this could be absorbed into Conjunction PipelineAnnotations query = 1; - repeated PipelineAnnotations preamble = 2; + repeated FunctionAnnotations preamble = 2; FetchAnnotations fetch = 3; message FunctionAnnotations { From 4d51f8f54fef2fc7a54999075c2300e8f91bf367 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 2 Oct 2025 16:02:26 +0200 Subject: [PATCH 43/50] Support Thing & Type --- proto/analyze.proto | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index b0a6ff8..ff9ad44 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -167,12 +167,13 @@ message Analyze { message VariableAnnotations { oneof annotations { - ConceptVariableAnnotations concept_annotations = 1; - ValueType value_annotations = 2; + ConceptVariableAnnotations thing = 1; + ConceptVariableAnnotations type = 2; + ValueType value_annotations = 3; } message ConceptVariableAnnotations { - repeated Type annotations = 1; + repeated Type thing = 1; } } } From a45dc234ea9ec14ec106d1edfb9494c1dd63c239 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 2 Oct 2025 16:12:26 +0200 Subject: [PATCH 44/50] Bad field name in ConceptVariableAnnotations --- proto/analyze.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index ff9ad44..270c0b6 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -173,7 +173,7 @@ message Analyze { } message ConceptVariableAnnotations { - repeated Type thing = 1; + repeated Type types = 1; } } } From 8e7077e4562bc0d6e8b4b64b400544615dfa447e Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 2 Oct 2025 16:43:43 +0200 Subject: [PATCH 45/50] Oopsies. Do analyze errors properly --- proto/BUILD | 1 + proto/analyze.proto | 280 +++++++++++++++++++++++--------------------- 2 files changed, 145 insertions(+), 136 deletions(-) diff --git a/proto/BUILD b/proto/BUILD index 2e22a0f..f860708 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -110,6 +110,7 @@ proto_library( deps = [ ":conjunction-proto", ":concept-proto", + ":error-proto", ], ) diff --git a/proto/analyze.proto b/proto/analyze.proto index 270c0b6..de5db76 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -6,6 +6,7 @@ syntax = "proto3"; import "proto/conjunction.proto"; import "proto/concept.proto"; +import "proto/error.proto"; package typedb.protocol; @@ -16,164 +17,171 @@ message Analyze { } message Res { - QueryStructure structure = 1; - QueryAnnotations annotations = 2; - - message QueryStructure { - PipelineStructure query = 1; - repeated FunctionStructure preamble = 2; - - message FunctionStructure { - PipelineStructure body = 1; - repeated ConjunctionStructure.Variable arguments = 2; - oneof returns {// TODO: Does this need to be flattened up? - ReturnOpStream stream = 3; - ReturnOpSingle single = 4; - ReturnOpCheck check = 5; - ReturnOpReduce reduce = 6; - }; - - message ReturnOpStream { - repeated ConjunctionStructure.Variable variables = 1; - } - message ReturnOpSingle { - string selector = 1; - repeated ConjunctionStructure.Variable variables = 2; - } - message ReturnOpCheck {} - message ReturnOpReduce { - repeated Reducer reducers = 1; - } - } - - message PipelineStructure { - repeated ConjunctionStructure conjunctions = 1; - repeated PipelineStage stages = 2; - map variable_info = 3; - repeated ConjunctionStructure.Variable outputs = 4; - - message VariableInfo { - string name = 1; - } - - message PipelineStage { - oneof stage { - Match match = 1; - Insert insert = 2; - Put put = 3; - Update update = 4; - Delete delete = 5; - Select select = 6; - Sort sort = 7; - Require require = 8; - Offset offset = 9; - Limit limit = 10; - Distinct distinct = 11; - Reduce reduce = 12; - } + oneof result { + Error err = 1; + AnalyzedQuery ok = 2; + } - // They're all the same structure. Should we just use one? - message Match { - uint32 block = 1; - } - message Insert { - uint32 block = 1; - } - message Put { - uint32 block = 1; + message AnalyzedQuery { + QueryStructure structure = 1; + QueryAnnotations annotations = 2; + + message QueryStructure { + PipelineStructure query = 1; + repeated FunctionStructure preamble = 2; + + message FunctionStructure { + PipelineStructure body = 1; + repeated ConjunctionStructure.Variable arguments = 2; + oneof returns {// TODO: Does this need to be flattened up? + ReturnOpStream stream = 3; + ReturnOpSingle single = 4; + ReturnOpCheck check = 5; + ReturnOpReduce reduce = 6; + }; + + message ReturnOpStream { + repeated ConjunctionStructure.Variable variables = 1; } - message Update { - uint32 block = 1; + message ReturnOpSingle { + string selector = 1; + repeated ConjunctionStructure.Variable variables = 2; } - message Delete { - uint32 block = 1; - repeated ConjunctionStructure.Variable deleted_variables = 2; + message ReturnOpCheck {} + message ReturnOpReduce { + repeated Reducer reducers = 1; } + } - message Select { - repeated ConjunctionStructure.Variable variables = 1; + message PipelineStructure { + repeated ConjunctionStructure conjunctions = 1; + repeated PipelineStage stages = 2; + map variable_info = 3; + repeated ConjunctionStructure.Variable outputs = 4; + + message VariableInfo { + string name = 1; } - message Sort { - repeated SortVariable sort_variables = 1; - message SortVariable { - ConjunctionStructure.Variable variable = 1; - SortDirection direction = 2; - enum SortDirection { - ASC = 0; - DESC = 1; + + message PipelineStage { + oneof stage { + Match match = 1; + Insert insert = 2; + Put put = 3; + Update update = 4; + Delete delete = 5; + Select select = 6; + Sort sort = 7; + Require require = 8; + Offset offset = 9; + Limit limit = 10; + Distinct distinct = 11; + Reduce reduce = 12; + } + + // They're all the same structure. Should we just use one? + message Match { + uint32 block = 1; + } + message Insert { + uint32 block = 1; + } + message Put { + uint32 block = 1; + } + message Update { + uint32 block = 1; + } + message Delete { + uint32 block = 1; + repeated ConjunctionStructure.Variable deleted_variables = 2; + } + + message Select { + repeated ConjunctionStructure.Variable variables = 1; + } + message Sort { + repeated SortVariable sort_variables = 1; + message SortVariable { + ConjunctionStructure.Variable variable = 1; + SortDirection direction = 2; + enum SortDirection { + ASC = 0; + DESC = 1; + } } } - } - message Require { - repeated ConjunctionStructure.Variable variables = 1; - } - message Offset { - uint64 offset = 1; - } - message Limit { - uint64 limit = 1; - } - message Distinct {} - message Reduce { - repeated ReduceAssign reducers = 1; - repeated ConjunctionStructure.Variable groupby = 2; - - message ReduceAssign { - ConjunctionStructure.Variable assigned = 1; - Reducer reducer = 2; + message Require { + repeated ConjunctionStructure.Variable variables = 1; + } + message Offset { + uint64 offset = 1; + } + message Limit { + uint64 limit = 1; + } + message Distinct {} + message Reduce { + repeated ReduceAssign reducers = 1; + repeated ConjunctionStructure.Variable groupby = 2; + + message ReduceAssign { + ConjunctionStructure.Variable assigned = 1; + Reducer reducer = 2; + } } } } - } - message Reducer { - string reducer = 1; - repeated ConjunctionStructure.Variable variables = 2; + message Reducer { + string reducer = 1; + repeated ConjunctionStructure.Variable variables = 2; + } } - } - message QueryAnnotations { - PipelineAnnotations query = 1; - repeated FunctionAnnotations preamble = 2; - FetchAnnotations fetch = 3; + message QueryAnnotations { + PipelineAnnotations query = 1; + repeated FunctionAnnotations preamble = 2; + FetchAnnotations fetch = 3; - message FunctionAnnotations { - repeated VariableAnnotations arguments = 1; - repeated VariableAnnotations returns = 2; - bool returns_stream = 3; - PipelineAnnotations body = 4; - } + message FunctionAnnotations { + repeated VariableAnnotations arguments = 1; + repeated VariableAnnotations returns = 2; + bool returns_stream = 3; + PipelineAnnotations body = 4; + } - message PipelineAnnotations { - repeated ConjunctionAnnotations conjunctions = 1; - message ConjunctionAnnotations { + message PipelineAnnotations { + repeated ConjunctionAnnotations conjunctions = 1; + message ConjunctionAnnotations { map variable_annotations = 1; + } } - } - message FetchAnnotations { - oneof node { - Object object = 1; - FetchAnnotations list = 2; - Leaf leaf = 3; - } - message Object { - map annotations = 1; - } - message Leaf { - repeated ValueType annotations = 1; + message FetchAnnotations { + oneof node { + Object object = 1; + FetchAnnotations list = 2; + Leaf leaf = 3; + } + message Object { + map annotations = 1; + } + message Leaf { + repeated ValueType annotations = 1; + } } - } - message VariableAnnotations { - oneof annotations { - ConceptVariableAnnotations thing = 1; - ConceptVariableAnnotations type = 2; - ValueType value_annotations = 3; + message VariableAnnotations { + oneof annotations { + ConceptVariableAnnotations thing = 1; + ConceptVariableAnnotations type = 2; + ValueType value_annotations = 3; - } - message ConceptVariableAnnotations { - repeated Type types = 1; + } + message ConceptVariableAnnotations { + repeated Type types = 1; + } } } } From 8095df420ba92cd91db1c9ddf408871925bbe3f7 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 6 Oct 2025 12:13:22 +0200 Subject: [PATCH 46/50] Remove TOOD --- proto/analyze.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/analyze.proto b/proto/analyze.proto index de5db76..44fa5f9 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -33,7 +33,7 @@ message Analyze { message FunctionStructure { PipelineStructure body = 1; repeated ConjunctionStructure.Variable arguments = 2; - oneof returns {// TODO: Does this need to be flattened up? + oneof returns { ReturnOpStream stream = 3; ReturnOpSingle single = 4; ReturnOpCheck check = 5; From ba56e0987b62129ce5efa2eae61ff79488b0bbfd Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 6 Oct 2025 12:49:30 +0200 Subject: [PATCH 47/50] Rename Label.label::(failedInference to unresolved) --- proto/conjunction.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index d378d6e..f3fa55c 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -25,7 +25,7 @@ message ConjunctionStructure { message Label { oneof label { Type resolved = 1; - string failedInference = 2; + string unresolved = 2; } } } From deae6552abaa782e9977461b27210ec2fb258593 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 6 Oct 2025 13:08:47 +0200 Subject: [PATCH 48/50] Move StructureVertex::Label::unresolved to a new Label::NamedRole variant; Flatten Label --- proto/conjunction.proto | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index f3fa55c..c77dbe8 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -18,15 +18,14 @@ message ConjunctionStructure { message StructureVertex { oneof vertex { Variable variable = 1; - Label label = 2; + Type label = 2; Value value = 3; + NamedRole named_role = 4; } - message Label { - oneof label { - Type resolved = 1; - string unresolved = 2; - } + message NamedRole { + Variable variable = 1; + string name = 2; } } From bf987393f6eb1462846d6c62bf2ffe7ae4b6e90d Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 6 Oct 2025 13:17:30 +0200 Subject: [PATCH 49/50] Add unresolved as a variant in vertex --- proto/conjunction.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proto/conjunction.proto b/proto/conjunction.proto index c77dbe8..9da6ab9 100644 --- a/proto/conjunction.proto +++ b/proto/conjunction.proto @@ -21,6 +21,8 @@ message ConjunctionStructure { Type label = 2; Value value = 3; NamedRole named_role = 4; + // Error condition. Should be unreachable. + string unresolved = 5; } message NamedRole { From f2aa192196c4ea1a643cc34f8de2a37d818eb97a Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Thu, 9 Oct 2025 13:17:02 +0200 Subject: [PATCH 50/50] Rename conjunction.proto to structure.proto --- grpc/java/BUILD | 2 +- grpc/nodejs/BUILD | 2 +- grpc/rust/BUILD | 2 +- grpc/rust/build.rs | 2 +- proto/BUILD | 8 ++++---- proto/analyze.proto | 2 +- proto/{conjunction.proto => structure.proto} | 0 7 files changed, 9 insertions(+), 9 deletions(-) rename proto/{conjunction.proto => structure.proto} (100%) diff --git a/grpc/java/BUILD b/grpc/java/BUILD index 66f77a1..5ffbcec 100644 --- a/grpc/java/BUILD +++ b/grpc/java/BUILD @@ -23,7 +23,7 @@ java_grpc_library( "//proto:query-proto", "//proto:transaction-proto", "//proto:analyze-proto", - "//proto:conjunction-proto", + "//proto:structure-proto", "//proto:version-proto", ], # TypeDB Core bundles JARs by maven coordinate, we can remove this when Core is rewritten in Rust diff --git a/grpc/nodejs/BUILD b/grpc/nodejs/BUILD index fe57fbb..b436020 100644 --- a/grpc/nodejs/BUILD +++ b/grpc/nodejs/BUILD @@ -39,7 +39,7 @@ ts_grpc_compile( "//proto:query-proto", "//proto:transaction-proto", "//proto:analyze-proto", - "//proto:conjunction-proto", + "//proto:structure-proto", "//proto:version-proto", ] ) diff --git a/grpc/rust/BUILD b/grpc/rust/BUILD index 55f9340..ad0f56a 100644 --- a/grpc/rust/BUILD +++ b/grpc/rust/BUILD @@ -26,7 +26,7 @@ rust_tonic_compile( "//proto:query-proto", "//proto:transaction-proto", "//proto:analyze-proto", - "//proto:conjunction-proto", + "//proto:structure-proto", "//proto:version-proto", ] ) diff --git a/grpc/rust/build.rs b/grpc/rust/build.rs index 2e2cda9..10e52dc 100644 --- a/grpc/rust/build.rs +++ b/grpc/rust/build.rs @@ -9,7 +9,7 @@ fn main() -> std::io::Result<()> { "../../proto/authentication.proto", "../../proto/concept.proto", "../../proto/connection.proto", - "../../proto/conjunction.proto", + "../../proto/structure.proto", "../../proto/database.proto", "../../proto/error.proto", "../../proto/migration.proto", diff --git a/proto/BUILD b/proto/BUILD index f860708..c7fabfe 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -108,15 +108,15 @@ proto_library( name = "analyze-proto", srcs = ["analyze.proto"], deps = [ - ":conjunction-proto", + ":structure-proto", ":concept-proto", ":error-proto", ], ) proto_library( - name = "conjunction-proto", - srcs = ["conjunction.proto"], + name = "structure-proto", + srcs = ["structure.proto"], deps = [ ":answer-proto", ":concept-proto", @@ -138,7 +138,7 @@ filegroup( "answer.proto", "concept.proto", "connection.proto", - "conjunction.proto", + "structure.proto", "options.proto", "query.proto", "transaction.proto", diff --git a/proto/analyze.proto b/proto/analyze.proto index 44fa5f9..2fcda75 100644 --- a/proto/analyze.proto +++ b/proto/analyze.proto @@ -4,7 +4,7 @@ syntax = "proto3"; -import "proto/conjunction.proto"; +import "proto/structure.proto"; import "proto/concept.proto"; import "proto/error.proto"; diff --git a/proto/conjunction.proto b/proto/structure.proto similarity index 100% rename from proto/conjunction.proto rename to proto/structure.proto