== Abstract Syntax Tree ==
LogicalSink(table=[fluss.nexmark.output_8c098fd8b7184b778ed8d2b589c2281f], 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_8c098fd8b7184b778ed8d2b589c2281f], fields=[category, EXPR$1])
+- GroupAggregate(groupBy=[category], select=[category, AVG_RETRACT(final) AS EXPR$1])
   +- Exchange(distribution=[hash[category]])
      +- Calc(select=[category, final])
         +- GroupAggregate(groupBy=[id, category], select=[id, category, MAX(price) AS final])
            +- Exchange(distribution=[hash[id, category]])
               +- 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])
                     :- 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)])
                     :     +- 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)])
                           +- 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_8c098fd8b7184b778ed8d2b589c2281f], fields=[category, EXPR$1])
+- GroupAggregate(groupBy=[category], select=[category, AVG_RETRACT(final) AS EXPR$1])
   +- Exchange(distribution=[hash[category]])
      +- Calc(select=[category, final])
         +- GroupAggregate(groupBy=[id, category], select=[id, category, MAX(price) AS final])
            +- Exchange(distribution=[hash[id, category]])
               +- 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])
                     :- 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)])
                     :     +- 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)])
                           +- 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" : 833,
    "type" : "Source: events[553]",
    "pact" : "Data Source",
    "contents" : "[553]: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" : 834,
    "type" : "Calc[554]",
    "pact" : "Operator",
    "contents" : "[554]: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" : 833,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 836,
    "type" : "Source: events[556]",
    "pact" : "Data Source",
    "contents" : "[556]: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" : 837,
    "type" : "Calc[557]",
    "pact" : "Operator",
    "contents" : "[557]: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" : 836,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 839,
    "type" : "Join[559]",
    "pact" : "Operator",
    "contents" : "[559]:Join(joinType=[InnerJoin], where=[((id = auction) AND (dateTime0 >= dateTime) AND (dateTime0 <= expires))], select=[id, dateTime, expires, category, auction, price, dateTime0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 834,
      "ship_strategy" : "HASH",
      "side" : "second"
    }, {
      "id" : 837,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 840,
    "type" : "Calc[560]",
    "pact" : "Operator",
    "contents" : "[560]:Calc(select=[id, category, price])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 839,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 842,
    "type" : "GroupAggregate[562]",
    "pact" : "Operator",
    "contents" : "[562]:GroupAggregate(groupBy=[id, category], select=[id, category, MAX(price) AS final])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 840,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 843,
    "type" : "Calc[563]",
    "pact" : "Operator",
    "contents" : "[563]:Calc(select=[category, final])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 842,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 845,
    "type" : "GroupAggregate[565]",
    "pact" : "Operator",
    "contents" : "[565]:GroupAggregate(groupBy=[category], select=[category, AVG_RETRACT(final) AS EXPR$1])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 843,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 846,
    "type" : "ConstraintEnforcer[566]",
    "pact" : "Operator",
    "contents" : "[566]:ConstraintEnforcer[NotNullEnforcer(fields=[id])]",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 845,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 854,
    "type" : "Sink(nexmark.output_8c098fd8b7184b778ed8d2b589c2281f): Writer",
    "pact" : "Operator",
    "contents" : "Sink(nexmark.output_8c098fd8b7184b778ed8d2b589c2281f): Writer",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 846,
      "ship_strategy" : "BUCKET",
      "side" : "second"
    } ]
  } ]
}