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

AvroConfluent

输入输出别名

描述

AvroConfluent 支持解码常用于 KafkaConfluent Schema Registry 的单对象 Avro 消息。 每个 Avro 消息包含一个可以通过 Schema Registry 解析到实际模式的模式 ID。 模式在解析后被缓存。

数据类型匹配

下面的表格显示了 Apache Avro 格式支持的所有数据类型,以及它们在 INSERTSELECT 查询中的对应 ClickHouse 数据类型

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

示例用法

要快速验证模式解析,您可以使用 kafkacat 配合 clickhouse-local:

要使用 AvroConfluentKafka:

格式设置

Schema Registry URL 通过 format_avro_schema_registry_url 配置。

备注

设置 format_avro_schema_registry_url 需要在 users.xml 中进行配置,以便在重新启动后保持其值。您也可以使用 Kafka 表引擎的 format_avro_schema_registry_url 设置。

设置描述默认值
input_format_avro_allow_missing_fields对于 Avro/AvroConfluent 格式:当模式中未找到字段时,使用默认值而不是错误0
input_format_avro_null_as_default对于 Avro/AvroConfluent 格式:在空值和非 Nullable 列的情况下插入默认值0
format_avro_schema_registry_url对于 AvroConfluent 格式:Confluent Schema Registry URL。