refactor store ops

main
Ziyang Hu 1 year ago
parent a880431726
commit 4c3fb1fdde

@ -13,11 +13,13 @@ query_script_inner_no_bracket = { (option | rule | const_rule | fixed_rule)+ }
imperative_script = {SOI ~ imperative_stmt+ ~ EOI} imperative_script = {SOI ~ imperative_stmt+ ~ EOI}
sys_script = {SOI ~ "::" ~ (list_relations_op | list_relation_op | remove_relations_op | trigger_relation_op | sys_script = {SOI ~ "::" ~ (list_relations_op | list_relation_op | remove_relations_op | trigger_relation_op |
trigger_relation_show_op | rename_relations_op | running_op | kill_op | explain_op | trigger_relation_show_op | rename_relations_op | running_op | kill_op | explain_op |
access_level_op | index_op | vec_idx_op | compact_op | list_fixed_rules) ~ EOI} access_level_op | index_op | vec_idx_op | fts_idx_op | lsh_idx_op | compact_op | list_fixed_rules) ~ EOI}
index_op = {"index" ~ (index_create | index_drop)} index_op = {"index" ~ (index_create | index_drop)}
vec_idx_op = {"hnsw" ~ (index_create_hnsw | index_drop)} vec_idx_op = {"hnsw" ~ (index_create_adv | index_drop)}
fts_idx_op = {"fts" ~ (index_create_adv | index_drop)}
lsh_idx_op = {"lsh" ~ (index_create_adv | index_drop)}
index_create = {"create" ~ compound_ident ~ ":" ~ ident ~ "{" ~ (ident ~ ",")* ~ ident? ~ "}"} index_create = {"create" ~ compound_ident ~ ":" ~ ident ~ "{" ~ (ident ~ ",")* ~ ident? ~ "}"}
index_create_hnsw = {"create" ~ compound_ident ~ ":" ~ ident ~ "{" ~ (index_opt_field ~ ",")* ~ index_opt_field? ~ "}"} index_create_adv = {"create" ~ compound_ident ~ ":" ~ ident ~ "{" ~ (index_opt_field ~ ",")* ~ index_opt_field? ~ "}"}
index_drop = {"drop" ~ compound_ident ~ ":" ~ ident } index_drop = {"drop" ~ compound_ident ~ ":" ~ ident }
compact_op = {"compact"} compact_op = {"compact"}
list_fixed_rules = {"fixed_rules"} list_fixed_rules = {"fixed_rules"}

@ -825,6 +825,7 @@ pub(crate) fn get_op(name: &str) -> Option<&'static Op> {
"regex_replace_all" => &OP_REGEX_REPLACE_ALL, "regex_replace_all" => &OP_REGEX_REPLACE_ALL,
"regex_extract" => &OP_REGEX_EXTRACT, "regex_extract" => &OP_REGEX_EXTRACT,
"regex_extract_first" => &OP_REGEX_EXTRACT_FIRST, "regex_extract_first" => &OP_REGEX_EXTRACT_FIRST,
"t2s" => &OP_T2S,
"encode_base64" => &OP_ENCODE_BASE64, "encode_base64" => &OP_ENCODE_BASE64,
"decode_base64" => &OP_DECODE_BASE64, "decode_base64" => &OP_DECODE_BASE64,
"first" => &OP_FIRST, "first" => &OP_FIRST,

@ -137,7 +137,7 @@ fn get_json_path<'a>(
.get_int() .get_int()
.ok_or_else(|| miette!("json path must be a string or a number"))? .ok_or_else(|| miette!("json path must be a string or a number"))?
as usize; as usize;
if arr.len() >= key + 1 { if arr.len() <= key + 1 {
arr.resize_with(key + 1, || JsonValue::Null); arr.resize_with(key + 1, || JsonValue::Null);
} }
@ -1445,6 +1445,14 @@ pub(crate) fn op_regex_extract_first(args: &[DataValue]) -> Result<DataValue> {
} }
} }
define_op!(OP_T2S, 1, false);
fn op_t2s(args: &[DataValue]) -> Result<DataValue> {
Ok(match &args[0] {
DataValue::Str(s) => DataValue::Str(fast2s::convert(s).into()),
d => d.clone(),
})
}
define_op!(OP_IS_NULL, 1, false); define_op!(OP_IS_NULL, 1, false);
pub(crate) fn op_is_null(args: &[DataValue]) -> Result<DataValue> { pub(crate) fn op_is_null(args: &[DataValue]) -> Result<DataValue> {
Ok(DataValue::from(matches!(args[0], DataValue::Null))) Ok(DataValue::from(matches!(args[0], DataValue::Null)))
@ -1753,7 +1761,7 @@ fn get_impl(args: &[DataValue]) -> Result<DataValue> {
.get_int() .get_int()
.ok_or_else(|| miette!("second argument to 'get' mut be an integer"))?; .ok_or_else(|| miette!("second argument to 'get' mut be an integer"))?;
let idx = get_index(n, l.len())?; let idx = get_index(n, l.len())?;
return Ok(l[idx].clone()); Ok(l[idx].clone())
} }
DataValue::Json(json) => { DataValue::Json(json) => {
let res = match &args[1] { let res = match &args[1] {
@ -1770,8 +1778,7 @@ fn get_impl(args: &[DataValue]) -> Result<DataValue> {
.clone() .clone()
} }
DataValue::List(l) => { DataValue::List(l) => {
let mut v = json.clone(); get_json_path_immutable(json, l)?.clone()
get_json_path_immutable(&mut v, l)?.clone()
} }
_ => bail!("second argument to 'get' mut be a string or integer"), _ => bail!("second argument to 'get' mut be a string or integer"),
}; };

@ -263,7 +263,7 @@ impl TokenizerCache {
hashed_cache.insert(hash.as_ref().to_vec(), analyzer.clone()); hashed_cache.insert(hash.as_ref().to_vec(), analyzer.clone());
let mut idx_cache = self.named_cache.write().unwrap(); let mut idx_cache = self.named_cache.write().unwrap();
idx_cache.insert(tokenizer_name.into(), analyzer.clone()); idx_cache.insert(tokenizer_name.into(), analyzer.clone());
return Ok(analyzer); Ok(analyzer)
} }
} }
} }

@ -10,7 +10,7 @@ use std::collections::BTreeMap;
use std::sync::Arc; use std::sync::Arc;
use itertools::Itertools; use itertools::Itertools;
use miette::{ensure, miette, Diagnostic, Result, bail}; use miette::{bail, ensure, miette, Diagnostic, Result};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use thiserror::Error; use thiserror::Error;
@ -54,7 +54,7 @@ pub(crate) struct HnswIndexConfig {
pub(crate) m_neighbours: usize, pub(crate) m_neighbours: usize,
pub(crate) index_filter: Option<String>, pub(crate) index_filter: Option<String>,
pub(crate) extend_candidates: bool, pub(crate) extend_candidates: bool,
pub(crate) keep_pruned_connections: bool pub(crate) keep_pruned_connections: bool,
} }
#[derive( #[derive(
@ -175,10 +175,16 @@ pub(crate) fn parse_sys(
} }
SysOp::SetTriggers(rel, puts, rms, replaces) SysOp::SetTriggers(rel, puts, rms, replaces)
} }
Rule::fts_idx_op => {
todo!()
}
Rule::lsh_idx_op => {
todo!()
}
Rule::vec_idx_op => { Rule::vec_idx_op => {
let inner = inner.into_inner().next().unwrap(); let inner = inner.into_inner().next().unwrap();
match inner.as_rule() { match inner.as_rule() {
Rule::index_create_hnsw => { Rule::index_create_adv => {
let mut inner = inner.into_inner(); let mut inner = inner.into_inner();
let rel = inner.next().unwrap(); let rel = inner.next().unwrap();
let name = inner.next().unwrap(); let name = inner.next().unwrap();

File diff suppressed because it is too large Load Diff

@ -151,7 +151,7 @@ impl VectorCache {
impl<'a> SessionTx<'a> { impl<'a> SessionTx<'a> {
fn hnsw_put_vector( fn hnsw_put_vector(
&mut self, &mut self,
tuple: &Tuple, tuple: &[DataValue],
q: &Vector, q: &Vector,
idx: usize, idx: usize,
subidx: i32, subidx: i32,
@ -685,7 +685,7 @@ impl<'a> SessionTx<'a> {
idx_table: &RelationHandle, idx_table: &RelationHandle,
filter: Option<&Vec<Bytecode>>, filter: Option<&Vec<Bytecode>>,
stack: &mut Vec<DataValue>, stack: &mut Vec<DataValue>,
tuple: &Tuple, tuple: &[DataValue],
) -> Result<bool> { ) -> Result<bool> {
if let Some(code) = filter { if let Some(code) = filter {
if !eval_bytecode_pred(code, tuple, stack, Default::default())? { if !eval_bytecode_pred(code, tuple, stack, Default::default())? {

Loading…
Cancel
Save