(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('"subkey" $1))
(let $4 '('('"_logical_id" '8759) '('"_id" '"c84c0f71-dfae4e11-790f300d-95f242f6") '('"_wide_channels" (StructType $2 $3))))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $19 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $20 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $19)))
  (let $21 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $22 (YtStat '('Id '"Input") '('RecordsCount '"14") '('DataSize '"614") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $23 (YtTable '"Input" $20 $21 $22 '() (Void) (Void) '"/Root/plato"))
  (let $24 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $23 '('"key" '"subkey") (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $24 '())))
))) $4))
(let $6 (DqCnHashShuffle (TDqOutput $5 '0) '('1) '0 '"HashV2"))
(let $7 (DataType 'Double))
(let $8 (StructType '('"Bins" (ListType (StructType '('"Frequency" $7) '('"Position" $7)))) '('"Kind" $1) '('"Max" $7) '('"Min" $7) '('"WeightsSum" $7)))
(let $9 (OptionalType $8))
(let $10 (DataType 'Uint64))
(let $11 (StructType '('"c" $10) '('"hh" $9) '('"maxk" $1) '('"mink" $1) $3))
(let $12 '('('"_logical_id" '9294) '('"_id" '"ecac7407-6f155ea5-3d1b93a8-387eb6ac") '('"_wide_channels" $11)))
(let $13 (DqPhyStage '($6) (lambda '($25) (block '(
  (let $26 (NarrowSqueezeToDict (ToFlow $25) (lambda '($31 $32) $32) (lambda '($33 $34) (AsStruct '('"key" $33) '('"subkey" $34))) '('Auto 'Many)))
  (let $27 (Bool 'true))
  (let $28 (Chopper (OrderedFlatMap $26 (lambda '($35) (OrderedFlatMap (DictPayloads $35) (lambda '($36) (Sort $36 $27 (lambda '($37) (Member $37 '"key"))))))) (lambda '($38) (Member $38 '"subkey")) (lambda '($39 $40) (AggrNotEquals $39 (Member $40 '"subkey"))) (lambda '($41 $42) (block '(
    (let $43 (DataType 'Uint32))
    (let $44 (OptionalType $43))
    (let $45 (Int32 '"10"))
    (let $46 (ResourceType '"Histogram.AdaptiveWard"))
    (let $47 '($46))
    (let $48 '($7))
    (let $49 (CallableType '() $47 $48 $48 '($43)))
    (let $50 (Udf '"Histogram.AdaptiveWardHistogram_Create" (Void) (VoidType) '"" $49 (VoidType) '"" '()))
    (let $51 (Double '"2."))
    (let $52 (Uint32 '100))
    (let $53 (DependsOn (Uint32 '2)))
    (let $54 (Nothing (OptionalType $46)))
    (let $55 (lambda '($73) (block '(
      (let $74 (CallableType '() '($8) $47))
      (let $75 (Udf '"Histogram.AdaptiveWardHistogram_GetResult" (Void) (VoidType) '"" $74 (VoidType) '"" '()))
      (return (Just (Apply $75 $73)))
    ))))
    (let $56 (Nothing $9))
    (let $57 (Chain1Map $42 (lambda '($62) (block '(
      (let $63 '('Count0 (Uint64 '1)))
      (let $64 (Member $62 '"key"))
      (let $65 (% (SafeCast $64 $44) $45))
      (let $66 '((Convert (Unwrap $65) $7) $51 $52))
      (let $67 (If (Exists $65) (Just (NamedApply $50 $66 (AsStruct) $53)) $54))
      (let $68 (IfPresent $67 $55 $56))
      (let $69 '('Max0 $64))
      (let $70 '('Min0 $64))
      (let $71 (AsStruct $63 '('Histogram0 $68) $69 $70 '('"key" $64) '('"subkey" (Member $62 '"subkey"))))
      (let $72 (AsStruct $63 '('Histogram0 $67) $69 $70))
      (return '($71 $72))
    ))) (lambda '($76 $77) (block '(
      (let $78 (Nth $77 '1))
      (let $79 '('Count0 (Inc (Member $78 'Count0))))
      (let $80 (Member $76 '"key"))
      (let $81 (% (SafeCast $80 $44) $45))
      (let $82 (Exists $81))
      (let $83 (Convert (Unwrap $81) $7))
      (let $84 '($83 $51 $52))
      (let $85 (If $82 (Just (NamedApply $50 $84 (AsStruct) $53)) $54))
      (let $86 (IfPresent (Member $78 'Histogram0) (lambda '($92) (block '(
        (let $93 (CallableType '() $47 $47 $48 $48))
        (let $94 (Udf '"Histogram.AdaptiveWardHistogram_AddValue" (Void) (VoidType) '"" $93 (VoidType) '"" '()))
        (let $95 '($92 $83 $51))
        (let $96 (NamedApply $94 $95 (AsStruct) $53))
        (return (Just (If $82 $96 $92)))
      ))) $85))
      (let $87 (IfPresent $86 $55 $56))
      (let $88 '('Max0 (AggrMax $80 (Member $78 'Max0))))
      (let $89 '('Min0 (AggrMin $80 (Member $78 'Min0))))
      (let $90 (AsStruct $79 '('Histogram0 $87) $88 $89 '('"key" $80) '('"subkey" (Member $76 '"subkey"))))
      (let $91 (AsStruct $79 '('Histogram0 $86) $88 $89))
      (return '($90 $91))
    )))))
    (let $58 (StructType '('Count0 $10) '('Histogram0 $9) '('Max0 $1) '('Min0 $1) $2 $3))
    (let $59 (ListType $58))
    (let $60 (VariantType (StructType '('group $59) '('singleRow $58))))
    (let $61 (Condense1 $57 (lambda '($97) (block '(
      (let $98 (Nth $97 '0))
      (let $99 (Variant $98 'singleRow $60))
      (return '((Member $98 '"key") $99))
    ))) (lambda '($100 $101) (AggrNotEquals (Member (Nth $100 '0) '"key") (Nth $101 '0))) (lambda '($102 $103) (block '(
      (let $104 (Nth $102 '0))
      (let $105 (Visit (Nth $103 '1) 'group (lambda '($106) (Variant (Insert $106 $104) 'group $60)) 'singleRow (lambda '($107) (Variant (AsList $107 $104) 'group $60))))
      (return '((Nth $103 '0) $105))
    )))))
    (return (OrderedFlatMap $61 (lambda '($108) (block '(
      (let $109 (Visit (Nth $108 '1) 'group (lambda '($110) (IfPresent (Last $110) (lambda '($111) (OrderedMap (Collect (Map $110 (lambda '($112) (AsStruct '('"key" (Member $112 '"key")) '('"subkey" (Member $112 '"subkey")))))) (lambda '($113) (AsStruct '('Count0 (Member $111 'Count0)) '('Histogram0 (Member $111 'Histogram0)) '('Max0 (Member $111 'Max0)) '('Min0 (Member $111 'Min0)) '('"key" (Member $113 '"key")) '('"subkey" (Member $113 '"subkey")))))) (List $59))) 'singleRow (lambda '($114) (AsList $114))))
      (return (Map $109 (lambda '($115) (AsStruct '('Count0 (Member $115 'Count0)) '('Histogram0 (Member $115 'Histogram0)) '('Max0 (Member $115 'Max0)) '('Min0 (Member $115 'Min0)) '('"subkey" (Member $115 '"subkey"))))))
    )))))
  )))))
  (let $29 (Sort (Map $28 (lambda '($116) (AsStruct '('"c" (Member $116 'Count0)) '('"hh" (Member $116 'Histogram0)) '('"maxk" (Member $116 'Max0)) '('"mink" (Member $116 'Min0)) '('"subkey" (Member $116 '"subkey"))))) '($27 $27) (lambda '($117) '((Member $117 '"subkey") (Member $117 '"c")))))
  (let $30 (lambda '($118) (Member $118 '"c") (Member $118 '"hh") (Member $118 '"maxk") (Member $118 '"mink") (Member $118 '"subkey")))
  (return (FromFlow (ExpandMap $29 $30)))
))) $12))
(let $14 (DqCnMerge (TDqOutput $13 '0) '('('"4" '"Asc") '('0 '"Asc"))))
(let $15 (DqPhyStage '($14) (lambda '($119) (FromFlow (NarrowMap (ToFlow $119) (lambda '($120 $121 $122 $123 $124) (AsStruct '('"c" $120) '('"hh" $121) '('"maxk" $122) '('"mink" $123) '('"subkey" $124)))))) '('('"_logical_id" '9306) '('"_id" '"dbddd7ed-b8345e88-899ee0e6-c2e7837b"))))
(let $16 '($5 $13 $15))
(let $17 '('"subkey" '"hh" '"c" '"mink" '"maxk"))
(let $18 (DqCnResult (TDqOutput $15 '0) $17))
(return (KqpPhysicalQuery '((KqpPhysicalTx $16 '($18) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $11) '0 '0)) '('('"type" '"query"))))
)
