I am using flink 1.15.4 (because the only version ...
# troubleshooting
t
I am using flink 1.15.4 (because the only version AWS is supporting currently). I have the following query:
Copy code
WITH context_stages_data AS (
    SELECT
        uid,
        organization,
        environment,
        client,
        'context_stage' AS type,
        data as payload,
        timezone_date,
        EXTRACT(epoch FROM min_timestamp) * 1000 as `timestamp`,
        EXTRACT(epoch FROM max_timestamp) * 1000 as max_timestamp,
        time_ltz
    FROM {{ contextStages }}
    WHERE
        deleted = FALSE
        AND (uid, organization, environment, timezone_date) IN (
            SELECT
                uid,
                organization,
                environment,
                timezone_date
            FROM {{ environmentAnalyticsNew }}
        )
)

    SELECT
        *,
        `timestamp` - lag(`timestamp`) over (PARTITION BY uid, organization, environment, timezone_date ORDER BY time_ltz) as inactivity_milliseconds
    FROM
        context_stages_data;
The
time_ltz
is configured as:
Copy code
time_ltz AS TO_TIMESTAMP_LTZ(`timestamp`, 3),
   WATERMARK FOR time_ltz AS time_ltz - INTERVAL '5' SECOND
For both
{{ contextStages }} and {{ environmentAnalyticsNew }}
table. But I couldn't get through the following error:
Copy code
org.apache.flink.table.api.TableException: OVER windows' ordering in stream mode must be defined on a time attribute.
        at org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecOverAggregate.translateToPlanInternal(StreamExecOverAggregate.java:174)
        at org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase.translateToPlan(ExecNodeBase.java:158)
        at org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.translateToPlan(ExecEdge.java:249)
        at org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecCalc.translateToPlanInternal(CommonExecCalc.java:94)
        at org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase.translateToPlan(ExecNodeBase.java:158)
        at org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.translateToPlan(ExecEdge.java:249)
        at org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.java:136)
        at org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase.translateToPlan(ExecNodeBase.java:158)
        at org.apache.flink.table.planner.delegation.StreamPlanner.$anonfun$translateToPlan$1(StreamPlanner.scala:82)
        at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:233)
It seems when the CTE has a WHERE clause of another table, the result is no longer having time attribute? Please help.