ksql json 带有破折号 (-) 的字段名
ksql json fieldname with a dash (-)
我的 JSON 中的一个字段名称是 "User-Agent"。当我尝试使用该字段名称创建流时,KSQL 不喜欢破折号。我试过单引号、双引号,并以各种方式转义——没有成功。
如何从主题中的 json 中获取该字段以放入 KSQL 流中?
这是我的一些尝试的日志:
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, 'user-agent' varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
line 1:76: extraneous input ''user-agent'' expecting {'ADD', ...}
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, user-agent varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
line 1:80: extraneous input '-' expecting {'ADD', ...}
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, "user-agent" varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
Message
----------------
Stream created
----------------
ksql> select * from tmpstream;
Code generation failed for SelectValueMapper
Caused by: Line 1, Column 15: Expression "TMPSTREAM_user" is not an rvalue
ksql> drop stream tmpstream;
Message
--------------------------------
Source TMPSTREAM was dropped.
--------------------------------
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, "user\-agent" varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
Message
----------------
Stream created
----------------
ksql> select * from tmpstream;
Code generation failed for SelectValueMapper
Caused by: Line 1, Column 15: Expression "TMPSTREAM_user" is not an rvalue
我的 JSON 中的一个字段名称是 "User-Agent"。当我尝试使用该字段名称创建流时,KSQL 不喜欢破折号。我试过单引号、双引号,并以各种方式转义——没有成功。
如何从主题中的 json 中获取该字段以放入 KSQL 流中?
这是我的一些尝试的日志:
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, 'user-agent' varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
line 1:76: extraneous input ''user-agent'' expecting {'ADD', ...}
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, user-agent varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
line 1:80: extraneous input '-' expecting {'ADD', ...}
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, "user-agent" varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
Message
----------------
Stream created
----------------
ksql> select * from tmpstream;
Code generation failed for SelectValueMapper
Caused by: Line 1, Column 15: Expression "TMPSTREAM_user" is not an rvalue
ksql> drop stream tmpstream;
Message
--------------------------------
Source TMPSTREAM was dropped.
--------------------------------
ksql> create stream tmpstream (startTimeEpoch bigint, type VARCHAR, src VARCHAR, "user\-agent" varchar) with (KAFKA_TOPIC='foo', VALUE_FORMAT='JSON');
Message
----------------
Stream created
----------------
ksql> select * from tmpstream;
Code generation failed for SelectValueMapper
Caused by: Line 1, Column 15: Expression "TMPSTREAM_user" is not an rvalue