xiangfu0 opened a new pull request, #18407:
URL: https://github.com/apache/pinot/pull/18407
## Summary
Extends the query / read path to handle columns whose forward index stores
raw values while a **standalone dictionary** is also present (e.g. the
dictionary exists purely to back a secondary index such as
inverted/sorted/FST/IFST). Builds on the SPI surface introduced in #18364 and
the per-index dictionary contract in #18365 — independent of the
auto-create-dictionary loader work, can ship in parallel.
Previously the read path implicitly assumed `_dictionary != null` ↔ "forward
index is dict-encoded". This PR decouples the two, using the encoding signal
from #18364 (`ForwardIndexReader.isDictionaryEncoded()`) as the canonical check
and translating raw values to dict IDs only when callers (group-by,
dict-id-keyed aggregators, etc.) explicitly request them.
## Changes
### Read path (`DataFetcher`, `PinotSegmentColumnReader`)
- `DataFetcher.ColumnValueReader` gains a cached `_useDictionary` field
(`dictionary != null && reader.isDictionaryEncoded()`); all read methods branch
on it instead of `_dictionary != null`.
- New `readDictIdsFromRawValues` (SV) and `readDictIdsFromRawValuesMV` (MV)
helpers translate raw forward-index values to dictionary IDs via
`Dictionary.indexOf` for the new column shape; covers
INT/LONG/FLOAT/DOUBLE/BIG_DECIMAL/STRING/BYTES.
- A `checkDictId` guard fails fast with `IllegalStateException` if
`Dictionary.indexOf` returns `NULL_VALUE_INDEX` (`-1`); writing `-1` into a
dict-id buffer would silently corrupt downstream group-by / distinct buckets.
- Threading model is documented; `_useDictionary`, `_dictionary`,
`_storedType`, `_singleValue` made `final` for safe publication.
- `PinotSegmentColumnReader` switches read-path checks from `_dictionary !=
null` to a cached `_dictEncoded` (`forwardIndexReader.isDictionaryEncoded()`);
`getDictId(int)` now asserts `_dictEncoded` (RAW forward indexes do not store
dict IDs); new `isDictionaryEncoded()` accessor disambiguates from
`hasDictionary()`.
### Predicate selection (`PredicateEvaluatorProvider`, `FilterPlanNode`)
New `PredicateEvaluatorProvider.getDictionaryUsableForFiltering(predicate,
dataSource, queryContext)` decides per-predicate-type whether to drive
evaluation through the column's dictionary or directly against raw values:
| Predicate | Keep dictionary if …
|
|-------------------------------------|-------------------------------------------------------------|
| `EQ` / `NOT_EQ` / `IN` / `NOT_IN` | a sorted or inverted index can fire
|
| `RANGE` | a sorted index can fire (range index
works on raw values) |
| `REGEXP_LIKE` | a sorted, inverted, FST, or IFST
index can fire |
| Other | conservative default — keep
dictionary |
Honors the `skipIndexes` query option via `QueryContext.isIndexUseAllowed`.
`FilterPlanNode` REGEXP_LIKE path now routes through the dataSource-aware
overload so the dict-drop helper applies.
### Filter-operator selection (`FilterOperatorUtils`)
- Drops the now-dead raw-value inverted-operator branch: with #18365
enforcing inverted-index-requires-dictionary at the SPI layer, a non-dict-based
predicate evaluator on a column with an inverted index falls through to scan.
- Removes the `RawValueInvertedIndexFilterOperator` class and its priority
comparator entry — the dispatch site is gone and no other caller exists in tree.
### Mutable segment (`MutableSegmentImpl`, `MutableIndexContext`)
- `MutableSegmentImpl` plumbs the encoding signal
(`FieldConfig.EncodingType`) through to `MutableIndexContext` so the upcoming
shared-dictionary mutable-segment work can produce `RAW` mutable forward
indexes alongside a `MutableDictionary` from a single context.
- `MutableIndexContext` gains `getForwardIndexEncoding()` and
`Builder.withForwardIndexEncoding(...)`; the previous 11-arg constructor is
preserved as `@Deprecated` delegating to the new 12-arg form with
`EncodingType.DICTIONARY` default — preserves binary compatibility for external
`IndexType` plugins compiled against the previous SPI.
## Backward compatibility
- **No wire-format change.** No DataTable, segment metadata, REST/JSON, or
Protobuf changes.
- **SPI:** `MutableIndexContext` adds an SPI surface — old 11-arg
constructor preserved as `@Deprecated`. Plugin authors should migrate to the
`Builder` (or 12-arg constructor); the deprecated form is targeted for removal
once external plugins have had a release cycle.
- **Behavior preserved on existing segments:** for columns where `dictionary
!= null && forwardIndex.isDictionaryEncoded()` (the legacy case), every code
path behaves identically to before.
## Tests
- New `PredicateEvaluatorProviderTest` (15 cases): no-dict, dict-encoded
forward index, and raw-forward + dict across
EQ/NOT_EQ/IN/NOT_IN/RANGE/REGEXP_LIKE × sorted/inverted/FST/IFST/skipIndexes
combinations.
- New `DataFetcherDictTranslationTest` (6 cases): SV translation, MV
translation, dict-encoded fast path, BIG_DECIMAL MV regression, and SV + MV
`Dictionary.indexOf == -1` fail-fast paths.
- `FilterOperatorUtilsTest` (+2): pins down that a raw-value predicate
evaluator on a column with an inverted index now falls through to
`ScanBasedFilterOperator`, while a dict-based predicate evaluator still selects
`InvertedIndexFilterOperator`.
## Test plan
- [x] `pinot-segment-spi`, `pinot-segment-local`, `pinot-core` compile clean
against rebased origin/master.
- [x] `FilterOperatorUtilsTest` (89), `DataFetcherTest` (8),
`DataFetcherDictTranslationTest` (6), `PredicateEvaluatorProviderTest` (15),
`PinotSegmentColumnReaderImplTest` (54): all pass.
- [x] `spotless:apply` / `checkstyle:check` / `license:check` clean on
`pinot-core`, `pinot-segment-spi`, `pinot-segment-local`.
## Follow-ups (not in this PR)
- Integration test under `pinot-integration-tests/.../custom/` that ingests
a table whose config produces RAW-forward + standalone-dictionary columns and
asserts EQ/IN/RANGE/REGEXP_LIKE correctness end-to-end.
- Per-`DataType` `@DataProvider` expansion in
`DataFetcherDictTranslationTest`.
- Per-row allocation optimization (reusable buffers) on the new RAW-to-dict
MV translation paths.
- Release-notes entry for the new
`MutableIndexContext.withForwardIndexEncoding(...)` builder method.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]