|
|
|
@ -41,7 +41,7 @@ use crate::data::value::{DataValue, ValidityTs, LARGEST_UTF_CHAR};
|
|
|
|
|
use crate::fixed_rule::DEFAULT_FIXED_RULES;
|
|
|
|
|
use crate::fts::TokenizerCache;
|
|
|
|
|
use crate::parse::sys::SysOp;
|
|
|
|
|
use crate::parse::{parse_script, CozoScript, SourceSpan};
|
|
|
|
|
use crate::parse::{parse_expressions, parse_script, CozoScript, SourceSpan};
|
|
|
|
|
use crate::query::compile::{CompiledProgram, CompiledRule, CompiledRuleSet};
|
|
|
|
|
use crate::query::ra::{
|
|
|
|
|
FilteredRA, FtsSearchRA, HnswSearchRA, InnerJoin, LshSearchRA, NegJoin, RelAlgebra, ReorderRA,
|
|
|
|
@ -51,11 +51,13 @@ use crate::query::ra::{
|
|
|
|
|
use crate::runtime::callback::{
|
|
|
|
|
CallbackCollector, CallbackDeclaration, CallbackOp, EventCallbackRegistry,
|
|
|
|
|
};
|
|
|
|
|
use crate::runtime::relation::{extend_tuple_from_v, AccessLevel, InsufficientAccessLevel, RelationHandle, RelationId};
|
|
|
|
|
use crate::runtime::relation::{
|
|
|
|
|
extend_tuple_from_v, AccessLevel, InsufficientAccessLevel, RelationHandle, RelationId,
|
|
|
|
|
};
|
|
|
|
|
use crate::runtime::transact::SessionTx;
|
|
|
|
|
use crate::storage::temp::TempStorage;
|
|
|
|
|
use crate::storage::{Storage, StoreTx};
|
|
|
|
|
use crate::{decode_tuple_from_kv, FixedRule};
|
|
|
|
|
use crate::{decode_tuple_from_kv, FixedRule, Symbol};
|
|
|
|
|
|
|
|
|
|
pub(crate) struct RunningQueryHandle {
|
|
|
|
|
pub(crate) started_at: f64,
|
|
|
|
@ -377,7 +379,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
|
pub fn export_relations<I, T>(&'s self, relations: I) -> Result<BTreeMap<String, NamedRows>>
|
|
|
|
|
where
|
|
|
|
|
T: AsRef<str>,
|
|
|
|
|
I: Iterator<Item=T>,
|
|
|
|
|
I: Iterator<Item = T>,
|
|
|
|
|
{
|
|
|
|
|
let tx = self.transact()?;
|
|
|
|
|
let mut ret: BTreeMap<String, NamedRows> = BTreeMap::new();
|
|
|
|
@ -757,7 +759,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
|
ret.is_some()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn obtain_relation_locks<'a, T: Iterator<Item=&'a SmartString<LazyCompact>>>(
|
|
|
|
|
pub(crate) fn obtain_relation_locks<'a, T: Iterator<Item = &'a SmartString<LazyCompact>>>(
|
|
|
|
|
&'s self,
|
|
|
|
|
rels: T,
|
|
|
|
|
) -> Vec<Arc<ShardedLock<()>>> {
|
|
|
|
@ -1493,7 +1495,8 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
|
)
|
|
|
|
|
.wrap_err_with(|| format!("when executing against relation '{}'", meta.name))?;
|
|
|
|
|
clean_ups.extend(to_clear);
|
|
|
|
|
let returned_rows = tx.get_returning_rows(callback_collector, &meta.name, returning)?;
|
|
|
|
|
let returned_rows =
|
|
|
|
|
tx.get_returning_rows(callback_collector, &meta.name, returning)?;
|
|
|
|
|
Ok((returned_rows, clean_ups))
|
|
|
|
|
} else {
|
|
|
|
|
// not sorting outputs
|
|
|
|
@ -1548,7 +1551,8 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
|
)
|
|
|
|
|
.wrap_err_with(|| format!("when executing against relation '{}'", meta.name))?;
|
|
|
|
|
clean_ups.extend(to_clear);
|
|
|
|
|
let returned_rows = tx.get_returning_rows(callback_collector, &meta.name, returning)?;
|
|
|
|
|
let returned_rows =
|
|
|
|
|
tx.get_returning_rows(callback_collector, &meta.name, returning)?;
|
|
|
|
|
|
|
|
|
|
Ok((returned_rows, clean_ups))
|
|
|
|
|
} else {
|
|
|
|
@ -1756,6 +1760,41 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Evaluate a string expression in the context of a set of parameters and variables
|
|
|
|
|
pub fn evaluate_expressions(
|
|
|
|
|
src: &str,
|
|
|
|
|
params: &BTreeMap<String, DataValue>,
|
|
|
|
|
vars: &BTreeMap<String, DataValue>,
|
|
|
|
|
) -> Result<Vec<DataValue>> {
|
|
|
|
|
_evaluate_expressions(src, params, vars).map_err(|err| {
|
|
|
|
|
if err.source().is_none() {
|
|
|
|
|
err.with_source_code(format!("{src} "))
|
|
|
|
|
} else {
|
|
|
|
|
err
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _evaluate_expressions(
|
|
|
|
|
src: &str,
|
|
|
|
|
params: &BTreeMap<String, DataValue>,
|
|
|
|
|
vars: &BTreeMap<String, DataValue>,
|
|
|
|
|
) -> Result<Vec<DataValue>> {
|
|
|
|
|
let mut exprs = parse_expressions(src, params)?;
|
|
|
|
|
let mut ctx = vec![];
|
|
|
|
|
let mut binding_map = BTreeMap::new();
|
|
|
|
|
for (i, (k, v)) in vars.iter().enumerate() {
|
|
|
|
|
ctx.push(v.clone());
|
|
|
|
|
binding_map.insert(Symbol::new(k, Default::default()), i);
|
|
|
|
|
}
|
|
|
|
|
let mut ret = vec![];
|
|
|
|
|
for expr in exprs.iter_mut() {
|
|
|
|
|
expr.fill_binding_indices(&binding_map)?;
|
|
|
|
|
ret.push(expr.eval(&ctx)?);
|
|
|
|
|
}
|
|
|
|
|
Ok(ret)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Used for user-initiated termination of running queries
|
|
|
|
|
#[derive(Clone, Default)]
|
|
|
|
|
pub struct Poison(pub(crate) Arc<AtomicBool>);
|
|
|
|
|