(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('('"_logical_id" '6870) '('"_id" '"336b1845-76e4aee3-a88155a2-330f0007") '('"_wide_channels" (StructType $2))))
(let $4 (DqPhyStage '() (lambda '() (block '(
  (let $16 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $17 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $16)))
  (let $18 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $19 (YtStat '('Id '"Input") '('RecordsCount '"14") '('DataSize '"614") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $20 (YtTable '"Input" $17 $18 $19 '() (Void) (Void) '"/Root/plato"))
  (let $21 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $20 '('"key") (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $21 '())))
))) $3))
(let $5 (DqCnUnionAll (TDqOutput $4 '0)))
(let $6 (DataType 'Uint64))
(let $7 (OptionalType $6))
(let $8 (StructType '('"c" $6) '('"dbl_sum" $7) '('"maxk" $1) '('"mink" $1)))
(let $9 '('('"_logical_id" '7310) '('"_id" '"a627a81d-62216473-b10725bf-f28b0a9c") '('"_wide_channels" $8)))
(let $10 (DqPhyStage '($5) (lambda '($22) (block '(
  (let $23 (Bool 'true))
  (let $24 (OptionalType (DataType 'Uint32)))
  (let $25 (lambda '($44) (Just (SafeCast $44 $6))))
  (let $26 (Nothing $7))
  (let $27 (Chain1Map (NarrowMap (WideSort (ToFlow $22) '('('0 $23))) (lambda '($34) (AsStruct '('"key" $34)))) (lambda '($35) (block '(
    (let $36 '('Count0 (Uint64 '1)))
    (let $37 (Member $35 '"key"))
    (let $38 '('Max0 $37))
    (let $39 '('Min0 $37))
    (let $40 (IfPresent (SafeCast $37 $24) $25 $26))
    (let $41 '('Sum0 $40))
    (let $42 (AsStruct $36 $38 $39 $41 '('"key" $37)))
    (let $43 (AsStruct $36 $38 $39 $41))
    (return '($42 $43))
  ))) (lambda '($45 $46) (block '(
    (let $47 (Nth $46 '1))
    (let $48 '('Count0 (Inc (Member $47 'Count0))))
    (let $49 (Member $45 '"key"))
    (let $50 '('Max0 (AggrMax $49 (Member $47 'Max0))))
    (let $51 '('Min0 (AggrMin $49 (Member $47 'Min0))))
    (let $52 (IfPresent (SafeCast $49 $24) $25 $26))
    (let $53 '('Sum0 (AggrAdd $52 (Member $47 'Sum0))))
    (let $54 (AsStruct $48 $50 $51 $53 '('"key" $49)))
    (let $55 (AsStruct $48 $50 $51 $53))
    (return '($54 $55))
  )))))
  (let $28 (StructType '('Count0 $6) '('Max0 $1) '('Min0 $1) '('Sum0 $7) $2))
  (let $29 (ListType $28))
  (let $30 (VariantType (StructType '('group $29) '('singleRow $28))))
  (let $31 (Condense1 $27 (lambda '($56) (block '(
    (let $57 (Nth $56 '0))
    (let $58 (Variant $57 'singleRow $30))
    (return '((Member $57 '"key") $58))
  ))) (lambda '($59 $60) (AggrNotEquals (Member (Nth $59 '0) '"key") (Nth $60 '0))) (lambda '($61 $62) (block '(
    (let $63 (Nth $61 '0))
    (let $64 (Visit (Nth $62 '1) 'group (lambda '($65) (Variant (Insert $65 $63) 'group $30)) 'singleRow (lambda '($66) (Variant (AsList $66 $63) 'group $30))))
    (return '((Nth $62 '0) $64))
  )))))
  (let $32 (Sort (Map (OrderedFlatMap $31 (lambda '($67) (block '(
    (let $68 (Visit (Nth $67 '1) 'group (lambda '($69) (IfPresent (Last $69) (lambda '($70) (OrderedMap (Collect (Map $69 (lambda '($71) (AsStruct '('"key" (Member $71 '"key")))))) (lambda '($72) (AsStruct '('Count0 (Member $70 'Count0)) '('Max0 (Member $70 'Max0)) '('Min0 (Member $70 'Min0)) '('Sum0 (Member $70 'Sum0)) '('"key" (Member $72 '"key")))))) (List $29))) 'singleRow (lambda '($73) (AsList $73))))
    (return (Map $68 (lambda '($74) (AsStruct '('Count0 (Member $74 'Count0)) '('Max0 (Member $74 'Max0)) '('Min0 (Member $74 'Min0)) '('Sum0 (Member $74 'Sum0))))))
  )))) (lambda '($75) (AsStruct '('"c" (Member $75 'Count0)) '('"dbl_sum" (* (Int32 '"2") (Member $75 'Sum0))) '('"maxk" (Member $75 'Max0)) '('"mink" (Member $75 'Min0))))) $23 (lambda '($76) (Member $76 '"c"))))
  (let $33 (lambda '($77) (Member $77 '"c") (Member $77 '"dbl_sum") (Member $77 '"maxk") (Member $77 '"mink")))
  (return (FromFlow (ExpandMap $32 $33)))
))) $9))
(let $11 (DqCnMerge (TDqOutput $10 '0) '('('0 '"Asc"))))
(let $12 (DqPhyStage '($11) (lambda '($78) (FromFlow (NarrowMap (ToFlow $78) (lambda '($79 $80 $81 $82) (AsStruct '('"c" $79) '('"dbl_sum" $80) '('"maxk" $81) '('"mink" $82)))))) '('('"_logical_id" '7322) '('"_id" '"3066da75-42f6c54b-dd3a4be-e34bcc64"))))
(let $13 '($4 $10 $12))
(let $14 '('"dbl_sum" '"c" '"mink" '"maxk"))
(let $15 (DqCnResult (TDqOutput $12 '0) $14))
(return (KqpPhysicalQuery '((KqpPhysicalTx $13 '($15) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $8) '0 '0)) '('('"type" '"query"))))
)
