mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-08 17:54:22 +01:00
Merge 'refactor: remove RC<String> requirement for build_text and new text' from Pedro Muniz
This PR aims to simplify text creation and to reduce allocation overhead of creating a new OwnedValue::Text. Instead of creating Rc<String> every time you need to create a text, you just pass the string slice and the Rc<String> is created at the end. This change, at least on my machine, has removed a lot of variability in the benchmarking performance, while maintaining roughly the same performance. Closes #961
This commit is contained in:
@@ -4,7 +4,6 @@ use crate::Result;
|
||||
use chrono::{
|
||||
DateTime, Datelike, NaiveDate, NaiveDateTime, NaiveTime, TimeDelta, TimeZone, Timelike, Utc,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Execution of date/time/datetime functions
|
||||
#[inline(always)]
|
||||
@@ -48,8 +47,7 @@ enum DateTimeOutput {
|
||||
|
||||
fn exec_datetime(values: &[OwnedValue], output_type: DateTimeOutput) -> OwnedValue {
|
||||
if values.is_empty() {
|
||||
let now =
|
||||
parse_naive_date_time(&OwnedValue::build_text(Rc::new("now".to_string()))).unwrap();
|
||||
let now = parse_naive_date_time(&OwnedValue::build_text("now")).unwrap();
|
||||
|
||||
let formatted_str = match output_type {
|
||||
DateTimeOutput::DateTime => now.format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||
@@ -59,7 +57,7 @@ fn exec_datetime(values: &[OwnedValue], output_type: DateTimeOutput) -> OwnedVal
|
||||
};
|
||||
|
||||
// Parse here
|
||||
return OwnedValue::build_text(Rc::new(formatted_str));
|
||||
return OwnedValue::build_text(&formatted_str);
|
||||
}
|
||||
if let Some(mut dt) = parse_naive_date_time(&values[0]) {
|
||||
// if successful, treat subsequent entries as modifiers
|
||||
@@ -85,17 +83,17 @@ fn modify_dt(
|
||||
match apply_modifier(dt, text_rc.as_str()) {
|
||||
Ok(true) => subsec_requested = true,
|
||||
Ok(false) => {}
|
||||
Err(_) => return OwnedValue::build_text(Rc::new(String::new())),
|
||||
Err(_) => return OwnedValue::build_text(""),
|
||||
}
|
||||
} else {
|
||||
return OwnedValue::build_text(Rc::new(String::new()));
|
||||
return OwnedValue::build_text("");
|
||||
}
|
||||
}
|
||||
if is_leap_second(dt) || *dt > get_max_datetime_exclusive() {
|
||||
return OwnedValue::build_text(Rc::new(String::new()));
|
||||
return OwnedValue::build_text("");
|
||||
}
|
||||
let formatted = format_dt(*dt, output_type, subsec_requested);
|
||||
OwnedValue::build_text(Rc::new(formatted))
|
||||
OwnedValue::build_text(&formatted)
|
||||
}
|
||||
|
||||
fn format_dt(dt: NaiveDateTime, output_type: DateTimeOutput, subsec: bool) -> String {
|
||||
@@ -662,7 +660,6 @@ fn parse_modifier(modifier: &str) -> Result<Modifier> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[test]
|
||||
fn test_valid_get_date_from_time_value() {
|
||||
@@ -674,201 +671,135 @@ mod tests {
|
||||
|
||||
let test_cases = vec![
|
||||
// Format 1: YYYY-MM-DD (no timezone applicable)
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21".to_string())),
|
||||
test_date_str,
|
||||
),
|
||||
(OwnedValue::build_text("2024-07-21"), test_date_str),
|
||||
// Format 2: YYYY-MM-DD HH:MM
|
||||
(OwnedValue::build_text("2024-07-21 22:30"), test_date_str),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30+02:00"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30+02:00".to_string())),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30-05:00"),
|
||||
next_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 01:30+05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 01:30+05:00"),
|
||||
prev_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30Z".to_string())),
|
||||
test_date_str,
|
||||
),
|
||||
(OwnedValue::build_text("2024-07-21 22:30Z"), test_date_str),
|
||||
// Format 3: YYYY-MM-DD HH:MM:SS
|
||||
(OwnedValue::build_text("2024-07-21 22:30:45"), test_date_str),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45+02:00"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45+02:00".to_string())),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45-05:00"),
|
||||
next_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 01:30:45+05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 01:30:45+05:00"),
|
||||
prev_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45Z"),
|
||||
test_date_str,
|
||||
),
|
||||
// Format 4: YYYY-MM-DD HH:MM:SS.SSS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123+02:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123+02:00"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123-05:00"),
|
||||
next_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 01:30:45.123+05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 01:30:45.123+05:00"),
|
||||
prev_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123Z"),
|
||||
test_date_str,
|
||||
),
|
||||
// Format 5: YYYY-MM-DDTHH:MM
|
||||
(OwnedValue::build_text("2024-07-21T22:30"), test_date_str),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30+02:00"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30+02:00".to_string())),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30-05:00"),
|
||||
next_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T01:30+05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T01:30+05:00"),
|
||||
prev_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30Z".to_string())),
|
||||
test_date_str,
|
||||
),
|
||||
(OwnedValue::build_text("2024-07-21T22:30Z"), test_date_str),
|
||||
// Format 6: YYYY-MM-DDTHH:MM:SS
|
||||
(OwnedValue::build_text("2024-07-21T22:30:45"), test_date_str),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45+02:00"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45+02:00".to_string())),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45-05:00"),
|
||||
next_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T01:30:45+05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T01:30:45+05:00"),
|
||||
prev_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45Z"),
|
||||
test_date_str,
|
||||
),
|
||||
// Format 7: YYYY-MM-DDTHH:MM:SS.SSS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123+02:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123+02:00"),
|
||||
test_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123-05:00"),
|
||||
next_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T01:30:45.123+05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T01:30:45.123+05:00"),
|
||||
prev_date_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123Z"),
|
||||
test_date_str,
|
||||
),
|
||||
// Format 8: HH:MM
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30+02:00".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30-05:00".to_string())),
|
||||
"2000-01-02",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("01:30+05:00".to_string())),
|
||||
"1999-12-31",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30Z".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(OwnedValue::build_text("22:30"), "2000-01-01"),
|
||||
(OwnedValue::build_text("22:30+02:00"), "2000-01-01"),
|
||||
(OwnedValue::build_text("22:30-05:00"), "2000-01-02"),
|
||||
(OwnedValue::build_text("01:30+05:00"), "1999-12-31"),
|
||||
(OwnedValue::build_text("22:30Z"), "2000-01-01"),
|
||||
// Format 9: HH:MM:SS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45+02:00".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45-05:00".to_string())),
|
||||
"2000-01-02",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("01:30:45+05:00".to_string())),
|
||||
"1999-12-31",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45Z".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(OwnedValue::build_text("22:30:45"), "2000-01-01"),
|
||||
(OwnedValue::build_text("22:30:45+02:00"), "2000-01-01"),
|
||||
(OwnedValue::build_text("22:30:45-05:00"), "2000-01-02"),
|
||||
(OwnedValue::build_text("01:30:45+05:00"), "1999-12-31"),
|
||||
(OwnedValue::build_text("22:30:45Z"), "2000-01-01"),
|
||||
// Format 10: HH:MM:SS.SSS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123+02:00".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123-05:00".to_string())),
|
||||
"2000-01-02",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("01:30:45.123+05:00".to_string())),
|
||||
"1999-12-31",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123Z".to_string())),
|
||||
"2000-01-01",
|
||||
),
|
||||
(OwnedValue::build_text("22:30:45.123"), "2000-01-01"),
|
||||
(OwnedValue::build_text("22:30:45.123+02:00"), "2000-01-01"),
|
||||
(OwnedValue::build_text("22:30:45.123-05:00"), "2000-01-02"),
|
||||
(OwnedValue::build_text("01:30:45.123+05:00"), "1999-12-31"),
|
||||
(OwnedValue::build_text("22:30:45.123Z"), "2000-01-01"),
|
||||
// Test Format 11: 'now'
|
||||
(OwnedValue::build_text(Rc::new("now".to_string())), &now),
|
||||
(OwnedValue::build_text("now"), &now),
|
||||
// Format 12: DDDDDDDDDD (Julian date as float or integer)
|
||||
(OwnedValue::Float(2460512.5), test_date_str),
|
||||
(OwnedValue::Integer(2460513), test_date_str),
|
||||
@@ -878,7 +809,7 @@ mod tests {
|
||||
let result = exec_date(&[input.clone()]);
|
||||
assert_eq!(
|
||||
result,
|
||||
OwnedValue::build_text(Rc::new(expected.to_string())),
|
||||
OwnedValue::build_text(expected),
|
||||
"Failed for input: {:?}",
|
||||
input
|
||||
);
|
||||
@@ -888,31 +819,31 @@ mod tests {
|
||||
#[test]
|
||||
fn test_invalid_get_date_from_time_value() {
|
||||
let invalid_cases = vec![
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 25:00".to_string())), // Invalid hour
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 24:00:00".to_string())), // Invalid hour
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 23:60:00".to_string())), // Invalid minute
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:58:60".to_string())), // Invalid second
|
||||
OwnedValue::build_text(Rc::new("2024-07-32".to_string())), // Invalid day
|
||||
OwnedValue::build_text(Rc::new("2024-13-01".to_string())), // Invalid month
|
||||
OwnedValue::build_text(Rc::new("invalid_date".to_string())), // Completely invalid string
|
||||
OwnedValue::build_text(Rc::new("".to_string())), // Empty string
|
||||
OwnedValue::Integer(i64::MAX), // Large Julian day
|
||||
OwnedValue::Integer(-1), // Negative Julian day
|
||||
OwnedValue::Float(f64::MAX), // Large float
|
||||
OwnedValue::Float(-1.0), // Negative Julian day as float
|
||||
OwnedValue::Float(f64::NAN), // NaN
|
||||
OwnedValue::Float(f64::INFINITY), // Infinity
|
||||
OwnedValue::Null, // Null value
|
||||
OwnedValue::Blob(vec![1, 2, 3].into()), // Blob (unsupported type)
|
||||
OwnedValue::build_text("2024-07-21 25:00"), // Invalid hour
|
||||
OwnedValue::build_text("2024-07-21 24:00:00"), // Invalid hour
|
||||
OwnedValue::build_text("2024-07-21 23:60:00"), // Invalid minute
|
||||
OwnedValue::build_text("2024-07-21 22:58:60"), // Invalid second
|
||||
OwnedValue::build_text("2024-07-32"), // Invalid day
|
||||
OwnedValue::build_text("2024-13-01"), // Invalid month
|
||||
OwnedValue::build_text("invalid_date"), // Completely invalid string
|
||||
OwnedValue::build_text(""), // Empty string
|
||||
OwnedValue::Integer(i64::MAX), // Large Julian day
|
||||
OwnedValue::Integer(-1), // Negative Julian day
|
||||
OwnedValue::Float(f64::MAX), // Large float
|
||||
OwnedValue::Float(-1.0), // Negative Julian day as float
|
||||
OwnedValue::Float(f64::NAN), // NaN
|
||||
OwnedValue::Float(f64::INFINITY), // Infinity
|
||||
OwnedValue::Null, // Null value
|
||||
OwnedValue::Blob(vec![1, 2, 3].into()), // Blob (unsupported type)
|
||||
// Invalid timezone tests
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+24:00".to_string())), // Invalid timezone offset (too large)
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00-24:00".to_string())), // Invalid timezone offset (too small)
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+00:60".to_string())), // Invalid timezone minutes
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+00:00:00".to_string())), // Invalid timezone format (extra seconds)
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+".to_string())), // Incomplete timezone
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+Z".to_string())), // Invalid timezone format
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+00:00Z".to_string())), // Mixing offset and Z
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00UTC".to_string())), // Named timezone (not supported)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+24:00"), // Invalid timezone offset (too large)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00-24:00"), // Invalid timezone offset (too small)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+00:60"), // Invalid timezone minutes
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+00:00:00"), // Invalid timezone format (extra seconds)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+"), // Incomplete timezone
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+Z"), // Invalid timezone format
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+00:00Z"), // Mixing offset and Z
|
||||
OwnedValue::build_text("2024-07-21T12:00:00UTC"), // Named timezone (not supported)
|
||||
];
|
||||
|
||||
for case in invalid_cases.iter() {
|
||||
@@ -935,163 +866,94 @@ mod tests {
|
||||
|
||||
let test_cases = vec![
|
||||
// Format 1: YYYY-MM-DD (no timezone applicable)
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21".to_string())),
|
||||
"00:00:00",
|
||||
),
|
||||
(OwnedValue::build_text("2024-07-21"), "00:00:00"),
|
||||
// Format 2: YYYY-MM-DD HH:MM
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30".to_string())),
|
||||
"22:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30+02:00".to_string())),
|
||||
"20:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30-05:00".to_string())),
|
||||
"03:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30Z".to_string())),
|
||||
"22:30:00",
|
||||
),
|
||||
(OwnedValue::build_text("2024-07-21 22:30"), "22:30:00"),
|
||||
(OwnedValue::build_text("2024-07-21 22:30+02:00"), "20:30:00"),
|
||||
(OwnedValue::build_text("2024-07-21 22:30-05:00"), "03:30:00"),
|
||||
(OwnedValue::build_text("2024-07-21 22:30Z"), "22:30:00"),
|
||||
// Format 3: YYYY-MM-DD HH:MM:SS
|
||||
(OwnedValue::build_text("2024-07-21 22:30:45"), test_time_str),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45".to_string())),
|
||||
test_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45+02:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45+02:00"),
|
||||
prev_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45-05:00"),
|
||||
next_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45Z"),
|
||||
test_time_str,
|
||||
),
|
||||
// Format 4: YYYY-MM-DD HH:MM:SS.SSS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123"),
|
||||
test_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123+02:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123+02:00"),
|
||||
prev_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123-05:00"),
|
||||
next_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:30:45.123Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21 22:30:45.123Z"),
|
||||
test_time_str,
|
||||
),
|
||||
// Format 5: YYYY-MM-DDTHH:MM
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30".to_string())),
|
||||
"22:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30+02:00".to_string())),
|
||||
"20:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30-05:00".to_string())),
|
||||
"03:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30Z".to_string())),
|
||||
"22:30:00",
|
||||
),
|
||||
(OwnedValue::build_text("2024-07-21T22:30"), "22:30:00"),
|
||||
(OwnedValue::build_text("2024-07-21T22:30+02:00"), "20:30:00"),
|
||||
(OwnedValue::build_text("2024-07-21T22:30-05:00"), "03:30:00"),
|
||||
(OwnedValue::build_text("2024-07-21T22:30Z"), "22:30:00"),
|
||||
// Format 6: YYYY-MM-DDTHH:MM:SS
|
||||
(OwnedValue::build_text("2024-07-21T22:30:45"), test_time_str),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45".to_string())),
|
||||
test_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45+02:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45+02:00"),
|
||||
prev_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45-05:00"),
|
||||
next_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45Z"),
|
||||
test_time_str,
|
||||
),
|
||||
// Format 7: YYYY-MM-DDTHH:MM:SS.SSS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123"),
|
||||
test_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123+02:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123+02:00"),
|
||||
prev_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123-05:00".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123-05:00"),
|
||||
next_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T22:30:45.123Z".to_string())),
|
||||
OwnedValue::build_text("2024-07-21T22:30:45.123Z"),
|
||||
test_time_str,
|
||||
),
|
||||
// Format 8: HH:MM
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30".to_string())),
|
||||
"22:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30+02:00".to_string())),
|
||||
"20:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30-05:00".to_string())),
|
||||
"03:30:00",
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30Z".to_string())),
|
||||
"22:30:00",
|
||||
),
|
||||
(OwnedValue::build_text("22:30"), "22:30:00"),
|
||||
(OwnedValue::build_text("22:30+02:00"), "20:30:00"),
|
||||
(OwnedValue::build_text("22:30-05:00"), "03:30:00"),
|
||||
(OwnedValue::build_text("22:30Z"), "22:30:00"),
|
||||
// Format 9: HH:MM:SS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45".to_string())),
|
||||
test_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45+02:00".to_string())),
|
||||
prev_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45-05:00".to_string())),
|
||||
next_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45Z".to_string())),
|
||||
test_time_str,
|
||||
),
|
||||
(OwnedValue::build_text("22:30:45"), test_time_str),
|
||||
(OwnedValue::build_text("22:30:45+02:00"), prev_time_str),
|
||||
(OwnedValue::build_text("22:30:45-05:00"), next_time_str),
|
||||
(OwnedValue::build_text("22:30:45Z"), test_time_str),
|
||||
// Format 10: HH:MM:SS.SSS
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123".to_string())),
|
||||
test_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123+02:00".to_string())),
|
||||
prev_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123-05:00".to_string())),
|
||||
next_time_str,
|
||||
),
|
||||
(
|
||||
OwnedValue::build_text(Rc::new("22:30:45.123Z".to_string())),
|
||||
test_time_str,
|
||||
),
|
||||
(OwnedValue::build_text("22:30:45.123"), test_time_str),
|
||||
(OwnedValue::build_text("22:30:45.123+02:00"), prev_time_str),
|
||||
(OwnedValue::build_text("22:30:45.123-05:00"), next_time_str),
|
||||
(OwnedValue::build_text("22:30:45.123Z"), test_time_str),
|
||||
// Format 12: DDDDDDDDDD (Julian date as float or integer)
|
||||
(OwnedValue::Float(2460082.1), "14:24:00"),
|
||||
(OwnedValue::Integer(2460082), "12:00:00"),
|
||||
@@ -1110,31 +972,31 @@ mod tests {
|
||||
#[test]
|
||||
fn test_invalid_get_time_from_datetime_value() {
|
||||
let invalid_cases = vec![
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 25:00".to_string())), // Invalid hour
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 24:00:00".to_string())), // Invalid hour
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 23:60:00".to_string())), // Invalid minute
|
||||
OwnedValue::build_text(Rc::new("2024-07-21 22:58:60".to_string())), // Invalid second
|
||||
OwnedValue::build_text(Rc::new("2024-07-32".to_string())), // Invalid day
|
||||
OwnedValue::build_text(Rc::new("2024-13-01".to_string())), // Invalid month
|
||||
OwnedValue::build_text(Rc::new("invalid_date".to_string())), // Completely invalid string
|
||||
OwnedValue::build_text(Rc::new("".to_string())), // Empty string
|
||||
OwnedValue::Integer(i64::MAX), // Large Julian day
|
||||
OwnedValue::Integer(-1), // Negative Julian day
|
||||
OwnedValue::Float(f64::MAX), // Large float
|
||||
OwnedValue::Float(-1.0), // Negative Julian day as float
|
||||
OwnedValue::Float(f64::NAN), // NaN
|
||||
OwnedValue::Float(f64::INFINITY), // Infinity
|
||||
OwnedValue::Null, // Null value
|
||||
OwnedValue::Blob(vec![1, 2, 3].into()), // Blob (unsupported type)
|
||||
OwnedValue::build_text("2024-07-21 25:00"), // Invalid hour
|
||||
OwnedValue::build_text("2024-07-21 24:00:00"), // Invalid hour
|
||||
OwnedValue::build_text("2024-07-21 23:60:00"), // Invalid minute
|
||||
OwnedValue::build_text("2024-07-21 22:58:60"), // Invalid second
|
||||
OwnedValue::build_text("2024-07-32"), // Invalid day
|
||||
OwnedValue::build_text("2024-13-01"), // Invalid month
|
||||
OwnedValue::build_text("invalid_date"), // Completely invalid string
|
||||
OwnedValue::build_text(""), // Empty string
|
||||
OwnedValue::Integer(i64::MAX), // Large Julian day
|
||||
OwnedValue::Integer(-1), // Negative Julian day
|
||||
OwnedValue::Float(f64::MAX), // Large float
|
||||
OwnedValue::Float(-1.0), // Negative Julian day as float
|
||||
OwnedValue::Float(f64::NAN), // NaN
|
||||
OwnedValue::Float(f64::INFINITY), // Infinity
|
||||
OwnedValue::Null, // Null value
|
||||
OwnedValue::Blob(vec![1, 2, 3].into()), // Blob (unsupported type)
|
||||
// Invalid timezone tests
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+24:00".to_string())), // Invalid timezone offset (too large)
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00-24:00".to_string())), // Invalid timezone offset (too small)
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+00:60".to_string())), // Invalid timezone minutes
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+00:00:00".to_string())), // Invalid timezone format (extra seconds)
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+".to_string())), // Incomplete timezone
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+Z".to_string())), // Invalid timezone format
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00+00:00Z".to_string())), // Mixing offset and Z
|
||||
OwnedValue::build_text(Rc::new("2024-07-21T12:00:00UTC".to_string())), // Named timezone (not supported)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+24:00"), // Invalid timezone offset (too large)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00-24:00"), // Invalid timezone offset (too small)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+00:60"), // Invalid timezone minutes
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+00:00:00"), // Invalid timezone format (extra seconds)
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+"), // Incomplete timezone
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+Z"), // Invalid timezone format
|
||||
OwnedValue::build_text("2024-07-21T12:00:00+00:00Z"), // Mixing offset and Z
|
||||
OwnedValue::build_text("2024-07-21T12:00:00UTC"), // Named timezone (not supported)
|
||||
];
|
||||
|
||||
for case in invalid_cases {
|
||||
@@ -1441,7 +1303,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn text(value: &str) -> OwnedValue {
|
||||
OwnedValue::build_text(Rc::new(value.to_string()))
|
||||
OwnedValue::build_text(value)
|
||||
}
|
||||
|
||||
fn format(dt: NaiveDateTime) -> String {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::types::OwnedValue;
|
||||
use crate::LimboError;
|
||||
|
||||
@@ -73,16 +71,15 @@ pub fn exec_printf(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(OwnedValue::build_text(Rc::new(result)))
|
||||
Ok(OwnedValue::build_text(&result))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn text(value: &str) -> OwnedValue {
|
||||
OwnedValue::build_text(Rc::new(value.to_string()))
|
||||
OwnedValue::build_text(value)
|
||||
}
|
||||
|
||||
fn integer(value: i64) -> OwnedValue {
|
||||
|
||||
@@ -197,7 +197,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn create_json(s: &str) -> OwnedValue {
|
||||
OwnedValue::Text(Text::json(Rc::new(s.to_string())))
|
||||
OwnedValue::Text(Text::json(s))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
292
core/json/mod.rs
292
core/json/mod.rs
@@ -4,8 +4,6 @@ mod json_operations;
|
||||
mod json_path;
|
||||
mod ser;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
pub use crate::json::de::from_str;
|
||||
use crate::json::de::ordered_object;
|
||||
use crate::json::error::Error as JsonError;
|
||||
@@ -47,13 +45,13 @@ pub fn get_json(json_value: &OwnedValue, indent: Option<&str>) -> crate::Result<
|
||||
None => to_string(&json_val)?,
|
||||
};
|
||||
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(json))))
|
||||
Ok(OwnedValue::Text(Text::json(&json)))
|
||||
}
|
||||
OwnedValue::Blob(b) => {
|
||||
// TODO: use get_json_value after we implement a single Struct
|
||||
// to represent both JSON and JSONB
|
||||
if let Ok(json) = jsonb::from_slice(b) {
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(json.to_string()))))
|
||||
Ok(OwnedValue::Text(Text::json(&json.to_string())))
|
||||
} else {
|
||||
crate::bail_parse_error!("malformed JSON");
|
||||
}
|
||||
@@ -66,7 +64,7 @@ pub fn get_json(json_value: &OwnedValue, indent: Option<&str>) -> crate::Result<
|
||||
None => to_string(&json_val)?,
|
||||
};
|
||||
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(json))))
|
||||
Ok(OwnedValue::Text(Text::json(&json)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +128,7 @@ pub fn json_array(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
}
|
||||
|
||||
s.push(']');
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(s))))
|
||||
Ok(OwnedValue::Text(Text::json(&s)))
|
||||
}
|
||||
|
||||
pub fn json_array_length(
|
||||
@@ -209,7 +207,7 @@ pub fn json_arrow_extract(value: &OwnedValue, path: &OwnedValue) -> crate::Resul
|
||||
if let Some(val) = extracted {
|
||||
let json = to_string(val)?;
|
||||
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(json))))
|
||||
Ok(OwnedValue::Text(Text::json(&json)))
|
||||
} else {
|
||||
Ok(OwnedValue::Null)
|
||||
}
|
||||
@@ -273,7 +271,7 @@ pub fn json_extract(value: &OwnedValue, paths: &[OwnedValue]) -> crate::Result<O
|
||||
result.pop(); // remove the final comma
|
||||
result.push(']');
|
||||
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(result))))
|
||||
Ok(OwnedValue::Text(Text::json(&result)))
|
||||
}
|
||||
|
||||
/// Returns a value with type defined by SQLite documentation:
|
||||
@@ -304,9 +302,9 @@ fn convert_json_to_db_type(extracted: &Val, all_as_db: bool) -> crate::Result<Ow
|
||||
_ => {
|
||||
let json = to_string(&extracted)?;
|
||||
if all_as_db {
|
||||
Ok(OwnedValue::Text(Text::new(Rc::new(json))))
|
||||
Ok(OwnedValue::build_text(&json))
|
||||
} else {
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(json))))
|
||||
Ok(OwnedValue::Text(Text::json(&json)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,7 +366,7 @@ pub fn json_type(value: &OwnedValue, path: Option<&OwnedValue>) -> crate::Result
|
||||
Val::Removed => unreachable!(),
|
||||
};
|
||||
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(val.to_string()))))
|
||||
Ok(OwnedValue::Text(Text::json(val)))
|
||||
}
|
||||
|
||||
/// Returns the value at the given JSON path. If the path does not exist, it returns None.
|
||||
@@ -656,7 +654,7 @@ pub fn json_object(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
.collect::<Result<IndexMap<String, Val>, _>>()?;
|
||||
|
||||
let result = crate::json::to_string(&value_map)?;
|
||||
Ok(OwnedValue::Text(Text::json(Rc::new(result))))
|
||||
Ok(OwnedValue::Text(Text::json(&result)))
|
||||
}
|
||||
|
||||
pub fn is_json_valid(json_value: &OwnedValue) -> crate::Result<OwnedValue> {
|
||||
@@ -698,13 +696,13 @@ pub fn json_quote(value: &OwnedValue) -> crate::Result<OwnedValue> {
|
||||
}
|
||||
escaped_value.push('"');
|
||||
|
||||
Ok(OwnedValue::Text(Text::new(Rc::new(escaped_value))))
|
||||
Ok(OwnedValue::build_text(&escaped_value))
|
||||
}
|
||||
// Numbers are unquoted in json
|
||||
OwnedValue::Integer(ref int) => Ok(OwnedValue::Integer(int.to_owned())),
|
||||
OwnedValue::Float(ref float) => Ok(OwnedValue::Float(float.to_owned())),
|
||||
OwnedValue::Blob(_) => crate::bail_constraint_error!("JSON cannot hold BLOB values"),
|
||||
OwnedValue::Null => Ok(OwnedValue::Text(Text::new(Rc::new("null".to_string())))),
|
||||
OwnedValue::Null => Ok(OwnedValue::build_text("null")),
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
@@ -713,12 +711,14 @@ pub fn json_quote(value: &OwnedValue) -> crate::Result<OwnedValue> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::*;
|
||||
use crate::types::OwnedValue;
|
||||
|
||||
#[test]
|
||||
fn test_get_json_valid_json5() {
|
||||
let input = OwnedValue::build_text(Rc::new("{ key: 'value' }".to_string()));
|
||||
let input = OwnedValue::build_text("{ key: 'value' }");
|
||||
let result = get_json(&input, None).unwrap();
|
||||
if let OwnedValue::Text(result_str) = result {
|
||||
assert!(result_str.as_str().contains("\"key\":\"value\""));
|
||||
@@ -730,7 +730,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_json_valid_json5_double_single_quotes() {
|
||||
let input = OwnedValue::build_text(Rc::new("{ key: ''value'' }".to_string()));
|
||||
let input = OwnedValue::build_text("{ key: ''value'' }");
|
||||
let result = get_json(&input, None).unwrap();
|
||||
if let OwnedValue::Text(result_str) = result {
|
||||
assert!(result_str.as_str().contains("\"key\":\"value\""));
|
||||
@@ -742,7 +742,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_json_valid_json5_infinity() {
|
||||
let input = OwnedValue::build_text(Rc::new("{ \"key\": Infinity }".to_string()));
|
||||
let input = OwnedValue::build_text("{ \"key\": Infinity }");
|
||||
let result = get_json(&input, None).unwrap();
|
||||
if let OwnedValue::Text(result_str) = result {
|
||||
assert!(result_str.as_str().contains("{\"key\":9e999}"));
|
||||
@@ -754,7 +754,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_json_valid_json5_negative_infinity() {
|
||||
let input = OwnedValue::build_text(Rc::new("{ \"key\": -Infinity }".to_string()));
|
||||
let input = OwnedValue::build_text("{ \"key\": -Infinity }");
|
||||
let result = get_json(&input, None).unwrap();
|
||||
if let OwnedValue::Text(result_str) = result {
|
||||
assert!(result_str.as_str().contains("{\"key\":-9e999}"));
|
||||
@@ -766,7 +766,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_json_valid_json5_nan() {
|
||||
let input = OwnedValue::build_text(Rc::new("{ \"key\": NaN }".to_string()));
|
||||
let input = OwnedValue::build_text("{ \"key\": NaN }");
|
||||
let result = get_json(&input, None).unwrap();
|
||||
if let OwnedValue::Text(result_str) = result {
|
||||
assert!(result_str.as_str().contains("{\"key\":null}"));
|
||||
@@ -778,7 +778,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_json_invalid_json5() {
|
||||
let input = OwnedValue::build_text(Rc::new("{ key: value }".to_string()));
|
||||
let input = OwnedValue::build_text("{ key: value }");
|
||||
let result = get_json(&input, None);
|
||||
match result {
|
||||
Ok(_) => panic!("Expected error for malformed JSON"),
|
||||
@@ -788,7 +788,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_json_valid_jsonb() {
|
||||
let input = OwnedValue::build_text(Rc::new("{\"key\":\"value\"}".to_string()));
|
||||
let input = OwnedValue::build_text("{\"key\":\"value\"}");
|
||||
let result = get_json(&input, None).unwrap();
|
||||
if let OwnedValue::Text(result_str) = result {
|
||||
assert!(result_str.as_str().contains("\"key\":\"value\""));
|
||||
@@ -800,7 +800,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_json_invalid_jsonb() {
|
||||
let input = OwnedValue::build_text(Rc::new("{key:\"value\"".to_string()));
|
||||
let input = OwnedValue::build_text("{key:\"value\"");
|
||||
let result = get_json(&input, None);
|
||||
match result {
|
||||
Ok(_) => panic!("Expected error for malformed JSON"),
|
||||
@@ -845,8 +845,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_simple() {
|
||||
let text = OwnedValue::build_text(Rc::new("value1".to_string()));
|
||||
let json = OwnedValue::Text(Text::json(Rc::new("\"value2\"".to_string())));
|
||||
let text = OwnedValue::build_text("value1");
|
||||
let json = OwnedValue::Text(Text::json("\"value2\""));
|
||||
let input = vec![text, json, OwnedValue::Integer(1), OwnedValue::Float(1.1)];
|
||||
|
||||
let result = json_array(&input).unwrap();
|
||||
@@ -887,7 +887,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length() {
|
||||
let input = OwnedValue::build_text(Rc::new("[1,2,3,4]".to_string()));
|
||||
let input = OwnedValue::build_text("[1,2,3,4]");
|
||||
let result = json_array_length(&input, None).unwrap();
|
||||
if let OwnedValue::Integer(res) = result {
|
||||
assert_eq!(res, 4);
|
||||
@@ -898,7 +898,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_empty() {
|
||||
let input = OwnedValue::build_text(Rc::new("[]".to_string()));
|
||||
let input = OwnedValue::build_text("[]");
|
||||
let result = json_array_length(&input, None).unwrap();
|
||||
if let OwnedValue::Integer(res) = result {
|
||||
assert_eq!(res, 0);
|
||||
@@ -909,12 +909,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_root() {
|
||||
let input = OwnedValue::build_text(Rc::new("[1,2,3,4]".to_string()));
|
||||
let result = json_array_length(
|
||||
&input,
|
||||
Some(&OwnedValue::build_text(Rc::new("$".to_string()))),
|
||||
)
|
||||
.unwrap();
|
||||
let input = OwnedValue::build_text("[1,2,3,4]");
|
||||
let result = json_array_length(&input, Some(&OwnedValue::build_text("$"))).unwrap();
|
||||
if let OwnedValue::Integer(res) = result {
|
||||
assert_eq!(res, 4);
|
||||
} else {
|
||||
@@ -924,7 +920,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_not_array() {
|
||||
let input = OwnedValue::build_text(Rc::new("{one: [1,2,3,4]}".to_string()));
|
||||
let input = OwnedValue::build_text("{one: [1,2,3,4]}");
|
||||
let result = json_array_length(&input, None).unwrap();
|
||||
if let OwnedValue::Integer(res) = result {
|
||||
assert_eq!(res, 0);
|
||||
@@ -935,12 +931,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_via_prop() {
|
||||
let input = OwnedValue::build_text(Rc::new("{one: [1,2,3,4]}".to_string()));
|
||||
let result = json_array_length(
|
||||
&input,
|
||||
Some(&OwnedValue::build_text(Rc::new("$.one".to_string()))),
|
||||
)
|
||||
.unwrap();
|
||||
let input = OwnedValue::build_text("{one: [1,2,3,4]}");
|
||||
let result = json_array_length(&input, Some(&OwnedValue::build_text("$.one"))).unwrap();
|
||||
if let OwnedValue::Integer(res) = result {
|
||||
assert_eq!(res, 4);
|
||||
} else {
|
||||
@@ -950,12 +942,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_via_index() {
|
||||
let input = OwnedValue::build_text(Rc::new("[[1,2,3,4]]".to_string()));
|
||||
let result = json_array_length(
|
||||
&input,
|
||||
Some(&OwnedValue::build_text(Rc::new("$[0]".to_string()))),
|
||||
)
|
||||
.unwrap();
|
||||
let input = OwnedValue::build_text("[[1,2,3,4]]");
|
||||
let result = json_array_length(&input, Some(&OwnedValue::build_text("$[0]"))).unwrap();
|
||||
if let OwnedValue::Integer(res) = result {
|
||||
assert_eq!(res, 4);
|
||||
} else {
|
||||
@@ -965,12 +953,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_via_index_not_array() {
|
||||
let input = OwnedValue::build_text(Rc::new("[1,2,3,4]".to_string()));
|
||||
let result = json_array_length(
|
||||
&input,
|
||||
Some(&OwnedValue::build_text(Rc::new("$[2]".to_string()))),
|
||||
)
|
||||
.unwrap();
|
||||
let input = OwnedValue::build_text("[1,2,3,4]");
|
||||
let result = json_array_length(&input, Some(&OwnedValue::build_text("$[2]"))).unwrap();
|
||||
if let OwnedValue::Integer(res) = result {
|
||||
assert_eq!(res, 0);
|
||||
} else {
|
||||
@@ -980,18 +964,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_via_index_bad_prop() {
|
||||
let input = OwnedValue::build_text(Rc::new("{one: [1,2,3,4]}".to_string()));
|
||||
let result = json_array_length(
|
||||
&input,
|
||||
Some(&OwnedValue::build_text(Rc::new("$.two".to_string()))),
|
||||
)
|
||||
.unwrap();
|
||||
let input = OwnedValue::build_text("{one: [1,2,3,4]}");
|
||||
let result = json_array_length(&input, Some(&OwnedValue::build_text("$.two"))).unwrap();
|
||||
assert_eq!(OwnedValue::Null, result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_array_length_simple_json_subtype() {
|
||||
let input = OwnedValue::build_text(Rc::new("[1,2,3]".to_string()));
|
||||
let input = OwnedValue::build_text("[1,2,3]");
|
||||
let wrapped = get_json(&input, None).unwrap();
|
||||
let result = json_array_length(&wrapped, None).unwrap();
|
||||
|
||||
@@ -1005,8 +985,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_json_extract_missing_path() {
|
||||
let result = json_extract(
|
||||
&OwnedValue::build_text(Rc::new("{\"a\":2}".to_string())),
|
||||
&[OwnedValue::build_text(Rc::new("$.x".to_string()))],
|
||||
&OwnedValue::build_text("{\"a\":2}"),
|
||||
&[OwnedValue::build_text("$.x")],
|
||||
);
|
||||
|
||||
match result {
|
||||
@@ -1016,10 +996,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_json_extract_null_path() {
|
||||
let result = json_extract(
|
||||
&OwnedValue::build_text(Rc::new("{\"a\":2}".to_string())),
|
||||
&[OwnedValue::Null],
|
||||
);
|
||||
let result = json_extract(&OwnedValue::build_text("{\"a\":2}"), &[OwnedValue::Null]);
|
||||
|
||||
match result {
|
||||
Ok(OwnedValue::Null) => (),
|
||||
@@ -1030,7 +1007,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_json_path_invalid() {
|
||||
let result = json_extract(
|
||||
&OwnedValue::build_text(Rc::new("{\"a\":2}".to_string())),
|
||||
&OwnedValue::build_text("{\"a\":2}"),
|
||||
&[OwnedValue::Float(1.1)],
|
||||
);
|
||||
|
||||
@@ -1042,28 +1019,28 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_error_position_no_error() {
|
||||
let input = OwnedValue::build_text(Rc::new("[1,2,3]".to_string()));
|
||||
let input = OwnedValue::build_text("[1,2,3]");
|
||||
let result = json_error_position(&input).unwrap();
|
||||
assert_eq!(result, OwnedValue::Integer(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_error_position_no_error_more() {
|
||||
let input = OwnedValue::build_text(Rc::new(r#"{"a":55,"b":72 , }"#.to_string()));
|
||||
let input = OwnedValue::build_text(r#"{"a":55,"b":72 , }"#);
|
||||
let result = json_error_position(&input).unwrap();
|
||||
assert_eq!(result, OwnedValue::Integer(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_error_position_object() {
|
||||
let input = OwnedValue::build_text(Rc::new(r#"{"a":55,"b":72,,}"#.to_string()));
|
||||
let input = OwnedValue::build_text(r#"{"a":55,"b":72,,}"#);
|
||||
let result = json_error_position(&input).unwrap();
|
||||
assert_eq!(result, OwnedValue::Integer(16));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_error_position_array() {
|
||||
let input = OwnedValue::build_text(Rc::new(r#"["a",55,"b",72,,]"#.to_string()));
|
||||
let input = OwnedValue::build_text(r#"["a",55,"b",72,,]"#);
|
||||
let result = json_error_position(&input).unwrap();
|
||||
assert_eq!(result, OwnedValue::Integer(16));
|
||||
}
|
||||
@@ -1098,8 +1075,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_object_simple() {
|
||||
let key = OwnedValue::build_text(Rc::new("key".to_string()));
|
||||
let value = OwnedValue::build_text(Rc::new("value".to_string()));
|
||||
let key = OwnedValue::build_text("key");
|
||||
let value = OwnedValue::build_text("value");
|
||||
let input = vec![key, value];
|
||||
|
||||
let result = json_object(&input).unwrap();
|
||||
@@ -1111,17 +1088,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_object_multiple_values() {
|
||||
let text_key = OwnedValue::build_text(Rc::new("text_key".to_string()));
|
||||
let text_value = OwnedValue::build_text(Rc::new("text_value".to_string()));
|
||||
let json_key = OwnedValue::build_text(Rc::new("json_key".to_string()));
|
||||
let json_value = OwnedValue::Text(Text::json(Rc::new(
|
||||
r#"{"json":"value","number":1}"#.to_string(),
|
||||
)));
|
||||
let integer_key = OwnedValue::build_text(Rc::new("integer_key".to_string()));
|
||||
let text_key = OwnedValue::build_text("text_key");
|
||||
let text_value = OwnedValue::build_text("text_value");
|
||||
let json_key = OwnedValue::build_text("json_key");
|
||||
let json_value = OwnedValue::Text(Text::json(r#"{"json":"value","number":1}"#));
|
||||
let integer_key = OwnedValue::build_text("integer_key");
|
||||
let integer_value = OwnedValue::Integer(1);
|
||||
let float_key = OwnedValue::build_text(Rc::new("float_key".to_string()));
|
||||
let float_key = OwnedValue::build_text("float_key");
|
||||
let float_value = OwnedValue::Float(1.1);
|
||||
let null_key = OwnedValue::build_text(Rc::new("null_key".to_string()));
|
||||
let null_key = OwnedValue::build_text("null_key");
|
||||
let null_value = OwnedValue::Null;
|
||||
|
||||
let input = vec![
|
||||
@@ -1149,8 +1124,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_object_json_value_is_rendered_as_json() {
|
||||
let key = OwnedValue::build_text(Rc::new("key".to_string()));
|
||||
let value = OwnedValue::Text(Text::json(Rc::new(r#"{"json":"value"}"#.to_string())));
|
||||
let key = OwnedValue::build_text("key");
|
||||
let value = OwnedValue::Text(Text::json(r#"{"json":"value"}"#));
|
||||
let input = vec![key, value];
|
||||
|
||||
let result = json_object(&input).unwrap();
|
||||
@@ -1162,8 +1137,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_object_json_text_value_is_rendered_as_regular_text() {
|
||||
let key = OwnedValue::build_text(Rc::new("key".to_string()));
|
||||
let value = OwnedValue::Text(Text::new(Rc::new(r#"{"json":"value"}"#.to_string())));
|
||||
let key = OwnedValue::build_text("key");
|
||||
let value = OwnedValue::Text(Text::new(r#"{"json":"value"}"#));
|
||||
let input = vec![key, value];
|
||||
|
||||
let result = json_object(&input).unwrap();
|
||||
@@ -1175,11 +1150,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_object_nested() {
|
||||
let key = OwnedValue::build_text(Rc::new("key".to_string()));
|
||||
let value = OwnedValue::build_text(Rc::new("value".to_string()));
|
||||
let key = OwnedValue::build_text("key");
|
||||
let value = OwnedValue::build_text("value");
|
||||
let input = vec![key, value];
|
||||
|
||||
let parent_key = OwnedValue::build_text(Rc::new("parent_key".to_string()));
|
||||
let parent_key = OwnedValue::build_text("parent_key");
|
||||
let parent_value = json_object(&input).unwrap();
|
||||
let parent_input = vec![parent_key, parent_value];
|
||||
|
||||
@@ -1193,8 +1168,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_object_duplicated_keys() {
|
||||
let key = OwnedValue::build_text(Rc::new("key".to_string()));
|
||||
let value = OwnedValue::build_text(Rc::new("value".to_string()));
|
||||
let key = OwnedValue::build_text("key");
|
||||
let value = OwnedValue::build_text("value");
|
||||
let input = vec![key.clone(), value.clone(), key, value];
|
||||
|
||||
let result = json_object(&input).unwrap();
|
||||
@@ -1218,7 +1193,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_json_object_non_text_key() {
|
||||
let key = OwnedValue::Integer(1);
|
||||
let value = OwnedValue::build_text(Rc::new("value".to_string()));
|
||||
let value = OwnedValue::build_text("value");
|
||||
let input = vec![key, value];
|
||||
|
||||
match json_object(&input) {
|
||||
@@ -1229,8 +1204,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_odd_number_of_values() {
|
||||
let key = OwnedValue::build_text(Rc::new("key".to_string()));
|
||||
let value = OwnedValue::build_text(Rc::new("value".to_string()));
|
||||
let key = OwnedValue::build_text("key");
|
||||
let value = OwnedValue::build_text("value");
|
||||
let input = vec![key.clone(), value, key];
|
||||
|
||||
match json_object(&input) {
|
||||
@@ -1337,7 +1312,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_root_strict() {
|
||||
let path = OwnedValue::Text(Text::new(Rc::new("$".to_string())));
|
||||
let path = OwnedValue::Text(Text::new("$"));
|
||||
|
||||
let result = json_path_from_owned_value(&path, true);
|
||||
assert!(result.is_ok());
|
||||
@@ -1354,7 +1329,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_root_non_strict() {
|
||||
let path = OwnedValue::Text(Text::new(Rc::new("$".to_string())));
|
||||
let path = OwnedValue::Text(Text::new("$"));
|
||||
|
||||
let result = json_path_from_owned_value(&path, false);
|
||||
assert!(result.is_ok());
|
||||
@@ -1371,14 +1346,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_named_strict() {
|
||||
let path = OwnedValue::Text(Text::new(Rc::new("field".to_string())));
|
||||
let path = OwnedValue::Text(Text::new("field"));
|
||||
|
||||
assert!(json_path_from_owned_value(&path, true).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_path_from_owned_value_named_non_strict() {
|
||||
let path = OwnedValue::Text(Text::new(Rc::new("field".to_string())));
|
||||
let path = OwnedValue::Text(Text::new("field"));
|
||||
|
||||
let result = json_path_from_owned_value(&path, false);
|
||||
assert!(result.is_ok());
|
||||
@@ -1465,10 +1440,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_json_set_field_empty_object() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("{}".to_string())),
|
||||
&OwnedValue::build_text("{}"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$.field".to_string())),
|
||||
OwnedValue::build_text(Rc::new("value".to_string())),
|
||||
OwnedValue::build_text("$.field"),
|
||||
OwnedValue::build_text("value"),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1476,17 +1451,17 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(r#"{"field":"value"}"#.to_string()))
|
||||
OwnedValue::build_text(r#"{"field":"value"}"#)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_replace_field() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new(r#"{"field":"old_value"}"#.to_string())),
|
||||
&OwnedValue::build_text(r#"{"field":"old_value"}"#),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$.field".to_string())),
|
||||
OwnedValue::build_text(Rc::new("new_value".to_string())),
|
||||
OwnedValue::build_text("$.field"),
|
||||
OwnedValue::build_text("new_value"),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1494,17 +1469,17 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(r#"{"field":"new_value"}"#.to_string()))
|
||||
OwnedValue::build_text(r#"{"field":"new_value"}"#)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_set_deeply_nested_key() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("{}".to_string())),
|
||||
&OwnedValue::build_text("{}"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$.object.doesnt.exist".to_string())),
|
||||
OwnedValue::build_text(Rc::new("value".to_string())),
|
||||
OwnedValue::build_text("$.object.doesnt.exist"),
|
||||
OwnedValue::build_text("value"),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1512,36 +1487,31 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(
|
||||
r#"{"object":{"doesnt":{"exist":"value"}}}"#.to_string()
|
||||
))
|
||||
OwnedValue::build_text(r#"{"object":{"doesnt":{"exist":"value"}}}"#)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_add_value_to_empty_array() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("[]".to_string())),
|
||||
&OwnedValue::build_text("[]"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$[0]".to_string())),
|
||||
OwnedValue::build_text(Rc::new("value".to_string())),
|
||||
OwnedValue::build_text("$[0]"),
|
||||
OwnedValue::build_text("value"),
|
||||
],
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(r#"["value"]"#.to_string()))
|
||||
);
|
||||
assert_eq!(result.unwrap(), OwnedValue::build_text(r#"["value"]"#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_add_value_to_nonexistent_array() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("{}".to_string())),
|
||||
&OwnedValue::build_text("{}"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$.some_array[0]".to_string())),
|
||||
OwnedValue::build_text("$.some_array[0]"),
|
||||
OwnedValue::Integer(123),
|
||||
],
|
||||
);
|
||||
@@ -1550,104 +1520,80 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(r#"{"some_array":[123]}"#.to_string()))
|
||||
OwnedValue::build_text(r#"{"some_array":[123]}"#)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_add_value_to_array() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("[123]".to_string())),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$[1]".to_string())),
|
||||
OwnedValue::Integer(456),
|
||||
],
|
||||
&OwnedValue::build_text("[123]"),
|
||||
&[OwnedValue::build_text("$[1]"), OwnedValue::Integer(456)],
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new("[123,456]".to_string()))
|
||||
);
|
||||
assert_eq!(result.unwrap(), OwnedValue::build_text("[123,456]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_add_value_to_array_out_of_bounds() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("[123]".to_string())),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$[200]".to_string())),
|
||||
OwnedValue::Integer(456),
|
||||
],
|
||||
&OwnedValue::build_text("[123]"),
|
||||
&[OwnedValue::build_text("$[200]"), OwnedValue::Integer(456)],
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new("[123]".to_string()))
|
||||
);
|
||||
assert_eq!(result.unwrap(), OwnedValue::build_text("[123]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_replace_value_in_array() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("[123]".to_string())),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$[0]".to_string())),
|
||||
OwnedValue::Integer(456),
|
||||
],
|
||||
&OwnedValue::build_text("[123]"),
|
||||
&[OwnedValue::build_text("$[0]"), OwnedValue::Integer(456)],
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new("[456]".to_string()))
|
||||
);
|
||||
assert_eq!(result.unwrap(), OwnedValue::build_text("[456]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_null_path() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("{}".to_string())),
|
||||
&OwnedValue::build_text("{}"),
|
||||
&[OwnedValue::Null, OwnedValue::Integer(456)],
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new("{}".to_string()))
|
||||
);
|
||||
assert_eq!(result.unwrap(), OwnedValue::build_text("{}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_multiple_keys() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("[123]".to_string())),
|
||||
&OwnedValue::build_text("[123]"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$[0]".to_string())),
|
||||
OwnedValue::build_text("$[0]"),
|
||||
OwnedValue::Integer(456),
|
||||
OwnedValue::build_text(Rc::new("$[1]".to_string())),
|
||||
OwnedValue::build_text("$[1]"),
|
||||
OwnedValue::Integer(789),
|
||||
],
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new("[456,789]".to_string()))
|
||||
);
|
||||
assert_eq!(result.unwrap(), OwnedValue::build_text("[456,789]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_missing_value() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("[123]".to_string())),
|
||||
&[OwnedValue::build_text(Rc::new("$[0]".to_string()))],
|
||||
&OwnedValue::build_text("[123]"),
|
||||
&[OwnedValue::build_text("$[0]")],
|
||||
);
|
||||
|
||||
assert!(result.is_err());
|
||||
@@ -1656,9 +1602,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_json_set_add_array_in_nested_object() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("{}".to_string())),
|
||||
&OwnedValue::build_text("{}"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$.object[0].field".to_string())),
|
||||
OwnedValue::build_text("$.object[0].field"),
|
||||
OwnedValue::Integer(123),
|
||||
],
|
||||
);
|
||||
@@ -1667,16 +1613,16 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(r#"{"object":[{"field":123}]}"#.to_string()))
|
||||
OwnedValue::build_text(r#"{"object":[{"field":123}]}"#)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_add_array_in_array_in_nested_object() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("{}".to_string())),
|
||||
&OwnedValue::build_text("{}"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$.object[0][0]".to_string())),
|
||||
OwnedValue::build_text("$.object[0][0]"),
|
||||
OwnedValue::Integer(123),
|
||||
],
|
||||
);
|
||||
@@ -1685,19 +1631,19 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(r#"{"object":[[123]]}"#.to_string()))
|
||||
OwnedValue::build_text(r#"{"object":[[123]]}"#)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_set_add_array_in_array_in_nested_object_out_of_bounds() {
|
||||
let result = json_set(
|
||||
&OwnedValue::build_text(Rc::new("{}".to_string())),
|
||||
&OwnedValue::build_text("{}"),
|
||||
&[
|
||||
OwnedValue::build_text(Rc::new("$.object[123].another".to_string())),
|
||||
OwnedValue::build_text(Rc::new("value".to_string())),
|
||||
OwnedValue::build_text(Rc::new("$.field".to_string())),
|
||||
OwnedValue::build_text(Rc::new("value".to_string())),
|
||||
OwnedValue::build_text("$.object[123].another"),
|
||||
OwnedValue::build_text("value"),
|
||||
OwnedValue::build_text("$.field"),
|
||||
OwnedValue::build_text("value"),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1705,7 +1651,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
result.unwrap(),
|
||||
OwnedValue::build_text(Rc::new(r#"{"field":"value"}"#.to_string()))
|
||||
OwnedValue::build_text(r#"{"field":"value"}"#)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1418,7 +1418,7 @@ mod tests {
|
||||
#[case(&[], SerialType::ConstInt0, OwnedValue::Integer(0))]
|
||||
#[case(&[], SerialType::ConstInt1, OwnedValue::Integer(1))]
|
||||
#[case(&[1, 2, 3], SerialType::Blob(3), OwnedValue::Blob(vec![1, 2, 3].into()))]
|
||||
#[case(&[65, 66, 67], SerialType::String(3), OwnedValue::build_text("ABC".to_string().into()))]
|
||||
#[case(&[65, 66, 67], SerialType::String(3), OwnedValue::build_text("ABC"))]
|
||||
fn test_read_value(
|
||||
#[case] buf: &[u8],
|
||||
#[case] serial_type: SerialType,
|
||||
|
||||
@@ -56,17 +56,17 @@ pub struct Text {
|
||||
|
||||
impl Text {
|
||||
pub fn from_str<S: Into<String>>(value: S) -> Self {
|
||||
Self::new(Rc::new(value.into()))
|
||||
Self::new(&value.into())
|
||||
}
|
||||
|
||||
pub fn new(value: Rc<String>) -> Self {
|
||||
pub fn new(value: &str) -> Self {
|
||||
Self {
|
||||
value: Rc::new(value.as_bytes().to_vec()),
|
||||
subtype: TextSubtype::Text,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn json(value: Rc<String>) -> Self {
|
||||
pub fn json(value: &str) -> Self {
|
||||
Self {
|
||||
value: Rc::new(value.as_bytes().to_vec()),
|
||||
subtype: TextSubtype::Json,
|
||||
@@ -91,7 +91,7 @@ pub enum OwnedValue {
|
||||
|
||||
impl OwnedValue {
|
||||
// A helper function that makes building a text OwnedValue easier.
|
||||
pub fn build_text(text: Rc<String>) -> Self {
|
||||
pub fn build_text(text: &str) -> Self {
|
||||
Self::Text(Text::new(text))
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ impl OwnedValue {
|
||||
}
|
||||
|
||||
pub fn from_text(text: &str) -> Self {
|
||||
OwnedValue::Text(Text::new(Rc::new(text.to_string())))
|
||||
OwnedValue::Text(Text::new(text))
|
||||
}
|
||||
|
||||
pub fn value_type(&self) -> OwnedValueType {
|
||||
@@ -242,7 +242,7 @@ impl OwnedValue {
|
||||
let Some(text) = v.to_text() else {
|
||||
return Ok(OwnedValue::Null);
|
||||
};
|
||||
Ok(OwnedValue::build_text(Rc::new(text.to_string())))
|
||||
Ok(OwnedValue::build_text(text))
|
||||
}
|
||||
ExtValueType::Blob => {
|
||||
let Some(blob) = v.to_blob() else {
|
||||
@@ -381,22 +381,22 @@ impl std::ops::Add<OwnedValue> for OwnedValue {
|
||||
(Self::Float(float_left), Self::Float(float_right)) => {
|
||||
Self::Float(float_left + float_right)
|
||||
}
|
||||
(Self::Text(string_left), Self::Text(string_right)) => Self::build_text(Rc::new(
|
||||
string_left.as_str().to_string() + &string_right.as_str(),
|
||||
)),
|
||||
(Self::Text(string_left), Self::Integer(int_right)) => Self::build_text(Rc::new(
|
||||
string_left.as_str().to_string() + &int_right.to_string(),
|
||||
)),
|
||||
(Self::Text(string_left), Self::Text(string_right)) => {
|
||||
Self::build_text(&(string_left.as_str().to_string() + string_right.as_str()))
|
||||
}
|
||||
(Self::Text(string_left), Self::Integer(int_right)) => {
|
||||
Self::build_text(&(string_left.as_str().to_string() + &int_right.to_string()))
|
||||
}
|
||||
(Self::Integer(int_left), Self::Text(string_right)) => {
|
||||
Self::build_text(Rc::new(int_left.to_string() + &string_right.as_str()))
|
||||
Self::build_text(&(int_left.to_string() + string_right.as_str()))
|
||||
}
|
||||
(Self::Text(string_left), Self::Float(float_right)) => {
|
||||
let string_right = Self::Float(float_right).to_string();
|
||||
Self::build_text(Rc::new(string_left.as_str().to_string() + &string_right))
|
||||
Self::build_text(&(string_left.as_str().to_string() + &string_right))
|
||||
}
|
||||
(Self::Float(float_left), Self::Text(string_right)) => {
|
||||
let string_left = Self::Float(float_left).to_string();
|
||||
Self::build_text(Rc::new(string_left + &string_right.as_str()))
|
||||
Self::build_text(&(string_left + string_right.as_str()))
|
||||
}
|
||||
(lhs, Self::Null) => lhs,
|
||||
(Self::Null, rhs) => rhs,
|
||||
@@ -865,8 +865,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_serialize_text() {
|
||||
let text = Rc::new("hello".to_string());
|
||||
let record = Record::new(vec![OwnedValue::Text(Text::new(text.clone()))]);
|
||||
let text = "hello";
|
||||
let record = Record::new(vec![OwnedValue::Text(Text::new(text))]);
|
||||
let mut buf = Vec::new();
|
||||
record.serialize(&mut buf);
|
||||
|
||||
@@ -903,12 +903,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_serialize_mixed_types() {
|
||||
let text = Rc::new("test".to_string());
|
||||
let text = "test";
|
||||
let record = Record::new(vec![
|
||||
OwnedValue::Null,
|
||||
OwnedValue::Integer(42),
|
||||
OwnedValue::Float(3.15),
|
||||
OwnedValue::Text(Text::new(text.clone())),
|
||||
OwnedValue::Text(Text::new(text)),
|
||||
]);
|
||||
let mut buf = Vec::new();
|
||||
record.serialize(&mut buf);
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
target_pc.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("Start at {}", target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -26,7 +26,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]+r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -35,7 +35,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]-r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -44,7 +44,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]*r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -53,7 +53,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]/r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -62,7 +62,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]&r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -71,7 +71,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]|r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -80,7 +80,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=~r[{}]", dest, reg),
|
||||
),
|
||||
@@ -93,7 +93,7 @@ pub fn insn_to_str(
|
||||
*database as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=~r[{}]", dest, database),
|
||||
),
|
||||
@@ -102,7 +102,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]%r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -111,7 +111,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
*dest as i32,
|
||||
dest_end.map_or(0, |end| end as i32),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
dest_end.map_or(format!("r[{}]=NULL", dest), |end| {
|
||||
format!("r[{}..{}]=NULL", dest, end)
|
||||
@@ -122,7 +122,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("Set cursor {} to a (pseudo) NULL row", cursor_id),
|
||||
),
|
||||
@@ -131,7 +131,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]!=NULL -> goto {}", reg, target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -144,7 +144,7 @@ pub fn insn_to_str(
|
||||
*start_reg_a as i32,
|
||||
*start_reg_b as i32,
|
||||
*count as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"r[{}..{}]==r[{}..{}]",
|
||||
@@ -163,7 +163,7 @@ pub fn insn_to_str(
|
||||
target_pc_lt.to_debug_int(),
|
||||
target_pc_eq.to_debug_int(),
|
||||
target_pc_gt.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -176,7 +176,7 @@ pub fn insn_to_str(
|
||||
*source_reg as i32,
|
||||
*dest_reg as i32,
|
||||
*count as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"r[{}..{}]=r[{}..{}]",
|
||||
@@ -195,7 +195,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"r[{}]>0 -> r[{}]-={}, goto {}",
|
||||
@@ -215,7 +215,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
target_pc.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"if r[{}]==r[{}] goto {}",
|
||||
@@ -234,7 +234,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
target_pc.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"if r[{}]!=r[{}] goto {}",
|
||||
@@ -253,7 +253,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
target_pc.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("if r[{}]<r[{}] goto {}", lhs, rhs, target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -267,7 +267,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
target_pc.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"if r[{}]<=r[{}] goto {}",
|
||||
@@ -286,7 +286,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
target_pc.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("if r[{}]>r[{}] goto {}", lhs, rhs, target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -300,7 +300,7 @@ pub fn insn_to_str(
|
||||
*lhs as i32,
|
||||
*rhs as i32,
|
||||
target_pc.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"if r[{}]>=r[{}] goto {}",
|
||||
@@ -318,7 +318,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
*jump_if_null as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("if r[{}] goto {}", reg, target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -331,7 +331,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
*jump_if_null as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("if !r[{}] goto {}", reg, target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -343,7 +343,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*root_page as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"table={}, root={}",
|
||||
@@ -359,7 +359,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -368,7 +368,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -377,7 +377,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -391,7 +391,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
pc_if_empty.to_debug_int(),
|
||||
*arg_count as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -404,7 +404,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*column as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -416,7 +416,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
pc_if_next.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -429,7 +429,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*content_reg as i32,
|
||||
*num_fields as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("{} columns in r[{}]", num_fields, content_reg),
|
||||
),
|
||||
@@ -438,7 +438,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -450,7 +450,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
pc_if_empty.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"Rewind table {}",
|
||||
@@ -487,7 +487,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*column as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"r[{}]={}.{}",
|
||||
@@ -508,7 +508,7 @@ pub fn insn_to_str(
|
||||
*start_reg as i32,
|
||||
*count as i32,
|
||||
*dest_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"r[{}]=mkrec(r[{}..{}])",
|
||||
@@ -522,7 +522,7 @@ pub fn insn_to_str(
|
||||
*start_reg as i32,
|
||||
*count as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
if *count == 1 {
|
||||
format!("output=r[{}]", start_reg)
|
||||
@@ -535,7 +535,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -547,7 +547,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
pc_if_next.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -559,7 +559,7 @@ pub fn insn_to_str(
|
||||
*err_code as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -568,7 +568,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
*write as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -577,7 +577,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
target_pc.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -589,7 +589,7 @@ pub fn insn_to_str(
|
||||
*return_reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -598,7 +598,7 @@ pub fn insn_to_str(
|
||||
*return_reg as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -607,7 +607,7 @@ pub fn insn_to_str(
|
||||
*value as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]={}", dest, value),
|
||||
),
|
||||
@@ -625,7 +625,7 @@ pub fn insn_to_str(
|
||||
*register as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -634,7 +634,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new(value.clone())),
|
||||
OwnedValue::build_text(value),
|
||||
0,
|
||||
format!("r[{}]='{}'", dest, value),
|
||||
),
|
||||
@@ -657,7 +657,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"r[{}]={}.rowid",
|
||||
@@ -677,7 +677,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*src_reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"if (r[{}]!={}.rowid) goto {}",
|
||||
@@ -697,7 +697,7 @@ pub fn insn_to_str(
|
||||
*index_cursor_id as i32,
|
||||
*table_cursor_id as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -712,7 +712,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
target_pc.to_debug_int(),
|
||||
*start_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -727,7 +727,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
target_pc.to_debug_int(),
|
||||
*start_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -741,7 +741,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
target_pc.to_debug_int(),
|
||||
*start_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -755,7 +755,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
target_pc.to_debug_int(),
|
||||
*start_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -764,7 +764,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("if (--r[{}]==0) goto {}", reg, target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -778,7 +778,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
*col as i32,
|
||||
*acc_reg as i32,
|
||||
OwnedValue::build_text(Rc::new(func.to_string().into())),
|
||||
OwnedValue::build_text(func.to_string()),
|
||||
0,
|
||||
format!("accum=r[{}] step(r[{}])", *acc_reg, *col),
|
||||
),
|
||||
@@ -787,7 +787,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
*register as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new(func.to_string().into())),
|
||||
OwnedValue::build_text(func.to_string()),
|
||||
0,
|
||||
format!("accum=r[{}]", *register),
|
||||
),
|
||||
@@ -816,11 +816,9 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*columns as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new(format!(
|
||||
"k({},{})",
|
||||
order.values.len(),
|
||||
to_print.join(",")
|
||||
))),
|
||||
OwnedValue::build_text(
|
||||
&(format!("k({},{})", order.values.len(), to_print.join(","))),
|
||||
),
|
||||
0,
|
||||
format!("cursor={}", cursor_id),
|
||||
)
|
||||
@@ -834,7 +832,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*dest_reg as i32,
|
||||
*pseudo_cursor as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=data", dest_reg),
|
||||
),
|
||||
@@ -858,7 +856,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
pc_if_empty.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -870,7 +868,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
pc_if_next.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -884,7 +882,7 @@ pub fn insn_to_str(
|
||||
*constant_mask,
|
||||
*start_reg as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new(func.func.to_string())),
|
||||
OwnedValue::build_text(&func.func.to_string()),
|
||||
0,
|
||||
if func.arg_count == 0 {
|
||||
format!("r[{}]=func()", dest)
|
||||
@@ -908,7 +906,7 @@ pub fn insn_to_str(
|
||||
*yield_reg as i32,
|
||||
jump_on_definition.to_debug_int(),
|
||||
start_offset.to_debug_int(),
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -917,7 +915,7 @@ pub fn insn_to_str(
|
||||
*yield_reg as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -929,7 +927,7 @@ pub fn insn_to_str(
|
||||
*yield_reg as i32,
|
||||
end_offset.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -943,7 +941,7 @@ pub fn insn_to_str(
|
||||
*cursor as i32,
|
||||
*record_reg as i32,
|
||||
*key_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
*flag as u16,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -952,7 +950,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -961,7 +959,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -970,7 +968,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -983,7 +981,7 @@ pub fn insn_to_str(
|
||||
*cursor as i32,
|
||||
*rowid_reg as i32,
|
||||
*prev_largest_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -992,7 +990,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1001,7 +999,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1014,7 +1012,7 @@ pub fn insn_to_str(
|
||||
*cursor as i32,
|
||||
target_pc.to_debug_int(),
|
||||
*rowid_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1027,7 +1025,7 @@ pub fn insn_to_str(
|
||||
*limit_reg as i32,
|
||||
*combined_reg as i32,
|
||||
*offset_reg as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"if r[{}]>0 then r[{}]=r[{}]+max(0,r[{}]) else r[{}]=(-1)",
|
||||
@@ -1042,7 +1040,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
*root_page as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1051,7 +1049,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1064,7 +1062,7 @@ pub fn insn_to_str(
|
||||
*src_reg as i32,
|
||||
*dst_reg as i32,
|
||||
*amount as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}]", dst_reg, src_reg),
|
||||
),
|
||||
@@ -1073,7 +1071,7 @@ pub fn insn_to_str(
|
||||
*db as i32,
|
||||
*root as i32,
|
||||
*flags as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=root iDb={} flags={}", root, db, flags),
|
||||
),
|
||||
@@ -1082,7 +1080,7 @@ pub fn insn_to_str(
|
||||
*cursor_id as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1091,7 +1089,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1100,7 +1098,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
target_pc.to_debug_int(),
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("if (r[{}]==NULL) goto {}", reg, target_pc.to_debug_int()),
|
||||
),
|
||||
@@ -1109,7 +1107,7 @@ pub fn insn_to_str(
|
||||
*db as i32,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new(where_clause.clone())),
|
||||
OwnedValue::build_text(where_clause),
|
||||
0,
|
||||
where_clause.clone(),
|
||||
),
|
||||
@@ -1118,7 +1116,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1127,7 +1125,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1136,7 +1134,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
@@ -1145,7 +1143,7 @@ pub fn insn_to_str(
|
||||
*rhs as i32,
|
||||
*lhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}] >> r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -1154,7 +1152,7 @@ pub fn insn_to_str(
|
||||
*rhs as i32,
|
||||
*lhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}] << r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -1163,7 +1161,7 @@ pub fn insn_to_str(
|
||||
usize::from(*index) as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=parameter({})", *dest, *index),
|
||||
),
|
||||
@@ -1172,7 +1170,7 @@ pub fn insn_to_str(
|
||||
*rg1 as i32,
|
||||
*dest as i32,
|
||||
*rg2 as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!(
|
||||
"((r[{}]=NULL)|(r[{}]=NULL)) ? r[{}]=NULL : r[{}]=0",
|
||||
@@ -1184,7 +1182,7 @@ pub fn insn_to_str(
|
||||
*reg as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=!r[{}]", dest, reg),
|
||||
),
|
||||
@@ -1193,7 +1191,7 @@ pub fn insn_to_str(
|
||||
*rhs as i32,
|
||||
*lhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=r[{}] + r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
@@ -1202,7 +1200,7 @@ pub fn insn_to_str(
|
||||
*rhs as i32,
|
||||
*lhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=(r[{}] && r[{}])", dest, lhs, rhs),
|
||||
),
|
||||
@@ -1211,7 +1209,7 @@ pub fn insn_to_str(
|
||||
*rhs as i32,
|
||||
*lhs as i32,
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
format!("r[{}]=(r[{}] || r[{}])", dest, lhs, rhs),
|
||||
),
|
||||
@@ -1220,7 +1218,7 @@ pub fn insn_to_str(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
String::new(),
|
||||
),
|
||||
@@ -1229,7 +1227,7 @@ pub fn insn_to_str(
|
||||
*db as i32,
|
||||
*dest as i32,
|
||||
0,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
OwnedValue::build_text(""),
|
||||
0,
|
||||
"".to_string(),
|
||||
),
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::num::NonZero;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::{AggFunc, BranchOffset, CursorID, FuncCtx, PageIdx};
|
||||
use crate::storage::wal::CheckpointMode;
|
||||
@@ -985,56 +984,56 @@ pub fn exec_boolean_not(mut reg: &OwnedValue) -> OwnedValue {
|
||||
pub fn exec_concat(lhs: &OwnedValue, rhs: &OwnedValue) -> OwnedValue {
|
||||
match (lhs, rhs) {
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_text.as_str().to_string() + &rhs_text.as_str()))
|
||||
OwnedValue::build_text(&(lhs_text.as_str().to_string() + rhs_text.as_str()))
|
||||
}
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Integer(rhs_int)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_text.as_str().to_string() + &rhs_int.to_string()),
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Integer(rhs_int)) => {
|
||||
OwnedValue::build_text(&(lhs_text.as_str().to_string() + &rhs_int.to_string()))
|
||||
}
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Float(rhs_float)) => {
|
||||
OwnedValue::build_text(&(lhs_text.as_str().to_string() + &rhs_float.to_string()))
|
||||
}
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(
|
||||
(lhs_text.as_str().to_string() + &rhs_agg.final_value().to_string()).as_str(),
|
||||
),
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Float(rhs_float)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_text.as_str().to_string() + &rhs_float.to_string()),
|
||||
),
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(Rc::new(
|
||||
lhs_text.as_str().to_string() + &rhs_agg.final_value().to_string(),
|
||||
)),
|
||||
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_int.to_string() + rhs_text.as_str()))
|
||||
OwnedValue::build_text(&(lhs_int.to_string() + rhs_text.as_str()))
|
||||
}
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Integer(rhs_int)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_int.to_string() + &rhs_int.to_string()))
|
||||
OwnedValue::build_text(&(lhs_int.to_string() + &rhs_int.to_string()))
|
||||
}
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Float(rhs_float)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_int.to_string() + &rhs_float.to_string()))
|
||||
OwnedValue::build_text(&(lhs_int.to_string() + &rhs_float.to_string()))
|
||||
}
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Agg(rhs_agg)) => {
|
||||
OwnedValue::build_text(&(lhs_int.to_string() + &rhs_agg.final_value().to_string()))
|
||||
}
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_int.to_string() + &rhs_agg.final_value().to_string()),
|
||||
),
|
||||
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_float.to_string() + rhs_text.as_str()))
|
||||
OwnedValue::build_text(&(lhs_float.to_string() + rhs_text.as_str()))
|
||||
}
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Integer(rhs_int)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_float.to_string() + &rhs_int.to_string()))
|
||||
OwnedValue::build_text(&(lhs_float.to_string() + &rhs_int.to_string()))
|
||||
}
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Float(rhs_float)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_float.to_string() + &rhs_float.to_string()))
|
||||
OwnedValue::build_text(&(lhs_float.to_string() + &rhs_float.to_string()))
|
||||
}
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Agg(rhs_agg)) => {
|
||||
OwnedValue::build_text(&(lhs_float.to_string() + &rhs_agg.final_value().to_string()))
|
||||
}
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_float.to_string() + &rhs_agg.final_value().to_string()),
|
||||
),
|
||||
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Text(rhs_text)) => OwnedValue::build_text(Rc::new(
|
||||
lhs_agg.final_value().to_string() + rhs_text.as_str(),
|
||||
)),
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Integer(rhs_int)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_agg.final_value().to_string() + &rhs_int.to_string()),
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(&(lhs_agg.final_value().to_string() + rhs_text.as_str()))
|
||||
}
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Integer(rhs_int)) => {
|
||||
OwnedValue::build_text(&(lhs_agg.final_value().to_string() + &rhs_int.to_string()))
|
||||
}
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Float(rhs_float)) => {
|
||||
OwnedValue::build_text(&(lhs_agg.final_value().to_string() + &rhs_float.to_string()))
|
||||
}
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(
|
||||
&(lhs_agg.final_value().to_string() + &rhs_agg.final_value().to_string()),
|
||||
),
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Float(rhs_float)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_agg.final_value().to_string() + &rhs_float.to_string()),
|
||||
),
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(Rc::new(
|
||||
lhs_agg.final_value().to_string() + &rhs_agg.final_value().to_string(),
|
||||
)),
|
||||
|
||||
(OwnedValue::Null, _) | (_, OwnedValue::Null) => OwnedValue::Null,
|
||||
(OwnedValue::Blob(_), _) | (_, OwnedValue::Blob(_)) => {
|
||||
|
||||
450
core/vdbe/mod.rs
450
core/vdbe/mod.rs
File diff suppressed because it is too large
Load Diff
@@ -56,16 +56,12 @@ pub fn vector_extract(args: &[OwnedValue]) -> Result<OwnedValue> {
|
||||
};
|
||||
|
||||
if blob.is_empty() {
|
||||
return Ok(OwnedValue::Text(crate::types::Text::new(std::rc::Rc::new(
|
||||
"[]".to_string(),
|
||||
))));
|
||||
return Ok(OwnedValue::build_text("[]"));
|
||||
}
|
||||
|
||||
let vector_type = vector_type(blob)?;
|
||||
let vector = vector_deserialize(vector_type, blob)?;
|
||||
Ok(OwnedValue::Text(crate::types::Text::new(std::rc::Rc::new(
|
||||
vector_to_text(&vector),
|
||||
))))
|
||||
Ok(OwnedValue::build_text(&vector_to_text(&vector)))
|
||||
}
|
||||
|
||||
pub fn vector_distance_cos(args: &[OwnedValue]) -> Result<OwnedValue> {
|
||||
|
||||
Reference in New Issue
Block a user