Do not use JSON for intermediate results

main
Ziyang Hu 2 years ago
parent 14c9813fd4
commit ba333c3883

@ -447,7 +447,7 @@ impl Expr {
if let Some(symb) = args[0].get_binding() {
if let Some(val) = args[1].get_const() {
if target == symb {
let s = val.get_string().ok_or_else(|| {
let s = val.get_str().ok_or_else(|| {
#[derive(Debug, Error, Diagnostic)]
#[error("Cannot prefix scan with {0:?}")]
#[diagnostic(code(eval::bad_string_range_scan))]

@ -94,7 +94,7 @@ define_op!(OP_IS_IN, 2, false);
pub(crate) fn op_is_in(args: &[DataValue]) -> Result<DataValue> {
let left = &args[0];
let right = args[1]
.get_list()
.get_slice()
.ok_or_else(|| miette!("right hand side of 'is_in' must be a list"))?;
Ok(DataValue::Bool(right.contains(left)))
}
@ -1005,7 +1005,7 @@ pub(crate) fn op_unicode_normalize(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_SORTED, 1, false);
pub(crate) fn op_sorted(args: &[DataValue]) -> Result<DataValue> {
let mut arg = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("'sort' requires lists"))?
.to_vec();
arg.sort();
@ -1015,7 +1015,7 @@ pub(crate) fn op_sorted(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_REVERSE, 1, false);
pub(crate) fn op_reverse(args: &[DataValue]) -> Result<DataValue> {
let mut arg = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("'reverse' requires lists"))?
.to_vec();
arg.reverse();
@ -1071,7 +1071,7 @@ pub(crate) fn op_rad_to_deg(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_FIRST, 1, false);
pub(crate) fn op_first(args: &[DataValue]) -> Result<DataValue> {
Ok(args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("'first' requires lists"))?
.first()
.cloned()
@ -1081,7 +1081,7 @@ pub(crate) fn op_first(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_LAST, 1, false);
pub(crate) fn op_last(args: &[DataValue]) -> Result<DataValue> {
Ok(args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("'last' requires lists"))?
.last()
.cloned()
@ -1091,7 +1091,7 @@ pub(crate) fn op_last(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_CHUNKS, 2, false);
pub(crate) fn op_chunks(args: &[DataValue]) -> Result<DataValue> {
let arg = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("first argument of 'chunks' must be a list"))?;
let n = args[1]
.get_int()
@ -1107,7 +1107,7 @@ pub(crate) fn op_chunks(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_CHUNKS_EXACT, 2, false);
pub(crate) fn op_chunks_exact(args: &[DataValue]) -> Result<DataValue> {
let arg = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("first argument of 'chunks_exact' must be a list"))?;
let n = args[1]
.get_int()
@ -1123,7 +1123,7 @@ pub(crate) fn op_chunks_exact(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_WINDOWS, 2, false);
pub(crate) fn op_windows(args: &[DataValue]) -> Result<DataValue> {
let arg = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("first argument of 'windows' must be a list"))?;
let n = args[1]
.get_int()
@ -1155,7 +1155,7 @@ fn get_index(mut i: i64, total: usize) -> Result<usize> {
define_op!(OP_GET, 2, false);
pub(crate) fn op_get(args: &[DataValue]) -> Result<DataValue> {
let l = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("first argument to 'get' mut be a list"))?;
let n = args[1]
.get_int()
@ -1167,7 +1167,7 @@ pub(crate) fn op_get(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_MAYBE_GET, 2, false);
pub(crate) fn op_maybe_get(args: &[DataValue]) -> Result<DataValue> {
let l = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("first argument to 'maybe_get' mut be a list"))?;
let n = args[1]
.get_int()
@ -1182,7 +1182,7 @@ pub(crate) fn op_maybe_get(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_SLICE, 3, false);
pub(crate) fn op_slice(args: &[DataValue]) -> Result<DataValue> {
let l = args[0]
.get_list()
.get_slice()
.ok_or_else(|| miette!("first argument to 'slice' mut be a list"))?;
let m = args[1]
.get_int()
@ -1199,7 +1199,7 @@ define_op!(OP_CHARS, 1, false);
pub(crate) fn op_chars(args: &[DataValue]) -> Result<DataValue> {
Ok(DataValue::List(
args[0]
.get_string()
.get_str()
.ok_or_else(|| miette!("'chars' requires strings"))?
.chars()
.map(|c| {
@ -1536,7 +1536,7 @@ pub(crate) fn op_format_timestamp(args: &[DataValue]) -> Result<DataValue> {
};
match args.get(1) {
Some(tz_v) => {
let tz_s = tz_v.get_string().ok_or_else(|| {
let tz_s = tz_v.get_str().ok_or_else(|| {
miette!("'format_timestamp' timezone specification requires a string")
})?;
let tz = chrono_tz::Tz::from_str(tz_s)
@ -1555,7 +1555,7 @@ pub(crate) fn op_format_timestamp(args: &[DataValue]) -> Result<DataValue> {
define_op!(OP_PARSE_TIMESTAMP, 1, false);
pub(crate) fn op_parse_timestamp(args: &[DataValue]) -> Result<DataValue> {
let s = args[0]
.get_string()
.get_str()
.ok_or_else(|| miette!("'parse_timestamp' expects a string"))?;
let dt = DateTime::parse_from_rfc3339(s).map_err(|_| miette!("bad datetime: {}", s))?;
let st: SystemTime = dt.into();

@ -9,7 +9,6 @@
use approx::AbsDiffEq;
use num_traits::FloatConst;
use regex::Regex;
use serde_json::json;
use smartstring::SmartString;
use crate::data::functions::*;
@ -1446,9 +1445,9 @@ fn test_to_bool() {
fn test_coalesce() {
let db = new_cozo_mem().unwrap();
let res = db.run_script("?[a] := a = null ~ 1 ~ 2", Default::default()).unwrap().rows;
assert_eq!(res[0][0], json!(1));
assert_eq!(res[0][0], DataValue::from(1));
let res = db.run_script("?[a] := a = null ~ null ~ null", Default::default()).unwrap().rows;
assert_eq!(res[0][0], json!(null));
assert_eq!(res[0][0], DataValue::Null);
let res = db.run_script("?[a] := a = 2 ~ null ~ 1", Default::default()).unwrap().rows;
assert_eq!(res[0][0], json!(2));
assert_eq!(res[0][0], DataValue::from(2));
}

@ -7,6 +7,7 @@
*
*/
use crate::data::value::DataValue;
use crate::DbInstance;
use serde_json::json;
use std::env;
@ -124,7 +125,7 @@ fn test_validity() {
.unwrap()
.rows;
assert_eq!(res.len(), 1);
assert_eq!(res[0][2].as_i64().unwrap(), 2);
assert_eq!(res[0][2].get_int().unwrap(), 2);
let res = db
.run_script(
@ -197,7 +198,7 @@ fn test_validity() {
.unwrap()
.rows;
assert_eq!(res.len(), 1);
assert_eq!(res[0][2], json!(null));
assert_eq!(res[0][2], DataValue::Null);
let res = db
.run_script(

@ -286,19 +286,22 @@ impl Display for DataValue {
}
impl DataValue {
pub(crate) fn get_list(&self) -> Option<&[DataValue]> {
/// Returns a slice of DataValues if this one is a List
pub fn get_slice(&self) -> Option<&[DataValue]> {
match self {
DataValue::List(l) => Some(l),
_ => None,
}
}
pub(crate) fn get_string(&self) -> Option<&str> {
/// Returns the raw str if this one is a Str
pub fn get_str(&self) -> Option<&str> {
match self {
DataValue::Str(s) => Some(s),
_ => None,
}
}
pub(crate) fn get_int(&self) -> Option<i64> {
/// Returns int if this one is an int
pub fn get_int(&self) -> Option<i64> {
match self {
DataValue::Num(n) => n.get_int(),
_ => None,
@ -312,19 +315,20 @@ impl DataValue {
_ => None,
}
}
pub(crate) fn get_float(&self) -> Option<f64> {
/// Returns float if this one is.
pub fn get_float(&self) -> Option<f64> {
match self {
DataValue::Num(n) => Some(n.get_float()),
_ => None,
}
}
pub(crate) fn get_bool(&self) -> Option<bool> {
pub fn get_bool(&self) -> Option<bool> {
match self {
DataValue::Bool(b) => Some(*b),
_ => None,
}
}
pub(crate) fn uuid(uuid: uuid::Uuid) -> Self {
pub(crate) fn uuid(uuid: Uuid) -> Self {
Self::Uuid(UuidWrapper(uuid))
}
pub(crate) fn get_uuid(&self) -> Option<Uuid> {

@ -123,7 +123,7 @@ impl FixedRule for ShortestPathBFS {
#[cfg(test)]
mod tests {
use serde_json::json;
use crate::data::value::DataValue;
use crate::new_cozo_mem;
@ -150,7 +150,7 @@ mod tests {
.unwrap()
.rows;
println!("{:?}", res);
assert_eq!(res[0][2].as_array().unwrap().len(), 3);
assert_eq!(res[0][2].get_slice().unwrap().len(), 3);
let res = db
.run_script(
r#"
@ -170,7 +170,7 @@ mod tests {
)
.unwrap()
.rows;
assert_eq!(res[0][2], json!(null));
assert_eq!(res[0][2], DataValue::Null);
println!("{:?}", res);
}
}

@ -31,9 +31,9 @@ impl FixedRule for Constant {
_poison: Poison,
) -> Result<()> {
let data = payload.expr_option("data", None).unwrap();
let data = data.get_const().unwrap().get_list().unwrap();
let data = data.get_const().unwrap().get_slice().unwrap();
for row in data {
let tuple = row.get_list().unwrap().into();
let tuple = row.get_slice().unwrap().into();
out.put(tuple)
}
Ok(())
@ -50,7 +50,7 @@ impl FixedRule for Constant {
.unwrap()
.get_const()
.unwrap()
.get_list()
.get_slice()
.unwrap();
Ok(if data.is_empty() {
match rule_head.len() {
@ -67,7 +67,7 @@ impl FixedRule for Constant {
i => i,
}
} else {
data.first().unwrap().get_list().unwrap().len()
data.first().unwrap().get_slice().unwrap().len()
})
}

@ -61,8 +61,8 @@ impl FixedRule for CsvReader {
};
let types_opts = typing.coerce(types_opts, TERMINAL_VALIDITY.timestamp)?;
let mut types = vec![];
for type_str in types_opts.get_list().unwrap() {
let type_str = type_str.get_string().unwrap();
for type_str in types_opts.get_slice().unwrap() {
let type_str = type_str.get_str().unwrap();
let typ = parse_type(type_str).map_err(|e| WrongFixedRuleOptionError {
name: "types".to_string(),
span: payload.span(),
@ -203,7 +203,7 @@ impl FixedRule for CsvReader {
rule_name: "CsvReader".to_string(),
})?;
let columns = columns.clone().eval_to_const()?;
if let Some(l) = columns.get_list() {
if let Some(l) = columns.get_slice() {
return Ok(l.len() + with_row_num);
}
bail!(CannotDetermineArity(

@ -125,7 +125,7 @@ impl UnificationRA {
.iter(tx, delta_rule, stores)?
.map_ok(move |tuple| -> Result<Vec<Tuple>> {
let result_list = self.expr.eval(&tuple)?;
let result_list = result_list.get_list().ok_or_else(|| {
let result_list = result_list.get_slice().ok_or_else(|| {
#[derive(Debug, Error, Diagnostic)]
#[error("Invalid spread unification")]
#[diagnostic(code(eval::invalid_spread_unif))]
@ -2038,7 +2038,7 @@ impl<'a> Iterator for CachedMaterializedIterator<'a> {
#[cfg(test)]
mod tests {
use serde_json::json;
use crate::data::value::DataValue;
use crate::new_cozo_mem;
@ -2055,6 +2055,6 @@ mod tests {
)
.unwrap()
.rows;
assert_eq!(res, vec![vec![json!(1)], vec![json!(2)]])
assert_eq!(res, vec![vec![DataValue::from(1)], vec![DataValue::from(2)]])
}
}

@ -111,15 +111,24 @@ pub struct NamedRows {
/// The headers
pub headers: Vec<String>,
/// The rows
pub rows: Vec<Vec<JsonValue>>,
pub rows: Vec<Tuple>,
}
impl NamedRows {
/// Convert to a JSON object
pub fn into_json(self) -> JsonValue {
let rows = self
.rows
.into_iter()
.map(|row| {
row.into_iter()
.map(|val| JsonValue::from(val))
.collect::<JsonValue>()
})
.collect::<JsonValue>();
json!({
"headers": self.headers,
"rows": self.rows
"rows": rows
})
}
}
@ -208,8 +217,7 @@ impl<'s, S: Storage<'s>> Db<S> {
for data in tx.store_tx.range_scan(&start, &end) {
let (k, v) = data?;
let tuple = decode_tuple_from_kv(&k, &v);
let row = tuple.into_iter().map(JsonValue::from).collect_vec();
rows.push(row);
rows.push(tuple);
}
let headers = cols.iter().map(|col| col.to_string()).collect_vec();
ret.insert(rel.to_string(), NamedRows { headers, rows });
@ -304,7 +312,7 @@ impl<'s, S: Storage<'s>> Db<S> {
let v = row
.get(*i)
.ok_or_else(|| miette!("row too short: {:?}", row))?;
col.typing.coerce(DataValue::from(v), cur_vld)
col.typing.coerce(v.clone(), cur_vld)
})
.try_collect()?;
let k_store = handle.encode_key_for_store(&keys, Default::default())?;
@ -317,7 +325,7 @@ impl<'s, S: Storage<'s>> Db<S> {
let v = row
.get(*i)
.ok_or_else(|| miette!("row too short: {:?}", row))?;
col.typing.coerce(DataValue::from(v), cur_vld)
col.typing.coerce(v.clone(), cur_vld)
})
.try_collect()?;
let v_store = handle.encode_val_only_for_store(&vals, Default::default())?;
@ -734,7 +742,7 @@ impl<'s, S: Storage<'s>> Db<S> {
.map(|m| {
headers
.iter()
.map(|i| m.get(i).unwrap_or(&JsonValue::Null).clone())
.map(|i| DataValue::from(m.get(i).unwrap_or(&JsonValue::Null)))
.collect_vec()
})
.collect_vec();
@ -756,7 +764,7 @@ impl<'s, S: Storage<'s>> Db<S> {
self.compact_relation()?;
Ok(NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!(OK_STR)]],
rows: vec![vec![DataValue::Str(SmartString::from(OK_STR))]],
})
}
SysOp::ListRelations => self.list_relations(),
@ -775,7 +783,7 @@ impl<'s, S: Storage<'s>> Db<S> {
}
Ok(NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!(OK_STR)]],
rows: vec![vec![DataValue::Str(SmartString::from(OK_STR))]],
})
}
SysOp::ListRelation(rs) => self.list_relation(&rs),
@ -787,7 +795,7 @@ impl<'s, S: Storage<'s>> Db<S> {
tx.commit_tx()?;
Ok(NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!(OK_STR)]],
rows: vec![vec![DataValue::Str(SmartString::from(OK_STR))]],
})
}
SysOp::ListRunning => self.list_running(),
@ -796,13 +804,13 @@ impl<'s, S: Storage<'s>> Db<S> {
Ok(match queries.get(&id) {
None => NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!("NOT_FOUND")]],
rows: vec![vec![DataValue::Str(SmartString::from("NOT_FOUND"))]],
},
Some(handle) => {
handle.poison.0.store(true, Ordering::Relaxed);
NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!("KILLING")]],
rows: vec![vec![DataValue::Str(SmartString::from("KILLING"))]],
}
}
})
@ -820,6 +828,14 @@ impl<'s, S: Storage<'s>> Db<S> {
for (i, trigger) in rel.replace_triggers.iter().enumerate() {
rows.push(vec![json!("replace"), json!(i), json!(trigger)])
}
let rows = rows
.into_iter()
.map(|row| {
row.into_iter()
.map(|val| DataValue::from(val))
.collect_vec()
})
.collect_vec();
tx.commit_tx()?;
Ok(NamedRows {
headers: vec!["type".to_string(), "idx".to_string(), "trigger".to_string()],
@ -832,7 +848,7 @@ impl<'s, S: Storage<'s>> Db<S> {
tx.commit_tx()?;
Ok(NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!(OK_STR)]],
rows: vec![vec![DataValue::Str(SmartString::from(OK_STR))]],
})
}
SysOp::SetAccessLevel(names, level) => {
@ -843,7 +859,7 @@ impl<'s, S: Storage<'s>> Db<S> {
tx.commit_tx()?;
Ok(NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!(OK_STR)]],
rows: vec![vec![DataValue::Str(SmartString::from(OK_STR))]],
})
}
}
@ -1002,17 +1018,13 @@ impl<'s, S: Storage<'s>> Db<S> {
Ok((
NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!(OK_STR)]],
rows: vec![vec![DataValue::Str(SmartString::from(OK_STR))]],
},
clean_ups,
))
} else {
// not sorting outputs
let rows: Vec<Vec<JsonValue>> = sorted_iter
.map(|tuple| -> Vec<JsonValue> {
tuple.into_iter().map(JsonValue::from).collect()
})
.collect_vec();
let rows: Vec<Tuple> = sorted_iter.collect_vec();
Ok((
NamedRows {
headers: entry_head_or_default
@ -1058,16 +1070,12 @@ impl<'s, S: Storage<'s>> Db<S> {
Ok((
NamedRows {
headers: vec![STATUS_STR.to_string()],
rows: vec![vec![json!(OK_STR)]],
rows: vec![vec![DataValue::Str(SmartString::from(OK_STR))]],
},
clean_ups,
))
} else {
let rows: Vec<Vec<JsonValue>> = scan
.map(|tuple| -> Vec<JsonValue> {
tuple.into_iter().map(JsonValue::from).collect()
})
.collect_vec();
let rows: Vec<Tuple> = scan.collect_vec();
Ok((
NamedRows {
@ -1088,7 +1096,12 @@ impl<'s, S: Storage<'s>> Db<S> {
.lock()
.unwrap()
.iter()
.map(|(k, v)| vec![json!(k), json!(format!("{:?}", v.started_at))])
.map(|(k, v)| {
vec![
DataValue::from(*k as i64),
DataValue::Str(SmartString::from(format!("{:?}", v.started_at))),
]
})
.collect_vec();
Ok(NamedRows {
headers: vec!["id".to_string(), "started_at".to_string()],
@ -1121,6 +1134,14 @@ impl<'s, S: Storage<'s>> Db<S> {
idx += 1;
}
tx.commit_tx()?;
let rows = rows
.into_iter()
.map(|row| {
row.into_iter()
.map(|val| DataValue::from(val))
.collect_vec()
})
.collect_vec();
Ok(NamedRows {
headers: vec![
"column".to_string(),
@ -1162,6 +1183,14 @@ impl<'s, S: Storage<'s>> Db<S> {
json!(meta.replace_triggers.len()),
]);
}
let rows = rows
.into_iter()
.map(|row| {
row.into_iter()
.map(|val| DataValue::from(val))
.collect_vec()
})
.collect_vec();
Ok(NamedRows {
headers: vec![
"name".to_string(),
@ -1233,11 +1262,7 @@ fn propagate_previous_results(
val: DataValue::List(
v.rows
.iter()
.map(|row| {
DataValue::List(
row.iter().map(DataValue::from).collect_vec(),
)
})
.map(|row| DataValue::List(row.clone()))
.collect_vec(),
),
span: Default::default(),

@ -7,9 +7,10 @@
*
*/
use itertools::Itertools;
use crate::data::value::DataValue;
use log::debug;
use serde_json::json;
use smartstring::SmartString;
use crate::new_cozo_mem;
@ -19,44 +20,32 @@ fn test_limit_offset() {
let res = db
.run_script("?[a] := a in [5,3,1,2,4] :limit 2", Default::default())
.unwrap()
.rows
.into_iter()
.flatten()
.collect_vec();
assert_eq!(json!(res), json!([3, 5]));
.into_json();
assert_eq!(res["rows"], json!([[3], [5]]));
let res = db
.run_script(
"?[a] := a in [5,3,1,2,4] :limit 2 :offset 1",
Default::default(),
)
.unwrap()
.rows
.into_iter()
.flatten()
.collect_vec();
assert_eq!(json!(res), json!([1, 3]));
.into_json();
assert_eq!(res["rows"], json!([[1], [3]]));
let res = db
.run_script(
"?[a] := a in [5,3,1,2,4] :limit 2 :offset 4",
Default::default(),
)
.unwrap()
.rows
.into_iter()
.flatten()
.collect_vec();
assert_eq!(json!(res), json!([4]));
.into_json();
assert_eq!(res["rows"], json!([[4]]));
let res = db
.run_script(
"?[a] := a in [5,3,1,2,4] :limit 2 :offset 5",
Default::default(),
)
.unwrap()
.rows
.into_iter()
.flatten()
.collect_vec();
assert_eq!(json!(res), json!([]));
.into_json();
assert_eq!(res["rows"], json!([]));
}
#[test]
fn test_normal_aggr_empty() {
@ -65,7 +54,7 @@ fn test_normal_aggr_empty() {
.run_script("?[count(a)] := a in []", Default::default())
.unwrap()
.rows;
assert_eq!(res, vec![vec![json!(0)]]);
assert_eq!(res, vec![vec![DataValue::from(0)]]);
}
#[test]
fn test_meet_aggr_empty() {
@ -74,13 +63,13 @@ fn test_meet_aggr_empty() {
.run_script("?[min(a)] := a in []", Default::default())
.unwrap()
.rows;
assert_eq!(res, vec![vec![json!(null)]]);
assert_eq!(res, vec![vec![DataValue::Null]]);
let res = db
.run_script("?[min(a), count(a)] := a in []", Default::default())
.unwrap()
.rows;
assert_eq!(res, vec![vec![json!(null), json!(0)]]);
assert_eq!(res, vec![vec![DataValue::Null, DataValue::from(0)]]);
}
#[test]
fn test_layers() {
@ -99,7 +88,7 @@ fn test_layers() {
)
.unwrap()
.rows;
assert_eq!(res[0][0], json!(21.))
assert_eq!(res[0][0], DataValue::from(21.))
}
#[test]
fn test_conditions() {
@ -130,7 +119,7 @@ fn test_conditions() {
)
.unwrap()
.rows;
assert_eq!(res[0][0], json!(1.1))
assert_eq!(res[0][0], DataValue::from(1.1))
}
#[test]
fn test_classical() {
@ -150,7 +139,7 @@ grandparent[gcld, gp] := parent[gcld, p], parent[p, gp]
.unwrap()
.rows;
println!("{:?}", res);
assert_eq!(res[0][0], json!("jakob"))
assert_eq!(res[0][0], DataValue::Str(SmartString::from("jakob")))
}
#[test]
@ -291,8 +280,8 @@ fn returning_relations() {
Default::default(),
)
.unwrap()
.rows;
assert_eq!(json!(res), json!([[1, 2, 3]]));
.into_json();
assert_eq!(res["rows"], json!([[1, 2, 3]]));
let res = db
.run_script(
@ -313,8 +302,8 @@ fn returning_relations() {
Default::default(),
)
.unwrap()
.rows;
assert_eq!(json!(res), json!([[1], [2]]));
.into_json();
assert_eq!(res["rows"], json!([[1], [2]]));
let res = db.run_script(
r#"
@ -366,8 +355,11 @@ fn test_trigger() {
.export_relations(["friends", "friends.rev"].into_iter())
.unwrap();
let frs = ret.get("friends").unwrap();
assert_eq!(vec![json!(1), json!(2)], frs.rows[0]);
assert_eq!(vec![DataValue::from(1), DataValue::from(2)], frs.rows[0]);
let frs_rev = ret.get("friends.rev").unwrap();
assert_eq!(vec![json!(2), json!(1)], frs_rev.rows[0]);
assert_eq!(
vec![DataValue::from(2), DataValue::from(1)],
frs_rev.rows[0]
);
}

@ -173,11 +173,11 @@ fn dfs() {
.rows;
assert_eq!(rows.len(), 1);
let row = rows.get(0).unwrap();
assert_eq!(row.get(0).unwrap().as_str().unwrap(), "PEK");
assert_eq!(row.get(1).unwrap().as_str().unwrap(), "LHR");
let path = row.get(2).unwrap().as_array().unwrap();
assert_eq!(path.first().unwrap().as_str().unwrap(), "PEK");
assert_eq!(path.last().unwrap().as_str().unwrap(), "LHR");
assert_eq!(row.get(0).unwrap().get_str().unwrap(), "PEK");
assert_eq!(row.get(1).unwrap().get_str().unwrap(), "LHR");
let path = row.get(2).unwrap().get_slice().unwrap();
assert_eq!(path.first().unwrap().get_str().unwrap(), "PEK");
assert_eq!(path.last().unwrap().get_str().unwrap(), "LHR");
dbg!(dfs.elapsed());
}
@ -212,7 +212,7 @@ fn parallel_counts() {
.rows
.remove(0)
.remove(0)
.as_i64()
.get_int()
.unwrap();
assert_eq!(res, 50637 * 5);
}
@ -234,11 +234,11 @@ fn bfs() {
assert_eq!(rows.len(), 1);
let row = rows.get(0).unwrap();
assert_eq!(row.get(0).unwrap().as_str().unwrap(), "PEK");
assert_eq!(row.get(1).unwrap().as_str().unwrap(), "LHR");
let path = row.get(2).unwrap().as_array().unwrap();
assert_eq!(path.first().unwrap().as_str().unwrap(), "PEK");
assert_eq!(path.last().unwrap().as_str().unwrap(), "LHR");
assert_eq!(row.get(0).unwrap().get_str().unwrap(), "PEK");
assert_eq!(row.get(1).unwrap().get_str().unwrap(), "LHR");
let path = row.get(2).unwrap().get_slice().unwrap();
assert_eq!(path.first().unwrap().get_str().unwrap(), "PEK");
assert_eq!(path.last().unwrap().get_str().unwrap(), "LHR");
dbg!(bfs.elapsed());
}
@ -361,10 +361,10 @@ fn starts_with() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
json!([
["USA"],
["USH"],
@ -395,9 +395,12 @@ fn range_check() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[7176.0], [7270.0], [7311.0], [7722.0]]));
assert_eq!(
rows["rows"],
json!([[7176.0], [7270.0], [7311.0], [7722.0]])
);
dbg!(range_check.elapsed());
}
@ -414,10 +417,10 @@ fn no_airports() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
json!([
["Andorra"],
["Liechtenstein"],
@ -442,10 +445,10 @@ fn no_routes_airport() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["AFW"],["APA"],["APK"],["BID"],["BVS"],["BWU"],["CRC"],["CVT"],["EKA"],["GYZ"],
@ -471,10 +474,10 @@ fn runway_distribution() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
json!([
[1, 2429],
[2, 775],
@ -503,10 +506,10 @@ fn most_out_routes() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["FRA",310],["IST",309],["CDG",293],["AMS",283],["MUC",270],["ORD",265],["DFW",253],
@ -536,10 +539,10 @@ fn most_out_routes_again() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["FRA",310],["IST",309],["CDG",293],["AMS",283],["MUC",270],["ORD",265],["DFW",253],
@ -570,10 +573,10 @@ fn most_routes() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["FRA",620],["IST",618],["CDG",587],["AMS",568],["MUC",541],["ORD",529],["DFW",506],
@ -600,9 +603,9 @@ fn airport_with_one_route() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[777]]));
assert_eq!(rows["rows"], json!([[777]]));
dbg!(airport_with_one_route.elapsed());
}
@ -625,10 +628,10 @@ fn single_runway_with_most_routes() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["LGW","London",232],["STN","London",211],["CTU","Chengdu",139],["LIS","Lisbon",139],
@ -657,10 +660,10 @@ fn most_routes_in_canada() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
json!([
["YYZ", "Toronto", 195],
["YUL", "Montreal", 123],
@ -690,10 +693,10 @@ fn uk_count() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
json!([["GB-ENG", 27], ["GB-NIR", 3], ["GB-SCT", 25], ["GB-WLS", 3]])
);
dbg!(uk_count.elapsed());
@ -716,10 +719,10 @@ fn airports_by_country() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["AD",0],["LI",0],["MC",0],["PN",0],["SM",0],["AG",1],["AI",1],["AL",1],["AS",1],["AW",1],
@ -768,10 +771,10 @@ fn n_airports_by_continent() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[["AF",326],["AN",0],["AS",972],["EU",605],["NA",994],["OC",305],["SA",339]]"#
)
@ -794,10 +797,10 @@ fn routes_per_airport() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[["AMS",283],["AUS",98],["DUB",185],["JFK",204],["MEX",116]]"#
)
@ -820,9 +823,9 @@ fn airports_by_route_number() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[106, ["TFS", "YVR"]]]));
assert_eq!(rows["rows"], json!([[106, ["TFS", "YVR"]]]));
dbg!(airports_by_route_number.elapsed());
}
@ -841,10 +844,10 @@ fn out_from_aus() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[8354,[[1,9],[2,24],[3,30],[4,24],[5,5],[6,4],[7,2]]]]"#)
.unwrap()
);
@ -864,9 +867,9 @@ fn const_return() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([["OK", 4]]));
assert_eq!(rows["rows"], json!([["OK", 4]]));
dbg!(const_return.elapsed());
}
@ -890,10 +893,10 @@ fn multi_res() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[3504,6,3204,53,59]]"#).unwrap()
);
dbg!(multi_res.elapsed());
@ -913,10 +916,10 @@ fn multi_unification() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[["AAA",4],["AAE",8],["AAL",17],["AAN",5],["AAQ",11]]"#)
.unwrap()
);
@ -940,9 +943,9 @@ fn num_routes_from_eu_to_us() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[435]]));
assert_eq!(rows["rows"], json!([[435]]));
dbg!(num_routes_from_eu_to_us.elapsed());
}
@ -961,9 +964,9 @@ fn num_airports_in_us_with_routes_from_eu() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[45]]));
assert_eq!(rows["rows"], json!([[45]]));
dbg!(num_airports_in_us_with_routes_from_eu.elapsed());
}
@ -981,10 +984,10 @@ fn num_routes_in_us_airports_from_eu() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["ANC",1],["BNA",1],["CHS",1],["CLE",1],["IND",1],["MCI",1],["BDL",2],["BWI",2],
@ -1015,10 +1018,10 @@ fn routes_from_eu_to_us_starting_with_l() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["LGW","AUS"],["LGW","BOS"],["LGW","DEN"],["LGW","FLL"],["LGW","JFK"],["LGW","LAS"],
@ -1052,10 +1055,10 @@ fn len_of_names_count() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[891.0]]"#).unwrap()
);
dbg!(len_of_names_count.elapsed());
@ -1079,10 +1082,10 @@ fn group_count_by_out() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[[0,29],[1,777],[2,649],[3,357],[4,234],[5,149],[6,140],[7,100],[8,73],[9,64]]"#
)
@ -1108,7 +1111,7 @@ fn mean_group_count() {
.unwrap()
.rows;
let v = rows.get(0).unwrap().get(0).unwrap().as_f64().unwrap();
let v = rows.get(0).unwrap().get(0).unwrap().get_float().unwrap();
assert!(v.abs_diff_eq(&14.451198630136986, 1e-8));
dbg!(mean_group_count.elapsed());
@ -1127,10 +1130,10 @@ fn n_routes_from_london_uk() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[["LCY",51],["LGW",232],["LHR",221],["LTN",130],["STN",211]]"#
)
@ -1154,9 +1157,9 @@ fn reachable_from_london_uk_in_two_hops() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[2353]]));
assert_eq!(rows["rows"], json!([[2353]]));
dbg!(reachable_from_london_uk_in_two_hops.elapsed());
}
@ -1174,10 +1177,10 @@ fn routes_within_england() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["BHX","NCL"],["BRS","NCL"],["EMA","SOU"],["EXT","ISC"],["EXT","MAN"],["EXT","NQY"],
@ -1209,10 +1212,10 @@ fn routes_within_england_time_no_dup() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
[["BHX","NCL"]],[["BRS","NCL"]],[["EMA","SOU"]],[["EXT","ISC"]],[["EXT","MAN"]],[["EXT","NQY"]],
@ -1245,10 +1248,10 @@ fn hard_route_finding() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[[["AUS","YYC","YQT","YTS","YMO","YFA","ZKE","YAT","YPO"]]]"#
)
@ -1273,10 +1276,10 @@ fn na_from_india() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["BOM","EWR"],["BOM","JFK"],["BOM","YYZ"],["DEL","EWR"],["DEL","IAD"],["DEL","JFK"],
@ -1301,10 +1304,10 @@ fn eu_cities_reachable_from_fll() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["Barcelona"],["Copenhagen"],["London"],["Madrid"],["Oslo"],["Paris"],["Stockholm"]
@ -1328,10 +1331,10 @@ fn clt_to_eu_or_sa() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["BCN"],["CDG"],["DUB"],["FCO"],["FRA"],["GIG"],["GRU"],["LHR"],["MAD"],["MUC"]
@ -1356,10 +1359,10 @@ fn london_to_us() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["LGW","AUS"],["LGW","BOS"],["LGW","DEN"],["LGW","FLL"],["LGW","JFK"],["LGW","LAS"],
@ -1391,10 +1394,10 @@ fn tx_to_ny() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["AUS","BUF"],["AUS","EWR"],["AUS","JFK"],["DAL","LGA"],["DFW","BUF"],["DFW","EWR"],
@ -1420,10 +1423,10 @@ fn denver_to_mexico() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["Cancun"],["Cozumel"],["Guadalajara"],["Mexico City"],["Monterrey"],
@ -1449,10 +1452,10 @@ fn three_cities() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["CDG","LCY"],["CDG","LGW"],["CDG","LHR"],["CDG","LTN"],["CDG","MUC"],["LCY","CDG"],
@ -1481,10 +1484,10 @@ fn long_distance_from_lgw() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["Austin",4921.0],["Beijing",5070.0],["Bridgetown",4197.0],["Buenos Aires",6908.0],["Calgary",4380.0],
@ -1516,10 +1519,10 @@ fn long_routes_one_dir() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["AKL",8186.0,"ORD"],["AKL",8818.0,"DXB"],["AKL",9025.0,"DOH"],["ATL",8434.0,"JNB"],
@ -1551,10 +1554,10 @@ fn longest_routes() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["JFK",9526.0,"SIN"],["EWR",9523.0,"SIN"],["AKL",9025.0,"DOH"],["LHR",9009.0,"PER"],
@ -1582,10 +1585,10 @@ fn longest_routes_from_each_airports() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["AAA",968.0,"FAC"],["AAE",1161.0,"ALG"],["AAL",1693.0,"AAR"],["AAN",1613.0,"CAI"],
@ -1611,10 +1614,10 @@ fn total_distance_from_three_cities() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[2739039.0]]"#).unwrap()
);
dbg!(total_distance_from_three_cities.elapsed());
@ -1634,10 +1637,10 @@ fn total_distance_within_three_cities() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[10282.0]]"#).unwrap()
);
dbg!(total_distance_within_three_cities.elapsed());
@ -1656,10 +1659,10 @@ fn specific_distance() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[748.0]]"#).unwrap()
);
dbg!(specific_distance.elapsed());
@ -1680,10 +1683,10 @@ fn n_routes_between() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[597]]"#).unwrap()
);
dbg!(n_routes_between.elapsed());
@ -1706,10 +1709,10 @@ fn one_stop_distance() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["DTW",4893.0],["YYZ",4901.0],["ORD",4912.0],["PIT",4916.0],["BNA",4923.0],
@ -1735,10 +1738,10 @@ fn airport_most_routes() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
["FRA",310],["IST",309],["CDG",293],["AMS",283],["MUC",270],["ORD",265],["DFW",253],
@ -1762,10 +1765,10 @@ fn north_of_77() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[["Longyearbyen",78.0],["Qaanaaq",77.0]]"#).unwrap()
);
dbg!(north_of_77.elapsed());
@ -1784,10 +1787,10 @@ fn greenwich_meridian() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[["CDT"], ["LCY"], ["LDE"], ["LEH"]]"#).unwrap()
);
dbg!(greenwich_meridian.elapsed());
@ -1808,10 +1811,10 @@ fn box_around_heathrow() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[["LCY"], ["LGW"], ["LHR"], ["LTN"], ["SOU"], ["STN"]]"#)
.unwrap()
);
@ -1833,10 +1836,10 @@ fn dfw_by_region() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"
[["US-CA",["BFL","BUR","FAT","LAX","MRY","OAK","ONT","PSP","SAN","SBA","SFO","SJC","SMF","SNA"]],
["US-CO",["ASE","COS","DEN","DRO","EGE","GJT","GUC","HDN","MTJ"]],
@ -1865,10 +1868,10 @@ fn great_circle_distance() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[1.0]]"#).unwrap()
);
dbg!(great_circle_distance.elapsed());
@ -1894,10 +1897,10 @@ fn aus_to_edi() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(r#"[[["AUS", "BOS", "EDI"]]]"#).unwrap()
);
dbg!(aus_to_edi.elapsed());
@ -1923,10 +1926,10 @@ fn reachable_from_lhr() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
[8,["LHR","YYZ","YTS","YMO","YFA","ZKE","YAT","YPO"]],
@ -1968,10 +1971,10 @@ fn furthest_from_lhr() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(
json!(rows),
rows["rows"],
serde_json::Value::from_str(
r#"[
[12922.0,["LHR","JNB","HLE","ASI","BZZ"]],[12093.0,["LHR","PVG","CHC","IVC"]],
@ -1997,9 +2000,9 @@ fn skip_limit() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[3], [4], [5], [6], [7], [8], [9]]));
assert_eq!(rows["rows"], json!([[3], [4], [5], [6], [7], [8], [9]]));
let rows = TEST_DB
.run_script(
@ -2009,9 +2012,9 @@ fn skip_limit() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[3], [4], [5], [6], [7], [8], [9]]));
assert_eq!(rows["rows"], json!([[3], [4], [5], [6], [7], [8], [9]]));
let rows = TEST_DB
.run_script(
@ -2022,9 +2025,9 @@ fn skip_limit() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[8], [9]]));
assert_eq!(rows["rows"], json!([[8], [9]]));
let rows = TEST_DB
.run_script(
@ -2036,9 +2039,9 @@ fn skip_limit() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[7], [8]]));
assert_eq!(rows["rows"], json!([[7], [8]]));
let rows = TEST_DB
.run_script(
@ -2050,7 +2053,7 @@ fn skip_limit() {
Default::default(),
)
.unwrap()
.rows;
.into_json();
assert_eq!(json!(rows), json!([[3], [4], [5], [6], [7], [8]]));
assert_eq!(rows["rows"], json!([[3], [4], [5], [6], [7], [8]]));
}

Loading…
Cancel
Save