AvroConfluent
Input | Output | Alias |
---|---|---|
✔ | ✗ |
Description
AvroConfluent 支持解码在 Kafka 和 Confluent Schema Registry 中常用的单对象 Avro 消息。每个 Avro 消息嵌入一个 schema ID,可以借助 Schema Registry 解析为实际的 schema。schemas 在解析后会被缓存。
Data Types Matching
The table below shows all data types supported by the Apache Avro format, and their corresponding ClickHouse data types in INSERT
and SELECT
queries.
Avro 数据类型 INSERT | ClickHouse 数据类型 | Avro 数据类型 SELECT |
---|---|---|
boolean , int , long , float , double | Int(8\16\32), UInt(8\16\32) | int |
boolean , int , long , float , double | Int64, UInt64 | long |
boolean , int , long , float , double | Float32 | float |
boolean , int , long , float , double | Float64 | double |
bytes , string , fixed , enum | String | bytes 或 string * |
bytes , string , fixed | FixedString(N) | fixed(N) |
enum | Enum(8\16) | enum |
array(T) | Array(T) | array(T) |
map(V, K) | Map(V, K) | map(string, K) |
union(null, T) , union(T, null) | Nullable(T) | union(null, T) |
union(T1, T2, …) ** | Variant(T1, T2, …) | union(T1, T2, …) ** |
null | Nullable(Nothing) | null |
int (date) *** | Date, Date32 | int (date) *** |
long (timestamp-millis) *** | DateTime64(3) | long (timestamp-millis) *** |
long (timestamp-micros) *** | DateTime64(6) | long (timestamp-micros) *** |
bytes (decimal) *** | DateTime64(N) | bytes (decimal) *** |
int | IPv4 | int |
fixed(16) | IPv6 | fixed(16) |
bytes (decimal) *** | Decimal(P, S) | bytes (decimal) *** |
string (uuid) *** | UUID | string (uuid) *** |
fixed(16) | Int128/UInt128 | fixed(16) |
fixed(32) | Int256/UInt256 | fixed(32) |
record | Tuple | record |
* bytes
是默认值,通过设置 output_format_avro_string_column_pattern
控制。
** Variant类型 隐式接受 null
作为字段值,因此,例如 Avro union(T1, T2, null)
将转换为 Variant(T1, T2)
。因此,在从 ClickHouse 生成 Avro 时,我们必须始终将 null
类型包含在 Avro union
类型集中,因为我们不知道在模式推理过程中任何值是否实际为 null
。
*** Avro 逻辑类型
不支持的 Avro 逻辑数据类型:
time-millis
time-micros
duration
Example Usage
要快速验证 schema 的解析,可以使用 kafkacat 与 clickhouse-local:
要在 Kafka 中使用 AvroConfluent
:
Format Settings
Schema Registry URL 通过 format_avro_schema_registry_url
进行配置。
设置 format_avro_schema_registry_url
需要在 users.xml
中配置,以便在重启后保持其值。您也可以使用 Kafka
表引擎的 format_avro_schema_registry_url
设置。
Setting | Description | Default |
---|---|---|
input_format_avro_allow_missing_fields | 对于 Avro/AvroConfluent 格式:当在 schema 中找不到字段时,使用默认值而不是错误。 | 0 |
input_format_avro_null_as_default | 对于 Avro/AvroConfluent 格式:在 null 和非 Nullable 列的情况下插入默认值。 | 0 |
format_avro_schema_registry_url | 对于 AvroConfluent 格式:Confluent Schema Registry URL。 |