== Abstract Syntax Tree ==
LogicalSink(table=[fluss.nexmark.output_33bef226a05c4665b703e797c6e0f110], fields=[category, EXPR$1])
+- LogicalAggregate(group=[{0}], EXPR$1=[AVG($1)])
   +- LogicalProject(category=[$1], final=[$0])
      +- LogicalProject(final=[$2], category=[$1])
         +- LogicalAggregate(group=[{0, 1}], final=[MAX($2)])
            +- LogicalProject(id=[$0], category=[$8], price=[$12])
               +- LogicalFilter(condition=[AND(=($0, $10), >=($15, $5), <=($15, $6))])
                  +- LogicalJoin(condition=[true], joinType=[inner])
                     :- LogicalProject(id=[$2.id], itemName=[$2.itemName], description=[$2.description], initialBid=[$2.initialBid], reserve=[$2.reserve], dateTime=[$5], expires=[TO_TIMESTAMP_LTZ($2.expires, 3)], seller=[$2.seller], category=[$2.category], extra=[$2.extra])
                     :  +- LogicalFilter(condition=[=($0, 1)])
                     :     +- 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(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_33bef226a05c4665b703e797c6e0f110], fields=[category, EXPR$1])
+- GlobalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT((sum$0, count$1)) AS EXPR$1])
   +- Exchange(distribution=[hash[category]])
      +- LocalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT(final) AS (sum$0, count$1), COUNT_RETRACT(*) AS count1$2])
         +- Calc(select=[category, final])
            +- GlobalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(max$0) AS final])
               +- Exchange(distribution=[hash[id, category]])
                  +- LocalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(price) AS max$0])
                     +- Calc(select=[id, category, price])
                        +- Join(joinType=[InnerJoin], where=[AND(=(id, auction), >=(dateTime0, dateTime), <=(dateTime0, expires))], select=[id, dateTime, expires, category, auction, price, dateTime0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], miniBatch=[true])
                           :- Exchange(distribution=[hash[id]])
                           :  +- Calc(select=[auction.id AS id, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, TO_TIMESTAMP_LTZ(auction.expires, 3) AS expires, auction.category AS category], where=[=(event_type, 1)])
                           :     +- MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])
                           :        +- TableSourceScan(table=[[fluss, nexmark, events, project=[event_type, auction, dateTime], watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic], filter=[]]], fields=[event_type, auction, dateTime])
                           +- Exchange(distribution=[hash[auction]])
                              +- Calc(select=[bid.auction AS auction, bid.price AS price, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime], 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])

== Optimized Execution Plan ==
Sink(table=[fluss.nexmark.output_33bef226a05c4665b703e797c6e0f110], fields=[category, EXPR$1])
+- GlobalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT((sum$0, count$1)) AS EXPR$1])
   +- Exchange(distribution=[hash[category]])
      +- LocalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT(final) AS (sum$0, count$1), COUNT_RETRACT(*) AS count1$2])
         +- Calc(select=[category, final])
            +- GlobalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(max$0) AS final])
               +- Exchange(distribution=[hash[id, category]])
                  +- LocalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(price) AS max$0])
                     +- Calc(select=[id, category, price])
                        +- Join(joinType=[InnerJoin], where=[((id = auction) AND (dateTime0 >= dateTime) AND (dateTime0 <= expires))], select=[id, dateTime, expires, category, auction, price, dateTime0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], miniBatch=[true])
                           :- Exchange(distribution=[hash[id]])
                           :  +- Calc(select=[auction.id AS id, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, TO_TIMESTAMP_LTZ(auction.expires, 3) AS expires, auction.category AS category], where=[(event_type = 1)])
                           :     +- MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])
                           :        +- TableSourceScan(table=[[fluss, nexmark, events, project=[event_type, auction, dateTime], watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic], filter=[]]], fields=[event_type, auction, dateTime])
                           +- Exchange(distribution=[hash[auction]])
                              +- Calc(select=[bid.auction AS auction, bid.price AS price, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime], 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])

== Physical Execution Plan ==
{
  "nodes" : [ {
    "id" : 977,
    "type" : "Source: events[697]",
    "pact" : "Data Source",
    "contents" : "[697]:TableSourceScan(table=[[fluss, nexmark, events, project=[event_type, auction, dateTime], watermark=[-(TO_TIMESTAMP_LTZ(dateTime, 3), 4000:INTERVAL SECOND)], watermarkEmitStrategy=[on-periodic], filter=[]]], fields=[event_type, auction, dateTime])",
    "parallelism" : 4
  }, {
    "id" : 978,
    "type" : "MiniBatchAssigner[698]",
    "pact" : "Operator",
    "contents" : "[698]:MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 977,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 979,
    "type" : "Calc[699]",
    "pact" : "Operator",
    "contents" : "[699]:Calc(select=[auction.id AS id, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, TO_TIMESTAMP_LTZ(auction.expires, 3) AS expires, auction.category AS category], where=[(event_type = 1)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 978,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 981,
    "type" : "Source: events[701]",
    "pact" : "Data Source",
    "contents" : "[701]: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" : 982,
    "type" : "MiniBatchAssigner[702]",
    "pact" : "Operator",
    "contents" : "[702]:MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 981,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 983,
    "type" : "Calc[703]",
    "pact" : "Operator",
    "contents" : "[703]:Calc(select=[bid.auction AS auction, bid.price AS price, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime], where=[(event_type = 2)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 982,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 985,
    "type" : "Join[705]",
    "pact" : "Operator",
    "contents" : "[705]:Join(joinType=[InnerJoin], where=[((id = auction) AND (dateTime0 >= dateTime) AND (dateTime0 <= expires))], select=[id, dateTime, expires, category, auction, price, dateTime0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], miniBatch=[true])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 979,
      "ship_strategy" : "HASH",
      "side" : "second"
    }, {
      "id" : 983,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 986,
    "type" : "Calc[706]",
    "pact" : "Operator",
    "contents" : "[706]:Calc(select=[id, category, price])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 985,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 987,
    "type" : "LocalGroupAggregate[707]",
    "pact" : "Operator",
    "contents" : "[707]:LocalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(price) AS max$0])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 986,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 989,
    "type" : "GlobalGroupAggregate[709]",
    "pact" : "Operator",
    "contents" : "[709]:GlobalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(max$0) AS final])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 987,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 990,
    "type" : "Calc[710]",
    "pact" : "Operator",
    "contents" : "[710]:Calc(select=[category, final])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 989,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 991,
    "type" : "LocalGroupAggregate[711]",
    "pact" : "Operator",
    "contents" : "[711]:LocalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT(final) AS (sum$0, count$1), COUNT_RETRACT(*) AS count1$2])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 990,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 993,
    "type" : "GlobalGroupAggregate[713]",
    "pact" : "Operator",
    "contents" : "[713]:GlobalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT((sum$0, count$1)) AS EXPR$1])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 991,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 994,
    "type" : "ConstraintEnforcer[714]",
    "pact" : "Operator",
    "contents" : "[714]:ConstraintEnforcer[NotNullEnforcer(fields=[id])]",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 993,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 1002,
    "type" : "Sink(nexmark.output_33bef226a05c4665b703e797c6e0f110): Writer",
    "pact" : "Operator",
    "contents" : "Sink(nexmark.output_33bef226a05c4665b703e797c6e0f110): Writer",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 994,
      "ship_strategy" : "BUCKET",
      "side" : "second"
    } ]
  } ]
}