== Abstract Syntax Tree ==
LogicalSink(table=[default_catalog.default_database.sink], fields=[auction, num])
+- LogicalProject(auction=[$0], num=[$1])
   +- LogicalJoin(condition=[AND(=($2, $5), =($3, $6), >=($1, $4))], joinType=[inner])
      :- LogicalProject(auction=[$0], num=[$3], starttime=[$1], endtime=[$2])
      :  +- LogicalAggregate(group=[{0, 1, 2}], num=[COUNT()])
      :     +- LogicalProject(auction=[$0], starttime=[$7], endtime=[$8])
      :        +- LogicalTableFunctionScan(invocation=[HOP(TABLE(#0), DESCRIPTOR(_UTF-16LE'dateTime'), 2000:INTERVAL SECOND, 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]])
      +- LogicalProject(maxn=[$2], starttime=[$0], endtime=[$1])
         +- LogicalAggregate(group=[{0, 1}], maxn=[MAX($2)])
            +- LogicalProject(starttime=[$1], endtime=[$2], num=[$0])
               +- LogicalProject(num=[$3], starttime=[$1], endtime=[$2])
                  +- LogicalAggregate(group=[{0, 1, 2}], num=[COUNT()])
                     +- LogicalProject(auction=[$0], starttime=[$7], endtime=[$8])
                        +- LogicalTableFunctionScan(invocation=[HOP(TABLE(#0), DESCRIPTOR(_UTF-16LE'dateTime'), 2000:INTERVAL SECOND, 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, num])
+- Calc(select=[auction, num])
   +- WindowJoin(leftWindow=[HOP(win_start=[window_start], win_end=[window_end], size=[10 s], slide=[2 s])], rightWindow=[HOP(win_start=[window_start], win_end=[window_end], size=[10 s], slide=[2 s])], joinType=[InnerJoin], where=[>=(num, maxn)], select=[auction, num, window_start, window_end, maxn, window_start0, window_end0])
      :- Exchange(distribution=[single])
      :  +- GlobalWindowAggregate(groupBy=[auction], window=[HOP(slice_end=[$slice_end], size=[10 s], slide=[2 s])], select=[auction, COUNT(count1$0) AS num, start('w$) AS window_start, end('w$) AS window_end])
      :     +- Exchange(distribution=[hash[auction]])
      :        +- LocalWindowAggregate(groupBy=[auction], window=[HOP(time_col=[dateTime], size=[10 s], slide=[2 s])], select=[auction, COUNT(*) AS count1$0, slice_end('w$) AS $slice_end])
      :           +- Calc(select=[bid.auction AS auction, 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])
      +- Exchange(distribution=[single])
         +- GlobalWindowAggregate(window=[HOP(win_end=[$window_end], size=[10 s], slide=[2 s])], select=[MAX(max$0) AS maxn, COUNT(count1$1) AS window_start, start('w$) AS window_end])
            +- Exchange(distribution=[single])
               +- LocalWindowAggregate(window=[HOP(win_start=[starttime], win_end=[endtime], size=[10 s], slide=[2 s])], select=[MAX(num) AS max$0, COUNT(*) AS count1$1, slice_end('w$) AS $window_end])
                  +- Calc(select=[window_start AS starttime, window_end AS endtime, num])
                     +- GlobalWindowAggregate(groupBy=[auction], window=[HOP(slice_end=[$slice_end], size=[10 s], slide=[2 s])], select=[auction, COUNT(count1$0) AS num, start('w$) AS window_start, end('w$) AS window_end])
                        +- Exchange(distribution=[hash[auction]])
                           +- LocalWindowAggregate(groupBy=[auction], window=[HOP(time_col=[dateTime], size=[10 s], slide=[2 s])], select=[auction, COUNT(*) AS count1$0, slice_end('w$) AS $slice_end])
                              +- Calc(select=[bid.auction AS auction, 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, num])
+- Calc(select=[auction, num])
   +- WindowJoin(leftWindow=[HOP(win_start=[window_start], win_end=[window_end], size=[10 s], slide=[2 s])], rightWindow=[HOP(win_start=[window_start], win_end=[window_end], size=[10 s], slide=[2 s])], joinType=[InnerJoin], where=[(num >= maxn)], select=[auction, num, window_start, window_end, maxn, window_start0, window_end0])
      :- Exchange(distribution=[single])
      :  +- GlobalWindowAggregate(groupBy=[auction], window=[HOP(slice_end=[$slice_end], size=[10 s], slide=[2 s])], select=[auction, COUNT(count1$0) AS num, start('w$) AS window_start, end('w$) AS window_end])(reuse_id=[1])
      :     +- Exchange(distribution=[hash[auction]])
      :        +- LocalWindowAggregate(groupBy=[auction], window=[HOP(time_col=[dateTime], size=[10 s], slide=[2 s])], select=[auction, COUNT(*) AS count1$0, slice_end('w$) AS $slice_end])
      :           +- Calc(select=[bid.auction AS auction, 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])
      +- Exchange(distribution=[single])
         +- GlobalWindowAggregate(window=[HOP(win_end=[$window_end], size=[10 s], slide=[2 s])], select=[MAX(max$0) AS maxn, COUNT(count1$1) AS window_start, start('w$) AS window_end])
            +- Exchange(distribution=[single])
               +- LocalWindowAggregate(window=[HOP(win_start=[starttime], win_end=[endtime], size=[10 s], slide=[2 s])], select=[MAX(num) AS max$0, COUNT(*) AS count1$1, slice_end('w$) AS $window_end])
                  +- Calc(select=[window_start AS starttime, window_end AS endtime, num])
                     +- Reused(reference_id=[1])

== Physical Execution Plan ==
{
  "nodes" : [ {
    "id" : 6117,
    "type" : "Source: src[2821]",
    "pact" : "Data Source",
    "contents" : "[2821]: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" : 6118,
    "type" : "Calc[2822]",
    "pact" : "Operator",
    "contents" : "[2822]:Calc(select=[bid.auction AS auction, Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS dateTime], where=[(event_type = 2)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 6117,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 6119,
    "type" : "LocalWindowAggregate[2823]",
    "pact" : "Operator",
    "contents" : "[2823]:LocalWindowAggregate(groupBy=[auction], window=[HOP(time_col=[dateTime], size=[10 s], slide=[2 s])], select=[auction, COUNT(*) AS count1$0, slice_end('w$) AS $slice_end])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 6118,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 6121,
    "type" : "GlobalWindowAggregate[2825]",
    "pact" : "Operator",
    "contents" : "[2825]:GlobalWindowAggregate(groupBy=[auction], window=[HOP(slice_end=[$slice_end], size=[10 s], slide=[2 s])], select=[auction, COUNT(count1$0) AS num, start('w$) AS window_start, end('w$) AS window_end])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 6119,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 6123,
    "type" : "Calc[2827]",
    "pact" : "Operator",
    "contents" : "[2827]:Calc(select=[window_start AS starttime, window_end AS endtime, num])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 6121,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 6124,
    "type" : "LocalWindowAggregate[2828]",
    "pact" : "Operator",
    "contents" : "[2828]:LocalWindowAggregate(window=[HOP(win_start=[starttime], win_end=[endtime], size=[10 s], slide=[2 s])], select=[MAX(num) AS max$0, COUNT(*) AS count1$1, slice_end('w$) AS $window_end])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 6123,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 6126,
    "type" : "GlobalWindowAggregate[2830]",
    "pact" : "Operator",
    "contents" : "[2830]:GlobalWindowAggregate(window=[HOP(win_end=[$window_end], size=[10 s], slide=[2 s])], select=[MAX(max$0) AS maxn, COUNT(count1$1) AS window_start, start('w$) AS window_end])",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 6124,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    } ]
  }, {
    "id" : 6128,
    "type" : "WindowJoin[2832]",
    "pact" : "Operator",
    "contents" : "[2832]:WindowJoin(leftWindow=[HOP(win_start=[window_start], win_end=[window_end], size=[10 s], slide=[2 s])], rightWindow=[HOP(win_start=[window_start], win_end=[window_end], size=[10 s], slide=[2 s])], joinType=[InnerJoin], where=[(num >= maxn)], select=[auction, num, window_start, window_end, maxn, window_start0, window_end0])",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 6121,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    }, {
      "id" : 6126,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    } ]
  }, {
    "id" : 6129,
    "type" : "Calc[2833]",
    "pact" : "Operator",
    "contents" : "[2833]:Calc(select=[auction, num])",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 6128,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 6130,
    "type" : "Map",
    "pact" : "Operator",
    "contents" : "Map",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 6129,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 6132,
    "type" : "Writer : table",
    "pact" : "Operator",
    "contents" : "Writer : table",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 6130,
      "ship_strategy" : "shuffle by bucket",
      "side" : "second"
    } ]
  }, {
    "id" : 6133,
    "type" : "Global Committer : table",
    "pact" : "Operator",
    "contents" : "Global Committer : table",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 6132,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 6140,
    "type" : "end: Writer",
    "pact" : "Operator",
    "contents" : "end: Writer",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 6133,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  } ]
}