(
(let $1 '('"key" '"subkey"))
(let $2 (DataType 'Double))
(let $3 (OptionalType $2))
(let $4 (ResourceType '"Histogram.AdaptiveWard"))
(let $5 '($4))
(let $6 '((DataType 'Uint32)))
(let $7 (Uint32 '100))
(let $8 (Nothing (OptionalType $4)))
(let $9 (Bool 'false))
(let $10 (DataType 'String))
(let $11 '($10))
(let $12 (OptionalType $10))
(let $13 '('('"_logical_id" '5283) '('"_id" '"c7d16281-cdab36e4-782a5f60-953baa1f") '('"_wide_channels" (StructType '('_yql_agg_0 $12) '('_yql_agg_1 $12)))))
(let $14 (DqPhyStage '() (lambda '() (block '(
  (let $25 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $26 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $25)))
  (let $27 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $28 (YtStat '('Id '"Input4") '('RecordsCount '"9") '('DataSize '"369") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $29 (YtTable '"Input4" $26 $27 $28 '() (Void) (Void) '"/Root/plato"))
  (let $30 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $29 $1 (Void) (Void))) '()))))
  (let $31 '($2))
  (let $32 (CallableType '() $5 $31 $31 $6))
  (let $33 (Udf '"Histogram.AdaptiveWardHistogram_Create" (Void) (VoidType) '"" $32 (VoidType) '"" '()))
  (let $34 (Double '1.0))
  (let $35 (DependsOn (Uint32 '0)))
  (let $36 (DependsOn (Uint32 '1)))
  (let $37 (lambda '($41 $42) (block '(
    (let $43 (SafeCast $42 $3))
    (let $44 '((Unwrap $43) $34 $7))
    (let $45 (If (Exists $43) (Just (NamedApply $33 $44 (AsStruct) $35)) $8))
    (let $46 (SafeCast $41 $3))
    (let $47 '((Unwrap $46) $34 $7))
    (let $48 (If (Exists $46) (Just (NamedApply $33 $47 (AsStruct) $36)) $8))
    (return $45 $48)
  ))))
  (let $38 (lambda '($53 $54 $55 $56) (block '(
    (let $57 (SafeCast $54 $3))
    (let $58 (Exists $57))
    (let $59 (CallableType '() $5 $5 $31 $31))
    (let $60 (Udf '"Histogram.AdaptiveWardHistogram_AddValue" (Void) (VoidType) '"" $59 (VoidType) '"" '()))
    (let $61 (Unwrap $57))
    (let $62 '($61 $34 $7))
    (let $63 (If $58 (Just (NamedApply $33 $62 (AsStruct) $35)) $8))
    (let $64 (IfPresent $55 (lambda '($71) (block '(
      (let $72 '($71 $61 $34))
      (let $73 (NamedApply $60 $72 (AsStruct) $35))
      (return (Just (If $58 $73 $71)))
    ))) $63))
    (let $65 (SafeCast $53 $3))
    (let $66 (Exists $65))
    (let $67 (Unwrap $65))
    (let $68 '($67 $34 $7))
    (let $69 (If $66 (Just (NamedApply $33 $68 (AsStruct) $36)) $8))
    (let $70 (IfPresent $56 (lambda '($74) (block '(
      (let $75 '($74 $67 $34))
      (let $76 (NamedApply $60 $75 (AsStruct) $36))
      (return (Just (If $66 $76 $74)))
    ))) $69))
    (return $64 $70)
  ))))
  (let $39 (WideCondense1 (DqReadWideWrap $30 '()) $37 (lambda '($49 $50 $51 $52) $9) $38))
  (let $40 (lambda '($77 $78) (block '(
    (let $79 (lambda '($83) (block '(
      (let $84 (CallableType '() $11 $5))
      (let $85 (Udf '"Histogram.AdaptiveWardHistogram_Serialize" (Void) (VoidType) '"" $84 (VoidType) '"" '()))
      (return (Just (Apply $85 $83)))
    ))))
    (let $80 (Nothing $12))
    (let $81 (IfPresent $77 $79 $80))
    (let $82 (IfPresent $78 $79 $80))
    (return $81 $82)
  ))))
  (return (FromFlow (WideMap $39 $40)))
))) $13))
(let $15 (DqCnUnionAll (TDqOutput $14 '0)))
(let $16 (StructType '('"Bins" (ListType (StructType '('"Frequency" $2) '('"Position" $2)))) '('"Kind" $10) '('"Max" $2) '('"Min" $2) '('"WeightsSum" $2)))
(let $17 (OptionalType $16))
(let $18 (StructType '('AdaptiveWardHistogramCDF0 $17) '('HistogramCDF0 $17)))
(let $19 '('('"_logical_id" '5457) '('"_id" '"b3782f3b-2f59b70f-c16f5dc9-99cec38d") '('"_partition_mode" '"aggregate") '('"_wide_channels" $18)))
(let $20 (DqPhyStage '($15) (lambda '($86) (block '(
  (let $87 (CallableType '() $5 $11 $6))
  (let $88 (Udf '"Histogram.AdaptiveWardHistogram_Deserialize" (Void) (VoidType) '"" $87 (VoidType) '"" '()))
  (let $89 (lambda '($98) (Just (Apply $88 $98 $7))))
  (let $90 (lambda '($94 $95) (block '(
    (let $96 (IfPresent $94 $89 $8))
    (let $97 (IfPresent $95 $89 $8))
    (return $96 $97)
  ))))
  (let $91 (lambda '($103 $104 $105 $106) (block '(
    (let $107 (CallableType '() $5 $5 $5))
    (let $108 (Udf '"Histogram.AdaptiveWardHistogram_Merge" (Void) (VoidType) '"" $107 (VoidType) '"" '()))
    (let $109 (IfPresent $103 (lambda '($111) (block '(
      (let $112 (IfPresent $103 $89 $8))
      (return (IfPresent $105 (lambda '($113) (block '(
        (let $114 (Apply $88 $111 $7))
        (return (Just (Apply $108 $114 $113)))
      ))) $112))
    ))) $105))
    (let $110 (IfPresent $104 (lambda '($115) (block '(
      (let $116 (IfPresent $104 $89 $8))
      (return (IfPresent $106 (lambda '($117) (block '(
        (let $118 (Apply $88 $115 $7))
        (return (Just (Apply $108 $118 $117)))
      ))) $116))
    ))) $106))
    (return $109 $110)
  ))))
  (let $92 (WideCondense1 (ToFlow $86) $90 (lambda '($99 $100 $101 $102) $9) $91))
  (let $93 (lambda '($119 $120) (block '(
    (let $121 (lambda '($125) (block '(
      (let $126 '($16))
      (let $127 '($16 '"" '1))
      (let $128 (CallableType '() $126 $127))
      (let $129 '('('"strict")))
      (let $130 (Udf '"Histogram.ToCumulativeDistributionFunction" (Void) (VoidType) '"" $128 (VoidType) '"" $129))
      (let $131 (CallableType '('"2") $126 $127 '($3) '((OptionalType (DataType 'Bool)))))
      (let $132 (Udf '"Histogram.Normalize" (Void) (VoidType) '"" $131 (VoidType) '"" $129))
      (let $133 (CallableType '() $126 $5))
      (let $134 (Udf '"Histogram.AdaptiveWardHistogram_GetResult" (Void) (VoidType) '"" $133 (VoidType) '"" '()))
      (return (Just (Apply $130 (Apply $132 (Apply $134 $125)))))
    ))))
    (let $122 (Nothing $17))
    (let $123 (IfPresent $119 $121 $122))
    (let $124 (IfPresent $120 $121 $122))
    (return $123 $124)
  ))))
  (return (FromFlow (WideMap $92 $93)))
))) $19))
(let $21 (DqCnUnionAll (TDqOutput $20 '0)))
(let $22 (DqPhyStage '($21) (lambda '($135) (block '(
  (let $136 (Condense (NarrowMap (ToFlow $135) (lambda '($137 $138) (AsStruct '('AdaptiveWardHistogramCDF0 $137) '('HistogramCDF0 $138)))) (List (ListType $18)) (lambda '($139 $140) $9) (lambda '($141 $142) (AsList $141))))
  (return (FromFlow (Map $136 (lambda '($143) (block '(
    (let $144 (ToOptional $143))
    (return (AsStruct '('"key" (Member $144 'HistogramCDF0)) '('"subkey" (Member $144 'AdaptiveWardHistogramCDF0))))
  ))))))
))) '('('"_logical_id" '5633) '('"_id" '"b8e3af2f-f4f94245-fc8f24bd-64319aa0"))))
(let $23 '($14 $20 $22))
(let $24 (DqCnResult (TDqOutput $22 '0) $1))
(return (KqpPhysicalQuery '((KqpPhysicalTx $23 '($24) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType '('"key" $17) '('"subkey" $17))) '0 '0)) '('('"type" '"query"))))
)
