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 5374938
Browse filesBrowse the repository at this point in the historyBrowse files
feat(go): bind a jsonpath predicate on a JsonSearch field as one parameter
An application that compiles a filter language into SQL targets
jsonb_path_match(col, $1, $2): the predicate and its variables, two
parameters. On an encrypted column the same filter was one Go call per
leaf and a hand-assembled WHERE, one cast per parameter. The engine's
match operator (#1441) compiles the predicate into one operand; this is
the Go call on top (#1443).
Fields.<Field>.Match(ctx, cipher, predicate, vars, opts) is generated on
every JsonSearch field and returns eql.JSONSearchPredicateQuery, which
binds as col @@ $1::eql_v4.query_json_predicate or
eql_v4.json_tree_match(col, $1::...). The predicate crosses as text and
vars as JSON text written by gensupport.JSONText, so Go adds no grammar:
nil, or a value that writes null, sends no vars, and a Go string is
refused as a Contains needle is. opts.WildcardBound bounds the filters
that compile to the element match, as Elements.<Array>.Match takes it.
The guest now names eql_v4.query_json_predicate, so the engine lists
match (input predicate) on every JsonSearch field; the checker and
stashgen read it, and stashgen refuses a document field the engine
answers no match on. The guest maps Error::Predicate to STATUS_ENCODING:
a refused predicate is the caller's input, not an internal failure.
Diagnostic gains Construct and At, which read the construct and the byte
offset the refusal carries.
testusers.Entity grows the RC2 model's members (score, weight, address,
country, preferred languages; $.weight ordered). The PostgreSQL test runs
the seven filters of the customer's request and checks @@, json_tree_match,
the per-operator query and jsonb_path_match over the plaintexts return the
same rows; it joins go:test:postgres.
Claude-Session: https://claude.ai/code/session_01MrxG73fnX1p7oiizh3GRG5
{"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"},
575
600
{"a nil document that does not say null=sql", "\tPrefs *json.RawMessage `stash:\"prefs,encrypt_into=JsonSearch\"`", "null=sql"},
returnnil, fmt.Errorf("%w: gensupport: %s: a %T needle is one JSON string, not JSON text; pass JSON text as json.RawMessage, or a map or struct", encrypt.ErrEncoding, f.name, needle)
186
203
}
187
204
ifneedle==nil {
@@ -306,6 +323,60 @@ func JSONElementMatch[Q ~[]byte, T any](ctx context.Context, f Field[T], c *encr
306
323
returnQ(term.Terms[0]), nil
307
324
}
308
325
326
+
// JSONMatch derives match on a JSON field: the one operand
327
+
// eql_v4.json_tree_match and `@@` take, a jsonpath predicate compiled into
328
+
// a boolean tree of the other operators' operands. The predicate crosses
329
+
// as it is: the engine parses and compiles it, and nothing here reads it.
330
+
//
331
+
// vars are the predicate's variables ($name), the jsonb that
332
+
// jsonb_path_match takes third: any value [JSONText] writes as a JSON
333
+
// object, such as a map, a struct or a json.RawMessage of one. nil, a nil
334
+
// pointer of any type, a nil map, or a json.RawMessage of the literal null
335
+
// sends none. Any other json.RawMessage crosses as it is, so an empty or
336
+
// whitespace-only one is refused by the engine as not JSON, as "{" is. A Go
337
+
// string or a non-nil pointer to one is refused, as [JSONQuery] refuses a
338
+
// needle: it writes one JSON string, and JSON text in a Go string is the
339
+
// likely mistake.
340
+
//
341
+
// What the engine refuses (text it does not read, a construct the index
342
+
// cannot answer, a variable vars do not hold, vars that are not an
343
+
// object, an ordering at a path the field does not order) is its
344
+
// [encrypt.Diagnostic]. opts.WildcardBound 0 sends no bound, and the
returnnil, fmt.Errorf("%w: gensupport: %s: Match takes vars as a JSON object, and a %T is one JSON string; pass JSON text as json.RawMessage, or a map or struct", encrypt.ErrEncoding, f.name, vars)
354
+
}
355
+
text, err:=f.jsonOperand(vars)
356
+
iferr!=nil {
357
+
returnnil, err
358
+
}
359
+
// The literal null, which encoding/json writes for a nil map, slice
360
+
// or pointer: no variables. Anything else, empty text included, is
0 commit comments