Anshul Garg
02/07/2024, 7:15 AMevent_time.
• The second query creates time aggregating HOP windows on event_time every minute aggregating data for last 60 mins.
The problem comes on at the next step.
• The third query uses the window_end time from the 2nd query to create another HOP window, this is where an error is thrown.
Exception in thread "main" org.apache.flink.table.api.TableException: Window aggregate can only be defined over a time attribute column, but TIMESTAMP(3) encountered.
at org.apache.flink.table.planner.plan.rules.logical.StreamLogicalWindowAggregateRule.getInAggregateGroupExpression(StreamLogicalWindowAggregateRule.scala:49)
at org.apache.flink.table.planner.plan.rules.logical.LogicalWindowAggregateRuleBase.onMatch(LogicalWindowAggregateRuleBase.scala:79)
Can anyone help me with this? I have also tried using a single nested query for this purpose and still it throws the same error.
I understand that the window_end field in the third query isn't a time attribute, but how do I achieve that in my case? Also is this a good practice?
Sample queries:
query 1:
CREATE TABLE events (
`col1` STRING,
`EventTime` STRING,
`event_time` as to_timestamp(`EventTime`, 'yyyy-MM-dd''T''HH:mm:ss''Z'''),
WATERMARK FOR `event_time` as `event_time` - INTERVAL '60' SECOND ) WITH (
'connector' = 'kafka',
'topic' = 'sample_topic',
'properties.bootstrap.servers' = 'brokers',
'properties.group.id' = 'cg')
query 2:
select col1,
HOP_END(event_time, INTERVAL '1' MINUTE, INTERVAL '60' MINUTE) AS window_end,
get_count(concat(col1, "suffix")) AS items
FROM events
GROUP BY HOP_END(event_time, INTERVAL '1' MINUTE, INTERVAL '60' MINUTE),
col1
And register a temporary table on this ☝️ named table1. get_count is a simle udf to dedup number of events.
query3:
select col1,
max(items)
HOP_START(window_end, INTERVAL '1' MINUTE, INTERVAL '15' MINUTE) as start_time,
HOP_END(window_end, INTERVAL '1' MINUTE, INTERVAL '15' MINUTE) as start_end
FROM table1
GROUP BY HOP_END(window_end, INTERVAL '1' MINUTE, INTERVAL '15' MINUTE),
col1
and the last query is a simple sink query.
Can anyone help me with this??Tilman Krokotsch
02/08/2024, 8:23 AMevent_time which is therefore the event time of the row. The second window needs to be defined on event_time , too. I would suggest including it in in the select of query 2. Doing this, you should be able to rewrite query 3 to HOP_START(event_time, INTERVAL '1' MINUTE, INTERVAL '15' MINUTE). The column event_time of query 2 should contain the last event timestamp that is possible in the window, i.e., window_end - 1 .Anshul Garg
02/08/2024, 8:33 AMevent_time which I don't want to do because its a time aggregation query. Apologies, I missed the fact that both query 2 and query 3 are also grouped by on the time window and rest of the columns.Tilman Krokotsch
02/08/2024, 9:33 AMAnshul Garg
02/08/2024, 9:38 AMAnshul Garg
02/12/2024, 5:20 AMTilman Krokotsch
02/13/2024, 1:49 PMHOP directly instead of HOP_END and HOP_START ? HOP should give you an additional column window_time that serves as the event time of the new windows. Using window_time in the last query should enable you to window again.Anshul Garg
03/15/2024, 11:48 AMException in thread "main" org.apache.flink.table.api.ValidationException: SQL validation failed. From line 5, column 8 to line 5, column 65: Group function '$HOP' can only appear in GROUP BY clause
at org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$validate(FlinkPlannerImpl.scala:187)
at org.apache.flink.table.planner.calcite.FlinkPlannerImpl.validate(FlinkPlannerImpl.scala:113)Tilman Krokotsch
03/18/2024, 7:38 AM