跳到主要内容
跳到主要内容

AvroConfluent

InputOutputAlias

Description

AvroConfluent 支持解码在 KafkaConfluent 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 数据类型 INSERTClickHouse 数据类型Avro 数据类型 SELECT
boolean, int, long, float, doubleInt(8\16\32), UInt(8\16\32)int
boolean, int, long, float, doubleInt64, UInt64long
boolean, int, long, float, doubleFloat32float
boolean, int, long, float, doubleFloat64double
bytes, string, fixed, enumStringbytesstring *
bytes, string, fixedFixedString(N)fixed(N)
enumEnum(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, …) **
nullNullable(Nothing)null
int (date) ***Date, Date32int (date) ***
long (timestamp-millis) ***DateTime64(3)long (timestamp-millis) ***
long (timestamp-micros) ***DateTime64(6)long (timestamp-micros) ***
bytes (decimal) ***DateTime64(N)bytes (decimal) ***
intIPv4int
fixed(16)IPv6fixed(16)
bytes (decimal) ***Decimal(P, S)bytes (decimal) ***
string (uuid) ***UUIDstring (uuid) ***
fixed(16)Int128/UInt128fixed(16)
fixed(32)Int256/UInt256fixed(32)
recordTuplerecord

* 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 的解析,可以使用 kafkacatclickhouse-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 设置。

SettingDescriptionDefault
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。