fix(eql_v3): empty-string ordered text sorts first instead of dropping out#316
Merged
Merged
Conversation
…g out
Encrypting "" as ordered text produces an empty ORE term (ob: []). The
eql_v3.ore_block_256 extractor collapsed that to NULL terms (array_agg over
zero rows is NULL), so compare_ore_block_256_terms returned NULL and an
empty-text row silently dropped out of ORDER BY, was wrongly returned by
eql_v3.max, and threw off range-query counts. The comparator's existing
"empty sorts first" cardinality guard was dead code because empty ob never
reached it as an empty array.
Fix: COALESCE the empty array_agg to an empty ore_block_256_term[] so the
extractor yields a zero-term composite. The cardinality = 0 guard now engages
and orders empty before every non-empty value. Storage and equality are
unaffected ("" keeps a real c and hm); a genuine SQL NULL row is unchanged
(the extractor is STRICT).
Tests:
- ore_block_comparator_tests: empty term sorts before non-empty (unit).
- sem.rs T7: characterization updated (empty ob -> non-NULL, zero terms).
- v3_text_empty_order_tests + v3_text_empty fixture: end-to-end ORDER BY /
min / max over text_ord with a real "" ciphertext. Proven non-vacuous by
reverting the fix (max wrongly returns "").
v2 carries the identical latent bug but is being removed, so it is left
unchanged (issue #262 part 2 is moot).
Refs: #262
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Encrypting the empty string "" as ordered text produces an empty ORE term (ob: []) -- the only value that does. The ORE-bearing eql_v3 domains (_ord / _ord_ore, and text _search) now carry a CHECK requiring ob to be a non-empty array, so casting or inserting an empty-ob payload into an ordered column fails loudly with a check violation (23514) rather than producing an unorderable row. The rule lives where term behaviour belongs (CLAUDE.md): a typed per-term property Term::nonempty_array_key (Ore => "ob"), collected by Term::nonempty_array_keys symmetric to term_json_keys, with unit tests. DomainBlock derives nonempty_array_keys from the domain's terms exactly like keys, and the types.sql.j2 template renders a non-empty-array CHECK per key generically -- no hardcoded ob, no ORE concept leaking into the codegen-context or template layers. Storage / equality / match / bool domains are unaffected; fixed-width scalars never produce an empty ob, so the clause is a structural invariant that is a no-op for them. The comparator's "empty sorts first" cardinality guard (02ab24b) is retained as defense-in-depth for any path that bypasses the domain (e.g. a composite built directly). - crates/eql-scalars: Term::nonempty_array_key{,s} + tests. - crates/eql-codegen: DomainBlock.nonempty_array_keys + template clause + unit test pinning the constraint to ORE-bearing domains only. - tests/codegen/reference/*/*_types.sql regenerated. - Rewrote v3_text_empty_order_tests -> v3_text_empty_constraint_tests: empty "" rejected on text_ord/text_ord_ore; controls accepted/ordered. - CHANGELOG + adding-a-scalar docs updated. Refs: #262
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Encrypting
""as ordered text produces an empty ORE term (ob: []). Theeql_v3.ore_block_256extractor collapsed that to NULL terms (array_aggover zero rows is NULL), socompare_ore_block_256_termsreturned NULL and an empty-text row silently:ORDER BY,eql_v3.max, andThe comparator's existing "empty sorts first"
cardinality = 0guard was effectively dead code, because an emptyobnever reached it as an empty array.Fix
COALESCEthe emptyarray_aggto an emptyore_block_256_term[]so the extractor yields a zero-term composite instead of NULL terms. Thecardinality = 0guard now engages and orders empty before every non-empty value.Storage and equality are unaffected (
""keeps a realcandhm); a genuine SQLNULLrow is unchanged (the extractor isSTRICT).Tests
ore_block_comparator_tests: empty term sorts before non-empty (unit).sem.rsT7: characterization updated (emptyob-> non-NULL, zero terms).v3_text_empty_order_tests+v3_text_emptyfixture: end-to-endORDER BY/min/maxovertext_ordwith a real""ciphertext. Proven non-vacuous by reverting the fix (maxwrongly returns"").Notes
v2carries the identical latent bug but is being removed, so it is left unchanged (issue #262 part 2 is moot).Refs #262
Summary by CodeRabbit
Bug Fixes
Tests