(
(declare %kqp%tx_result_binding_0_0 (OptionalType (StructType '('Count0 (DataType 'Uint64)) '('Percentile0 (DataType 'Double)))))
(let $1 (Uint64 '1))
(let $2 '((ResourceType '"Stat.TDigestResource")))
(let $3 (DataType 'Double))
(let $4 '($3))
(let $5 (OptionalType $3))
(let $6 (Bool 'false))
(let $7 '('('"strict")))
(let $8 (DataType 'String))
(let $9 '($8))
(let $10 (DataType 'Uint64))
(let $11 '('('"_logical_id" '5958) '('"_id" '"a3685a19-2731753d-baa3e1df-3a504fbe") '('"_wide_channels" (StructType '('_yql_agg_0 $10) '('_yql_agg_1 $8)))))
(let $12 (DqPhyStage '() (lambda '() (block '(
  (let $26 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $27 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $26)))
  (let $28 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $29 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $30 (YtTable '"Input" $27 $28 $29 '() (Void) (Void) '"/Root/plato"))
  (let $31 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $30 '('"key") (Void) (Void))) '()))))
  (let $32 (OptionalType (DataType 'Uint32)))
  (let $33 (Uint32 '0))
  (let $34 (DependsOn (Uint32 '1)))
  (let $35 (lambda '($39) (block '(
    (let $40 '($5))
    (let $41 (CallableType '('"2") $2 $4 $40 $40))
    (let $42 (Udf '"Stat.TDigest_Create" (Void) (VoidType) '"" $41 (VoidType) '"" '()))
    (let $43 (NamedApply $42 '((Convert (Coalesce (SafeCast $39 $32) $33) $3)) (AsStruct) $34))
    (return $1 $43)
  ))))
  (let $36 (lambda '($47 $48 $49) (block '(
    (let $50 (CallableType '() $2 $2 $4))
    (let $51 (Udf '"Stat.TDigest_AddValue" (Void) (VoidType) '"" $50 (VoidType) '"" $7))
    (let $52 (NamedApply $51 '($49 (Convert (Coalesce (SafeCast $47 $32) $33) $3)) (AsStruct) $34))
    (return (AggrAdd $48 $1) $52)
  ))))
  (let $37 (WideCondense1 (DqReadWideWrap $31 '()) $35 (lambda '($44 $45 $46) $6) $36))
  (let $38 (lambda '($53 $54) (block '(
    (let $55 (CallableType '() $9 $2))
    (let $56 (Udf '"Stat.TDigest_Serialize" (Void) (VoidType) '"" $55 (VoidType) '"" $7))
    (return $53 (Apply $56 $54))
  ))))
  (return (FromFlow (WideMap $37 $38)))
))) $11))
(let $13 (DqCnUnionAll (TDqOutput $12 '0)))
(let $14 (Double '"0.1"))
(let $15 (OptionalType (StructType '('Count0 $10) '('Percentile0 $3))))
(let $16 (DqPhyStage '($13) (lambda '($57) (block '(
  (let $58 (CallableType '() $2 $9))
  (let $59 (Udf '"Stat.TDigest_Deserialize" (Void) (VoidType) '"" $58 (VoidType) '"" '()))
  (let $60 (lambda '($63 $64) $63 (Apply $59 $64)))
  (let $61 (lambda '($69 $70 $71 $72) (block '(
    (let $73 (CallableType '() $2 $2 $2))
    (let $74 (Udf '"Stat.TDigest_Merge" (Void) (VoidType) '"" $73 (VoidType) '"" $7))
    (let $75 (Apply $74 (Apply $59 $70) $72))
    (return (AggrAdd $69 $71) $75)
  ))))
  (let $62 (WideCondense1 (ToFlow $57) $60 (lambda '($65 $66 $67 $68) $6) $61))
  (return (FromFlow (Condense (NarrowMap (Take $62 $1) (lambda '($76 $77) (block '(
    (let $78 (CallableType '() $4 $2 $4))
    (let $79 (Udf '"Stat.TDigest_GetPercentile" (Void) (VoidType) '"" $78 (VoidType) '"" $7))
    (let $80 (Apply $79 $77 $14))
    (return (AsStruct '('Count0 $76) '('Percentile0 $80)))
  )))) (Nothing $15) (lambda '($81 $82) $6) (lambda '($83 $84) (Just $83)))))
))) '('('"_logical_id" '6757) '('"_id" '"bbf34b4a-b4491265-7c15464f-60f7b41a"))))
(let $17 (DqCnValue (TDqOutput $16 '0)))
(let $18 (KqpPhysicalTx '($12 $16) '($17) '() '('('"type" '"compute"))))
(let $19 '"%kqp%tx_result_binding_0_0")
(let $20 '('('"_logical_id" '6877) '('"_id" '"55f8aac3-c5f420f0-ecc0b31-c48888e6") '('"_partition_mode" '"single")))
(let $21 (DqPhyStage '() (lambda '() (block '(
  (let $85 %kqp%tx_result_binding_0_0)
  (return (Iterator (AsList (AsStruct '('"count" (Coalesce (Member $85 'Count0) (Uint64 '0))) '('"key_q" (Member $85 'Percentile0)) '('"quantile" (* $14 (Int32 '"100")))))))
))) $20))
(let $22 '('"quantile" '"key_q" '"count"))
(let $23 (DqCnResult (TDqOutput $21 '0) $22))
(let $24 (KqpTxResultBinding $15 '0 '0))
(let $25 (KqpPhysicalTx '($21) '($23) '('($19 $24)) '('('"type" '"generic"))))
(return (KqpPhysicalQuery '($18 $25) '((KqpTxResultBinding (ListType (StructType '('"count" $10) '('"key_q" $5) '('"quantile" $3))) '1 '0)) '('('"type" '"query"))))
)
