Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/eql-v4-match-filter-one-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@cipherstash/eql': minor
---

**In EQL v4, a match filter follows one rule in every type.** The types are `TextMatch`, `TextSearch` and `TextSearchOre`. Some text cuts no match token: an empty string, one letter, or separators alone.

- **Stored values.** `eql-bindings` now stores such text in `TextMatch` with the empty filter, `"bf": []`, as it does in the two search types. Before, `TextMatch` refused the value. The three types store one filter type, `v4::terms::BloomFilter`. The type `v4::terms::SearchBloomFilter` is removed. No release has it.
- **Queries.** `eql_v4.match_term` over an `eql_v4.query_text_match` operand now raises (`invalid_parameter_value`) when the operand's `bf` is missing, JSON `null` or an empty array. The search query domains already raise this way. So `col @@ $1` raises on such an operand, where it could match the stored values with an empty filter. `eql-bindings` never builds such an operand: it refuses a query of text that cuts no token.

No `@@` query finds a stored empty filter. The empty filter tells anyone who can read the column that the value cuts no token.

The `eql_v3` functions do not change. Only the unreleased `v4` module and the EQL v4 SQL change.
2 changes: 1 addition & 1 deletion .changeset/eql-v4-match-short-words.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Every query path follows this rule, so a query's filter and its verify agree. Th

A query twin's filter has a new field type, `v4::terms::QueryBloomFilter`. A query twin is the struct that contains a query's terms. The new type is the `bf` of `TextMatchQuery`, `TextSearchMatchQuery`, `TextSearchOreMatchQuery`, `TextSearchQuery`, and `TextSearchOreQuery`. `QueryBloomFilter` has the JSON and JSON Schema of `BloomFilter`. Only fields of the `v4` module change, and that module is not released yet.

Text with no token at all, such as one letter or nothing, is handled as before. `TextMatch` refuses it. The search types store it with the empty filter.
Text with no token at all, such as one letter or nothing, is stored with the empty filter in all three types. No `@@` query finds that filter. A query of such text is refused.

**The v4 match format now includes short-word tokens.** A filter of text holding a two-letter word gains that word's bits; text with none derives the filter it did. EQL v4 is unreleased, so this is the format it ships with: a v4 value written by an earlier build that holds a two-letter word lacks the word's bits, and a query naming that word does not find it until the value is re-encrypted.

Expand Down
2 changes: 1 addition & 1 deletion .changeset/eql-v4-text-search-optional-terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@cipherstash/eql': minor
---

**An EQL v4 text search query carries only the terms its operator reads.** `eql_v4.query_text_search` and `eql_v4.query_text_search_ore` now require at least one of their terms (`hm`, `op` or `ob`, `bf`) instead of all of them, so `col = $1` and `col < $1` work on text too short to cut a 3-gram, which has no match term. Each extractor over such a query raises (`invalid_parameter_value`) wherever it reads the operand when the query lacks the term it reads, or holds it as JSON `null` or an empty array, naming the domain, the term and the operators that compare it: `=` without `hm`, `<` without `op`, `@@` without `bf`. So a missing term raises rather than matching no row silently, or every row; the raise is at evaluation, so a generic plan that never reaches the predicate returns no row and no error. Stored `eql_v4_text_search` values still carry every term. This change leaves the `eql_v3` domains as they were. With it, **Stack Encrypt produces `TextSearch`** (`eql-bindings`, `stack-encrypt` feature): `TextSearchQuery`'s terms are `Option`s, built per index through `TextSearchEqualityQuery`, `TextSearchOrderQuery` and `TextSearchMatchQuery`, and the stored value carries every term: text too short for a 3-gram stores the empty filter (`"bf": []`, the new `v4::terms::SearchBloomFilter` field type), so `=` and `<` find it and no `@@` query does, where `TextMatch` still refuses it. `TextSearchQuery`'s `Option` terms and `TextSearch`'s `SearchBloomFilter` change the fields of the unreleased `v4` module only; no published `eql-bindings` has it. See [U-001](../../docs/upgrading/v3.1.md#u-001-a-text-search-query-carries-only-the-terms-its-operator-reads) for what a hand-built query must carry, the raise, and the rollback.
**An EQL v4 text search query carries only the terms its operator reads.** `eql_v4.query_text_search` and `eql_v4.query_text_search_ore` now require at least one of their terms (`hm`, `op` or `ob`, `bf`) instead of all of them, so `col = $1` and `col < $1` work on text too short to cut a 3-gram, which has no match term. Each extractor over such a query raises (`invalid_parameter_value`) wherever it reads the operand when the query lacks the term it reads, or holds it as JSON `null` or an empty array, naming the domain, the term and the operators that compare it: `=` without `hm`, `<` without `op`, `@@` without `bf`. So a missing term raises rather than matching no row silently, or every row; the raise is at evaluation, so a generic plan that never reaches the predicate returns no row and no error. Stored `eql_v4_text_search` values still carry every term. This change leaves the `eql_v3` domains as they were. With it, **Stack Encrypt produces `TextSearch`** (`eql-bindings`, `stack-encrypt` feature): `TextSearchQuery`'s terms are `Option`s, built per index through `TextSearchEqualityQuery`, `TextSearchOrderQuery` and `TextSearchMatchQuery`, and the stored value carries every term: text too short for a 3-gram stores the empty filter (`"bf": []`), as it does in `TextMatch`, so `=` and `<` find it and no `@@` query does. `TextSearchQuery`'s `Option` terms change the fields of the unreleased `v4` module only; no published `eql-bindings` has it. See [U-001](../../docs/upgrading/v3.1.md#u-001-a-text-search-query-carries-only-the-terms-its-operator-reads) for what a hand-built query must carry, the raise, and the rollback.
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,12 @@ without loss, and refuses it otherwise.
`a.name @@ b.name`, or `matches(col, <a stored value as jsonb>)`) keeps
the shared guard, so two stored empty filters match each other there, as
they do in v3. No producer builds that predicate. A match
query of such text is refused, as it is for `TextMatch`, whose stored
value still refuses it too. The v3 domains are cipherstash-client's format
query of such text is refused, as it is for `TextMatch`. A stored
`TextMatch` value of such text has the empty filter too (amended
2026-12-05): a match filter is built the same way in every type. Before
the amendment, `TextMatch` refused to store such text. The extractor
over `eql_v4.query_text_match` refuses `"bf": []` too, from the same
date, so no match query has an empty filter. The v3 domains are cipherstash-client's format
and keep requiring every term, byte for byte, so here the v4 SQL differs
from the v3 SQL. The one source holds both forms between version-block directive lines (`-- {{#v3}}` … `-- {{/v3}}`,
`-- {{#v4}}` … `-- {{/v4}}`), which the renderer keeps for their own
Expand Down
11 changes: 11 additions & 0 deletions languages/golang/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit.

### Breaking

- **A `TextMatch` field stores text that cuts no token.** Such text is an
empty string, one letter, or separators alone. Before, `Encrypt` refused
it with `ErrTerm`. Now the value is stored with an empty match filter, as
a `TextSearch` field and a plain `match` index store it. So a match filter
is built the same way in every type.
- A program that relied on the refusal to reject short text has to check
the text itself.
- No `Matches` query finds a value with an empty filter. A `Matches` query
of such text is still refused with `ErrTerm`.
- The empty filter tells anyone who can read the column that the value
cuts no token.
- **vitaminc's Go packages `vcvalue` and `vcffi` are now `encrypt/value`
and `encrypt/frame`.** `encrypt.Date`, `Decimal`, `Int128` and `Uint128`
are still aliases, now of the types in `encrypt/value`. Code that names
Expand Down
6 changes: 3 additions & 3 deletions languages/golang/cmd/stashgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ A query on such a type derives its term under the context the cipher names, so i
The index names are `equality`, `match`, `ore`, `ope` and `json`.
A `match` index stores text with no token (an empty string, separator-only text, or text shorter than the n-gram length of 3 characters) as the empty filter, which no query matches, so an optional or short value can live under `match`; the empty filter tells a reader of the column that the value is one of those.
A match query of such text is refused, because an empty filter as a query would match every row.
An EQL `TextMatch` field is stricter: see below.
An EQL `TextMatch` field follows the same rule: see below.
An index takes its options in parentheses after its name, separated by commas: `index=equality;match(k=3)`.
This build refuses an index with options: a query term is derived with the default options only, so a stored term with other options would never match one.
These words are the same as the Rust API's words for the same behaviour, with two that only Go has.
Expand Down Expand Up @@ -437,8 +437,8 @@ The ordered date, timestamp and numeric types answer the four comparisons, as do

Any built-in Go integer field takes an integer type (ADR-0002) and seals at the type's width: an `int16` field always fits an `Integer`, and an `int64` field is range checked value by value, `Encrypt` refusing a value that does not fit with `encrypt.ErrEncoding`. `encrypt.Int128` and `encrypt.Uint128` are not converted. A float's width must match: a `float64` field is not a `Real`.
A `TextMatch` field indexes the 3-grams of its text, and each two-letter word as a whole word. A 3-gram is a run of three characters, such as "mik" in "Mike". So a two-letter surname such as "Ng" is stored, and the query "ng" finds it. A query asks for its two-letter words only when the whole query is one two-letter word. So the query "Mike Ng" asks for its 3-grams alone, and finds "Mike Nguyen" too.
A `TextMatch` field refuses text that cuts no token, such as an empty string or one letter; its query refuses such text too.
A `TextSearch` field stores such text with an empty match filter, so its `Eq`, `Lt`, `Lte`, `Gt` and `Gte` queries find it and no `Matches` query does; those queries take such text too, and its `Matches` query refuses it.
A `TextMatch` field stores text that cuts no token, such as an empty string or one letter, with an empty match filter. No `Matches` query finds that value, and a `Matches` query of such text is refused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Line 108 of this file still says the opposite.

Line 108, in the section on the match index, reads: "An EQL TextMatch field is stricter: see below." This line now says a TextMatch field stores such text. The matching sentence in languages/golang/encrypt/README.md was updated. Line 108 here was missed.

I checked the file, and the finding is correct. Fix: line 108 says that a TextMatch field follows the same rule.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6845026. Line 108 now says that an EQL TextMatch field follows the same rule.

A `TextSearch` field stores such text the same way. Its `Eq`, `Lt`, `Lte`, `Gt` and `Gte` queries find the value, and take such text too. Its `Matches` query refuses such text.
Put the column on the left of `@@` (`WHERE name @@ $1::eql_v4.query_text_match`): the other operand order finds nothing until #1171 is fixed.
`encrypt_into` with any other type is refused with the type's name and the reason it is not produced yet.
Separate columns work today for four indexes: `equality`, `match`, `ore` and `ope`.
Expand Down
11 changes: 6 additions & 5 deletions languages/golang/encrypt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ filter: a valid value that no query matches, so an optional or short value can
live under `match`. The empty filter tells anyone who can read the column that
the value is one of those. A match *query* of such text is refused with
`ErrTerm`, because an empty filter as a query would match every row. An EQL
`TextMatch` field is stricter, as "EQL columns" below says.
`TextMatch` field follows the same rule.

Terms are byte-equal to the ones the Rust crate derives, so a term from
`users.Fields.Email.Eq` compares against a stored term written from any
Expand Down Expand Up @@ -683,10 +683,11 @@ tell the rows that contain "Ng" from the rows that contain "Nguyen", and
count them. Without the word token, they see only the 3-gram that both
names share.

Text that cuts no token, such as an empty string or one letter, is refused. A
`TextSearch` value of such text is stored with an empty match filter: `Eq`,
`Lt`, `Lte`, `Gt` and `Gte` find it through its other terms, and no
`Matches` query does. A `TextSearch` query carries only the term its
Some text cuts no token, such as an empty string or one letter. A
`TextMatch` field stores such text with an empty match filter. No `Matches`
query finds that value, and a `Matches` query of such text is refused. A
`TextSearch` field stores such text the same way. Its `Eq`, `Lt`, `Lte`,
`Gt` and `Gte` queries find the value through its other terms. A `TextSearch` query carries only the term its
operator reads, so `Eq` and `Lt` on one-letter text work and `Matches` on it
is refused; EQL v4 raises if a query lacks the term its operator compares. The number
equality types compare as
Expand Down
39 changes: 39 additions & 0 deletions languages/golang/encrypt/eql_v4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,45 @@ func TestV4FieldsSealToTheirEQLTypesAndOpenBack(t *testing.T) {
}
}

// A TextMatch field stores text that cuts no match token (one letter, an
// empty string, or separators alone) with the empty filter, as a
// TextSearch field does: a match filter is built the same way in every
// type. The value opens to the text that went in. A Matches query of such
// text is refused (TestV4QueriesMatchTheRustFixture).
func TestV4TextMatchStoresTextThatCutsNoToken(t *testing.T) {
c := deterministicEQLClient(t)
ctx := context.Background()
cipher := c.DefaultKeyset()

short := []testusers.Profile{
{ID: 1, Name: "A", Email: "[email protected]"},
{ID: 2, Name: "", Email: "[email protected]"},
{ID: 3, Name: " ", Email: "[email protected]"},
}
encrypted, err := testusers.EncryptProfile(ctx, cipher, short)
if err != nil {
t.Fatalf("storing text that cuts no token in a TextMatch: %v", err)
}
for i, e := range encrypted {
keys, terms := keysAndTerms(t, e.Name)
if keys != "bf,c,i,v" {
t.Errorf("stored keys for %q %s, want bf,c,i,v", short[i].Name, keys)
}
if string(terms["bf"]) != "[]" {
t.Errorf("stored filter for %q is %s, want []", short[i].Name, terms["bf"])
}
}
decrypted, err := testusers.DecryptProfile(ctx, cipher, encrypted)
if err != nil {
t.Fatal(err)
}
for i := range short {
if decrypted[i] != short[i] {
t.Errorf("row %d: %+v, want %+v", i, decrypted[i], short[i])
}
}
}

// bloom is the set of filter positions in a TextMatch value or query.
func bloom(t *testing.T, value []byte) map[int]bool {
t.Helper()
Expand Down
4 changes: 2 additions & 2 deletions languages/golang/encrypt/eql_v4_text_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func TestV4TextSearchStoresEveryTermAndQueriesCarryOne(t *testing.T) {
t.Errorf(`the query "ng"'s bf %s is not the stored "Ng"'s %s`, q["bf"], ngTerms["bf"])
}
// Storing such text, an empty string included, keeps every term, the
// match term as the empty filter (where TextMatch refuses the text): Eq
// and Lt find the row through hm and op, and no Matches query does.
// match term as the empty filter (as TextMatch stores it): Eq and Lt
// find the row through hm and op, and no Matches query does.
short, err := testusers.EncryptEntry(ctx, cipher, []testusers.Entry{{ID: 2, Name: "A"}, {ID: 3, Name: ""}})
if err != nil {
t.Fatalf("storing short text in a TextSearch: %v", err)
Expand Down
21 changes: 9 additions & 12 deletions packages/eql/crates/eql-bindings/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`BETWEEN`.
- **`TextSearch` is producible** (`stack-encrypt` feature), from `String`.
The stored value carries `TextEq`'s `hm`, `TextOrd`'s `op` and
`TextMatch`'s `bf`. Text too short for a 3-gram (an empty string, a
two-letter code) is stored with the empty filter, `"bf": []`, where
`TextMatch` refuses it: `=` and `<` find the row through `hm` and `op`,
and no `@@` query does (a `@@` between two stored values is not a query,
and two stored empty filters match each other there, as in v3). Its `bf`
field is the new
`v4::terms::SearchBloomFilter` (as is `TextSearchOre`'s), whose JSON and
JSON Schema are `BloomFilter`'s and which takes the empty filter;
`TextMatch` and every query keep `BloomFilter`, which refuses it. Its
query is built per index, through
`TextMatch`'s `bf`. Some text cuts no match token, such as an empty
string or one letter. Such text is stored with the empty filter,
`"bf": []`, as `TextMatch` stores it. `=` and `<` find the row through
`hm` and `op`, and no `@@` query does. (A `@@` between two stored values
is not a query, and two stored empty filters match each other there, as
in v3.) The `bf` field of `TextSearch`, `TextSearchOre` and `TextMatch` is
one type, `BloomFilter`. The query of `TextSearch` is built per index,
through
`TextSearchEqualityQuery`, `TextSearchOrderQuery` or
`TextSearchMatchQuery` (each `EncryptTarget<String>` and
`Into<TextSearchQuery>`), so it carries only the term its operator reads:
Expand Down Expand Up @@ -504,8 +502,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`pub hm: Option<Hmac256>`, and likewise `op`/`ob` and `bf`: code that
builds one of these structs wraps each term in `Some`, code that reads
one handles `None`, and a JSON operand missing a term now deserializes
where it was refused. `TextSearch` and `TextSearchOre`'s `bf` is
`SearchBloomFilter`, not `BloomFilter` (`.0` reaches the `BloomFilter`).
where it was refused.
No published release of this crate has the `v4` module (3.0.6 does not),
so this breaks only code built against unreleased sources; the v3 twins
are unchanged, as cipherstash-client's query carries every term.
Expand Down
26 changes: 17 additions & 9 deletions packages/eql/crates/eql-bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,24 @@ The configuration is part of the stored
format, so changing it means a new domain or payload version. A filter can
match a row that does not contain the query, so re-check after decrypting
where that matters. Write the stored column on the left, `col @@ query`: the
other order finds nothing until #1171 is fixed. Text that cuts no token
(empty strings, one letter) cannot be stored in a `TextMatch` column, and a
`TextMatchQuery` for it is refused too: one filter type builds both, and an
empty filter as a query would match every row.
other order finds nothing until #1171 is fixed.

Some text cuts no token, such as an empty string or one letter. Every match
type stores such text with the empty filter, `"bf": []`: `TextMatch`,
`TextSearch` and `TextSearchOre`. No `@@` query finds an empty filter,
because a query's filter is never empty:

- This crate refuses a query of such text.
- EQL v4's SQL raises on a query operand whose `bf` is empty, in every
match query domain. So an operand built by hand is refused too.

The empty filter tells anyone who can read the column that the value cuts
no token. A `@@` between two stored values is not a query, and no producer
builds one. Two stored empty filters match each other there, as in v3.

`TextSearch` stores all three terms (`TextEq`'s `hm`, `TextOrd`'s `op` and
`TextMatch`'s `bf`). Text that cuts no token is stored with the empty
filter (`"bf": []`, the `SearchBloomFilter` field type): `=` and `<` find it
through `hm` and `op`, and no `@@` query does, because a query's filter is
never empty. (A `@@` between two stored values, which no producer builds, is
not a query: two stored empty filters match each other there, as in v3.) Its query carries only the term its operator reads: build it
`TextMatch`'s `bf`). `=` and `<` find text that cuts no token through `hm`
and `op`. Its query carries only the term its operator reads: build it
through `TextSearchEqualityQuery` (`=`, `<>`), `TextSearchOrderQuery` (`<`,
`<=`, `>`, `>=`) or `TextSearchMatchQuery` (`@@`) and convert into
`TextSearchQuery`, and the by-name dispatch picks the one for the index that
Expand Down
Loading
Loading