== Abstract Syntax Tree ==
LogicalSink(table=[fluss.nexmark.output_76178019b21041e483119559ce5d0527], 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_76178019b21041e483119559ce5d0527], 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_76178019b21041e483119559ce5d0527], 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" : 859,
    "type" : "Source: events[619]",
    "pact" : "Data Source",
    "contents" : "[619]: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" : 860,
    "type" : "MiniBatchAssigner[620]",
    "pact" : "Operator",
    "contents" : "[620]:MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 859,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 861,
    "type" : "Calc[621]",
    "pact" : "Operator",
    "contents" : "[621]: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" : 860,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 863,
    "type" : "Source: events[623]",
    "pact" : "Data Source",
    "contents" : "[623]: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" : 864,
    "type" : "MiniBatchAssigner[624]",
    "pact" : "Operator",
    "contents" : "[624]:MiniBatchAssigner(interval=[2000ms], mode=[ProcTime])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 863,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 865,
    "type" : "Calc[625]",
    "pact" : "Operator",
    "contents" : "[625]: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" : 864,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 867,
    "type" : "Join[627]",
    "pact" : "Operator",
    "contents" : "[627]: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" : 861,
      "ship_strategy" : "HASH",
      "side" : "second"
    }, {
      "id" : 865,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 868,
    "type" : "Calc[628]",
    "pact" : "Operator",
    "contents" : "[628]:Calc(select=[id, category, price])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 867,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 869,
    "type" : "LocalGroupAggregate[629]",
    "pact" : "Operator",
    "contents" : "[629]:LocalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(price) AS max$0])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 868,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 871,
    "type" : "GlobalGroupAggregate[631]",
    "pact" : "Operator",
    "contents" : "[631]:GlobalGroupAggregate(groupBy=[id, category], select=[id, category, MAX(max$0) AS final])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 869,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 872,
    "type" : "Calc[632]",
    "pact" : "Operator",
    "contents" : "[632]:Calc(select=[category, final])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 871,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 873,
    "type" : "LocalGroupAggregate[633]",
    "pact" : "Operator",
    "contents" : "[633]:LocalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT(final) AS (sum$0, count$1), COUNT_RETRACT(*) AS count1$2])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 872,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 875,
    "type" : "GlobalGroupAggregate[635]",
    "pact" : "Operator",
    "contents" : "[635]:GlobalGroupAggregate(groupBy=[category], select=[category, AVG_RETRACT((sum$0, count$1)) AS EXPR$1])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 873,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 876,
    "type" : "ConstraintEnforcer[636]",
    "pact" : "Operator",
    "contents" : "[636]:ConstraintEnforcer[NotNullEnforcer(fields=[id])]",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 875,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 884,
    "type" : "Sink(nexmark.output_76178019b21041e483119559ce5d0527): Writer",
    "pact" : "Operator",
    "contents" : "Sink(nexmark.output_76178019b21041e483119559ce5d0527): Writer",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 876,
      "ship_strategy" : "BUCKET",
      "side" : "second"
    } ]
  } ]
}