== Abstract Syntax Tree ==
LogicalSink(table=[fluss.nexmark.output_2ee541a9de1a4fdd9475c7bd1741bb30], fields=[auction, price, bidder, dateTime, extra])
+- LogicalProject(auction=[$0], price=[$2], bidder=[$1], dateTime=[$5], extra=[$6])
   +- LogicalFilter(condition=[AND(>=($5, -($8, 10000:INTERVAL SECOND)), <=($5, $8))])
      +- LogicalJoin(condition=[=($2, $7)], joinType=[inner])
         :- LogicalProject(auction=[$3.auction], bidder=[$3.bidder], price=[$3.price], channel=[$3.channel], url=[$3.url], dateTime=[$5], extra=[$3.extra])
         :  +- LogicalFilter(condition=[=($0, 2)])
         :     +- LogicalProject(event_type=[$0], person=[$1], auction=[$2], bid=[$3], dateTime=[$4], rowtime=[$5])
         :        +- LogicalWatermarkAssigner(rowtime=[rowtime], watermark=[-($5, 4000:INTERVAL SECOND)])
         :           +- LogicalProject(event_type=[$0], person=[$1], auction=[$2], bid=[$3], dateTime=[$4], rowtime=[TO_TIMESTAMP_LTZ($4, 3)])
         :              +- LogicalTableScan(table=[[fluss, nexmark, events]])
         +- LogicalProject(maxprice=[$2], dateTime=[$1])
            +- LogicalAggregate(group=[{0, 1}], maxprice=[MAX($2)])
               +- LogicalProject(window_start=[$7], dateTime=[$8], price=[$2])
                  +- LogicalTableFunctionScan(invocation=[TUMBLE(TABLE(#0), DESCRIPTOR(_UTF-16LE'dateTime'), 10000:INTERVAL SECOND)], rowType=[RecordType(BIGINT auction, BIGINT bidder, BIGINT price, VARCHAR(2147483647) channel, VARCHAR(2147483647) url, TIMESTAMP_LTZ(3) *ROWTIME* dateTime, VARCHAR(2147483647) extra, TIMESTAMP(3) window_start, TIMESTAMP(3) window_end, TIMESTAMP_LTZ(3) *ROWTIME* window_time)])
                     +- LogicalProject(auction=[$0], bidder=[$1], price=[$2], channel=[$3], url=[$4], dateTime=[$5], extra=[$6])
                        +- LogicalProject(auction=[$3.auction], bidder=[$3.bidder], price=[$3.price], channel=[$3.channel], url=[$3.url], dateTime=[$5], extra=[$3.extra])
                           +- LogicalFilter(condition=[=($0, 2)])
                              +- LogicalProject(event_type=[$0], person=[$1], auction=[$2], bid=[$3], dateTime=[$4], rowtime=[$5])
                                 +- LogicalWatermarkAssigner(rowtime=[rowtime], watermark=[-($5, 4000:INTERVAL SECOND)])
                                    +- LogicalProject(event_type=[$0], person=[$1], auction=[$2], bid=[$3], dateTime=[$4], rowtime=[TO_TIMESTAMP_LTZ($4, 3)])
                                       +- LogicalTableScan(table=[[fluss, nexmark, events]])

== Optimized Physical Plan ==
Sink(table=[fluss.nexmark.output_2ee541a9de1a4fdd9475c7bd1741bb30], fields=[auction, price, bidder, dateTime, extra])
+- Calc(select=[auction, price, bidder, dateTime, extra])
   +- Join(joinType=[InnerJoin], where=[AND(=(price, maxprice), >=(dateTime, -(dateTime0, 10000:INTERVAL SECOND)), <=(dateTime, dateTime0))], select=[auction, bidder, price, dateTime, extra, maxprice, dateTime0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], miniBatch=[true])
      :- Exchange(distribution=[hash[price]])
      :  +- Calc(select=[bid.auction AS auction, bid.bidder AS bidder, bid.price AS price, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, bid.extra AS extra], where=[=(event_type, 2)])
      :     +- MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])
      :        +- TableSourceScan(table=[[fluss, nexmark, events, project=[event_type, bid, dateTime], watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic], filter=[]]], fields=[event_type, bid, dateTime])
      +- Exchange(distribution=[hash[maxprice]])
         +- Calc(select=[maxprice, window_end AS dateTime])
            +- GlobalWindowAggregate(window=[TUMBLE(slice_end=[$slice_end], size=[10 s])], select=[MAX(max$0) AS maxprice, start('w$) AS window_start, end('w$) AS window_end])
               +- Exchange(distribution=[single])
                  +- LocalWindowAggregate(window=[TUMBLE(time_col=[dateTime], size=[10 s])], select=[MAX(price) AS max$0, slice_end('w$) AS $slice_end])
                     +- Calc(select=[bid.price AS price, Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS dateTime], where=[=(event_type, 2)])
                        +- MiniBatchAssigner(interval=[2000ms], mode=[RowTime])
                           +- TableSourceScan(table=[[fluss, nexmark, events, project=[event_type, bid, dateTime], watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic], filter=[]]], fields=[event_type, bid, dateTime])

== Optimized Execution Plan ==
Sink(table=[fluss.nexmark.output_2ee541a9de1a4fdd9475c7bd1741bb30], fields=[auction, price, bidder, dateTime, extra])
+- Calc(select=[auction, price, bidder, dateTime, extra])
   +- Join(joinType=[InnerJoin], where=[((price = maxprice) AND (dateTime >= (dateTime0 - 10000:INTERVAL SECOND)) AND (dateTime <= dateTime0))], select=[auction, bidder, price, dateTime, extra, maxprice, dateTime0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], miniBatch=[true])
      :- Exchange(distribution=[hash[price]])
      :  +- Calc(select=[bid.auction AS auction, bid.bidder AS bidder, bid.price AS price, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, bid.extra AS extra], where=[(event_type = 2)])
      :     +- MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])
      :        +- TableSourceScan(table=[[fluss, nexmark, events, project=[event_type, bid, dateTime], watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic], filter=[]]], fields=[event_type, bid, dateTime])(reuse_id=[1])
      +- Exchange(distribution=[hash[maxprice]])
         +- Calc(select=[maxprice, window_end AS dateTime])
            +- GlobalWindowAggregate(window=[TUMBLE(slice_end=[$slice_end], size=[10 s])], select=[MAX(max$0) AS maxprice, start('w$) AS window_start, end('w$) AS window_end])
               +- Exchange(distribution=[single])
                  +- LocalWindowAggregate(window=[TUMBLE(time_col=[dateTime], size=[10 s])], select=[MAX(price) AS max$0, slice_end('w$) AS $slice_end])
                     +- Calc(select=[bid.price AS price, Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS dateTime], where=[(event_type = 2)])
                        +- MiniBatchAssigner(interval=[2000ms], mode=[RowTime])
                           +- Reused(reference_id=[1])

== Physical Execution Plan ==
{
  "nodes" : [ {
    "id" : 1229,
    "type" : "Source: events[883]",
    "pact" : "Data Source",
    "contents" : "[883]:TableSourceScan(table=[[fluss, nexmark, events, project=[event_type, bid, dateTime], watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic], filter=[]]], fields=[event_type, bid, dateTime])",
    "parallelism" : 4
  }, {
    "id" : 1230,
    "type" : "MiniBatchAssigner[884]",
    "pact" : "Operator",
    "contents" : "[884]:MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1229,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1231,
    "type" : "Calc[885]",
    "pact" : "Operator",
    "contents" : "[885]:Calc(select=[bid.auction AS auction, bid.bidder AS bidder, bid.price AS price, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, bid.extra AS extra], where=[(event_type = 2)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1230,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1233,
    "type" : "MiniBatchAssigner[887]",
    "pact" : "Operator",
    "contents" : "[887]:MiniBatchAssigner(interval=[2000ms], mode=[RowTime])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1229,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1234,
    "type" : "Calc[888]",
    "pact" : "Operator",
    "contents" : "[888]:Calc(select=[bid.price AS price, Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS dateTime], where=[(event_type = 2)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1233,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1235,
    "type" : "LocalWindowAggregate[889]",
    "pact" : "Operator",
    "contents" : "[889]:LocalWindowAggregate(window=[TUMBLE(time_col=[dateTime], size=[10 s])], select=[MAX(price) AS max$0, slice_end('w$) AS $slice_end])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1234,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1237,
    "type" : "GlobalWindowAggregate[891]",
    "pact" : "Operator",
    "contents" : "[891]:GlobalWindowAggregate(window=[TUMBLE(slice_end=[$slice_end], size=[10 s])], select=[MAX(max$0) AS maxprice, start('w$) AS window_start, end('w$) AS window_end])",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 1235,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    } ]
  }, {
    "id" : 1238,
    "type" : "Calc[892]",
    "pact" : "Operator",
    "contents" : "[892]:Calc(select=[maxprice, window_end AS dateTime])",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 1237,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1240,
    "type" : "Join[894]",
    "pact" : "Operator",
    "contents" : "[894]:Join(joinType=[InnerJoin], where=[((price = maxprice) AND (dateTime >= (dateTime0 - 10000:INTERVAL SECOND)) AND (dateTime <= dateTime0))], select=[auction, bidder, price, dateTime, extra, maxprice, dateTime0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], miniBatch=[true])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1231,
      "ship_strategy" : "HASH",
      "side" : "second"
    }, {
      "id" : 1238,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 1241,
    "type" : "Calc[895]",
    "pact" : "Operator",
    "contents" : "[895]:Calc(select=[auction, price, bidder, dateTime, extra])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1240,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1246,
    "type" : "Sink(nexmark.output_2ee541a9de1a4fdd9475c7bd1741bb30): Writer",
    "pact" : "Operator",
    "contents" : "Sink(nexmark.output_2ee541a9de1a4fdd9475c7bd1741bb30): Writer",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1241,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  } ]
}