== Abstract Syntax Tree ==
LogicalSink(table=[default_catalog.default_database.sink], 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)])
         :     +- 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=[[default_catalog, default_database, src]])
         +- 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)])
                              +- 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=[[default_catalog, default_database, src]])

== Optimized Physical Plan ==
Sink(table=[default_catalog.default_database.sink], 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])
      :- 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)])
      :     +- TableSourceScan(table=[[default_catalog, default_database, src, watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic]]], fields=[event_type, person, auction, 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)])
                        +- TableSourceScan(table=[[default_catalog, default_database, src, watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic]]], fields=[event_type, person, auction, bid, dateTime])

== Optimized Execution Plan ==
Sink(table=[default_catalog.default_database.sink], 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])
      :- 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)])
      :     +- TableSourceScan(table=[[default_catalog, default_database, src, watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic]]], fields=[event_type, person, auction, 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)])
                        +- Reused(reference_id=[1])

== Physical Execution Plan ==
{
  "nodes" : [ {
    "id" : 1489,
    "type" : "Source: src[695]",
    "pact" : "Data Source",
    "contents" : "[695]:TableSourceScan(table=[[default_catalog, default_database, src, watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic]]], fields=[event_type, person, auction, bid, dateTime])",
    "parallelism" : 4
  }, {
    "id" : 1490,
    "type" : "Calc[696]",
    "pact" : "Operator",
    "contents" : "[696]: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" : 1489,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1492,
    "type" : "Calc[698]",
    "pact" : "Operator",
    "contents" : "[698]:Calc(select=[bid.price AS price, Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS dateTime], where=[(event_type = 2)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1489,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1493,
    "type" : "LocalWindowAggregate[699]",
    "pact" : "Operator",
    "contents" : "[699]: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" : 1492,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1495,
    "type" : "GlobalWindowAggregate[701]",
    "pact" : "Operator",
    "contents" : "[701]: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" : 1493,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    } ]
  }, {
    "id" : 1496,
    "type" : "Calc[702]",
    "pact" : "Operator",
    "contents" : "[702]:Calc(select=[maxprice, window_end AS dateTime])",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 1495,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1498,
    "type" : "Join[704]",
    "pact" : "Operator",
    "contents" : "[704]: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])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1490,
      "ship_strategy" : "HASH",
      "side" : "second"
    }, {
      "id" : 1496,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 1499,
    "type" : "Calc[705]",
    "pact" : "Operator",
    "contents" : "[705]:Calc(select=[auction, price, bidder, dateTime, extra])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1498,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1500,
    "type" : "Map",
    "pact" : "Operator",
    "contents" : "Map",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1499,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1502,
    "type" : "Writer : table",
    "pact" : "Operator",
    "contents" : "Writer : table",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 1500,
      "ship_strategy" : "shuffle by bucket",
      "side" : "second"
    } ]
  }, {
    "id" : 1503,
    "type" : "Global Committer : table",
    "pact" : "Operator",
    "contents" : "Global Committer : table",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 1502,
      "ship_strategy" : "REBALANCE",
      "side" : "second"
    } ]
  }, {
    "id" : 1509,
    "type" : "end: Writer",
    "pact" : "Operator",
    "contents" : "end: Writer",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 1503,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  } ]
}