swaminathanmanish opened a new pull request, #20345:
URL: https://github.com/apache/pinot/pull/20345
## Summary
Adds a reserved stream field, `__value`, for the whole message value,
alongside the existing `__key`, `__header$<name>` and `__metadata$<name>`. When
a table reads `__value`, `JSONMessageDecoder` stores the entire message as one
JSON value instead of splitting it into one field per top-level key. No new
config property is added; the table opts in by reading the field in a transform.
## Problem
`JSONMessageDecoder` turns each top-level key of a message into a field, and
a field fills the column with the same name. When the payload is not designed
around the table schema, this fails silently in two ways.
**Payload keys collide with columns.** A header `source=vehicle.cabin` is
mapped to the column `source` by a transform:
```
message: {"source": "internal", "state": "IDLE"}
stored: source = "internal"
```
Ingestion transforms skip a column that already has a value, so the header
value is never written. Payload keys are not known in advance, so renaming
columns does not prevent this.
**JSON values that are not objects are dropped.** `"IDLE"`, `42`, `true`,
`[1,2]` and `null` have no keys to split. The decoder throws "Top-level JSON
value must be an object", and the row is dropped together with its headers.
## Solution
```json
"transformConfigs": [
{"columnName": "payload", "transformFunction": "\"__value\""},
{"columnName": "source", "transformFunction":
"fromUtf8(\"__header$source\")"},
{"columnName": "state", "transformFunction": "jsonPathString(payload,
'$.state', null)"}
]
```
- If `__value` is in the decoder's `fieldsToRead`, `JSONMessageDecoder`
stores the whole message in `__value` as canonical JSON text and emits no field
per key.
- Any JSON value is accepted. A payload that is not exactly one JSON value
(plain text, trailing content, empty or truncated) is rejected, the same way a
malformed message is today.
- Payload fields become columns only through explicit transforms, which can
read the stored column or `__value` directly.
- Table config validation rejects combinations that would leave columns
empty or silently fall back to splitting.
| Message | Today | Reading `__value` |
|---|---|---|
| `{"source":"internal","state":"IDLE"}` | `source = internal`; header value
lost | `payload` = whole message; `source` = header value |
| `"IDLE"`, `42`, `true`, `[1,2]`, `null` | dropped | stored as-is |
| `{"a":1} junk` | stored as `{"a":1}`; trailing content silently lost |
rejected |
| plain text, empty | dropped | dropped |
Querying a stored payload:
```sql
SELECT JSON_EXTRACT_SCALAR(payload, '$.state', 'STRING', 'none') FROM t
SELECT * FROM t WHERE JSON_MATCH(payload, '"$" = ''IDLE''')
```
## Reviewer guide
| File | Change |
|---|---|
| `StreamDataDecoderImpl` | `VALUE_KEY = "__value"`, next to `KEY`,
`HEADER_KEY_PREFIX` and `METADATA_KEY_PREFIX` |
| `JSONMessageDecoder` | `init`: enables the mode when `fieldsToRead`
contains `__value`; rejects a custom record extractor or unsupported format.
`decode`: one branch ahead of the existing path, which is unchanged |
| `JsonPayloadParser` | default methods `supportsParseValue()` (false) and
`parseValue()` |
| `JacksonPayloadParser` | `parseValue()` using `FAIL_ON_TRAILING_TOKENS`
and `USE_BIG_DECIMAL_FOR_FLOATS`; covers `TEXT`, `SMILE` and `CBOR` |
| `PostgresJsonbPayloadParser`, `AutoDetectPayloadParser` | strip the
version byte / delegate to the detected parser. `SQLITE_JSONB` keeps the
default and is rejected at init |
| `TableConfigUtils` | `validateStreamValueField`, called from
`validateEffectiveTableConfig` |
The validation applies when a table transform, schema transform, filter or
ingestion aggregation reads `__value`. It rejects:
- OFFLINE tables;
- `schemaConformingTransformerConfig` or `complexTypeConfig`;
- a non-JSON decoder, a custom record extractor, or
`jsonFormat=SQLITE_JSONB`;
- an expression that reads a top-level payload key, and a schema column with
no transform, since neither can be populated.
Independently of that, a schema column named `__value` is rejected.
## Compatibility
- Decoding is unchanged for tables that do not read `__value`.
- Existing table configs are unaffected unless they have a column named
`__value`.
- Nothing changes in segment formats, communication between components or
query paths.
- Servers on older versions ignore `__value` and split the payload as
before, so enable it on a table only after every server consuming that table
has been upgraded.
## Testing
- **Unit tests:**
- `JSONMessageDecoderValueFieldTest`: every JSON value type,
pretty-printed and very large numbers; only `__value` emitted; unchanged
behaviour when `__value` is not read; invalid payloads rejected; Smile, CBOR,
Postgres JSONB and auto-detect; offset decoding; unsupported configs rejected
at init.
- `TableConfigUtilsStreamValueFieldTest`: every validation rule, accepted
configs, tables not reading `__value` unaffected, and the check running through
`TableConfigUtils.validate`.
- Existing `JSONMessageDecoderTest`, `TableConfigUtilsTest` and
`StreamDataDecoderImplTest` pass.
- **Backward compatibility:** decoder output with and without this change
compared on 122 cases (5 formats × 13 payloads × with and without a field
list). Byte-identical when `__value` is not read.
- **Query regression:** a table that splits the payload (header column, JSON
column with index, derived column, multi-value column), built with and without
the change. Identical results on 7 queries.
- **Performance:** decode time, 3 runs each.
- Not reading `__value`: within ±2% of master. 142 B payload ~510 ns (all
fields) or ~350 ns (selected fields); 100 KB payload ~435 µs or ~220 µs.
- Reading `__value`: ~870 ns (142 B) and ~545 µs (100 KB), because the
value is parsed, serialized and then parsed again by the JSON column.
- **End to end:** a local Kafka broker and a Pinot cluster (controller,
broker, 3 servers), with messages carrying headers consumed by three realtime
tables: today's config, `payload = "__value"` with derived columns, and columns
derived directly from `__value`. Checked that:
- header columns are no longer overridden;
- string, number, array and `null` payloads are ingested;
- invalid payloads are dropped;
- segments commit.
- **Queries:** on committed and consuming segments, identical results on the
single-stage and multi-stage engines:
- `JSON_EXTRACT_SCALAR` on nested paths and on `$`;
- `JSON_MATCH` on nested paths, `"$"` and `"$[*]"`;
- numeric filters;
- `GROUP BY` and `AVG` on derived columns;
- a multi-stage `JOIN`.
- **Columns added later:** reloading a segment with new derived columns
computed them from the stored payload.
🤖 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]