Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dd3b0f1
Get build & tests breaking
krishnangovindraj Sep 25, 2025
f577a13
Ok now maybe
krishnangovindraj Sep 25, 2025
8f8b888
I dont think I need from_proto
krishnangovindraj Sep 25, 2025
8ed4a94
WIP: Let AI fill in constraint
krishnangovindraj Sep 25, 2025
efd2352
Try using TryFromProto. pub super may work
krishnangovindraj Sep 26, 2025
852342f
WIP: Implement deserializing, but now need bdd
krishnangovindraj Sep 26, 2025
6d37d31
WIP: It kinda runs but stream single problems
krishnangovindraj Sep 27, 2025
c617882
Tests work except for some weird transaction closing
krishnangovindraj Sep 27, 2025
b2470ef
Bump protocol though no real changes
krishnangovindraj Sep 29, 2025
1152ada
OH GOD SO BUGGY
krishnangovindraj Oct 2, 2025
751b785
Need to implement steps
krishnangovindraj Oct 2, 2025
ba87900
Implement it all
krishnangovindraj Oct 2, 2025
0099907
Bump behaviour; implement unhappy steps
krishnangovindraj Oct 3, 2025
d90f9dd
Bump protocol; update for field renaming
krishnangovindraj Oct 6, 2025
ae37ec7
Bump behaviour
krishnangovindraj Oct 6, 2025
ad6573d
rustfmt + rearrange
krishnangovindraj Oct 6, 2025
2f00566
Small cleanup
krishnangovindraj Oct 6, 2025
66754fc
Small rearrangements
krishnangovindraj Oct 6, 2025
931b2d2
One more
krishnangovindraj Oct 6, 2025
1328d56
Fix build
krishnangovindraj Oct 6, 2025
fc9c98c
Remove misplaced cleanup_answers in analyze steps
krishnangovindraj Oct 6, 2025
3705f44
update url to myfork in typedb_protocol dependency
krishnangovindraj Oct 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,066 changes: 612 additions & 454 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dependencies/typedb/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def typedb_dependencies():
def typedb_protocol():
git_repository(
name = "typedb_protocol",
remote = "https://github.com/typedb/typedb-protocol",
tag = "3.4.0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_protocol
remote = "https://github.com/krishnangovindraj/typedb-protocol",
commit = "bf987393f6eb1462846d6c62bf2ffe7ae4b6e90d", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_protocol
)

def typedb_behaviour():
git_repository(
name = "typedb_behaviour",
remote = "https://github.com/typedb/typedb-behaviour",
commit = "095a58cb823dd8436600526ceb3ff2c0bdf377f9", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_behaviour
remote = "https://github.com/krishnangovindraj/typedb-behaviour",
commit = "8a0349d9c4dc7bda2d870df7dda41d395d6b1784", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_behaviour
)
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@

[dependencies.typedb-protocol]
features = []
rev = "bf987393f6eb1462846d6c62bf2ffe7ae4b6e90d"
git = "https://github.com/typedb/typedb-protocol"
tag = "3.4.0"
default-features = false

[dependencies.log]
Expand Down
69 changes: 69 additions & 0 deletions rust/src/analyze/annotations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use std::{collections::HashMap, vec::Vec};

use crate::{
analyze::conjunction::Variable,
concept::{type_::Type, ValueType},
};

#[derive(Debug)]
pub struct QueryAnnotations {
pub query: PipelineAnnotations,
pub preamble: Vec<FunctionAnnotations>,
pub fetch: Option<FetchAnnotations>,
}

#[derive(Debug)]
pub struct FunctionAnnotations {
pub arguments: Vec<VariableAnnotations>,
pub returns: FunctionReturnAnnotations,
pub body: PipelineAnnotations,
}

#[derive(Debug)]
pub enum FunctionReturnAnnotations {
Stream(Vec<VariableAnnotations>),
Single(Vec<VariableAnnotations>),
}

#[derive(Debug)]
pub enum FetchAnnotations {
List(Box<FetchAnnotations>),
Leaf(Vec<ValueType>),
Object(HashMap<String, FetchAnnotations>),
}

#[derive(Debug)]
pub struct PipelineAnnotations {
pub conjunction_annotations: Vec<ConjunctionAnnotations>,
}

#[derive(Debug)]
pub struct ConjunctionAnnotations {
pub variable_annotations: HashMap<Variable, VariableAnnotations>,
}

#[derive(Debug)]
pub enum VariableAnnotations {
Thing(Vec<Type>),
Type(Vec<Type>),
Value(ValueType),
}
170 changes: 170 additions & 0 deletions rust/src/analyze/conjunction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use crate::{
concept,
concept::{type_, ValueType},
};

#[derive(Debug, Clone, Copy)]
pub struct ConjunctionID(pub usize);

#[derive(Debug)]
pub struct Conjunction {
pub constraints: Vec<Constraint>,
}

#[derive(Debug)]
pub enum ConstraintExactness {
Exact,
Subtypes,
}

#[derive(Debug)]
pub enum Constraint {
Isa {
instance: ConstraintVertex,
r#type: ConstraintVertex,
exactness: ConstraintExactness,
},
Has {
owner: ConstraintVertex,
attribute: ConstraintVertex,
exactness: ConstraintExactness,
},
Links {
relation: ConstraintVertex,
player: ConstraintVertex,
role: ConstraintVertex,
exactness: ConstraintExactness,
},

Sub {
subtype: ConstraintVertex,
supertype: ConstraintVertex,
exactness: ConstraintExactness,
},
Owns {
owner: ConstraintVertex,
attribute: ConstraintVertex,
exactness: ConstraintExactness,
},
Relates {
relation: ConstraintVertex,
role: ConstraintVertex,
exactness: ConstraintExactness,
},
Plays {
player: ConstraintVertex,
role: ConstraintVertex,
exactness: ConstraintExactness,
},

FunctionCall {
name: String,
assigned: Vec<ConstraintVertex>,
arguments: Vec<ConstraintVertex>,
},
Expression {
text: String,
assigned: Vec<ConstraintVertex>,
arguments: Vec<ConstraintVertex>,
},
Is {
lhs: ConstraintVertex,
rhs: ConstraintVertex,
},
Iid {
concept: ConstraintVertex,
iid: Vec<u8>,
},
Comparison {
lhs: ConstraintVertex,
rhs: ConstraintVertex,
comparator: Comparator,
},
Kind {
kind: concept::Kind,
r#type: ConstraintVertex,
},
Label {
r#type: ConstraintVertex,
label: String,
},
Value {
attribute_type: ConstraintVertex,
value_type: ValueType,
},

// Nested patterns are now constraints too
Or {
branches: Vec<ConjunctionID>,
},
Not {
conjunction: ConjunctionID,
},
Try {
conjunction: ConjunctionID,
},
}

#[derive(Debug, Hash, Clone, Eq, PartialEq)]
pub struct Variable(pub u32);

#[derive(Debug)]
pub enum ConstraintVertex {
Variable(Variable),
Label(type_::Type),
Value(concept::Value),
NamedRole(NamedRole),
Unresolved(String), // Error condition
}

#[derive(Debug)]
pub struct NamedRole {
pub variable: Variable,
pub name: String,
}

#[derive(Debug)]
pub enum Comparator {
Equal,
NotEqual,
LessThan,
LessOrEqual,
Greater,
GreaterOrEqual,
Like,
Contains,
}

impl Comparator {
pub fn symbol(&self) -> &'static str {
match self {
Comparator::Equal => "==",
Comparator::NotEqual => "!=",
Comparator::LessThan => "<",
Comparator::LessOrEqual => "<=",
Comparator::Greater => ">",
Comparator::GreaterOrEqual => ">=",
Comparator::Like => "Like",
Comparator::Contains => "Contains",
}
}
}
55 changes: 55 additions & 0 deletions rust/src/analyze/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use crate::analyze::{
annotations::QueryAnnotations,
conjunction::Variable,
pipeline::{PipelineStructure, Reducer},
};

pub mod annotations;
pub mod conjunction;
pub mod pipeline;

#[derive(Debug)]
pub struct AnalyzedQuery {
pub structure: QueryStructure,
pub annotations: QueryAnnotations,
}

#[derive(Debug)]
pub struct QueryStructure {
pub query: PipelineStructure,
pub preamble: Vec<FunctionStructure>,
}

#[derive(Debug)]
pub struct FunctionStructure {
pub arguments: Vec<Variable>,
pub returns: ReturnOperation,
pub body: PipelineStructure,
}

#[derive(Debug)]
pub enum ReturnOperation {
Stream { variables: Vec<Variable> },
Single { selector: String, variables: Vec<Variable> },
Check {},
Reduce { reducers: Vec<Reducer> },
}
70 changes: 70 additions & 0 deletions rust/src/analyze/pipeline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use std::collections::HashMap;

use crate::analyze::conjunction::{Conjunction, ConjunctionID, Variable};

#[derive(Debug)]
pub struct PipelineStructure {
pub conjunctions: Vec<Conjunction>,
pub stages: Vec<PipelineStage>,
pub variable_names: HashMap<Variable, String>,
pub outputs: Vec<Variable>,
}

#[derive(Debug)]
pub enum PipelineStage {
Match { block: ConjunctionID },
Insert { block: ConjunctionID },
Put { block: ConjunctionID },
Update { block: ConjunctionID },
Delete { block: ConjunctionID, deleted_variables: Vec<Variable> },
Select { variables: Vec<Variable> },
Sort { variables: Vec<SortVariable> },
Require { variables: Vec<Variable> },
Offset { offset: u64 },
Limit { limit: u64 },
Distinct,
Reduce { reducers: Vec<ReduceAssign>, groupby: Vec<Variable> },
}

#[derive(Debug)]
pub struct ReduceAssign {
pub assigned: Variable,
pub reducer: Reducer,
}

#[derive(Debug)]
pub struct Reducer {
pub arguments: Vec<Variable>,
pub reducer: String,
}

#[derive(Debug)]
pub struct SortVariable {
pub variable: Variable,
pub order: SortOrder,
}

#[derive(Debug)]
pub enum SortOrder {
Ascending,
Descending,
}
Loading