简体   繁体   English

在 KSQLDB 中从具有字符串类型值的主题创建表

[英]Creating a table from topic with value of String type in KSQLDB

How can one create a table from a topic which contains value of type String?如何从包含字符串类型值的主题创建表?

We have some topics that contains rdf data embedded inside strings, in a sense it is just a string value.我们有一些主题包含嵌入在字符串中的 rdf 数据,在某种意义上它只是一个字符串值。 Based on the KSQLDB documentation, we need to use value_format='KAFKA' with WRAP_SINGLE_VALUE=false given that it is an anonymous value.根据 KSQLDB 文档,我们需要使用 value_format='KAFKA' 和 WRAP_SINGLE_VALUE=false ,因为它是一个匿名值。

CREATE SOURCE Table source_table_proxy (
    key VARCHAR primary KEY,
    value VARCHAR
) WITH (
    KEY_FORMAT='KAFKA',
    VALUE_FORMAT='KAFKA', 
    WRAP_SINGLE_VALUE=false,
    kafka_topic = 'topic'
); 

This is the topic info:这是主题信息:

Key Type: STRING
Value Type: STRING
Topic Info
Partitions: 12
Replication: 1

Weirdly we get the following error:奇怪的是,我们得到以下错误:

The 'KAFKA' format only supports a single field. Got: [`VALUE` STRING, `ROWPARTITION` INTEGER, `ROWOFFSET` BIGINT]

Is there any workaround this issue?有没有解决这个问题的方法?

Unclear why you need KAFKA format.不清楚为什么需要KAFKA格式。

The JSON format will work for plain (primitive) strings as well JSON格式也适用于普通(原始)字符串

supports reading and writing top-level primitives, arrays and maps.支持读写顶级原语,arrays 和映射。

For example, given a SQL statement with only a single field in the value schema and the WRAP_SINGLE_VALUE property set to false:例如,给定一个 SQL 语句,其值模式中只有一个字段,并且WRAP_SINGLE_VALUE属性设置为 false:

CREATE STREAM x (ID BIGINT) WITH (VALUE_FORMAT='JSON', WRAP_SINGLE_VALUE=false,...);

And a JSON value of: JSON 值为:

 10

ksqlDB can deserialize the values into the ID field of the stream ksqlDB 可以将值反序列化到 stream 的 ID 字段中

https://docs.ksqldb.io/en/latest/reference/serialization/#top-level-primitives-arrays-and-maps https://docs.ksqldb.io/en/latest/reference/serialization/#top-level-primitives-arrays-and-maps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM