【发布时间】:2021-03-24 12:53:18
【问题描述】:
我正在使用 KSQL 来跟踪车队管理系统停靠之间的延迟,为简单起见,我有 2 个流 trips 和 tasks,它们从 debezium 获取数据馈送,到目前为止一切顺利。
我的问题是当我创建一个反映一些聚合数据的 KSQL 表时,我假设支持主题最终应该有一个压缩的结果,但实际上它不是,如下例所示
-- trips stream
CREATE STREAM trips_raw (
id bigint, gross_merchandise_value double, vehicle_id bigint, trip_code string,
status string,time_slot string, number_of_orders integer, supplier_id integer,
trip_start_time bigint, agent_id integer, trip_number integer, returnes_handled BOOLEAN,
modification_date bigint, created_by integer, modified_by integer, creation_date bigint
)
WITH (KAFKA_TOPIC='trips', VALUE_FORMAT='json');
--tasks stream
CREATE STREAM tasks_raw (id bigint, delivery_trip_id bigint, agent_id integer, creation_date bigint,
modification_date bigint,
status string, created_by integer, modified_by integer, request_id bigint)
WITH (KAFKA_TOPIC='tasks',VALUE_FORMAT='json');
-- THE AGGREGATED TABLE (just simple view for sake of simplicity)
create table trips_actions_count as
select count(1), ID from trips_raw
group by ID;
----- TEST DATA ------
INSERT INTO trips_raw (
id, gmv, vehicle_id , trip_code, status, trip_start_time , MODIFICATION_DATE, CREATED_BY, MODIFIED_BY,CREATION_DATE
) VALUES (
1, 100.5, 523, 'TRIP_1', 'CREATED', 1616480285000, 1616530285000, 123, 123, 1616444781000
);
INSERT INTO trips_raw (
id, gmv, vehicle_id , trip_code, status, trip_start_time , MODIFICATION_DATE, CREATED_BY, MODIFIED_BY,CREATION_DATE
) VALUES (
1, 100.5, 523, 'TRIP_1', 'ARRIVED', 1616480285000, 1616540285000, 123, 123, 1616444781000
);
INSERT INTO trips_raw (
id, gmv, vehicle_id , trip_code, status, trip_start_time , MODIFICATION_DATE, CREATED_BY, MODIFIED_BY,CREATION_DATE
) VALUES (
1, 100.5, 523, 'TRIP_1', 'COMPLETED', 1616480285000, 1616550285000, 123, 123, 1616444781000
);
当我跟踪创建的支持表 TRIPS_ACTIONS_COUNT 的主题时,我得到了以下结果,
kafka-console-consumer --bootstrap-server localhost:9092 --topic TRIPS_ACTIONS_COUNT --from-beginning
{"KSQL_COL_0":1}
{"KSQL_COL_0":2}
{"KSQL_COL_0":3}
kafka-topics --bootstrap-server localhost:9092 --describe --topics-with-overrides --topic TRIPS_ACTIONS_COUNT
Topic: TRIPS_ACTIONS_COUNT PartitionCount: 3 ReplicationFactor: 1 Configs: cleanup.policy=compact,segment.bytes=1073741824
我假设TRIPS_ACTIONS_COUNT 应该被压缩,这样当消费者读取它时,它应该只获得特定键的最新值,在我的例子中是{"KSQL_COL_0":3}。
我想我错过了什么,不知道是什么?
【问题讨论】:
标签: apache-kafka ksqldb