raghavyadav01 opened a new pull request, #20303:
URL: https://github.com/apache/pinot/pull/20303

   ## Problem
   Every multi-stage query on a table with an OPEN_STRUCT column failed, even 
`SELECT COUNT(*)`, because building the
   table's row type threw `Unsupported type: OPEN_STRUCT`.
   
   ## Change
   - `TypeFactory` maps an OPEN_STRUCT column to `OpenStructSqlType`, a 
`MAP<VARCHAR, VARCHAR>` that carries the
     column's declared child field specs as Calcite types. The declared types 
are part of the digest, so different
     declarations are different types. A complex declared child (MAP, LIST, 
STRUCT, OPEN_STRUCT) is VARCHAR.
   - `PinotItemOperator` replaces Calcite's `ITEM`: for an OPEN_STRUCT operand 
and a literal key, `v['k']` has the key's
     declared type, else VARCHAR, always nullable. It matches the single-stage 
engine, which reads a declared key with its
     type and an undeclared key as STRING. A non-literal key (`v[col]`) is 
rejected at validation, since the leaf resolves
     the key once. Every other operand type behaves as before.
   - Selecting the whole column returns JSON text (`ColumnDataType.JSON`), as 
in the single-stage engine.
   - `TypeFactory.leastRestrictive` keeps the type through UNION ALL, keeping 
the keys every branch declares with the same
     type (nullability aside). `CASE ... ELSE NULL` and `COALESCE(v, NULL)` 
keep it too.
   - `LeafOperator` converts a value using its logical type where the plan 
types it differently (`TypeUtils.convert`):
     BOOLEAN to VARCHAR reads `true`/`false` and TIMESTAMP reads timestamp 
text, as `CAST(x AS VARCHAR)` does, instead of
     the stored `1`/`0` and epoch millis; an array reads as JSON text; numeric 
text converts to a number as ingestion does
     (a segment can serve a key as STRING while the table now declares it 
numeric), and text that does not convert fails
     with both types named.
   
   ## Behavior notes
   - The leaf conversion applies to any leaf column whose stored type differs 
from the plan, not only OPEN_STRUCT keys.
     Before this change BOOLEAN to VARCHAR returned `"1"`/`"0"` and STRING to a 
number failed with a ClassCastException.
   - An undeclared key compared to a number follows SQL coercion: `v['x'] > 5` 
casts the key and compares numerically,
     where the single-stage engine compares the text. A declared numeric key 
compared to text (`v['n'] = 'abc'`) fails at
     planning, as for any numeric column.
   - Known limitations: a key read the planner places above an exchange (for 
example on a subquery's output after
     `ORDER BY ... LIMIT`) fails with `Unsupported function: ITEM`, as for MAP 
columns today, since `ITEM` is only
     evaluated in the leaf stage. `SELECT v ... UNION ALL SELECT NULL ...` 
fails to plan, as it did before.
   - Upgrade servers before brokers: an older server cannot convert a STRING 
leaf value for a numeric plan type.
   
   ## Tests
   - `OpenStructMultiStagePlanningTest`: declared keys typed by their spec, 
undeclared and nested keys VARCHAR, numeric
     filter and aggregation plan, whole column JSON, UNION ALL keeps the type 
and merges declarations, CASE/COALESCE keep
     JSON, non-literal key rejected, undeclared key compared to a number is 
cast, queries not reading the column plan.
   - `TypeFactoryTest`: the OPEN_STRUCT mapping, nullability changes, and 
`leastRestrictive` keeping agreed keys.
   - `TypeUtilsTest`, `LeafOperatorTest`: BOOLEAN/TIMESTAMP/array to VARCHAR, 
numeric text converts or fails, never
     truncated or wrapped.
   - `OpenStructIngestionCommitTestBase#testMultiStageMatchesSingleStage` 
(offline and realtime): runs filters,
     aggregations, group-by and order-by on declared dense and sparse keys on 
both engines and compares results; plus a
     self-join on a key and the whole column as JSON.
   - Without this change every new test fails: planning throws `Unsupported 
type: OPEN_STRUCT`, the whole column maps to
     MAP, and booleans read `"1"`.
   - `pinot-query-planner` and `pinot-query-runtime` suites pass.
   


-- 
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]

Reply via email to