MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / plan_slice

Function plan_slice

nodedb-sql/src/planner/array_fn/table_fn.rs:62–148  ·  view source on GitHub ↗
(
    args: &[ast::Expr],
    catalog: &dyn SqlCatalog,
    temporal: TemporalScope,
)

Source from the content-addressed store, hash-verified

60}
61
62fn plan_slice(
63 args: &[ast::Expr],
64 catalog: &dyn SqlCatalog,
65 temporal: TemporalScope,
66) -> Result<SqlPlan> {
67 if args.len() < 2 || args.len() > 4 {
68 return Err(SqlError::Unsupported {
69 detail: format!(
70 "ARRAY_SLICE expects 2..=4 args (name, slice_obj, [attrs], [limit]); got {}",
71 args.len()
72 ),
73 });
74 }
75 let name = require_array_name(args, 0, "ARRAY_SLICE", catalog)?;
76 let view = catalog
77 .lookup_array(&name)
78 .ok_or_else(|| SqlError::Unsupported {
79 detail: format!("ARRAY_SLICE: array '{name}' not found"),
80 })?;
81
82 // Slice-predicate literal: encoded as a quoted string carrying the
83 // brace-form object literal. The PostgreSQL dialect does not accept
84 // bare `{...}` in expression position, so we decode the string
85 // contents here.
86 let slice_str = expect_string_literal(&args[1], "ARRAY_SLICE slice predicate")?;
87 let parsed = parse_object_literal(&slice_str).ok_or_else(|| SqlError::Unsupported {
88 detail: format!("ARRAY_SLICE: slice predicate must be an object literal: {slice_str}"),
89 })?;
90 let map = parsed.map_err(|detail| SqlError::Unsupported {
91 detail: format!("ARRAY_SLICE: slice parse: {detail}"),
92 })?;
93 let mut dim_ranges: Vec<NamedDimRange> = Vec::with_capacity(map.len());
94 for (dim, val) in map {
95 // Verify the dim exists on the array.
96 if !view.dims.iter().any(|d| d.name == dim) {
97 return Err(SqlError::Unsupported {
98 detail: format!("ARRAY_SLICE: array '{name}' has no dim '{dim}'"),
99 });
100 }
101 let arr = match val {
102 Value::Array(a) if a.len() == 2 => a,
103 _ => {
104 return Err(SqlError::Unsupported {
105 detail: format!(
106 "ARRAY_SLICE: dim '{dim}' range must be a 2-element array [lo, hi]"
107 ),
108 });
109 }
110 };
111 let lo = value_to_coord_literal(&arr[0], &dim)?;
112 let hi = value_to_coord_literal(&arr[1], &dim)?;
113 dim_ranges.push(NamedDimRange { dim, lo, hi });
114 }
115
116 let attr_projection = if args.len() >= 3 {
117 match &args[2] {
118 ast::Expr::Value(v) if matches!(v.value, ast::Value::SingleQuotedString(ref s) if s == "*") => {
119 Vec::new()

Callers 1

try_plan_array_table_fnFunction · 0.85

Calls 10

require_array_nameFunction · 0.85
expect_string_literalFunction · 0.85
parse_object_literalFunction · 0.85
value_to_coord_literalFunction · 0.85
expect_string_arrayFunction · 0.85
expect_u32Function · 0.85
lenMethod · 0.45
lookup_arrayMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected