(
(let $1 (Bool 'false))
(let $2 '('"d_date_sk"))
(let $3 (DataType 'Int64))
(let $4 '('('"_logical_id" '9425) '('"_id" '"a8543498-8a84ca4c-d88cc1e6-d6d8a79d") '('"_wide_channels" (StructType '('"d_date_sk" $3)))))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $42 (KqpTable '"/local/test_db/olap_yatests/tpcds/s1/date_dim" '"72075186224037897:11" '"" '1))
  (let $43 (KqpBlockReadOlapTableRanges $42 (Void) '('"d_date_sk" '"d_year") '() '() (lambda '($45) (block '(
    (let $46 '('eq '"d_year" (Int32 '"2000")))
    (let $47 '('?? $46 $1))
    (return (TKqpOlapExtractMembers (KqpOlapFilter $45 $47) $2))
  )))))
  (let $44 (lambda '($48 $49) (BlockMember (BlockAsStruct '('"d_date_sk" $48)) '"d_date_sk") $49))
  (return (FromFlow (WideMap $43 $44)))
))) $4))
(let $6 (DqCnBroadcast (TDqOutput $5 '0)))
(let $7 (lambda '($54) $54))
(let $8 '('Many 'Hashed 'Compact))
(let $9 (lambda '($86 $87 $88) $88 $86 $87))
(let $10 (DataType 'Double))
(let $11 (OptionalType $10))
(let $12 (OptionalType $3))
(let $13 (StructType '('_yql_agg_0 $11) '('"a.sr_customer_sk" $12) '('"a.sr_store_sk" $12)))
(let $14 '('('"_logical_id" '9880) '('"_id" '"bc626764-5b36fc2d-e48d5686-ae1d952c") '('"_wide_channels" $13)))
(let $15 (DqPhyStage '($6) (lambda '($50) (block '(
  (let $51 (NarrowSqueezeToDict (ToFlow (WideFromBlocks $50)) $7 (lambda '($55) (AsStruct '('"d_date_sk" $55))) $8))
  (let $52 (lambda '($71) (Member $71 '"a.sr_customer_sk") (Member $71 '"a.sr_return_amt") (Member $71 '"a.sr_store_sk")))
  (let $53 (lambda '($72 $73 $74) $72 $74))
  (return (FromFlow (WideCombiner (ExpandMap (FlatMap $51 (lambda '($56) (block '(
    (let $57 (KqpTable '"/local/test_db/olap_yatests/tpcds/s1/store_returns" '"72075186224037897:22" '"" '1))
    (let $58 '"sr_returned_date_sk")
    (let $59 '('"sr_customer_sk" '"sr_return_amt" $58 '"sr_store_sk"))
    (let $60 (KqpBlockReadOlapTableRanges $57 (Void) $59 '() '() (lambda '($63) $63)))
    (let $61 (lambda '($64 $65 $66 $67 $68) (block '(
      (let $69 (BlockAsStruct '('"sr_customer_sk" $64) '('"sr_return_amt" $65) '($58 $66) '('"sr_store_sk" $67)))
      (return $69 (BlockExists (BlockMember $69 $58)) $68)
    ))))
    (let $62 '('"sr_customer_sk" '"a.sr_customer_sk" '"sr_return_amt" '"a.sr_return_amt" '"sr_store_sk" '"a.sr_store_sk"))
    (return (MapJoinCore (NarrowMap (ToFlow (WideFromBlocks (FromFlow (BlockCompress (WideMap $60 $61) '1)))) (lambda '($70) $70)) $56 'Inner '($58) $2 $62 '() '('"a.sr_returned_date_sk") '('"b.d_date_sk")))
  )))) $52) '-1073741824 $53 (lambda '($75 $76 $77 $78 $79) $78) (lambda '($80 $81 $82 $83 $84 $85) (AggrAdd $83 $85)) $9)))
))) $14))
(let $16 (DqCnHashShuffle (TDqOutput $15 '0) '('1 '"2")))
(let $17 (DqPhyStage '($16) (lambda '($89) (block '(
  (let $90 (lambda '($93 $94 $95) $94 $95))
  (let $91 (WideCombiner (ToFlow $89) '"" $90 (lambda '($96 $97 $98 $99 $100) $98) (lambda '($101 $102 $103 $104 $105 $106) (AggrAdd $103 $106)) $9))
  (let $92 '('0))
  (return (FromFlow (Switch (NarrowMap $91 (lambda '($107 $108 $109) (AsStruct '('"ctr_customer_sk" $108) '('"ctr_store_sk" $109) '('"ctr_total_return" $107)))) '"134217728" $92 (lambda '($110) $110) $92 (lambda '($111) (block '(
    (let $112 (lambda '($119) (Just '($119 (Uint64 '1)))))
    (let $113 (Nothing (OptionalType (TupleType $10 (DataType 'Uint64)))))
    (return (CombineCore (Map $111 (lambda '($114) (AsStruct '('"ctr_store_sk" (Member $114 '"ctr_store_sk")) '('"ctr_total_return" (Member $114 '"ctr_total_return"))))) (lambda '($115) (Member $115 '"ctr_store_sk")) (lambda '($116 $117) (block '(
      (let $118 (IfPresent (Member $117 '"ctr_total_return") $112 $113))
      (return (AsStruct '('_yql_agg_0 $118)))
    ))) (lambda '($120 $121 $122) (block '(
      (let $123 (Member $121 '"ctr_total_return"))
      (let $124 (IfPresent $123 $112 $113))
      (let $125 (IfPresent (Member $122 '_yql_agg_0) (lambda '($126) (IfPresent $123 (lambda '($127) (Just '((AggrAdd (Nth $126 '0) $127) (Inc (Nth $126 '1))))) (Just $126))) $124))
      (return (AsStruct '('_yql_agg_0 $125)))
    ))) (lambda '($128 $129) (Just (AsStruct '('_yql_agg_0 (Member $129 '_yql_agg_0)) '('"ctr_store_sk" $128)))) '0))
  ))))))
))) '('('"_logical_id" '14336) '('"_id" '"e53480bf-41ae5d10-6f27cfe6-f0353308"))))
(let $18 '('"ctr_store_sk"))
(let $19 (DqCnHashShuffle (TDqOutput $17 '1) $18))
(let $20 (StructType '('Avg0 $11) '('"ctr_store_sk" $12)))
(let $21 '('('"_logical_id" '14458) '('"_id" '"21979ad8-ebc0494d-3105d9d7-fc27d142") '('"_partition_mode" '"aggregate") '('"_wide_channels" $20)))
(let $22 (DqPhyStage '($19) (lambda '($130) (block '(
  (let $131 (lambda '($133) (Member $133 '_yql_agg_0) (Member $133 '"ctr_store_sk")))
  (let $132 (lambda '($145 $146) (block '(
    (let $147 (IfPresent $146 (lambda '($148) (Just (Div (Nth $148 '0) (Nth $148 '1)))) (Nothing $11)))
    (return $147 $145)
  ))))
  (return (FromFlow (WideCombiner (ExpandMap (ToFlow $130) $131) '"" (lambda '($134 $135) $135) (lambda '($136 $137 $138) $137) (lambda '($139 $140 $141 $142) (IfPresent $140 (lambda '($143) (IfPresent $142 (lambda '($144) (Just '((AggrAdd (Nth $143 '0) (Nth $144 '0)) (AggrAdd (Nth $143 '1) (Nth $144 '1))))) $140)) $142)) $132)))
))) $21))
(let $23 '('"s_store_sk"))
(let $24 '('('"_logical_id" '9462) '('"_id" '"42ee08a0-4f6b4988-6a3e1aff-9cd248ff") '('"_wide_channels" (StructType '('"s_store_sk" $3)))))
(let $25 (DqPhyStage '() (lambda '() (block '(
  (let $149 (KqpTable '"/local/test_db/olap_yatests/tpcds/s1/store" '"72075186224037897:18" '"" '1))
  (let $150 (KqpBlockReadOlapTableRanges $149 (Void) '('"s_state" '"s_store_sk") '() '() (lambda '($152) (block '(
    (let $153 '('eq '"s_state" (String '"TN")))
    (let $154 '('?? $153 $1))
    (return (TKqpOlapExtractMembers (KqpOlapFilter $152 $154) $23))
  )))))
  (let $151 (lambda '($155 $156) (BlockMember (BlockAsStruct '('"s_store_sk" $155)) '"s_store_sk") $156))
  (return (FromFlow (WideMap $150 $151)))
))) $24))
(let $26 '('"c_customer_id" (OptionalType (DataType 'Utf8))))
(let $27 '('('"_logical_id" '15036) '('"_id" '"3d52d3b5-220e929c-ff449246-fba3b1fe") '('"_wide_channels" (StructType $26 '('"c_customer_sk" $3)))))
(let $28 (DqPhyStage '() (lambda '() (block '(
  (let $157 (KqpTable '"/local/test_db/olap_yatests/tpcds/s1/customer" '"72075186224037897:20" '"" '1))
  (let $158 (KqpBlockReadOlapTableRanges $157 (Void) '('"c_customer_id" '"c_customer_sk") '() '() (lambda '($160) $160)))
  (let $159 (lambda '($161 $162 $163) (block '(
    (let $164 (BlockAsStruct '('"c_customer_id" $161) '('"c_customer_sk" $162)))
    (return (BlockMember $164 '"c_customer_id") (BlockMember $164 '"c_customer_sk") $163)
  ))))
  (return (FromFlow (WideMap $158 $159)))
))) $27))
(let $29 (DqCnMap (TDqOutput $17 '0)))
(let $30 (DqCnBroadcast (TDqOutput $22 '0)))
(let $31 (DqCnBroadcast (TDqOutput $25 '0)))
(let $32 (DqCnBroadcast (TDqOutput $28 '0)))
(let $33 '($29 $30 $31 $32))
(let $34 (Uint64 '100))
(let $35 (StructType $26))
(let $36 '('('"_logical_id" '14841) '('"_id" '"fb41ab00-e73b9340-7b9d306a-c9127747") '('"_wide_channels" $35)))
(let $37 (DqPhyStage $33 (lambda '($165 $166 $167 $168) (block '(
  (let $169 (NarrowSqueezeToDict (ToFlow (WideFromBlocks $168)) (lambda '($173 $174) $174) (lambda '($175 $176) (AsStruct '('"c_customer_id" $175) '('"c_customer_sk" $176))) $8))
  (let $170 '"ctr1.ctr_total_return")
  (let $171 '"olap_yatests/tpcds/s1/customer.c_customer_id")
  (let $172 (TopSort (Map (Filter (FlatMap $169 (lambda '($177) (block '(
    (let $178 (NarrowSqueezeToDict (ToFlow (WideFromBlocks $167)) $7 (lambda '($182) (AsStruct '('"s_store_sk" $182))) $8))
    (let $179 '"ctr1.ctr_customer_sk")
    (let $180 '($179))
    (let $181 '($170 $170 '"ctr2.Avg0" '"ctr2.Avg0"))
    (return (MapJoinCore (OrderedFilter (FlatMap $178 (lambda '($183) (block '(
      (let $184 (SqueezeToDict (NarrowFlatMap (WideFilter (ToFlow $166) (lambda '($188 $189) (Exists $189))) (lambda '($190 $191) (IfPresent $191 (lambda '($192) (Just '($192 (AsStruct '('Avg0 $190) '('"ctr_store_sk" $191))))) (Nothing (OptionalType (TupleType $3 $20)))))) (lambda '($193) (Nth $193 '0)) (lambda '($194) (Nth $194 '1)) $8))
      (let $185 '"ctr1.ctr_store_sk")
      (let $186 '($185))
      (let $187 '($179 $179 $170 $170 '"ctr2.Avg0" '"ctr2.Avg0"))
      (return (MapJoinCore (OrderedFilter (FlatMap $184 (lambda '($195) (block '(
        (let $196 '('"ctr_customer_sk" $179 '"ctr_store_sk" $185 '"ctr_total_return" $170))
        (return (MapJoinCore (OrderedFilter (ToFlow $165) (lambda '($197) (Exists (Member $197 '"ctr_store_sk")))) $195 'Inner $18 $18 $196 '('Avg0 '"ctr2.Avg0") $186 '('"ctr2.ctr_store_sk")))
      )))) (lambda '($198) (Exists (Member $198 $185)))) $183 'Inner $186 $23 $187 '() $186 '('"olap_yatests/tpcds/s1/store.s_store_sk")))
    )))) (lambda '($199) (Exists (Member $199 $179)))) $177 'Inner $180 '('"c_customer_sk") $181 '('"c_customer_id" $171) $180 '('"olap_yatests/tpcds/s1/customer.c_customer_sk")))
  )))) (lambda '($200) (Coalesce (> (Member $200 $170) (* (Member $200 '"ctr2.Avg0") (Double '"1.2"))) $1))) (lambda '($201) (AsStruct '('"c_customer_id" (Member $201 $171))))) $34 (Bool 'true) (lambda '($202) (Member $202 '"c_customer_id"))))
  (return (FromFlow (ExpandMap $172 (lambda '($203) (Member $203 '"c_customer_id")))))
))) $36))
(let $38 (DqCnMerge (TDqOutput $37 '0) '('('0 '"Asc"))))
(let $39 (DqPhyStage '($38) (lambda '($204) (FromFlow (NarrowMap (Take (ToFlow $204) $34) (lambda '($205) (AsStruct '('"c_customer_id" $205)))))) '('('"_logical_id" '14854) '('"_id" '"bf09b729-aa7a8f71-a6aa8c8a-2bab7eec"))))
(let $40 '($5 $15 $17 $22 $25 $28 $37 $39))
(let $41 (DqCnResult (TDqOutput $39 '0) '('"c_customer_id")))
(return (KqpPhysicalQuery '((KqpPhysicalTx $40 '($41) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $35) '0 '0)) '('('"type" '"query"))))
)
