簡體   English   中英

如何從KSQL窗口表對應的kafka主題中獲取窗口開始或結束時間?

[英]How to get window start or end time from kafka topic corresponding to KSQL windowed table?

我想從 kafka-console-consumer 命令獲取窗口開始時間戳(這里是 1530008520000)。

它適用於 KSQL:

ksql> select * from DEV_MONITOR_RULE_2557_104782_233_2_TABLE;

1530008581051 | 2557 : Window{start=1530008520000 end=-} | 2557 | 2 | 1530008581051

但它不適用於 kafka-console-consumer?

./bin/kafka-console-consumer --zookeeper 10.12.0.157:2181 --topic DEV_MONITOR_RULE_2557_104782_233_2_TABLE

{"HITCOUNTS":2,"TENANTID":2557,"HITTIME":1530008581051}

如何從 kafka-console-consumer 打印窗口開始時間(這里是 1530008520000)?

謝謝!

窗口開始時間被反映在ROWTIME的KSQL消息,並且在消息卡夫卡的時間戳。 您可以使用用於處理 Kafka 消息的標准 API 訪問此時間戳。

AFAIK kafka-console-consumer不支持顯示時間戳。 但是像kafkacat這樣的東西。

這是 KSQL 中的一些聚合數據,其中ROWTIME顯示窗口的開始(並且TIMESTAMPTOSTRING用於漂亮地打印它):

ksql> SELECT TIMESTAMPTOSTRING(ROWTIME, 'yyyy-MM-dd HH:mm:ss'), ROWTIME, STARS, STAR_COUNT FROM RATINGS_AGG2;
2018-06-27 09:30:00 | 1530091800000 | 1 | 2
2018-06-27 09:30:00 | 1530091800000 | 4 | 6
2018-06-27 09:30:00 | 1530091800000 | 2 | 2
2018-06-27 09:30:00 | 1530091800000 | 3 | 3

現在kafkacat的相同主題:

$ kafkacat -b localhost:9092 -C -K: \
  -f '\nTimestamp: %T\t\tValue (%S bytes): %s' \
  -t RATINGS_AGG2

Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":1,"STARS":1}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":2,"STARS":1}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":3,"STARS":3}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":5,"STARS":1}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":6,"STARS":3}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":7,"STARS":1}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":7,"STARS":3}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":9,"STARS":1}
Timestamp: 1530091800000                Value (26 bytes): {"STAR_COUNT":9,"STARS":3}

您是否嘗試過 kafka-console-consumer 選項print.timestamp=true

$ kafka-console-consumer --property print.timestamp=true ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM