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", ] 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", ], ) diff --git a/proto/query-structure.proto b/proto/query-structure.proto new file mode 100644 index 0000000..5b82b7a --- /dev/null +++ b/proto/query-structure.proto @@ -0,0 +1,67 @@ +// 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 branches = 1; + + message Branch { + repeated StructureEdge constraints = 1; + } + + message StructureEdge { + EdgeType edge_type = 1; + StructureVertex from = 2; + StructureVertex 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 EdgeParameter { + oneof edge_parameter { + uint64 position = 1; // for variable role-types + string label = 3; // Constant role-types + uint64 index = 2; // Arguments & returns + } + } + } + + message StructureVertex { + oneof vertex { + uint64 variable_position = 1; + string label = 2; + Value value = 3; + DerivedVertex derived = 4; + } + + + 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) + } + } +} 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; } } }