diff --git a/grpc/java/BUILD b/grpc/java/BUILD index bce07da..5ffbcec 100644 --- a/grpc/java/BUILD +++ b/grpc/java/BUILD @@ -22,6 +22,8 @@ java_grpc_library( "//proto:options-proto", "//proto:query-proto", "//proto:transaction-proto", + "//proto:analyze-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 75a7495..b436020 100644 --- a/grpc/nodejs/BUILD +++ b/grpc/nodejs/BUILD @@ -38,6 +38,8 @@ ts_grpc_compile( "//proto:options-proto", "//proto:query-proto", "//proto:transaction-proto", + "//proto:analyze-proto", + "//proto:structure-proto", "//proto:version-proto", ] ) diff --git a/grpc/rust/BUILD b/grpc/rust/BUILD index 4340dd4..ad0f56a 100644 --- a/grpc/rust/BUILD +++ b/grpc/rust/BUILD @@ -25,6 +25,8 @@ rust_tonic_compile( "//proto:options-proto", "//proto:query-proto", "//proto:transaction-proto", + "//proto:analyze-proto", + "//proto:structure-proto", "//proto:version-proto", ] ) diff --git a/grpc/rust/build.rs b/grpc/rust/build.rs index 3dbc768..10e52dc 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/structure.proto", "../../proto/database.proto", "../../proto/error.proto", "../../proto/migration.proto", diff --git a/proto/BUILD b/proto/BUILD index ab0af9d..c7fabfe 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", @@ -103,6 +104,25 @@ proto_library( ] ) +proto_library( + name = "analyze-proto", + srcs = ["analyze.proto"], + deps = [ + ":structure-proto", + ":concept-proto", + ":error-proto", + ], +) + +proto_library( + name = "structure-proto", + srcs = ["structure.proto"], + deps = [ + ":answer-proto", + ":concept-proto", + ], +) + proto_library( name = "version-proto", srcs = ["version.proto"], @@ -114,9 +134,11 @@ proto_library( filegroup( name = "proto-raw-buffers", srcs = [ + "analyze.proto", "answer.proto", "concept.proto", "connection.proto", + "structure.proto", "options.proto", "query.proto", "transaction.proto", diff --git a/proto/analyze.proto b/proto/analyze.proto new file mode 100644 index 0000000..2fcda75 --- /dev/null +++ b/proto/analyze.proto @@ -0,0 +1,189 @@ +// 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/structure.proto"; +import "proto/concept.proto"; +import "proto/error.proto"; + +package typedb.protocol; + +message Analyze { + + message Req { + string query = 1; + } + + message Res { + oneof result { + Error err = 1; + AnalyzedQuery ok = 2; + } + + 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 { + 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; + } + + // 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 Reducer { + string reducer = 1; + repeated ConjunctionStructure.Variable variables = 2; + } + } + + 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 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 VariableAnnotations { + oneof annotations { + ConceptVariableAnnotations thing = 1; + ConceptVariableAnnotations type = 2; + ValueType value_annotations = 3; + + } + message ConceptVariableAnnotations { + repeated Type types = 1; + } + } + } + } + } +} diff --git a/proto/answer.proto b/proto/answer.proto index e6bf5a9..0ca455e 100644 --- a/proto/answer.proto +++ b/proto/answer.proto @@ -10,6 +10,7 @@ package typedb.protocol; message ConceptRow { repeated RowEntry row = 1; + bytes involved_blocks = 2; } message RowEntry { diff --git a/proto/structure.proto b/proto/structure.proto new file mode 100644 index 0000000..9da6ab9 --- /dev/null +++ b/proto/structure.proto @@ -0,0 +1,189 @@ +// 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/concept.proto"; + +package typedb.protocol; + +message ConjunctionStructure { + repeated StructureConstraint constraints = 1; + message Variable { + uint32 id = 1; + } + + message StructureVertex { + oneof vertex { + Variable variable = 1; + Type label = 2; + Value value = 3; + NamedRole named_role = 4; + // Error condition. Should be unreachable. + string unresolved = 5; + } + + message NamedRole { + Variable variable = 1; + string name = 2; + } + } + + message StructureConstraint { + ConstraintSpan span = 1; + oneof constraint { + Or or = 2; + Not not = 3; + Try try = 4; + + // Thing + Isa isa = 5; + Has has = 6; + Links links = 7; + + // Type + Kind kind = 8; + Sub sub = 9; + Owns owns = 10; + Relates relates = 11; + Plays plays = 12; + Value value = 13; + Label label = 14; + + + // Function + Comparison comparison = 15; + Expression expression = 16; + FunctionCall function_call = 17; + + // Special + Is is = 18; + IID iid = 19; + } + + message ConstraintSpan { + uint64 begin = 1; + uint64 end = 2; + } + + enum ConstraintExactness { + EXACT = 0; + SUBTYPES = 1; + } + + // Nested + message Or { + repeated uint32 branches = 1; + } + + message Not { + uint32 conjunction = 1; + } + + message Try { + uint32 conjunction = 1; + } + + // Edges + message Isa { + StructureVertex thing = 1; + StructureVertex type = 2; + ConstraintExactness exactness = 3; + }; + + message Has { + StructureVertex owner = 1; + StructureVertex attribute = 2; + ConstraintExactness exactness = 3; + }; + + message Links { + StructureVertex relation = 1; + StructureVertex player = 2; + StructureVertex role = 3; + ConstraintExactness exactness = 4; + }; + + // Type + message Kind { + protocol.ConceptDocument.Node.Leaf.Kind kind = 1; + StructureVertex type = 2; + } + + message Sub { + StructureVertex subtype = 1; + StructureVertex supertype = 2; + ConstraintExactness exactness = 3; + }; + + message Owns { + StructureVertex owner = 1; + StructureVertex attribute = 2; + ConstraintExactness exactness = 3; + }; + + message Relates { + StructureVertex relation = 1; + StructureVertex role = 2; + ConstraintExactness exactness = 3; + }; + + message Plays { + StructureVertex player = 1; + StructureVertex role = 2; + ConstraintExactness exactness = 3; + }; + + message Label { + StructureVertex type = 1; + string label = 2; + } + + message Value { + StructureVertex attribute_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 { + string text = 1; + repeated StructureVertex assigned = 2; + repeated StructureVertex arguments = 3; // Treats constants as part of the text. + }; + + message FunctionCall { + string name = 1; + repeated StructureVertex assigned = 2; + repeated StructureVertex arguments = 3; // Include constants, since variables are schema-objects + }; + + // Special + message Is { + StructureVertex lhs = 1; + StructureVertex rhs = 2; + }; + + message IID { + StructureVertex concept = 1; + bytes IID = 2; + }; + } +} 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; } }