prajwal-jadhav01 opened a new issue, #20431:
URL: https://github.com/apache/pinot/issues/20431
## Motivation
`pinot-flink-connector` only offers `PinotSink` for the DataStream API.
Flink SQL and Table API users can't write to Pinot directly. There is no
`DynamicTableSinkFactory`, so this doesn't work today:
```sql
CREATE TABLE orders_pinot (
order_id STRING,
amount DOUBLE,
ts TIMESTAMP(3)
) WITH (
'connector' = 'pinot',
'controller.url' = 'http://pinot-controller:9000',
'table.name' = 'orders'
);
INSERT INTO orders_pinot SELECT order_id, amount, ts FROM source_table;
```
Today users either write a Java DataStream job just for the sink, or add a
Kafka topic in between and let Pinot ingest from it. For batch loads,
backfills, and CDC/ETL pipelines that are fine with minute-level freshness, the
Kafka hop is extra infrastructure for no gain.
This would also pair with Pinot's own SQL-first direction (`CREATE TABLE ...
WITH (options)` DDL in #18723): a user could define and fill a Pinot table
entirely from SQL.
**Not the goal:** sub-second real-time ingestion. Pinot's native stream
ingestion stays the right choice there, and the docs would say so.
## Prior work
- FLIP-166 proposed a batch-only Pinot Table API sink inside Flink. It was
never voted on, and the Pinot connector now lives in this repo.
- Similar OLAP stores ship Flink SQL sinks (StarRocks, Doris). ClickHouse's
official Flink connector lists Table API support as planned.
- Commercial Flink platforms (e.g. Decodable) built their own Pinot sinks,
so users want this.
- No existing Pinot issue or PR covers a Table API sink (searched issues and
PRs).
## Proposal
Add a `PinotDynamicTableSinkFactory` (identifier `pinot`) to
`pinot-flink-connector`. It wraps the existing `PinotSink`, so segment build
and upload stay in one place and the new code is only the SQL glue:
- At planning time, fetch the Pinot `Schema` and `TableConfig` from the
controller with `PinotAdminClient`. Validate the SQL columns and types against
them and fail early with a clear error.
- Convert `RowData` to `GenericRow` with a new `RowDataGenericRowConverter`,
next to `FlinkRowGenericRowConverter`.
- `getChangelogMode()` returns insert-only. Updating queries are rejected by
the planner.
- Works in batch and streaming mode.
New classes in `org.apache.pinot.connector.flink.table`:
`PinotDynamicTableSinkFactory`, `PinotDynamicTableSink`,
`PinotConnectorOptions`, `RowDataGenericRowConverter`,
`PinotSqlSchemaValidator`, plus the `META-INF/services` factory file.
<details>
<summary>Options</summary>
| Option | Required | Default | Notes |
|---|---|---|---|
| `connector` | yes | — | `pinot` |
| `controller.url` | yes | — | e.g. `http://controller:9000` |
| `table.name` | yes | — | raw table name |
| `table.type` | no | `OFFLINE` | `OFFLINE` or `REALTIME` (uploaded
segments) |
| `auth.token` | no | — | used for the metadata fetch and segment upload
(builds on #20121); marked sensitive so it is never logged |
| `sink.segment.max-rows` | no | 500000 | same as the DataStream sink
default |
| `sink.upload.parallelism` | no | 5 | upload threads per subtask |
| `sink.segment.name-prefix` | no | — | passed through |
| `sink.output-dir` | no | `/tmp/pinotoutput` | local segment build dir |
| `sink.parallelism` | no | planner default | standard Flink option |
</details>
<details>
<summary>Type mapping (RowData → GenericRow)</summary>
| Flink SQL | Pinot |
|---|---|
| CHAR / VARCHAR / STRING | STRING (or JSON) |
| BOOLEAN | BOOLEAN |
| TINYINT / SMALLINT / INT | INT |
| BIGINT | LONG |
| FLOAT / DOUBLE | FLOAT / DOUBLE |
| DECIMAL(p,s) | BIG_DECIMAL |
| TIMESTAMP(p) / TIMESTAMP_LTZ | TIMESTAMP or LONG epoch millis, following
the field spec |
| DATE | INT days or STRING, following the field spec |
| BYTES / VARBINARY | BYTES |
| ARRAY<T> | multi-value column of T |
| ROW / MAP | rejected in v1 (JSON mapping could follow) |
Every SQL column must exist in the Pinot schema; single-value vs multi-value
mismatches are errors. Pinot columns missing from the SQL table get Pinot
defaults.
</details>
## Scope
**v1:** insert-only, OFFLINE and REALTIME (uploaded segments) tables, batch
and streaming mode, at-least-once delivery (same as `PinotSink` today: buffers
flush and uploads finish on checkpoint, so a failure can replay records into
new segments). The docs will state this plainly.
**Later, not v1:**
- Upsert tables. Rows must be partitioned like the table's stream
partitions, with parallelism equal to the partition count. This could use
Flink's `DISTRIBUTED BY` / `SupportsBucketing`.
- Effectively-once via deterministic segment names per (subtask, checkpoint)
plus a SinkV2 committer.
## Compatibility
Purely additive: a new package and service file inside
`pinot-flink-connector`. No change to `PinotSink` behaviour or existing APIs.
Adds `flink-table-api-java` and `flink-table-common` as `provided`
dependencies. Targets the Flink version already on master (2.3).
## Validation
- Unit tests: option validation, the type converter (every mapping, nulls,
arrays), the schema validator.
- Integration tests on the existing embedded-cluster setup:
`TableEnvironment` in batch mode with `INSERT INTO ... VALUES`, row counts
checked with a broker query; one streaming run with checkpoints; one run
against a Basic Auth cluster.
- README section and a pinot-docs page.
## Questions for maintainers
1. Is this welcome inside `pinot-flink-connector`, or would you prefer a
separate module (e.g. `pinot-flink-sql-connector`)?
2. OK to add the Flink table modules as `provided` dependencies?
3. Any preference on option names, e.g. matching the batch-ingestion
property names?
I'd like to implement this myself. I'm also working on the connector's auth
support (#20120 / #20121), which the `auth.token` option builds on. Could a
maintainer add the `PEP-Request` label if this looks reasonable?
--
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]