Commit 01c0bae
`MemoryAnalyticsService` mapped each cube operator to the NAME of a mingo
operator, and the call site filled that name in as
`matchStage[field] = {[name]: comparand}`. That shape can express "compare this
field to this value" and nothing else, so the two operators that need to WRAP
their comparand were pushed through it anyway.
`notContains` -> `'$not'` became `{name: {$not: 'et'}}`. mingo's `$not` takes a
regex or an operator expression; handed a bare scalar it constrains nothing, so
the predicate was emitted, appeared in the pipeline, and passed the whole table:
3 rows where `find()` returns 2. A predicate that is emitted and inert is
indistinguishable from a working one at the author's end — the same amplifying
direction as #3948, arrived at a third way. #5345 ruled on operators with NO
mapping, #5373 on the comparand ENCODING; this is a mapping pointing at the
wrong target, and #5431 did not shrink it (that call site now receives a real
value, which is orthogonal to what the operator layer does with it).
Route: let the map return a STRUCTURE rather than an operator name, which the
issue prefers and the code supports cleanly. `CUBE_OPERATOR_TO_MONGO_PREDICATE`
holds a builder per operator that returns the whole `{$op: …}` object, so
`notContains` can say `{$not: {$regex: …}}` and the CLASS of "this operator
needs a structure and the table can only hold a name" is gone rather than this
one instance. `$in`/`$nin`/`$lte`/`$exists`, which the call site had grown an
`if` chain for, are ordinary rows in that table now.
Measured on the issue's 3-row fixture, analytics vs `find()`:
| where | before | after | find() |
|----------------------------------|--------|-------|--------|
| {name:{$notContains:'et'}} | 3 | 2 | 2 |
| {name:{$notContains:'a'}} | 3 | 0 | 0 |
| {name:{$contains:'a.p'}} | 1 | 0 | 0 |
| {name:{$contains:'ALPHA'}} | 0 | 1 | 1 |
| {name:{$notContains:'ALPHA'}} | 3 | 2 | 2 |
| {made_at:{$contains:'<full ISO>'}}| 1 | 0 | 0 |
| {code:{$in:[]}} | 3 | 0 | 0 |
| {code:[]} | 3 | 0 | 0 |
Three more defects at the same call site fall inside this fix and are closed
with it, because writing a correct `notContains` requires settling each:
- `contains` was the right operator with the comparand handed in RAW, so it was
neither escaped (`.` matched any character) nor case-folded, while the live
path escapes and matches `/…/i`. Leaving that would have made the two
non-complementary in a new way — `alpha` would be in BOTH answers. The rule is
now borrowed from the driver (new narrow `filterSubstringPattern`, alongside
`filterComparandStorageForm`) rather than re-derived, per #5240.
- An operand that is NOT a comparand went through the storage-form conversion
anyway, so on a declared `datetime` column a `$contains` PATTERN was rewritten
into canonical form and then matched rows `find()` does not match. The builder
input carries both lists, the same split `normalizeFieldOperators` makes
(#4047).
- The call site's `values.length > 0` guard meant an empty `$in` emitted no
predicate at all and widened to the whole table. A list operator taking the
whole list has nothing to guard.
The two items the issue flagged as unmeasured, settled:
- `'inDateRange': '$gte'` compiles to NOTHING today — no `MONGO_TO_CUBE_OPERATOR`
entry lowers to that name, `timeDimensions` never reaches this function, and
both exits consume only `normalizeFilters` output. Dead, and wrong if it ever
had been reached (a one-ended `>=` for a two-ended range, which its own
comment conceded). Deleted, with the dead-and-inverted `'notSet': '$exists'`
beside it.
- `opMap[operator] || '$eq'` is unreachable for the same reason — but only until
someone widens the vocabulary, which #5345 deliberately made a one-line edit
to `MONGO_TO_CUBE_OPERATOR`. So it is not merely deleted: that table is `as
const`, the predicate table is keyed by the operator union derived from it,
and the widening edit now FAILS TO COMPILE until the predicate exists. The
remaining throw is a totality floor, not a fallback.
Tests go in the shared conformance file beside the #5345 shape table and the
#5373 comparand-type table, as a third axis with the same invariant: agree with
`find()`, or refuse. Plus the "declared = enforced" half — every operator
`ANALYTICS_FILTER_CAPABILITIES` declares is driven through both faces and must
agree, with a probe that must exclude at least one row, so an operator added to
the vocabulary without a working lowering fails here instead of shipping a
quietly wrong number. Reverting only the source change fails 14 of the new
assertions.
Out of scope, filed not fixed: #5440 (two operators on one field clobber each
other — the `$match` assembly layer, still broken after this), #5442
(`flattenFilterCondition` spreads an array comparand for every operator), #5444
(the `generateSql` exit emits `LIKE 'et'` with no `%` wildcards — filed as a
sub-issue of #5433, whose completion scope it falls inside). `operatorToSql` and
`generateSql` are untouched.
Claude-Session: https://claude.ai/code/session_01Pbu27iNUfQCHeuS551Rqo7
Co-authored-by: Claude <noreply@anthropic.com>
1 parent ed0d2aa commit 01c0bae
4 files changed
Lines changed: 494 additions & 57 deletions
File tree
- .changeset
- packages/plugins/driver-memory/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | | - | |
| 44 | + | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
| |||
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
49 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
50 | 64 | | |
51 | 65 | | |
52 | 66 | | |
| |||
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
102 | | - | |
| 116 | + | |
103 | 117 | | |
104 | 118 | | |
105 | 119 | | |
| |||
108 | 122 | | |
109 | 123 | | |
110 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
111 | 236 | | |
112 | 237 | | |
113 | 238 | | |
| |||
180 | 305 | | |
181 | 306 | | |
182 | 307 | | |
183 | | - | |
184 | 308 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
211 | 324 | | |
212 | 325 | | |
213 | 326 | | |
| |||
624 | 737 | | |
625 | 738 | | |
626 | 739 | | |
627 | | - | |
628 | | - | |
| 740 | + | |
| 741 | + | |
629 | 742 | | |
630 | 743 | | |
631 | 744 | | |
| |||
776 | 889 | | |
777 | 890 | | |
778 | 891 | | |
779 | | - | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
796 | 913 | | |
797 | 914 | | |
798 | 915 | | |
| |||
0 commit comments