我使用融合的Source Connector将数据从Postgres复制到Kafka
以下是我要复制到Kafka的表:
CREATE TABLE public.format_ts_v
(
alerts json,
updated timestamp with time zone NOT NULL DEFAULT now()
)
alerts字段是具有以下格式的json
{"alerts":[{"timedate":4587052516256796700,"elementName":"pariatur commodo","description":"ex eiusmod consectetur"}]
我创建了一个流
CREATE STREAM alerts_stream_json_array
(alerts ARRAY<STRUCT<
timedate INT,
elementName VARCHAR,
description VARCHAR>>,
updated INT)
WITH (KAFKA_TOPIC='cdc1_format_ts_v', VALUE_FORMAT='JSON');
并使用以下内容查看数据
SELECT EXPLODE(alerts)->timedate AS timedate,
EXPLODE(alerts)->elementName AS elementName,
EXPLODE(alerts)->description AS description
FROM alerts_stream_json_array
EMIT CHANGES;
如果我在没有源连接器的情况下直接向Kafka插入消息,则效果很好
/kafkacat/kafkacat/kafkacat -b 127.0.0.1:9092 -P -t cdc1_format_ts_v <<EOF
{"alerts":{"timedate":4587052516256796700,"elementName":"pariatur commodo","description":"ex eiusmod consectetur"}}
EOF
但是,当使用源连接器插入数据时,会在json字符串中添加额外的引号,并且ksql选择不再有效
{"alerts":"[{\x5C"timedate\x5C":4587052516256796700,"elementName\x5C":\x5C"pariatur commodo\x5C",\x5C"description\x5C":\x5C"ex eiusmod consectetur\x5C"}]","updated":1594909653789}
如何避免在json周围加上引号?连报价都可以使用吗?
谢谢