(
(let $1 (OptionalType (DataType 'Float)))
(let $2 (DataType 'Double))
(let $3 (OptionalType (TupleType $2 (DataType 'Uint64))))
(let $4 '('"key" (DataType 'String)))
(let $5 (StructType '('_yql_agg_0 $3) '('_yql_agg_1 $1) $4))
(let $6 '('('"_logical_id" '3346) '('"_id" '"70994f38-48d3c202-e7496199-234e8505") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $18 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $19 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $18)))
  (let $20 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $21 (YtStat '('Id '"Input") '('RecordsCount '"9") '('DataSize '"369") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $22 (YtTable '"Input" $19 $20 $21 '() (Void) (Void) '"/Root/plato"))
  (let $23 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $22 '('"key" '"subkey") (Void) (Void))) '()))))
  (let $24 (lambda '($36) (Just '((Convert $36 'Double) (Uint64 '1)))))
  (let $25 (Nothing $3))
  (let $26 (lambda '($31 $32 $33) (block '(
    (let $34 (SafeCast $33 $1))
    (let $35 (IfPresent $34 $24 $25))
    (return $35 $34)
  ))))
  (let $27 (lambda '($37 $38 $39 $40 $41) (block '(
    (let $42 (SafeCast $39 $1))
    (let $43 (IfPresent $42 $24 $25))
    (let $44 (IfPresent $40 (lambda '($45) (IfPresent $42 (lambda '($46) (Just '((AggrAdd (Nth $45 '0) (Convert $46 'Double)) (Inc (Nth $45 '1))))) (Just $45))) $43))
    (return $44 (AggrAdd $42 $41))
  ))))
  (let $28 (lambda '($47 $48 $49) $48 $49 $47))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow (DqReadWideWrap $23 '()))) '-1073741824 (lambda '($29 $30) $29) $26 $27 $28))
))) $6))
(let $8 (DqCnHashShuffle (TDqOutput $7 '0) '('"2") '0 '"HashV2"))
(let $9 (OptionalType $2))
(let $10 (StructType '('avg $9) $4 '('sum $1)))
(let $11 '('('"_logical_id" '3640) '('"_id" '"926bfc79-54cab5d-8b5a1cef-284aa0b7") '('"_wide_channels" $10)))
(let $12 (DqPhyStage '($8) (lambda '($50) (block '(
  (let $51 (NarrowSqueezeToDict (ToFlow (WideFromBlocks $50)) (lambda '($55 $56 $57) $57) (lambda '($58 $59 $60) (AsStruct '('_yql_agg_0 $58) '('_yql_agg_1 $59) '('"key" $60))) '('Auto 'Many)))
  (let $52 (Condense1 (OrderedFlatMap $51 (lambda '($61) (OrderedFlatMap (DictPayloads $61) (lambda '($62) $62)))) (lambda '($63) $63) (lambda '($64 $65) (AggrNotEquals (Member $64 '"key") (Member $65 '"key"))) (lambda '($66 $67) (block '(
    (let $68 (Member $66 '_yql_agg_0))
    (let $69 (Member $67 '_yql_agg_0))
    (let $70 (IfPresent $68 (lambda '($71) (IfPresent $69 (lambda '($72) (Just '((AggrAdd (Nth $71 '0) (Nth $72 '0)) (AggrAdd (Nth $71 '1) (Nth $72 '1))))) $68)) $69))
    (return (AsStruct '('_yql_agg_0 $70) '('_yql_agg_1 (AggrAdd (Member $66 '_yql_agg_1) (Member $67 '_yql_agg_1))) '('"key" (Member $67 '"key"))))
  )))))
  (let $53 (Sort (Map $52 (lambda '($73) (block '(
    (let $74 (IfPresent (Member $73 '_yql_agg_0) (lambda '($75) (Just (Div (Nth $75 '0) (Nth $75 '1)))) (Nothing $9)))
    (return (AsStruct '('avg $74) '('"key" (Member $73 '"key")) '('sum (Member $73 '_yql_agg_1))))
  )))) (Bool 'true) (lambda '($76) (Member $76 '"key"))))
  (let $54 (lambda '($77) (Member $77 'avg) (Member $77 '"key") (Member $77 'sum)))
  (return (FromFlow (ExpandMap $53 $54)))
))) $11))
(let $13 (DqCnMerge (TDqOutput $12 '0) '('('1 '"Asc"))))
(let $14 (DqPhyStage '($13) (lambda '($78) (FromFlow (NarrowMap (ToFlow $78) (lambda '($79 $80 $81) (AsStruct '('avg $79) '('"key" $80) '('sum $81)))))) '('('"_logical_id" '3652) '('"_id" '"50aad8b-3f995aba-57f53256-df1e95b7"))))
(let $15 '($7 $12 $14))
(let $16 '('"key" 'avg 'sum))
(let $17 (DqCnResult (TDqOutput $14 '0) $16))
(return (KqpPhysicalQuery '((KqpPhysicalTx $15 '($17) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $10) '0 '0)) '('('"type" '"query"))))
)
