(
(let $1 (DataType 'Double))
(let $2 (OptionalType (TupleType $1 (DataType 'Uint64))))
(let $3 '('2))
(let $4 (ResourceType '"Stat.TDigestResource"))
(let $5 '($4))
(let $6 '($1))
(let $7 (OptionalType $1))
(let $8 (Nothing (OptionalType $4)))
(let $9 '('('"strict")))
(let $10 (DataType 'String))
(let $11 '($10))
(let $12 (OptionalType $10))
(let $13 '('"key" $10))
(let $14 (StructType '('_yql_agg_0 $2) '('_yql_agg_1 $12) $13))
(let $15 '('('"_logical_id" '6359) '('"_id" '"7fbf70ad-1561c217-defed5e6-3612d167") '('"_wide_channels" $14)))
(let $16 (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 '"10") '('DataSize '"390") '('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" '"value") (Void) (Void))) '()))))
  (let $32 (OptionalType (DataType 'Int32)))
  (let $33 (lambda '($48) (Just '((Convert $48 'Double) (Uint64 '1)))))
  (let $34 (Nothing $2))
  (let $35 (DependsOn (Uint32 '1)))
  (let $36 (lambda '($49) (block '(
    (let $50 '($7))
    (let $51 (CallableType $3 $5 $6 $50 $50))
    (let $52 (Udf '"Stat.TDigest_Create" (Void) (VoidType) '"" $51 (VoidType) '"" '()))
    (return (Just (NamedApply $52 '((Convert $49 $1)) (AsStruct) $35)))
  ))))
  (let $37 (lambda '($42 $43 $44) (block '(
    (let $45 (SafeCast $44 $32))
    (let $46 (IfPresent $45 $33 $34))
    (let $47 (IfPresent $45 $36 $8))
    (return $46 $47)
  ))))
  (let $38 (lambda '($53 $54 $55 $56 $57) (block '(
    (let $58 (SafeCast $55 $32))
    (let $59 (IfPresent $58 $33 $34))
    (let $60 (IfPresent $56 (lambda '($63) (IfPresent $58 (lambda '($64) (Just '((AggrAdd (Nth $63 '0) (Convert $64 'Double)) (Inc (Nth $63 '1))))) (Just $63))) $59))
    (let $61 (IfPresent $58 $36 $8))
    (let $62 (IfPresent $57 (lambda '($65) (IfPresent $58 (lambda '($66) (block '(
      (let $67 (CallableType '() $5 $5 $6))
      (let $68 (Udf '"Stat.TDigest_AddValue" (Void) (VoidType) '"" $67 (VoidType) '"" $9))
      (return (Just (NamedApply $68 '($65 (Convert $66 $1)) (AsStruct) $35)))
    ))) (Just $65))) $61))
    (return $60 $62)
  ))))
  (let $39 (lambda '($69 $70 $71) (block '(
    (let $72 (IfPresent $71 (lambda '($73) (block '(
      (let $74 (CallableType '() $11 $5))
      (let $75 (Udf '"Stat.TDigest_Serialize" (Void) (VoidType) '"" $74 (VoidType) '"" $9))
      (return (Just (Apply $75 $73)))
    ))) (Nothing $12)))
    (return $70 $72 $69)
  ))))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow (DqReadWideWrap $31 '()))) '-1073741824 (lambda '($40 $41) $40) $37 $38 $39))
))) $15))
(let $17 (DqCnHashShuffle (TDqOutput $16 '0) $3 '0 '"HashV2"))
(let $18 (StructType '('avg $7) $13 '('"med" $7)))
(let $19 '('('"_logical_id" '9916) '('"_id" '"4f5244ca-d8409dd0-6b98add6-be5bded6") '('"_wide_channels" $18)))
(let $20 (DqPhyStage '($17) (lambda '($76) (block '(
  (let $77 (CallableType '() $5 $11))
  (let $78 (Udf '"Stat.TDigest_Deserialize" (Void) (VoidType) '"" $77 (VoidType) '"" '()))
  (let $79 (lambda '($93) (Just (Apply $78 $93))))
  (let $80 (lambda '($88 $89 $90 $91) (block '(
    (let $92 (IfPresent $90 $79 $8))
    (return $89 $92)
  ))))
  (let $81 (lambda '($94 $95 $96 $97 $98 $99) (block '(
    (let $100 (IfPresent $95 (lambda '($102) (IfPresent $98 (lambda '($103) (Just '((AggrAdd (Nth $102 '0) (Nth $103 '0)) (AggrAdd (Nth $102 '1) (Nth $103 '1))))) $95)) $98))
    (let $101 (IfPresent $96 (lambda '($104) (block '(
      (let $105 (IfPresent $96 $79 $8))
      (return (IfPresent $99 (lambda '($106) (block '(
        (let $107 (CallableType '() $5 $5 $5))
        (let $108 (Udf '"Stat.TDigest_Merge" (Void) (VoidType) '"" $107 (VoidType) '"" $9))
        (return (Just (Apply $108 (Apply $78 $104) $106)))
      ))) $105))
    ))) $99))
    (return $100 $101)
  ))))
  (let $82 (lambda '($109 $110 $111) (block '(
    (let $112 (Nothing $7))
    (let $113 (IfPresent $110 (lambda '($115) (Just (Div (Nth $115 '0) (Nth $115 '1)))) $112))
    (let $114 (IfPresent $111 (lambda '($116) (block '(
      (let $117 (CallableType '() $6 $5 $6))
      (let $118 (Udf '"Stat.TDigest_GetPercentile" (Void) (VoidType) '"" $117 (VoidType) '"" $9))
      (return (Just (Apply $118 $116 (Double '0.5))))
    ))) $112))
    (return $113 $114 $109)
  ))))
  (let $83 (WideCombiner (ToFlow (WideFromBlocks $76)) '"" (lambda '($85 $86 $87) $87) $80 $81 $82))
  (let $84 (lambda '($119 $120 $121) $119 $121 $120))
  (return (FromFlow (WideMap (WideSort $83 '('('2 (Bool 'true)))) $84)))
))) $19))
(let $21 (DqCnMerge (TDqOutput $20 '0) '('('1 '"Asc"))))
(let $22 (DqPhyStage '($21) (lambda '($122) (FromFlow (NarrowMap (ToFlow $122) (lambda '($123 $124 $125) (AsStruct '('avg $123) '('"key" $124) '('"med" $125)))))) '('('"_logical_id" '9928) '('"_id" '"57684e09-9dbe85a4-5367fff9-bdbdcc53"))))
(let $23 '($16 $20 $22))
(let $24 '('"key" '"med" 'avg))
(let $25 (DqCnResult (TDqOutput $22 '0) $24))
(return (KqpPhysicalQuery '((KqpPhysicalTx $23 '($25) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $18) '0 '0)) '('('"type" '"query"))))
)
