(
(let $1 (ResourceType '"Stat.TDigestResource"))
(let $2 '($1))
(let $3 (DataType 'Double))
(let $4 '($3))
(let $5 (OptionalType $3))
(let $6 (Nothing (OptionalType $1)))
(let $7 (Bool 'false))
(let $8 '('('"strict")))
(let $9 (DataType 'String))
(let $10 '($9))
(let $11 (OptionalType $9))
(let $12 '('('"_logical_id" '5143) '('"_id" '"f04335f6-f4c618e9-632ab3bf-a5ad59ea") '('"_wide_channels" (StructType '('_yql_agg_0 $11)))))
(let $13 (DqPhyStage '() (lambda '() (block '(
  (let $22 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $23 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $22)))
  (let $24 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $25 (YtStat '('Id '"Input") '('RecordsCount '"10") '('DataSize '"390") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $26 (YtTable '"Input" $23 $24 $25 '() (Void) (Void) '"/Root/plato"))
  (let $27 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $26 '('"value") (Void) (Void))) '()))))
  (let $28 (OptionalType (DataType 'Int32)))
  (let $29 (DependsOn (Uint32 '0)))
  (let $30 (lambda '($34) (block '(
    (let $35 '($5))
    (let $36 (CallableType '('"2") $2 $4 $35 $35))
    (let $37 (Udf '"Stat.TDigest_Create" (Void) (VoidType) '"" $36 (VoidType) '"" '()))
    (return (Just (NamedApply $37 '((Convert $34 $3)) (AsStruct) $29)))
  ))))
  (let $31 (Condense1 (NarrowMap (DqReadWideWrap $27 '()) (lambda '($32) (AsStruct '('"value" $32)))) (lambda '($33) (IfPresent (SafeCast (Member $33 '"value") $28) $30 $6)) (lambda '($38 $39) $7) (lambda '($40 $41) (block '(
    (let $42 (SafeCast (Member $40 '"value") $28))
    (let $43 (IfPresent $42 $30 $6))
    (return (IfPresent $41 (lambda '($44) (IfPresent $42 (lambda '($45) (block '(
      (let $46 (CallableType '() $2 $2 $4))
      (let $47 (Udf '"Stat.TDigest_AddValue" (Void) (VoidType) '"" $46 (VoidType) '"" $8))
      (return (Just (NamedApply $47 '($44 (Convert $45 $3)) (AsStruct) $29)))
    ))) (Just $44))) $43))
  )))))
  (return (FromFlow (ExpandMap $31 (lambda '($48) (IfPresent $48 (lambda '($49) (block '(
    (let $50 (CallableType '() $10 $2))
    (let $51 (Udf '"Stat.TDigest_Serialize" (Void) (VoidType) '"" $50 (VoidType) '"" $8))
    (return (Just (Apply $51 $49)))
  ))) (Nothing $11))))))
))) $12))
(let $14 (DqCnUnionAll (TDqOutput $13 '0)))
(let $15 (StructType '('Median0 $5) '('Percentile0 $5)))
(let $16 '('('"_logical_id" '5826) '('"_id" '"e30bd38a-2359b7ae-b52e14e6-a997ad6f") '('"_partition_mode" '"aggregate") '('"_wide_channels" $15)))
(let $17 (DqPhyStage '($14) (lambda '($52) (block '(
  (let $53 (CallableType '() $2 $10))
  (let $54 (Udf '"Stat.TDigest_Deserialize" (Void) (VoidType) '"" $53 (VoidType) '"" '()))
  (let $55 (lambda '($59) (Just (Apply $54 $59))))
  (let $56 (WideCondense1 (ToFlow $52) (lambda '($58) (IfPresent $58 $55 $6)) (lambda '($60 $61) $7) (lambda '($62 $63) (IfPresent $62 (lambda '($64) (block '(
    (let $65 (IfPresent $62 $55 $6))
    (return (IfPresent $63 (lambda '($66) (block '(
      (let $67 (CallableType '() $2 $2 $2))
      (let $68 (Udf '"Stat.TDigest_Merge" (Void) (VoidType) '"" $67 (VoidType) '"" $8))
      (return (Just (Apply $68 (Apply $54 $64) $66)))
    ))) $65))
  ))) $63))))
  (let $57 (lambda '($69) (block '(
    (let $70 (IfPresent $69 (lambda '($71) (block '(
      (let $72 (CallableType '() $4 $2 $4))
      (let $73 (Udf '"Stat.TDigest_GetPercentile" (Void) (VoidType) '"" $72 (VoidType) '"" $8))
      (let $74 (Apply $73 $71 (Double '0.5)))
      (let $75 (Apply $73 $71 (Double '"0.8")))
      (return (Just '($74 $75)))
    ))) (Nothing (OptionalType (TupleType $3 $3)))))
    (return (Nth $70 '0) (Nth $70 '1))
  ))))
  (return (FromFlow (WideMap $56 $57)))
))) $16))
(let $18 (DqCnUnionAll (TDqOutput $17 '0)))
(let $19 (DqPhyStage '($18) (lambda '($76) (block '(
  (let $77 (Condense (NarrowMap (ToFlow $76) (lambda '($78 $79) (AsStruct '('Median0 $78) '('Percentile0 $79)))) (List (ListType $15)) (lambda '($80 $81) $7) (lambda '($82 $83) (AsList $82))))
  (return (FromFlow (Map $77 (lambda '($84) (block '(
    (let $85 (ToOptional $84))
    (return (AsStruct '('"med" (Member $85 'Median0)) '('"p80" (Member $85 'Percentile0))))
  ))))))
))) '('('"_logical_id" '5880) '('"_id" '"65839ab8-76e8789c-bc264b5f-537b1b1d"))))
(let $20 '($13 $17 $19))
(let $21 (DqCnResult (TDqOutput $19 '0) '('"med" '"p80")))
(return (KqpPhysicalQuery '((KqpPhysicalTx $20 '($21) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType '('"med" $5) '('"p80" $5))) '0 '0)) '('('"type" '"query"))))
)
