mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-30 22:44:21 +01:00
rename functions
This commit is contained in:
@@ -27,7 +27,7 @@ pub fn exec_strftime(values: &[Register]) -> Value {
|
||||
return Value::Null;
|
||||
}
|
||||
|
||||
let value = &values[0].get_owned_value();
|
||||
let value = &values[0].get_value();
|
||||
let format_str = if matches!(value, Value::Text(_) | Value::Integer(_) | Value::Float(_)) {
|
||||
format!("{value}")
|
||||
} else {
|
||||
@@ -51,7 +51,7 @@ fn exec_datetime(values: &[Register], output_type: DateTimeOutput) -> Value {
|
||||
let now = parse_naive_date_time(&Value::build_text("now")).unwrap();
|
||||
return format_dt(now, output_type, false);
|
||||
}
|
||||
if let Some(mut dt) = parse_naive_date_time(values[0].get_owned_value()) {
|
||||
if let Some(mut dt) = parse_naive_date_time(values[0].get_value()) {
|
||||
// if successful, treat subsequent entries as modifiers
|
||||
modify_dt(&mut dt, &values[1..], output_type)
|
||||
} else {
|
||||
@@ -65,7 +65,7 @@ fn modify_dt(dt: &mut NaiveDateTime, mods: &[Register], output_type: DateTimeOut
|
||||
let mut subsec_requested = false;
|
||||
|
||||
for modifier in mods {
|
||||
if let Value::Text(ref text_rc) = modifier.get_owned_value() {
|
||||
if let Value::Text(ref text_rc) = modifier.get_value() {
|
||||
// TODO: to prevent double conversion and properly support 'utc'/'localtime', we also
|
||||
// need to keep track of the current timezone and apply it to the modifier.
|
||||
match apply_modifier(dt, text_rc.as_str()) {
|
||||
@@ -647,8 +647,8 @@ pub fn exec_timediff(values: &[Register]) -> Value {
|
||||
return Value::Null;
|
||||
}
|
||||
|
||||
let start = parse_naive_date_time(values[0].get_owned_value());
|
||||
let end = parse_naive_date_time(values[1].get_owned_value());
|
||||
let start = parse_naive_date_time(values[0].get_value());
|
||||
let end = parse_naive_date_time(values[1].get_value());
|
||||
|
||||
match (start, end) {
|
||||
(Some(start), Some(end)) => {
|
||||
@@ -1296,7 +1296,7 @@ mod tests {
|
||||
&[text("2023-06-15 12:30:45"), text("-1 day")],
|
||||
DateTimeOutput::DateTime,
|
||||
);
|
||||
assert_eq!(result, *text(&expected).get_owned_value());
|
||||
assert_eq!(result, *text(&expected).get_value());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1311,7 +1311,7 @@ mod tests {
|
||||
],
|
||||
DateTimeOutput::DateTime,
|
||||
);
|
||||
assert_eq!(result, *text(&expected).get_owned_value());
|
||||
assert_eq!(result, *text(&expected).get_value());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1338,7 +1338,7 @@ mod tests {
|
||||
],
|
||||
DateTimeOutput::DateTime,
|
||||
);
|
||||
assert_eq!(result, *text(&expected).get_owned_value());
|
||||
assert_eq!(result, *text(&expected).get_value());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1357,7 +1357,7 @@ mod tests {
|
||||
],
|
||||
DateTimeOutput::DateTime,
|
||||
);
|
||||
assert_eq!(result, *text(&expected).get_owned_value());
|
||||
assert_eq!(result, *text(&expected).get_value());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1377,7 +1377,7 @@ mod tests {
|
||||
],
|
||||
DateTimeOutput::DateTime,
|
||||
);
|
||||
assert_eq!(result, *text(&expected).get_owned_value());
|
||||
assert_eq!(result, *text(&expected).get_value());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1395,7 +1395,7 @@ mod tests {
|
||||
.format("%Y-%m-%d %H:%M:%S")
|
||||
.to_string()
|
||||
)
|
||||
.get_owned_value()
|
||||
.get_value()
|
||||
);
|
||||
// TODO: utc modifier assumes time given is not already utc
|
||||
// add test when fixed in the future
|
||||
@@ -1433,7 +1433,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let expected = format(max);
|
||||
let result = exec_datetime(&[text("9999-12-31 23:59:59")], DateTimeOutput::DateTime);
|
||||
assert_eq!(result, *text(&expected).get_owned_value());
|
||||
assert_eq!(result, *text(&expected).get_value());
|
||||
}
|
||||
|
||||
// leap second
|
||||
@@ -1445,7 +1445,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let expected = String::new(); // SQLite ignores leap seconds
|
||||
let result = exec_datetime(&[text(&leap_second.to_string())], DateTimeOutput::DateTime);
|
||||
assert_eq!(result, *text(&expected).get_owned_value());
|
||||
assert_eq!(result, *text(&expected).get_value());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -8,7 +8,7 @@ pub fn exec_printf(values: &[Register]) -> crate::Result<Value> {
|
||||
if values.is_empty() {
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
let format_str = match &values[0].get_owned_value() {
|
||||
let format_str = match &values[0].get_value() {
|
||||
Value::Text(t) => t.as_str(),
|
||||
_ => return Ok(Value::Null),
|
||||
};
|
||||
@@ -32,7 +32,7 @@ pub fn exec_printf(values: &[Register]) -> crate::Result<Value> {
|
||||
if args_index >= values.len() {
|
||||
return Err(LimboError::InvalidArgument("not enough arguments".into()));
|
||||
}
|
||||
let value = &values[args_index].get_owned_value();
|
||||
let value = &values[args_index].get_value();
|
||||
match value {
|
||||
Value::Integer(_) => result.push_str(&format!("{value}")),
|
||||
Value::Float(_) => result.push_str(&format!("{value}")),
|
||||
@@ -44,7 +44,7 @@ pub fn exec_printf(values: &[Register]) -> crate::Result<Value> {
|
||||
if args_index >= values.len() {
|
||||
return Err(LimboError::InvalidArgument("not enough arguments".into()));
|
||||
}
|
||||
match &values[args_index].get_owned_value() {
|
||||
match &values[args_index].get_value() {
|
||||
Value::Text(t) => result.push_str(t.as_str()),
|
||||
Value::Null => result.push_str("(null)"),
|
||||
v => result.push_str(&format!("{v}")),
|
||||
@@ -55,7 +55,7 @@ pub fn exec_printf(values: &[Register]) -> crate::Result<Value> {
|
||||
if args_index >= values.len() {
|
||||
return Err(LimboError::InvalidArgument("not enough arguments".into()));
|
||||
}
|
||||
let value = &values[args_index].get_owned_value();
|
||||
let value = &values[args_index].get_value();
|
||||
match value {
|
||||
Value::Float(f) => result.push_str(&format!("{f:.6}")),
|
||||
Value::Integer(i) => result.push_str(&format!("{:.6}", *i as f64)),
|
||||
@@ -103,7 +103,7 @@ mod tests {
|
||||
fn test_printf_basic_string() {
|
||||
assert_eq!(
|
||||
exec_printf(&[text("Hello World")]).unwrap(),
|
||||
*text("Hello World").get_owned_value()
|
||||
*text("Hello World").get_value()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ mod tests {
|
||||
(vec![text("100%% complete")], text("100% complete")),
|
||||
];
|
||||
for (input, output) in test_cases {
|
||||
assert_eq!(exec_printf(&input).unwrap(), *output.get_owned_value());
|
||||
assert_eq!(exec_printf(&input).unwrap(), *output.get_value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ mod tests {
|
||||
),
|
||||
];
|
||||
for (input, output) in test_cases {
|
||||
assert_eq!(exec_printf(&input).unwrap(), *output.get_owned_value())
|
||||
assert_eq!(exec_printf(&input).unwrap(), *output.get_value())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ mod tests {
|
||||
];
|
||||
|
||||
for (input, expected) in test_cases {
|
||||
assert_eq!(exec_printf(&input).unwrap(), *expected.get_owned_value());
|
||||
assert_eq!(exec_printf(&input).unwrap(), *expected.get_value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ mod tests {
|
||||
];
|
||||
|
||||
for (input, expected) in test_cases {
|
||||
assert_eq!(exec_printf(&input).unwrap(), *expected.get_owned_value());
|
||||
assert_eq!(exec_printf(&input).unwrap(), *expected.get_value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ mod tests {
|
||||
];
|
||||
|
||||
for (input, expected) in test_cases {
|
||||
assert_eq!(exec_printf(&input).unwrap(), *expected.get_owned_value());
|
||||
assert_eq!(exec_printf(&input).unwrap(), *expected.get_value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -896,7 +896,7 @@ impl Jsonb {
|
||||
Ok((header, offset))
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> Result<ElementType> {
|
||||
pub fn element_type(&self) -> Result<ElementType> {
|
||||
match self.read_header(0) {
|
||||
Ok((header, offset)) => {
|
||||
if self.data.get(offset..offset + header.1).is_some() {
|
||||
@@ -2746,7 +2746,7 @@ impl Jsonb {
|
||||
Ok(pos)
|
||||
}
|
||||
|
||||
// Primitive implementation could be optimized.
|
||||
// TODO Primitive implementation could be optimized.
|
||||
pub fn patch(&mut self, patch: &Jsonb) -> Result<()> {
|
||||
let (patch_header, _) = patch.read_header(0)?;
|
||||
|
||||
@@ -3578,14 +3578,14 @@ world""#,
|
||||
fn test_jsonb_is_valid() {
|
||||
// Valid JSONB
|
||||
let jsonb = Jsonb::from_str(r#"{"test":"value"}"#).unwrap();
|
||||
assert!(jsonb.is_valid().is_ok());
|
||||
assert!(jsonb.element_type().is_ok());
|
||||
|
||||
// Invalid JSONB (manually corrupted)
|
||||
let mut invalid = jsonb.data.clone();
|
||||
if !invalid.is_empty() {
|
||||
invalid[0] = 0xFF; // Invalid element type
|
||||
let jsonb = Jsonb::new(0, Some(&invalid));
|
||||
assert!(jsonb.is_valid().is_err());
|
||||
assert!(jsonb.element_type().is_err());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
104
core/json/mod.rs
104
core/json/mod.rs
@@ -51,7 +51,7 @@ pub fn get_json(json_value: &Value, indent: Option<&str>) -> crate::Result<Value
|
||||
}
|
||||
Value::Blob(b) => {
|
||||
let jsonbin = Jsonb::new(b.len(), Some(b));
|
||||
jsonbin.is_valid()?;
|
||||
jsonbin.element_type()?;
|
||||
Ok(Value::Text(Text {
|
||||
value: jsonbin.to_string()?.into_bytes(),
|
||||
subtype: TextSubtype::Json,
|
||||
@@ -63,7 +63,7 @@ pub fn get_json(json_value: &Value, indent: Option<&str>) -> crate::Result<Value
|
||||
let json = match indent {
|
||||
Some(indent) => Value::Text(Text::json(json_val.to_string_pretty(Some(indent))?)),
|
||||
None => {
|
||||
let element_type = json_val.is_valid()?;
|
||||
let element_type = json_val.element_type()?;
|
||||
json_string_to_db_type(json_val, element_type, OutputVariant::ElementType)?
|
||||
}
|
||||
};
|
||||
@@ -93,7 +93,7 @@ pub fn convert_dbtype_to_raw_jsonb(data: &Value) -> crate::Result<Vec<u8>> {
|
||||
|
||||
pub fn json_from_raw_bytes_agg(data: &[u8], raw: bool) -> crate::Result<Value> {
|
||||
let mut json = Jsonb::from_raw_data(data);
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
json.finalize_unsafe(el_type)?;
|
||||
if raw {
|
||||
json_string_to_db_type(json, el_type, OutputVariant::Binary)
|
||||
@@ -144,7 +144,7 @@ pub fn convert_ref_dbtype_to_jsonb(val: &RefValue, strict: Conv) -> crate::Resul
|
||||
}
|
||||
RefValue::Blob(blob) => {
|
||||
let json = Jsonb::from_raw_data(blob.to_slice());
|
||||
json.is_valid()?;
|
||||
json.element_type()?;
|
||||
Ok(json)
|
||||
}
|
||||
RefValue::Null => Ok(Jsonb::from_raw_data(
|
||||
@@ -168,10 +168,10 @@ pub fn json_array(values: &[Register]) -> crate::Result<Value> {
|
||||
let mut json = Jsonb::make_empty_array(values.len());
|
||||
|
||||
for value in values.iter() {
|
||||
if matches!(value.get_owned_value(), Value::Blob(_)) {
|
||||
if matches!(value.get_value(), Value::Blob(_)) {
|
||||
crate::bail_constraint_error!("JSON cannot hold BLOB values")
|
||||
}
|
||||
let value = convert_dbtype_to_jsonb(value.get_owned_value(), Conv::NotStrict)?;
|
||||
let value = convert_dbtype_to_jsonb(value.get_value(), Conv::NotStrict)?;
|
||||
json.append_jsonb_to_end(value.data());
|
||||
}
|
||||
json.finalize_unsafe(ElementType::ARRAY)?;
|
||||
@@ -183,10 +183,10 @@ pub fn jsonb_array(values: &[Register]) -> crate::Result<Value> {
|
||||
let mut json = Jsonb::make_empty_array(values.len());
|
||||
|
||||
for value in values.iter() {
|
||||
if matches!(value.get_owned_value(), Value::Blob(_)) {
|
||||
if matches!(value.get_value(), Value::Blob(_)) {
|
||||
crate::bail_constraint_error!("JSON cannot hold BLOB values")
|
||||
}
|
||||
let value = convert_dbtype_to_jsonb(value.get_owned_value(), Conv::NotStrict)?;
|
||||
let value = convert_dbtype_to_jsonb(value.get_value(), Conv::NotStrict)?;
|
||||
json.append_jsonb_to_end(value.data());
|
||||
}
|
||||
json.finalize_unsafe(ElementType::ARRAY)?;
|
||||
@@ -207,7 +207,7 @@ pub fn json_array_length(
|
||||
return Ok(Value::Integer(len as i64));
|
||||
}
|
||||
|
||||
let path = json_path_from_owned_value(path.expect("We already checked none"), true)?;
|
||||
let path = json_path_from_db_value(path.expect("We already checked none"), true)?;
|
||||
|
||||
if let Some(path) = path {
|
||||
let mut op = SearchOperation::new(json.len() / 2);
|
||||
@@ -225,20 +225,20 @@ pub fn json_set(args: &[Register], json_cache: &JsonCacheCell) -> crate::Result<
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
let other = args[1..].chunks_exact(2);
|
||||
|
||||
for chunk in other {
|
||||
let path = json_path_from_owned_value(chunk[0].get_owned_value(), true)?;
|
||||
let path = json_path_from_db_value(chunk[0].get_value(), true)?;
|
||||
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
let mut op = SetOperation::new(value);
|
||||
if let Some(path) = path {
|
||||
let _ = json.operate_on_path(&path, &mut op);
|
||||
}
|
||||
}
|
||||
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::String)
|
||||
}
|
||||
@@ -249,20 +249,20 @@ pub fn jsonb_set(args: &[Register], json_cache: &JsonCacheCell) -> crate::Result
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
let other = args[1..].chunks_exact(2);
|
||||
|
||||
for chunk in other {
|
||||
let path = json_path_from_owned_value(chunk[0].get_owned_value(), true)?;
|
||||
let path = json_path_from_db_value(chunk[0].get_value(), true)?;
|
||||
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
let mut op = SetOperation::new(value);
|
||||
if let Some(path) = path {
|
||||
let _ = json.operate_on_path(&path, &mut op);
|
||||
}
|
||||
}
|
||||
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::Binary)
|
||||
}
|
||||
@@ -278,7 +278,7 @@ pub fn json_arrow_extract(
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
|
||||
if let Some(path) = json_path_from_owned_value(path, false)? {
|
||||
if let Some(path) = json_path_from_db_value(path, false)? {
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(value, make_jsonb_fn)?;
|
||||
let mut op = SearchOperation::new(json.len());
|
||||
@@ -304,13 +304,13 @@ pub fn json_arrow_shift_extract(
|
||||
if let Value::Null = value {
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
if let Some(path) = json_path_from_owned_value(path, false)? {
|
||||
if let Some(path) = json_path_from_db_value(path, false)? {
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(value, make_jsonb_fn)?;
|
||||
let mut op = SearchOperation::new(json.len());
|
||||
let res = json.operate_on_path(&path, &mut op);
|
||||
let extracted = op.result();
|
||||
let element_type = match extracted.is_valid() {
|
||||
let element_type = match extracted.element_type() {
|
||||
Err(_) => return Ok(Value::Null),
|
||||
Ok(el) => el,
|
||||
};
|
||||
@@ -377,13 +377,13 @@ pub fn jsonb_extract(
|
||||
fn jsonb_extract_internal(value: Jsonb, paths: &[Register]) -> crate::Result<(Jsonb, ElementType)> {
|
||||
let null = Jsonb::from_raw_data(JsonbHeader::make_null().into_bytes().as_bytes());
|
||||
if paths.len() == 1 {
|
||||
if let Some(path) = json_path_from_owned_value(paths[0].get_owned_value(), true)? {
|
||||
if let Some(path) = json_path_from_db_value(paths[0].get_value(), true)? {
|
||||
let mut json = value;
|
||||
|
||||
let mut op = SearchOperation::new(json.len());
|
||||
let res = json.operate_on_path(&path, &mut op);
|
||||
let extracted = op.result();
|
||||
let element_type = match extracted.is_valid() {
|
||||
let element_type = match extracted.element_type() {
|
||||
Err(_) => return Ok((null, ElementType::NULL)),
|
||||
Ok(el) => el,
|
||||
};
|
||||
@@ -403,7 +403,7 @@ fn jsonb_extract_internal(value: Jsonb, paths: &[Register]) -> crate::Result<(Js
|
||||
// TODO: make an op to avoid creating new json for every path element
|
||||
let paths = paths
|
||||
.iter()
|
||||
.map(|p| json_path_from_owned_value(p.get_owned_value(), true));
|
||||
.map(|p| json_path_from_db_value(p.get_value(), true));
|
||||
for path in paths {
|
||||
if let Some(path) = path? {
|
||||
let mut op = SearchOperation::new(json.len());
|
||||
@@ -487,11 +487,11 @@ pub fn json_type(value: &Value, path: Option<&Value>) -> crate::Result<Value> {
|
||||
}
|
||||
if path.is_none() {
|
||||
let json = convert_dbtype_to_jsonb(value, Conv::Strict)?;
|
||||
let element_type = json.is_valid()?;
|
||||
let element_type = json.element_type()?;
|
||||
|
||||
return Ok(Value::Text(Text::json(element_type.into())));
|
||||
}
|
||||
if let Some(path) = json_path_from_owned_value(path.unwrap(), true)? {
|
||||
if let Some(path) = json_path_from_db_value(path.unwrap(), true)? {
|
||||
let mut json = convert_dbtype_to_jsonb(value, Conv::Strict)?;
|
||||
|
||||
if let Ok(mut path) = json.navigate_path(&path, PathOperationMode::ReplaceExisting) {
|
||||
@@ -510,7 +510,7 @@ pub fn json_type(value: &Value, path: Option<&Value>) -> crate::Result<Value> {
|
||||
}
|
||||
}
|
||||
|
||||
fn json_path_from_owned_value(path: &Value, strict: bool) -> crate::Result<Option<JsonPath>> {
|
||||
fn json_path_from_db_value(path: &Value, strict: bool) -> crate::Result<Option<JsonPath>> {
|
||||
let json_path = if strict {
|
||||
match path {
|
||||
Value::Text(t) => json_path(t.as_str())?,
|
||||
@@ -584,12 +584,12 @@ pub fn json_object(values: &[Register]) -> crate::Result<Value> {
|
||||
let mut json = Jsonb::make_empty_obj(values.len() * 50);
|
||||
|
||||
for chunk in values.chunks_exact(2) {
|
||||
if chunk[0].get_owned_value().value_type() != ValueType::Text {
|
||||
if chunk[0].get_value().value_type() != ValueType::Text {
|
||||
bail_constraint_error!("json_object() labels must be TEXT")
|
||||
}
|
||||
let key = convert_dbtype_to_jsonb(chunk[0].get_owned_value(), Conv::ToString)?;
|
||||
let key = convert_dbtype_to_jsonb(chunk[0].get_value(), Conv::ToString)?;
|
||||
json.append_jsonb_to_end(key.data());
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
json.append_jsonb_to_end(value.data());
|
||||
}
|
||||
|
||||
@@ -605,12 +605,12 @@ pub fn jsonb_object(values: &[Register]) -> crate::Result<Value> {
|
||||
let mut json = Jsonb::make_empty_obj(values.len() * 50);
|
||||
|
||||
for chunk in values.chunks_exact(2) {
|
||||
if chunk[0].get_owned_value().value_type() != ValueType::Text {
|
||||
if chunk[0].get_value().value_type() != ValueType::Text {
|
||||
bail_constraint_error!("json_object() labels must be TEXT")
|
||||
}
|
||||
let key = convert_dbtype_to_jsonb(chunk[0].get_owned_value(), Conv::ToString)?;
|
||||
let key = convert_dbtype_to_jsonb(chunk[0].get_value(), Conv::ToString)?;
|
||||
json.append_jsonb_to_end(key.data());
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
json.append_jsonb_to_end(value.data());
|
||||
}
|
||||
|
||||
@@ -1174,10 +1174,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_root_strict() {
|
||||
fn test_json_path_from_db_value_root_strict() {
|
||||
let path = Value::Text(Text::new("$"));
|
||||
|
||||
let result = json_path_from_owned_value(&path, true);
|
||||
let result = json_path_from_db_value(&path, true);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = result.unwrap();
|
||||
@@ -1191,10 +1191,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_root_non_strict() {
|
||||
fn test_json_path_from_db_value_root_non_strict() {
|
||||
let path = Value::Text(Text::new("$"));
|
||||
|
||||
let result = json_path_from_owned_value(&path, false);
|
||||
let result = json_path_from_db_value(&path, false);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = result.unwrap();
|
||||
@@ -1208,17 +1208,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_named_strict() {
|
||||
fn test_json_path_from_db_value_named_strict() {
|
||||
let path = Value::Text(Text::new("field"));
|
||||
|
||||
assert!(json_path_from_owned_value(&path, true).is_err());
|
||||
assert!(json_path_from_db_value(&path, true).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_named_non_strict() {
|
||||
fn test_json_path_from_db_value_named_non_strict() {
|
||||
let path = Value::Text(Text::new("field"));
|
||||
|
||||
let result = json_path_from_owned_value(&path, false);
|
||||
let result = json_path_from_db_value(&path, false);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = result.unwrap();
|
||||
@@ -1232,16 +1232,16 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_integer_strict() {
|
||||
fn test_json_path_from_db_value_integer_strict() {
|
||||
let path = Value::Integer(3);
|
||||
assert!(json_path_from_owned_value(&path, true).is_err());
|
||||
assert!(json_path_from_db_value(&path, true).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_integer_non_strict() {
|
||||
fn test_json_path_from_db_value_integer_non_strict() {
|
||||
let path = Value::Integer(3);
|
||||
|
||||
let result = json_path_from_owned_value(&path, false);
|
||||
let result = json_path_from_db_value(&path, false);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = result.unwrap();
|
||||
@@ -1255,10 +1255,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_null_strict() {
|
||||
fn test_json_path_from_db_value_null_strict() {
|
||||
let path = Value::Null;
|
||||
|
||||
let result = json_path_from_owned_value(&path, true);
|
||||
let result = json_path_from_db_value(&path, true);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = result.unwrap();
|
||||
@@ -1266,10 +1266,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_null_non_strict() {
|
||||
fn test_json_path_from_db_value_null_non_strict() {
|
||||
let path = Value::Null;
|
||||
|
||||
let result = json_path_from_owned_value(&path, false);
|
||||
let result = json_path_from_db_value(&path, false);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = result.unwrap();
|
||||
@@ -1277,17 +1277,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_float_strict() {
|
||||
fn test_json_path_from_db_value_float_strict() {
|
||||
let path = Value::Float(1.23);
|
||||
|
||||
assert!(json_path_from_owned_value(&path, true).is_err());
|
||||
assert!(json_path_from_db_value(&path, true).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_float_non_strict() {
|
||||
fn test_json_path_from_db_value_float_non_strict() {
|
||||
let path = Value::Float(1.23);
|
||||
|
||||
let result = json_path_from_owned_value(&path, false);
|
||||
let result = json_path_from_db_value(&path, false);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = result.unwrap();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{types::Value, vdbe::Register};
|
||||
|
||||
use super::{
|
||||
convert_dbtype_to_jsonb, curry_convert_dbtype_to_jsonb, json_path_from_owned_value,
|
||||
convert_dbtype_to_jsonb, curry_convert_dbtype_to_jsonb, json_path_from_db_value,
|
||||
json_string_to_db_type,
|
||||
jsonb::{DeleteOperation, InsertOperation, ReplaceOperation},
|
||||
Conv, JsonCacheCell, OutputVariant,
|
||||
@@ -25,7 +25,7 @@ pub fn json_patch(target: &Value, patch: &Value, cache: &JsonCacheCell) -> crate
|
||||
|
||||
target.patch(&patch)?;
|
||||
|
||||
let element_type = target.is_valid()?;
|
||||
let element_type = target.element_type()?;
|
||||
|
||||
json_string_to_db_type(target, element_type, OutputVariant::ElementType)
|
||||
}
|
||||
@@ -43,7 +43,7 @@ pub fn jsonb_patch(target: &Value, patch: &Value, cache: &JsonCacheCell) -> crat
|
||||
|
||||
target.patch(&patch)?;
|
||||
|
||||
let element_type = target.is_valid()?;
|
||||
let element_type = target.element_type()?;
|
||||
|
||||
json_string_to_db_type(target, element_type, OutputVariant::Binary)
|
||||
}
|
||||
@@ -54,15 +54,15 @@ pub fn json_remove(args: &[Register], json_cache: &JsonCacheCell) -> crate::Resu
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
for arg in &args[1..] {
|
||||
if let Some(path) = json_path_from_owned_value(arg.get_owned_value(), true)? {
|
||||
if let Some(path) = json_path_from_db_value(arg.get_value(), true)? {
|
||||
let mut op = DeleteOperation::new();
|
||||
let _ = json.operate_on_path(&path, &mut op);
|
||||
}
|
||||
}
|
||||
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::String)
|
||||
}
|
||||
@@ -73,9 +73,9 @@ pub fn jsonb_remove(args: &[Register], json_cache: &JsonCacheCell) -> crate::Res
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
for arg in &args[1..] {
|
||||
if let Some(path) = json_path_from_owned_value(arg.get_owned_value(), true)? {
|
||||
if let Some(path) = json_path_from_db_value(arg.get_value(), true)? {
|
||||
let mut op = DeleteOperation::new();
|
||||
let _ = json.operate_on_path(&path, &mut op);
|
||||
}
|
||||
@@ -90,12 +90,12 @@ pub fn json_replace(args: &[Register], json_cache: &JsonCacheCell) -> crate::Res
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
let other = args[1..].chunks_exact(2);
|
||||
for chunk in other {
|
||||
let path = json_path_from_owned_value(chunk[0].get_owned_value(), true)?;
|
||||
let path = json_path_from_db_value(chunk[0].get_value(), true)?;
|
||||
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
if let Some(path) = path {
|
||||
let mut op = ReplaceOperation::new(value);
|
||||
|
||||
@@ -103,7 +103,7 @@ pub fn json_replace(args: &[Register], json_cache: &JsonCacheCell) -> crate::Res
|
||||
}
|
||||
}
|
||||
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, super::OutputVariant::String)
|
||||
}
|
||||
@@ -114,11 +114,11 @@ pub fn jsonb_replace(args: &[Register], json_cache: &JsonCacheCell) -> crate::Re
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
let other = args[1..].chunks_exact(2);
|
||||
for chunk in other {
|
||||
let path = json_path_from_owned_value(chunk[0].get_owned_value(), true)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let path = json_path_from_db_value(chunk[0].get_value(), true)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
if let Some(path) = path {
|
||||
let mut op = ReplaceOperation::new(value);
|
||||
|
||||
@@ -126,7 +126,7 @@ pub fn jsonb_replace(args: &[Register], json_cache: &JsonCacheCell) -> crate::Re
|
||||
}
|
||||
}
|
||||
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::Binary)
|
||||
}
|
||||
@@ -137,11 +137,11 @@ pub fn json_insert(args: &[Register], json_cache: &JsonCacheCell) -> crate::Resu
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
let other = args[1..].chunks_exact(2);
|
||||
for chunk in other {
|
||||
let path = json_path_from_owned_value(chunk[0].get_owned_value(), true)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let path = json_path_from_db_value(chunk[0].get_value(), true)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
if let Some(path) = path {
|
||||
let mut op = InsertOperation::new(value);
|
||||
|
||||
@@ -149,7 +149,7 @@ pub fn json_insert(args: &[Register], json_cache: &JsonCacheCell) -> crate::Resu
|
||||
}
|
||||
}
|
||||
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::String)
|
||||
}
|
||||
@@ -160,11 +160,11 @@ pub fn jsonb_insert(args: &[Register], json_cache: &JsonCacheCell) -> crate::Res
|
||||
}
|
||||
|
||||
let make_jsonb_fn = curry_convert_dbtype_to_jsonb(Conv::Strict);
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_owned_value(), make_jsonb_fn)?;
|
||||
let mut json = json_cache.get_or_insert_with(args[0].get_value(), make_jsonb_fn)?;
|
||||
let other = args[1..].chunks_exact(2);
|
||||
for chunk in other {
|
||||
let path = json_path_from_owned_value(chunk[0].get_owned_value(), true)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_owned_value(), Conv::NotStrict)?;
|
||||
let path = json_path_from_db_value(chunk[0].get_value(), true)?;
|
||||
let value = convert_dbtype_to_jsonb(chunk[1].get_value(), Conv::NotStrict)?;
|
||||
if let Some(path) = path {
|
||||
let mut op = InsertOperation::new(value);
|
||||
|
||||
@@ -172,7 +172,7 @@ pub fn jsonb_insert(args: &[Register], json_cache: &JsonCacheCell) -> crate::Res
|
||||
}
|
||||
}
|
||||
|
||||
let el_type = json.is_valid()?;
|
||||
let el_type = json.element_type()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::Binary)
|
||||
}
|
||||
|
||||
@@ -1110,7 +1110,7 @@ impl ImmutableRecord {
|
||||
registers: impl IntoIterator<Item = &'a Register, IntoIter = I>,
|
||||
len: usize,
|
||||
) -> Self {
|
||||
Self::from_values(registers.into_iter().map(|x| x.get_owned_value()), len)
|
||||
Self::from_values(registers.into_iter().map(|x| x.get_value()), len)
|
||||
}
|
||||
|
||||
pub fn from_values<'a>(
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -365,7 +365,7 @@ impl ProgramState {
|
||||
}
|
||||
|
||||
impl Register {
|
||||
pub fn get_owned_value(&self) -> &Value {
|
||||
pub fn get_value(&self) -> &Value {
|
||||
match self {
|
||||
Register::Value(v) => v,
|
||||
Register::Record(r) => {
|
||||
@@ -631,7 +631,7 @@ pub fn registers_to_ref_values(registers: &[Register]) -> Vec<RefValue> {
|
||||
registers
|
||||
.iter()
|
||||
.map(|reg| {
|
||||
let value = reg.get_owned_value();
|
||||
let value = reg.get_value();
|
||||
match value {
|
||||
Value::Null => RefValue::Null,
|
||||
Value::Integer(i) => RefValue::Integer(*i),
|
||||
@@ -795,7 +795,7 @@ impl Row {
|
||||
pub fn get<'a, T: FromValueRow<'a> + 'a>(&'a self, idx: usize) -> Result<T> {
|
||||
let value = unsafe { self.values.add(idx).as_ref().unwrap() };
|
||||
let value = match value {
|
||||
Register::Value(owned_value) => owned_value,
|
||||
Register::Value(value) => value,
|
||||
_ => unreachable!("a row should be formed of values only"),
|
||||
};
|
||||
T::from_value(value)
|
||||
@@ -804,7 +804,7 @@ impl Row {
|
||||
pub fn get_value(&self, idx: usize) -> &Value {
|
||||
let value = unsafe { self.values.add(idx).as_ref().unwrap() };
|
||||
match value {
|
||||
Register::Value(owned_value) => owned_value,
|
||||
Register::Value(value) => value,
|
||||
_ => unreachable!("a row should be formed of values only"),
|
||||
}
|
||||
}
|
||||
@@ -813,7 +813,7 @@ impl Row {
|
||||
let values = unsafe { std::slice::from_raw_parts(self.values, self.count) };
|
||||
// This should be ownedvalues
|
||||
// TODO: add check for this
|
||||
values.iter().map(|v| v.get_owned_value())
|
||||
values.iter().map(|v| v.get_value())
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
|
||||
@@ -49,7 +49,7 @@ pub fn vector_extract(args: &[Register]) -> Result<Value> {
|
||||
));
|
||||
}
|
||||
|
||||
let blob = match &args[0].get_owned_value() {
|
||||
let blob = match &args[0].get_value() {
|
||||
Value::Blob(b) => b,
|
||||
_ => {
|
||||
return Err(LimboError::ConversionError(
|
||||
@@ -138,12 +138,12 @@ pub fn vector_slice(args: &[Register]) -> Result<Value> {
|
||||
let vector = parse_vector(&args[0], None)?;
|
||||
|
||||
let start_index = args[1]
|
||||
.get_owned_value()
|
||||
.get_value()
|
||||
.as_int()
|
||||
.ok_or_else(|| LimboError::InvalidArgument("start index must be an integer".into()))?;
|
||||
|
||||
let end_index = args[2]
|
||||
.get_owned_value()
|
||||
.get_value()
|
||||
.as_int()
|
||||
.ok_or_else(|| LimboError::InvalidArgument("end_index must be an integer".into()))?;
|
||||
|
||||
|
||||
@@ -153,13 +153,12 @@ pub fn parse_string_vector(vector_type: VectorType, value: &Value) -> Result<Vec
|
||||
}
|
||||
|
||||
pub fn parse_vector(value: &Register, vec_ty: Option<VectorType>) -> Result<Vector> {
|
||||
match value.get_owned_value().value_type() {
|
||||
ValueType::Text => parse_string_vector(
|
||||
vec_ty.unwrap_or(VectorType::Float32),
|
||||
value.get_owned_value(),
|
||||
),
|
||||
match value.get_value().value_type() {
|
||||
ValueType::Text => {
|
||||
parse_string_vector(vec_ty.unwrap_or(VectorType::Float32), value.get_value())
|
||||
}
|
||||
ValueType::Blob => {
|
||||
let Some(blob) = value.get_owned_value().to_blob() else {
|
||||
let Some(blob) = value.get_value().to_blob() else {
|
||||
return Err(LimboError::ConversionError(
|
||||
"Invalid vector value".to_string(),
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user