== Abstract Syntax Tree ==
LogicalSink(table=[fluss.nexmark.output_d84d0f0d8b61467ca6dea644e6a3a262], 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)])
      :                    +- 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(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)])
                                    +- 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_d84d0f0d8b61467ca6dea644e6a3a262], 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=[[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=[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=[[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_d84d0f0d8b61467ca6dea644e6a3a262], 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=[[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=[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" : 3809,
    "type" : "Source: events[2401]",
    "pact" : "Data Source",
    "contents" : "[2401]: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" : 3810,
    "type" : "Calc[2402]",
    "pact" : "Operator",
    "contents" : "[2402]:Calc(select=[bid.auction AS auction, Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS dateTime], where=[(event_type = 2)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 3809,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 3811,
    "type" : "LocalWindowAggregate[2403]",
    "pact" : "Operator",
    "contents" : "[2403]: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" : 3810,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 3813,
    "type" : "GlobalWindowAggregate[2405]",
    "pact" : "Operator",
    "contents" : "[2405]: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" : 3811,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 3815,
    "type" : "Calc[2407]",
    "pact" : "Operator",
    "contents" : "[2407]:Calc(select=[window_start AS starttime, window_end AS endtime, num])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 3813,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 3816,
    "type" : "LocalWindowAggregate[2408]",
    "pact" : "Operator",
    "contents" : "[2408]: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" : 3815,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 3818,
    "type" : "GlobalWindowAggregate[2410]",
    "pact" : "Operator",
    "contents" : "[2410]: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" : 3816,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    } ]
  }, {
    "id" : 3820,
    "type" : "WindowJoin[2412]",
    "pact" : "Operator",
    "contents" : "[2412]: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" : 3813,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    }, {
      "id" : 3818,
      "ship_strategy" : "GLOBAL",
      "side" : "second"
    } ]
  }, {
    "id" : 3821,
    "type" : "Calc[2413]",
    "pact" : "Operator",
    "contents" : "[2413]:Calc(select=[auction, num])",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 3820,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 3827,
    "type" : "Sink(nexmark.output_d84d0f0d8b61467ca6dea644e6a3a262): Writer",
    "pact" : "Operator",
    "contents" : "Sink(nexmark.output_d84d0f0d8b61467ca6dea644e6a3a262): Writer",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 3821,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  } ]
}