Hi, I am facing issue when trying to apply window ...
# troubleshooting
s
Hi, I am facing issue when trying to apply window aggregation after joining streams (interval join). Basically i am unable to retain time attribute column post join which I believe is needed for window aggregations. I tried using
window_time
after joining the streams but still throws the same error
org.apache.flink.table.api.ValidationException: The window function requires the timecol is a time attribute type, but is TIMESTAMP(3)
however when i checked the datatype it says
TIMESTAMP(3) *ROWTIME*
. Please let me know if i'm missing anything. Thanks in advance.
Sharing the queries for reference. For context, i am trying to join orders and transactions streams (both are continuous) and then extract agg metrics over intervals. There are cases of multiple records with same id (possible when status changes) so applying rank and de-duping the rows.
Copy code
create view orders_dedup as select order_id, order_status, order_ts  from (
  select *, ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY order_ts DESC) as rn from orders_kafka 
) where rn=1;


create view txns_dedup as select order_id, payment_method_type, gateway, txn_ts  from (
  select *, ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY txn_ts DESC) as rn from transaction_details_kafka 
) where rn=1;

with orders_joined as (SELECT L.order_id as order_id, R.payment_method_type, L.order_status,
  L.window_start as join_window_start, L.window_end as join_window_end, L.window_time rowtime
  FROM (
     SELECT * FROM TABLE(TUMBLE(TABLE orders_dedup, DESCRIPTOR(order_ts), INTERVAL '5' MINUTES))
  ) L
  INNER JOIN (
     SELECT * FROM TABLE(TUMBLE(TABLE txns_dedup, DESCRIPTOR(txn_ts), INTERVAL '5' MINUTES))
  ) R
  ON L.order_id = R.order_id AND L.window_start >= R.window_start - INTERVAL '15' MINUTES AND L.window_end <= R.window_end + INTERVAL '15' MINUTES
  group by L.window_start, L.window_end, L.window_time, L.order_id, R.payment_method_type, L.order_status
)
select join_window_start, join_window_end, payment_method_type, 
count(distinct order_id) total_orders
from TABLE(TUMBLE(TABLE orders_joined, DESCRIPTOR(rowtime), INTERVAL '5' MINUTES))
group by join_window_start, join_window_end, payment_method_type;
;
raised the same issue on stackoverflow
s
basically you need watermarks: https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/concepts/time_attributes/ and not just a timestamp field
s
@shikai ng thanks for getting back. I have set watermarks at sources (kafka timestamp in my case) and could even leverage that while doing windowing join. But i couldn't propagate this time attribute for window agg after join. I believe it has something to do with join operation because if I remove join that I'm able to do window aggregations as expected. please let me know if you meant something else.
I have also tried cascading window aggregation but it didn't help either.