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

Function validate_attrs

nodedb-sql/src/planner/array_dml.rs:89–125  ·  view source on GitHub ↗
(
    array: &str,
    row: usize,
    attrs: &[ArrayAttrLiteral],
    view: &ArrayCatalogView,
)

Source from the content-addressed store, hash-verified

87}
88
89fn validate_attrs(
90 array: &str,
91 row: usize,
92 attrs: &[ArrayAttrLiteral],
93 view: &ArrayCatalogView,
94) -> Result<()> {
95 if attrs.len() != view.attrs.len() {
96 return Err(SqlError::Parse {
97 detail: format!(
98 "ARRAY {array} row {row}: attr arity {} != attr count {}",
99 attrs.len(),
100 view.attrs.len()
101 ),
102 });
103 }
104 for (i, a) in attrs.iter().enumerate() {
105 let spec = &view.attrs[i];
106 match a {
107 ArrayAttrLiteral::Null if !spec.nullable => {
108 return Err(SqlError::TypeMismatch {
109 detail: format!("ARRAY {array} row {row}: attr `{}` is NOT NULL", spec.name),
110 });
111 }
112 ArrayAttrLiteral::Null => {}
113 other if !attr_compatible(other, spec.dtype) => {
114 return Err(SqlError::TypeMismatch {
115 detail: format!(
116 "ARRAY {array} row {row}: attr `{}` (declared {:?}) is incompatible",
117 spec.name, spec.dtype
118 ),
119 });
120 }
121 _ => {}
122 }
123 }
124 Ok(())
125}
126
127fn coord_compatible(c: &ArrayCoordLiteral, dtype: ArrayDimType) -> bool {
128 matches!(

Callers 1

plan_insert_arrayFunction · 0.85

Calls 3

attr_compatibleFunction · 0.85
lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected