== Abstract Syntax Tree ==
LogicalSink(table=[default_catalog.default_database.sink], fields=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, bid_dateTime, bid_extra])
+- LogicalProject(id=[$0], itemName=[$1], description=[$2], initialBid=[$3], reserve=[$4], dateTime=[$5], expires=[$6], seller=[$7], category=[$8], extra=[$9], auction=[$10], bidder=[$11], price=[$12], bid_dateTime=[$13], bid_extra=[$14])
   +- LogicalFilter(condition=[<=($15, 1)])
      +- LogicalProject(id=[$0], itemName=[$1], description=[$2], initialBid=[$3], reserve=[$4], dateTime=[$5], expires=[$6], seller=[$7], category=[$8], extra=[$9], auction=[$10], bidder=[$11], price=[$12], bid_dateTime=[$15], bid_extra=[$16], rownum=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $12 DESC NULLS LAST, $15 NULLS FIRST)])
         +- 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)])
               :     +- 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(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=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])
+- Rank(strategy=[AppendFastStrategy], rankType=[ROW_NUMBER], rankRange=[rankStart=1, rankEnd=1], partitionBy=[id], orderBy=[price DESC, dateTime0 ASC], select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])
   +- Exchange(distribution=[hash[id]])
      +- Calc(select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])
         +- Join(joinType=[InnerJoin], where=[AND(=(id, auction), >=(dateTime0, dateTime), <=(dateTime0, expires))], select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, channel, url, dateTime0, extra0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
            :- Exchange(distribution=[hash[id]])
            :  +- Calc(select=[auction.id AS id, auction.itemName AS itemName, auction.description AS description, auction.initialBid AS initialBid, auction.reserve AS reserve, 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.seller AS seller, auction.category AS category, auction.extra AS extra], where=[=(event_type, 1)])
            :     +- 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=[hash[auction]])
               +- Calc(select=[bid.auction AS auction, bid.bidder AS bidder, bid.price AS price, bid.channel AS channel, bid.url AS url, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, bid.extra AS extra], 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=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])
+- Rank(strategy=[AppendFastStrategy], rankType=[ROW_NUMBER], rankRange=[rankStart=1, rankEnd=1], partitionBy=[id], orderBy=[price DESC, dateTime0 ASC], select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])
   +- Exchange(distribution=[hash[id]])
      +- Calc(select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])
         +- Join(joinType=[InnerJoin], where=[((id = auction) AND (dateTime0 >= dateTime) AND (dateTime0 <= expires))], select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, channel, url, dateTime0, extra0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
            :- Exchange(distribution=[hash[id]])
            :  +- Calc(select=[auction.id AS id, auction.itemName AS itemName, auction.description AS description, auction.initialBid AS initialBid, auction.reserve AS reserve, 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.seller AS seller, auction.category AS category, auction.extra AS extra], where=[(event_type = 1)])
            :     +- 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])(reuse_id=[1])
            +- Exchange(distribution=[hash[auction]])
               +- Calc(select=[bid.auction AS auction, bid.bidder AS bidder, bid.price AS price, bid.channel AS channel, bid.url AS url, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, bid.extra AS extra], where=[(event_type = 2)])
                  +- Reused(reference_id=[1])

== Physical Execution Plan ==
{
  "nodes" : [ {
    "id" : 2268,
    "type" : "Source: src[1129]",
    "pact" : "Data Source",
    "contents" : "[1129]: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" : 2269,
    "type" : "Calc[1130]",
    "pact" : "Operator",
    "contents" : "[1130]:Calc(select=[auction.id AS id, auction.itemName AS itemName, auction.description AS description, auction.initialBid AS initialBid, auction.reserve AS reserve, 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.seller AS seller, auction.category AS category, auction.extra AS extra], where=[(event_type = 1)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2268,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 2271,
    "type" : "Calc[1132]",
    "pact" : "Operator",
    "contents" : "[1132]:Calc(select=[bid.auction AS auction, bid.bidder AS bidder, bid.price AS price, bid.channel AS channel, bid.url AS url, CAST(Reinterpret(TO_TIMESTAMP_LTZ(dateTime, 3)) AS TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)) AS dateTime, bid.extra AS extra], where=[(event_type = 2)])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2268,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 2273,
    "type" : "Join[1134]",
    "pact" : "Operator",
    "contents" : "[1134]:Join(joinType=[InnerJoin], where=[((id = auction) AND (dateTime0 >= dateTime) AND (dateTime0 <= expires))], select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, channel, url, dateTime0, extra0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2269,
      "ship_strategy" : "HASH",
      "side" : "second"
    }, {
      "id" : 2271,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 2274,
    "type" : "Calc[1135]",
    "pact" : "Operator",
    "contents" : "[1135]:Calc(select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2273,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 2276,
    "type" : "Rank[1137]",
    "pact" : "Operator",
    "contents" : "[1137]:Rank(strategy=[AppendFastStrategy], rankType=[ROW_NUMBER], rankRange=[rankStart=1, rankEnd=1], partitionBy=[id], orderBy=[price DESC, dateTime0 ASC], select=[id, itemName, description, initialBid, reserve, dateTime, expires, seller, category, extra, auction, bidder, price, dateTime0, extra0])",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2274,
      "ship_strategy" : "HASH",
      "side" : "second"
    } ]
  }, {
    "id" : 2277,
    "type" : "ConstraintEnforcer[1138]",
    "pact" : "Operator",
    "contents" : "[1138]:ConstraintEnforcer[NotNullEnforcer(fields=[id])]",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2276,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 2278,
    "type" : "Map",
    "pact" : "Operator",
    "contents" : "Map",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2277,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  }, {
    "id" : 2280,
    "type" : "Writer : table",
    "pact" : "Operator",
    "contents" : "Writer : table",
    "parallelism" : 4,
    "predecessors" : [ {
      "id" : 2278,
      "ship_strategy" : "shuffle by bucket",
      "side" : "second"
    } ]
  }, {
    "id" : 2281,
    "type" : "Global Committer : table",
    "pact" : "Operator",
    "contents" : "Global Committer : table",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 2280,
      "ship_strategy" : "REBALANCE",
      "side" : "second"
    } ]
  }, {
    "id" : 2287,
    "type" : "end: Writer",
    "pact" : "Operator",
    "contents" : "end: Writer",
    "parallelism" : 1,
    "predecessors" : [ {
      "id" : 2281,
      "ship_strategy" : "FORWARD",
      "side" : "second"
    } ]
  } ]
}