简体   繁体   中英

Get Timestamp difference in ksql

I need to calculate the difference of the two timestamp in KSQL confluent.cloud.

Below are my queries,

SELECT
  ENTITY -> IENTITYID,
  ENTITY -> DTINSERTDATE,
  ENTITY -> DTUPDATEDATE, 
  HEADERS -> OPERATION,
  TIMESTAMPTOSTRING(ROWTIME, 'yyyy-MM-dd HH:mm:ss.SSS') AS rowtime_formatted,
  CAST(ENTITY -> DTUPDATEDATE AS TIMESTAMP) AS UpdatedDateFROMtblEntity
FROM tblEntity
EMIT CHANGES
LIMIT 10;

Here, I have two timestamp such as ROWTIME and UpdatedDateFROMtblEntity. So, how to calculate the difference on those timestamps?. I need this in milliseconds. Please help me to resolve this issues.

SELECT UNIX_TIMESTAMP(col1) - UNIX_TIMESTAMP(col2) 
FROM STREAM1 EMIT CHANGES;

Reference: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-reference/scalar-functions/#unix_timestamp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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