简体   繁体   English

使用列的默认值创建 KSQL stream?

[英]Create KSQL stream with default values for a column?

Is it possible to create a stream from Kafka topic with default values or fixed value for a few columns which are not present in the topic?是否可以从 Kafka 主题创建 stream 主题中不存在的一些列的默认值或固定值?

create stream test
(
Balance BIGINT,
Name STRING <---- want to specify a fix value ("NA" or "no name")  for this column which is not in topic data
)
with (kafka_topic='test_topic', value_format='JSON');

You can't do this on the creation of the initial stream against the topic, but you could create a derived stream using coalesce :您不能在针对该主题创建初始 stream 时执行此操作,但您可以使用coalesce创建派生的 stream :

create stream test
    (Balance BIGINT,
     Name    STRING )
    with (kafka_topic='test_topic', value_format='JSON');

create stream test_2 AS
    SELECT BALANCE, 
           COALESCE(Name, 'No Name') as name
    from test;

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

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