...
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Motivation
...
Besides the main payload, the majority of sources (if not all of the sources) expose additional information. It can simply be simply a read-only metadata such as a Kafka read-offset , or ingestion time or a . Additionally, users might want to read and write only parts of the record that contain data but additionally serve different purposes (partitioning, compaction etc.)
...
Because of the reasons above Kafka will be used for a majority of the examples.
Examples
...
Kafka: ETL: read, transform and write back with key, value. All fields of the key are present in the value as well.
CREATE TABLE kafka_table (
|
...
new ProducerRecord<>( |
Kafka: Generate Kafka’s timestamp (it does not have to be a time attribute)
CREATE TABLE csv_table ( 'timestamp' = 'timestamp' |
Access read-only metadata e.g. partition
Kafka: represents partitions ids as longs:
CREATE TABLE kafka_table ( |
Kinesis: kinesis represents partitions keys as strings:
CREATE TABLE kinesis_table ( |
Kafka: Push down offset filter
CREATE TABLE kafka_table ( |
Kinesis: Specify custom partitioning
CREATE TABLE kinesis_table ( |
Both records will end up in the same partition.
Kafka: Manually specify target partition, overwrite partitioning by key.
CREATE TABLE kinses_table ( |
The two records end up in different partitions even though the resulting Kafka’s keys will be equal for both records.
Details
...
Reading and writing from key, value, timestamp
...
I suggest introducing connector specific properties that allow specifying which fields should end up in which parts of the record. The reason why I am not suggesting having a key-value-metadata format is that there are most often differences across records of different systems, e.g.
- kinesisKinesis, pravega Pravega do not have a key where users can store data
- hbase HBase does not have a concept of timestamp
...
- key.fields, key.format.type, key.format.(<properties-required-by-format>) - this controls which fields should end up in Kafka’s key and what should be the serialization format
- value.fields-include, value.fields-include -
- this controls which fields should end up in the value as well, possible values
- ALL (all fields of the schema, even if they are part of e.g. the key)
- EXCEPT_KEY (all fields of the schema - fields of the key)
- EXCEPT_KEY_TIMESTAMP (all fields of the schema - fields of the key - field of timestamp)
- value.format.type, value.format.(<properties-required-by-format>) - I suggest having the “value” prefix optional, this way we could be backwards compatible with previous declarations
- timestamp.field - property which tells which field to store as Kafka’s timestamp
- (optional support) fields.verify-integrity - controls if we should perform an equality check if a field is contained in different parts of consumer record
If a user has an old DDL statement that deserializes If a user has an old DDL statement that deserialized fields only from the value, but wants to also read data from the key.
...
CREATE TABLE kafka_table (...) WITH ( |
...
- timestamp.field - property which tells which field to store as Kafka’s timestamp
- (optional support) fields.verify-integrity - controls if we should perform an equality check if a field is contained in different parts of consumer record
Summary
...
CREATE TABLE kafka_table ( --optional: (false by default) if true and a field originates from more than a single location (e.g. both in key and value), a check will be performed both values are equal |
Rejected alternatives
...
Marking columns in the schema section:
...
- mixes logical schema definition with physical representation of format and/or source (kafka the only source that has a meaningful key, all other sources like pulsar/kinesis/pravega use key only as a partitioning hash and support string based keys only). Moreover it makes it harder to reason about when implementing CREATE TABLE … AS SELECT …
For CREATE TABLE … AS SELECT … there is no place to put the modifiers, as the schema is derived from the query.
...