|
|
|
@ -122,7 +122,7 @@ fn test_conditions() {
|
|
|
|
|
"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
debug!("real test begins");
|
|
|
|
|
let res = db
|
|
|
|
|
.run_script(
|
|
|
|
@ -168,7 +168,7 @@ fn default_columns() {
|
|
|
|
|
"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
db.run_script(
|
|
|
|
|
r#"
|
|
|
|
@ -177,7 +177,7 @@ fn default_columns() {
|
|
|
|
|
"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
@ -391,12 +391,12 @@ fn test_trigger() {
|
|
|
|
|
":create friends {fr: Int, to: Int => data: Any}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
":create friends.rev {to: Int, fr: Int => data: Any}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r#"
|
|
|
|
|
::set_triggers friends
|
|
|
|
@ -414,12 +414,12 @@ fn test_trigger() {
|
|
|
|
|
"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to, data] <- [[1,2,3]] :put friends {fr, to => data}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let ret = db
|
|
|
|
|
.export_relations(["friends", "friends.rev"].into_iter())
|
|
|
|
|
.unwrap();
|
|
|
|
@ -438,7 +438,7 @@ fn test_trigger() {
|
|
|
|
|
r"?[fr, to] <- [[1,2], [2,3]] :rm friends {fr, to}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let ret = db
|
|
|
|
|
.export_relations(["friends", "friends.rev"].into_iter())
|
|
|
|
|
.unwrap();
|
|
|
|
@ -455,22 +455,22 @@ fn test_callback() {
|
|
|
|
|
":create friends {fr: Int, to: Int => data: Any}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to, data] <- [[1,2,3],[4,5,6]] :put friends {fr, to => data}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to, data] <- [[1,2,4],[4,7,6]] :put friends {fr, to => data}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to] <- [[1,9],[4,5]] :rm friends {fr, to}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::thread::sleep(Duration::from_secs_f64(0.01));
|
|
|
|
|
while let Ok(d) = receiver.try_recv() {
|
|
|
|
|
collected.push(d);
|
|
|
|
@ -502,12 +502,12 @@ fn test_update() {
|
|
|
|
|
":create friends {fr: Int, to: Int => a: Any, b: Any, c: Any}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
"?[fr, to, a, b, c] <- [[1,2,3,4,5]] :put friends {fr, to => a, b, c}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let res = db
|
|
|
|
|
.run_script(
|
|
|
|
|
"?[fr, to, a, b, c] := *friends{fr, to, a, b, c}",
|
|
|
|
@ -520,7 +520,7 @@ fn test_update() {
|
|
|
|
|
"?[fr, to, b] <- [[1, 2, 100]] :update friends {fr, to => b}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let res = db
|
|
|
|
|
.run_script(
|
|
|
|
|
"?[fr, to, a, b, c] := *friends{fr, to, a, b, c}",
|
|
|
|
@ -538,13 +538,13 @@ fn test_index() {
|
|
|
|
|
":create friends {fr: Int, to: Int => data: Any}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to, data] <- [[1,2,3],[4,5,6]] :put friends {fr, to, data}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
assert!(db
|
|
|
|
|
.run_script("::index create friends:rev {to, no}", Default::default())
|
|
|
|
@ -556,12 +556,12 @@ fn test_index() {
|
|
|
|
|
r"?[fr, to, data] <- [[1,2,5],[6,5,7]] :put friends {fr, to => data}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to] <- [[4,5]] :rm friends {fr, to}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let rels_data = db
|
|
|
|
|
.export_relations(["friends", "friends:rev"].into_iter())
|
|
|
|
@ -629,7 +629,7 @@ fn test_json_objects() {
|
|
|
|
|
}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
@ -690,13 +690,13 @@ fn test_index_short() {
|
|
|
|
|
":create friends {fr: Int, to: Int => data: Any}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to, data] <- [[1,2,3],[4,5,6]] :put friends {fr, to => data}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
db.run_script("::index create friends:rev {to}", Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
@ -705,12 +705,12 @@ fn test_index_short() {
|
|
|
|
|
r"?[fr, to, data] <- [[1,2,5],[6,5,7]] :put friends {fr, to => data}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[fr, to] <- [[4,5]] :rm friends {fr, to}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let rels_data = db
|
|
|
|
|
.export_relations(["friends", "friends:rev"].into_iter())
|
|
|
|
@ -806,7 +806,7 @@ fn test_vec_types() {
|
|
|
|
|
"?[k, v] <- [['k', [1,2,3,4,5,6,7,8]]] :put a {k => v}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let res = db
|
|
|
|
|
.run_script("?[k, v] := *a{k, v}", Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
@ -851,7 +851,7 @@ fn test_vec_index() {
|
|
|
|
|
",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"
|
|
|
|
|
::hnsw create a:vec {
|
|
|
|
@ -867,7 +867,7 @@ fn test_vec_index() {
|
|
|
|
|
}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"
|
|
|
|
|
?[k, v] <- [
|
|
|
|
@ -882,7 +882,7 @@ fn test_vec_index() {
|
|
|
|
|
",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
println!("all links");
|
|
|
|
|
for (_, nrows) in db.export_relations(["a:vec"].iter()).unwrap() {
|
|
|
|
@ -917,7 +917,7 @@ fn test_fts_indexing() {
|
|
|
|
|
r"?[k, v] <- [['a', 'hello world!'], ['b', 'the world is round']] :put a {k => v}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"::fts create a:fts {
|
|
|
|
|
extractor: v,
|
|
|
|
@ -926,7 +926,7 @@ fn test_fts_indexing() {
|
|
|
|
|
}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[k, v] <- [
|
|
|
|
|
['b', 'the world is square!'],
|
|
|
|
@ -935,7 +935,7 @@ fn test_fts_indexing() {
|
|
|
|
|
] :put a {k => v}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let res = db
|
|
|
|
|
.run_script(
|
|
|
|
|
r"
|
|
|
|
@ -969,12 +969,12 @@ fn test_lsh_indexing() {
|
|
|
|
|
r"?[k, v] <- [['a', 'hello world!'], ['b', 'the world is round']] :put a {k => v}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"::lsh create a:lsh {extractor: v, tokenizer: Simple, n_gram: 3, target_threshold: 0.3 }",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"?[k, v] <- [
|
|
|
|
|
['b', 'the world is square!'],
|
|
|
|
@ -984,7 +984,7 @@ fn test_lsh_indexing() {
|
|
|
|
|
] :put a {k => v}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let res = db
|
|
|
|
|
.run_script("::columns a:lsh", Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
@ -1043,7 +1043,7 @@ fn test_insertions() {
|
|
|
|
|
r":create a {k => v: <F32; 1536> default rand_vec(1536)}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(r"?[k] <- [[1]] :put a {k}", Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(r"?[k, v] := *a{k, v}", Default::default())
|
|
|
|
@ -1055,7 +1055,7 @@ fn test_insertions() {
|
|
|
|
|
}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(r"?[count(fr_k)] := *a:i{fr_k}", Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(r"?[k] <- [[1]] :put a {k}", Default::default())
|
|
|
|
@ -1064,7 +1064,7 @@ fn test_insertions() {
|
|
|
|
|
r"?[k] := k in int_range(300) :put a {k}",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
let res = db
|
|
|
|
|
.run_script(
|
|
|
|
|
r"?[dist, k] := ~a:i{k | query: v, bind_distance: dist, k:10, ef: 50, filter: k % 2 == 0, radius: 245}, *a{k: 96, v}",
|
|
|
|
@ -1136,7 +1136,7 @@ fn multi_index_vec() {
|
|
|
|
|
"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r#"
|
|
|
|
|
::hnsw create product:semantic{
|
|
|
|
@ -1148,7 +1148,7 @@ fn multi_index_vec() {
|
|
|
|
|
"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r#"
|
|
|
|
|
?[id, name, description, price, name_vec, description_vec] <- [[1, "name", "description", 100, [1], [1]]]
|
|
|
|
@ -1168,23 +1168,54 @@ fn multi_index_vec() {
|
|
|
|
|
#[test]
|
|
|
|
|
fn ensure_not() {
|
|
|
|
|
let db = DbInstance::new("mem", "", "").unwrap();
|
|
|
|
|
db.run_script(r"
|
|
|
|
|
db.run_script(
|
|
|
|
|
r"
|
|
|
|
|
%ignore_error { :create id_alloc{id: Int => next_id: Int, last_id: Int}}
|
|
|
|
|
%ignore_error {
|
|
|
|
|
?[id, next_id, last_id] <- [[0, 1, 1000]];
|
|
|
|
|
:ensure_not id_alloc{id => next_id, last_id}
|
|
|
|
|
}
|
|
|
|
|
", Default::default()).unwrap();
|
|
|
|
|
",
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn insertion() {
|
|
|
|
|
let db = DbInstance::new("mem", "", "").unwrap();
|
|
|
|
|
db.run_script(r":create a {x => y}", Default::default()).unwrap();
|
|
|
|
|
assert!(db.run_script(r"?[x, y] <- [[1, 2]] :insert a {x => y}", Default::default())
|
|
|
|
|
db.run_script(r":create a {x => y}", Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(db
|
|
|
|
|
.run_script(
|
|
|
|
|
r"?[x, y] <- [[1, 2]] :insert a {x => y}",
|
|
|
|
|
Default::default()
|
|
|
|
|
)
|
|
|
|
|
.is_ok());
|
|
|
|
|
assert!(db.run_script(r"?[x, y] <- [[1, 3]] :insert a {x => y}", Default::default())
|
|
|
|
|
assert!(db
|
|
|
|
|
.run_script(
|
|
|
|
|
r"?[x, y] <- [[1, 3]] :insert a {x => y}",
|
|
|
|
|
Default::default()
|
|
|
|
|
)
|
|
|
|
|
.is_err());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn deletion() {
|
|
|
|
|
let db = DbInstance::new("mem", "", "").unwrap();
|
|
|
|
|
db.run_script(r":create a {x => y}", Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(db
|
|
|
|
|
.run_script(r"?[x] <- [[1]] :delete a {x}", Default::default())
|
|
|
|
|
.is_err());
|
|
|
|
|
assert!(db
|
|
|
|
|
.run_script(
|
|
|
|
|
r"?[x, y] <- [[1, 2]] :insert a {x => y}",
|
|
|
|
|
Default::default()
|
|
|
|
|
)
|
|
|
|
|
.is_ok());
|
|
|
|
|
db
|
|
|
|
|
.run_script(r"?[x] <- [[1]] :delete a {x}", Default::default()).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
@ -1198,12 +1229,12 @@ fn parser_corner_case() {
|
|
|
|
|
r#"?[C] := C = true, C inx[C] := C = 1"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(r#"?[k] := k in int_range(300)"#, Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
db.run_script(
|
|
|
|
|
r#"ywcc[a] <- [[1]] noto[A] := ywcc[A] ?[A] := noto[A]"#,
|
|
|
|
|
Default::default(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|