You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 586a67e
Browse filesBrowse the repository at this point in the historyBrowse files
feat(go): test several members of one array element of a JsonSearch field
A filter such as "a contact who is a sibling and was called more than
five times" had no Go method. An EqAt and an ordering at the contacts'
paths can each be answered by a different contact, so the application
had to read the array back and re-apply the predicate itself.
The engine and EQL already answer it: element_match derives one
eql_v4.query_json_elements operand, and json_tree_element_match is true
of a row where one element passes every predicate. This wires it into
the Go SDK.
The EQL guest's resolver now names the elements domain, so the engine
lists element_match (input path_predicates) on a field that orders a
path, and the checker and stashgen read the operator. The compiled
predicate domain stays unnamed: match is #1443's.
stashgen groups the tag's ordered paths by the array their last
wildcard names (record.TargetOptions.ElementArrays) and writes one
accessor per array under Elements, named as At names a path, with
Match(ctx, cipher, opts, predicates...). An array with no ordered
member beneath it gets none, and a root array ($[*]) is Root.
The members are compile-time names. stashgen writes Paths (NPaths with
-name), a tree nested as the JSON nests it, of encrypt.Path[E, T]
values: Paths.Profile.Visits.Place. E is a type stashgen writes for
each array, and T is the member's Go type, read from the document's
struct as encoding/json reads it, or any where the type names none (a
json.RawMessage, say). encrypt.AtPath(path) gives Eq, Lt, Lte, Gt, Gte
and Between, each taking a T and returning an
encrypt.ElementPredicate[E], and an array's Match takes only its own
E. So a value of another type, or a predicate on another array's
member, does not compile. Paths holds fields and no methods, so no JSON
key is reserved. For a filter built at run time, the array accessor's
Member("place") gives the same comparisons with any values.
An array gets no accessor, and a notice naming its ordered paths, when
its keys give no accessor name, when another array's keys give the
same one, or when Paths cannot name its members: a key that gives no
Go name on its own, or one name that would stand for two paths. A tag
that generated before still generates, with its At unchanged.
Match writes each value with gensupport.JSONText as the orderings do,
and returns an eql.JSONSearchElementsQuery. The member check runs in
the SDK, against the members the declaration orders beneath the array,
before the guest is called: the engine's json_path_not_ordered names
no member, so the first error a caller sees names the member, the
array and the members it orders. It wraps ErrTerm, as the engine's
refusal does; no predicates, a zero predicate, a zero Path and a
member with a wildcard wrap ErrEncoding. Every other refusal is the
engine's Diagnostic. A predicate prints and logs its member and
comparison, never its values, and copies the bytes of a
json.RawMessage or []byte value.
Tests: the hermetic suite pins the operand against the subtree reads
and the orderings of the same members, the run-time form against the
typed one, every pre-engine refusal, and each engine refusal's
sentinel and code through the guest. A type-checking test loads the
generated testusers package with a probe file and holds the two
compile errors, a value of another type and another array's
predicate; the stashgen test does the same against a generated module,
and pins the member types and every case that gets no accessor. The
PostgreSQL suite (go:test:postgres) finds the row where one contact
passes both predicates, by path and by name, and not the row where two
contacts each pass one, which the EqAt and ordering superset returns,
and raises SQLSTATE 22023 past the bound. The guest test now pins the
elements domain named and match not listed.
Closes#1442
Claude-Session: https://claude.ai/code/session_01MrxG73fnX1p7oiizh3GRG5
{"two arrays, one name", "$.a_b[*].x;$.aB[*].y;$.c[*].z", "ABX ProfileFieldPath // $.a_b[*].x", "no Elements accessor for the elements of $.a_b[*] (ordered $.a_b[*].x): another array's keys give the same accessor name, Elements.AB"},
522
+
{"an array with no name", "$.__[*].x;$.c[*].z", "X ProfileFieldPath // $.__[*].x", "no Elements accessor for the elements of $.__[*] (ordered $.__[*].x): its keys give no Go accessor name"},
523
+
// Paths names each key on its own, so a key of digits, which At
524
+
// joins to the keys before it, names nothing there.
525
+
{"a key with no name under Paths", "$.a.1[*].x;$.c[*].z", "A1X ProfileFieldPath // $.a.1[*].x", `no Elements accessor for the elements of $.a.1[*] (ordered $.a.1[*].x): the key "1" of $.a.1[*].x gives no Go name under Paths that starts with a letter`},
526
+
// Paths nests: a member that is also the object or array above
527
+
// another member, or two keys that give one name at one place,
528
+
// would make one name stand for two paths.
529
+
{"a member above a member", "$.a[*].b;$.a[*].b.c;$.c[*].z", "ABC ProfileFieldPath // $.a[*].b.c", "no Elements accessor for the elements of $.a[*] (ordered $.a[*].b, $.a[*].b.c): Paths.Profile.A.B would name both $.a[*].b and $.a[*].b.c, and can name one of them only"},
530
+
{"a member above an array", "$.a[*].b;$.a[*].b[*].d;$.c[*].z", "ABD ProfileFieldPath // $.a[*].b[*].d", "no Elements accessor for the elements of $.a[*].b[*] (ordered $.a[*].b[*].d): Paths.Profile.A.B would name both $.a[*].b and $.a[*].b[*].d, and can name one of them only"},
531
+
{"two keys, one name in Paths", "$.x.a_b[*].m;$.x.aB.n[*].o;$.c[*].z", "XABM ProfileFieldPath // $.x.a_b[*].m", "no Elements accessor for the elements of $.x.aB.n[*] (ordered $.x.aB.n[*].o): Paths.Profile.X.AB would name both $.x.a_b[*].m and $.x.aB.n[*].o, and can name one of them only"},
{"a sealed null", "\tPrefs *json.RawMessage `stash:\"prefs,encrypt_into=JsonSearch,null=sealed\"`", "Customer.Prefs: a nil has an equality term and no other, so another index's column would show which values are absent; write null=sql"},
478
603
{"a nil document that does not say null=sql", "\tPrefs *json.RawMessage `stash:\"prefs,encrypt_into=JsonSearch\"`", "null=sql"},
0 commit comments