From 567d9211d925a79776497c67e741af8b6e2246e9 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 24 Mar 2025 19:51:52 +0100 Subject: [PATCH 1/7] WIP: First attempt --- proto/query-structure.proto | 64 +++++++++++++++++++++++++++++++++++++ proto/query.proto | 2 ++ 2 files changed, 66 insertions(+) create mode 100644 proto/query-structure.proto diff --git a/proto/query-structure.proto b/proto/query-structure.proto new file mode 100644 index 0000000..f6b5626 --- /dev/null +++ b/proto/query-structure.proto @@ -0,0 +1,64 @@ +// 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/concept.proto"; + +package typedb.protocol; + +message QueryStructure { + map branch_constraints = 1; + + message Branch { + repeated ConstraintEdge constraint = 1; + } + + message ConstraintEdge { + EdgeType edge_type = 1; + ConstraintVertex from = 2; + ConstraintVertex to = 3; + EdgeParameter param = 4; + + enum EdgeType { + ISA = 0; + HAS = 1; + LINKS = 2; + + SUB = 3; + OWNS = 4; + RELATES = 5; + PLAYS = 6; + + FUNCTION_ARG = 7; + FUNCTION_RES = 8; + + EXPR_ARG = 9; + EXPR_RESULT = 10; + + COMPARATOR = 11; + } + + message ConstraintVertex { + oneof vertex { + uint64 variable_position = 1; + Concept constant = 2; + DerivedVertex derived = 3; + } + } + + message DerivedVertex { + uint64 function_id = 1; // Uniquely represents the constraint in the query. + string label = 2; // Function name or full expression + repeated uint64 variable_positions = 3; // Arguments (and return values) + } + + message EdgeParameter { + oneof edge_parameter { + uint64 variable_position = 1; // role-types + uint64 index = 2; // Arguments & returns + } + } + } +} diff --git a/proto/query.proto b/proto/query.proto index bfae4c9..4b91f5b 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/concept.proto"; +import "proto/query-structure.proto"; package typedb.protocol; @@ -51,6 +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; } } } From bb02125d11b4b7ebd768fa6e6889ad8e6879a466 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 24 Mar 2025 19:56:42 +0100 Subject: [PATCH 2/7] Fix up build files --- grpc/rust/BUILD | 1 + proto/BUILD | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/grpc/rust/BUILD b/grpc/rust/BUILD index 5d608c9..d0e478c 100644 --- a/grpc/rust/BUILD +++ b/grpc/rust/BUILD @@ -22,6 +22,7 @@ rust_tonic_compile( "//proto:logic-proto", "//proto:options-proto", "//proto:query-proto", + "//proto:query-structure-proto", "//proto:transaction-proto", "//proto:version-proto", ] diff --git a/proto/BUILD b/proto/BUILD index 9c9ec50..496148b 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -72,6 +72,15 @@ proto_library( ":logic-proto", ":options-proto", ":concept-proto", + ":query-structure-proto", + ], +) + +proto_library( + name = "query-structure-proto", + srcs = ["query-structure.proto"], + deps = [ + ":concept-proto", ], ) From 27d69c04da3e9c5e92da26dc87880fc9dea24c3e Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 24 Mar 2025 19:58:23 +0100 Subject: [PATCH 3/7] oopsies. Forgot rust wasn't the only language --- grpc/java/BUILD | 1 + grpc/nodejs/BUILD | 1 + 2 files changed, 2 insertions(+) diff --git a/grpc/java/BUILD b/grpc/java/BUILD index 33a8dc9..7150d05 100644 --- a/grpc/java/BUILD +++ b/grpc/java/BUILD @@ -19,6 +19,7 @@ java_grpc_library( "//proto:logic-proto", "//proto:options-proto", "//proto:query-proto", + "//proto:query-structure-proto", "//proto:transaction-proto", "//proto:version-proto", ], diff --git a/grpc/nodejs/BUILD b/grpc/nodejs/BUILD index 6233662..6efc67c 100644 --- a/grpc/nodejs/BUILD +++ b/grpc/nodejs/BUILD @@ -35,6 +35,7 @@ ts_grpc_compile( "//proto:logic-proto", "//proto:options-proto", "//proto:query-proto", + "//proto:query-structure-proto", "//proto:transaction-proto", "//proto:version-proto", ] From 6379c1ceab92a2c5e646a95639142fe447577ebc Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 24 Mar 2025 20:20:55 +0100 Subject: [PATCH 4/7] Better naming --- proto/query-structure.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/query-structure.proto b/proto/query-structure.proto index f6b5626..9adb84f 100644 --- a/proto/query-structure.proto +++ b/proto/query-structure.proto @@ -9,10 +9,10 @@ import "proto/concept.proto"; package typedb.protocol; message QueryStructure { - map branch_constraints = 1; + map branches = 1; message Branch { - repeated ConstraintEdge constraint = 1; + repeated ConstraintEdge constraints = 1; } message ConstraintEdge { From f4ee5048f20f97b06df877fd8d756545d5e975f2 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 24 Mar 2025 23:13:40 +0100 Subject: [PATCH 5/7] more naming --- proto/query-structure.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/query-structure.proto b/proto/query-structure.proto index 9adb84f..0066562 100644 --- a/proto/query-structure.proto +++ b/proto/query-structure.proto @@ -12,10 +12,10 @@ message QueryStructure { map branches = 1; message Branch { - repeated ConstraintEdge constraints = 1; + repeated StructureEdge constraints = 1; } - message ConstraintEdge { + message StructureEdge { EdgeType edge_type = 1; ConstraintVertex from = 2; ConstraintVertex to = 3; From 552a29923133e94381817ed59c1ac19ef6b47ece Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Mon, 24 Mar 2025 23:16:55 +0100 Subject: [PATCH 6/7] Eep --- proto/query-structure.proto | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/proto/query-structure.proto b/proto/query-structure.proto index 0066562..79ceaac 100644 --- a/proto/query-structure.proto +++ b/proto/query-structure.proto @@ -17,8 +17,8 @@ message QueryStructure { message StructureEdge { EdgeType edge_type = 1; - ConstraintVertex from = 2; - ConstraintVertex to = 3; + StructureVertex from = 2; + StructureVertex to = 3; EdgeParameter param = 4; enum EdgeType { @@ -40,25 +40,27 @@ message QueryStructure { COMPARATOR = 11; } - message ConstraintVertex { - oneof vertex { - uint64 variable_position = 1; - Concept constant = 2; - DerivedVertex derived = 3; + message EdgeParameter { + oneof edge_parameter { + uint64 variable_position = 1; // role-types + uint64 index = 2; // Arguments & returns } } + } + + message StructureVertex { + oneof vertex { + uint64 variable_position = 1; + Concept constant = 2; + DerivedVertex derived = 3; + } + message DerivedVertex { uint64 function_id = 1; // Uniquely represents the constraint in the query. string label = 2; // Function name or full expression repeated uint64 variable_positions = 3; // Arguments (and return values) } - - message EdgeParameter { - oneof edge_parameter { - uint64 variable_position = 1; // role-types - uint64 index = 2; // Arguments & returns - } - } } + } From 3835ce2ac21d679de8bd87598bbfc7aec9565237 Mon Sep 17 00:00:00 2001 From: Krishnan Govindraj Date: Tue, 25 Mar 2025 12:16:52 +0100 Subject: [PATCH 7/7] Revise fields --- proto/query-structure.proto | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/proto/query-structure.proto b/proto/query-structure.proto index 79ceaac..5b82b7a 100644 --- a/proto/query-structure.proto +++ b/proto/query-structure.proto @@ -42,7 +42,8 @@ message QueryStructure { message EdgeParameter { oneof edge_parameter { - uint64 variable_position = 1; // role-types + uint64 position = 1; // for variable role-types + string label = 3; // Constant role-types uint64 index = 2; // Arguments & returns } } @@ -51,8 +52,9 @@ message QueryStructure { message StructureVertex { oneof vertex { uint64 variable_position = 1; - Concept constant = 2; - DerivedVertex derived = 3; + string label = 2; + Value value = 3; + DerivedVertex derived = 4; } @@ -62,5 +64,4 @@ message QueryStructure { repeated uint64 variable_positions = 3; // Arguments (and return values) } } - }