Skip to content

Commit 71c04ff

Browse files
committed
feat(stack-encrypt): compile a jsonpath predicate into one JSON document operand
`match` takes what `jsonb_path_match` takes, `{"predicate", "vars"?, "wildcard_bound"?}`, and derives the `eql_v4.query_json_predicate` operand. A hand-written parser reads the subset of SQL/JSON path predicates the terms can answer: comparisons of a path (`$.a.b`, `$.a[*].b`, `$."a b"`) with a variable or a literal, `exists(path)`, `exists(path ? (@.x == $v && @.y > $w))`, `&&`, `||`, `!` and parentheses. Everything else is refused at the byte it starts, as `Error::Predicate`, naming the construct in the grammar's words and never quoting the text, whose keys and values can be customer data. Each comparison is compiled onto an existing operator's input and derived by that operator's code: `==` to `eq_at`'s needle, `!=` to a `selector` and not the needle, an ordering to a `selector`, not the `null` needle, and the ordering's leaf, so an absent path and a JSON null answer false as jsonpath has them; an ordering at a wildcard and a filter of more than one condition to `element_match`, a filter of one equality to `eq_at`. No new derivation. `!=` at a wildcard, which asks whether some element differs, is refused. New reasons: `json_predicate_syntax`, `json_predicate_unsupported`, `json_predicate_unknown_variable`, `json_predicate_value_type`, `json_predicate_not_equal_at_wildcard` and `json_predicate_too_deep`. The operator is listed only on a type that names the domain (`TargetDescriptor::with_predicate_query_sql_domain`), so a host that does not, such as the Go guest today, sees no new operator. Refs #1441
1 parent 77f7451 commit 71c04ff

9 files changed

Lines changed: 2845 additions & 45 deletions

File tree

‎packages/stack-encrypt/src/codes.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ mod tests {
212212
Error::UntypedIndex { .. } => Error::UntypedIndex { field: name() },
213213
Error::Source { .. } => Error::bad_source(Reason::FieldMissing),
214214
Error::Record { .. } => Error::bad_record(Reason::NoCiphertextNode),
215+
Error::Predicate { .. } => Error::Predicate {
216+
field: Some(name()),
217+
reason: Reason::JsonPredicateUnsupported,
218+
construct: "`like_regex`",
219+
at: 4,
220+
},
215221
Error::Internal => Error::Internal,
216222
Error::Target(_) => Error::Target(TargetError::NoTargets { name: target() }),
217223
Error::Cipher(_) => Error::Cipher(crate::Error::Aead),
@@ -596,6 +602,23 @@ mod tests {
596602
Box::new(Error::UntypedIndex { field: name() }),
597603
json!({ "field": "email" }),
598604
),
605+
(
606+
Box::new(
607+
Error::Predicate {
608+
field: None,
609+
reason: Reason::JsonPredicateUnsupported,
610+
construct: "`like_regex`",
611+
at: 4,
612+
}
613+
.in_field("email"),
614+
),
615+
json!({
616+
"field": "email",
617+
"reason": "json_predicate_unsupported",
618+
"construct": "`like_regex`",
619+
"at": 4
620+
}),
621+
),
599622
(Box::new(Error::Internal), json!({})),
600623
(
601624
Box::new(TargetError::NoTargets { name: target() }),

0 commit comments

Comments
 (0)