(
(let $1 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
(let $2 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $1)))
(let $3 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
(let $4 (YtStat '('Id '"Input") '('RecordsCount '"10") '('DataSize '"390") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
(let $5 (YtTable '"Input" $2 $3 $4 '() (Void) (Void) '"/Root/plato"))
(let $6 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $5 '('"key" '"value") (Void) (Void))) '()))))
(let $7 (DqReadWideWrap $6 '()))
(let $8 (OptionalType (DataType 'Int32)))
(let $9 '('"2"))
(let $10 (ResourceType '"Stat.TDigestResource"))
(let $11 '($10))
(let $12 (DataType 'Double))
(let $13 '($12))
(let $14 (OptionalType $12))
(let $15 (DependsOn (Uint32 '0)))
(let $16 (lambda '($59) (block '(
  (let $60 '($14))
  (let $61 (CallableType $9 $11 $13 $60 $60))
  (let $62 (Udf '"Stat.TDigest_Create" (Void) (VoidType) '"" $61 (VoidType) '"" '()))
  (return (Just (NamedApply $62 '((Convert $59 $12)) (AsStruct) $15)))
))))
(let $17 (OptionalType $10))
(let $18 (Nothing $17))
(let $19 (CallableType '() $11 $11 $13))
(let $20 '('('"strict")))
(let $21 (Udf '"Stat.TDigest_AddValue" (Void) (VoidType) '"" $19 (VoidType) '"" $20))
(let $22 (DataType 'String))
(let $23 '($22))
(let $24 (lambda '($73) (block '(
  (let $74 (CallableType '() $23 $11))
  (let $75 (Udf '"Stat.TDigest_Serialize" (Void) (VoidType) '"" $74 (VoidType) '"" $20))
  (return (Just (Apply $75 $73)))
))))
(let $25 (OptionalType $22))
(let $26 (Nothing $25))
(let $27 (OptionalType $25))
(let $28 (Nothing $27))
(let $29 '('"_logical_id" '11735))
(let $30 '('"key" $22))
(let $31 (StructType '('_yql_agg_0 $27) '('_yql_agg_1 $27) $30))
(let $32 '('"_wide_channels" $31))
(let $33 '($29 '('"_id" '"d22b437a-d95d5b51-27b02fd4-87bcaa58") $32))
(let $34 (DqPhyStage '() (lambda '() (block '(
  (let $53 (lambda '($71 $72) (Just (IfPresent $72 $24 $26)) $28 $71))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow $7)) '-1073741824 (lambda '($54 $55) $54) (lambda '($56 $57 $58) (IfPresent (SafeCast $58 $8) $16 $18)) (lambda '($63 $64 $65 $66) (block '(
    (let $67 (SafeCast $65 $8))
    (let $68 (IfPresent $67 $16 $18))
    (return (IfPresent $66 (lambda '($69) (IfPresent $67 (lambda '($70) (Just (NamedApply $21 '($69 (Convert $70 $12)) (AsStruct) $15))) (Just $69))) $68))
  ))) $53))
))) $33))
(let $35 '($29 '('"_id" '"3a67aadf-694aaadb-d8b20e7b-a370ba4d") '('"_wide_channels" (StructType $30 '('"val" $8)))))
(let $36 (DqPhyStage '() (lambda '() (block '(
  (let $76 (lambda '($80 $81) $80 (SafeCast $81 $8)))
  (let $77 (lambda '($82 $83 $84 $85) $82 $83))
  (let $78 (lambda '($86 $87 $88 $89 $90 $91) $90 $91))
  (let $79 (lambda '($92 $93 $94 $95) $94 $95))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow $7)) '-1073741824 $76 $77 $78 $79))
))) $35))
(let $37 (DqCnHashShuffle (TDqOutput $36 '0) '('0 '1) '0 '"HashV2"))
(let $38 '('('"_logical_id" '11908) '('"_id" '"acdc0123-459473b8-7029ecd7-7dbb7878") $32))
(let $39 (DqPhyStage '($37) (lambda '($96) (block '(
  (let $97 (lambda '($100 $101) $100 $101))
  (let $98 (lambda '($102 $103 $104 $105)))
  (let $99 (lambda '($118 $119) $28 (Just (IfPresent $119 $24 $26)) $118))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow (WideCombiner (ToFlow (WideFromBlocks $96)) '"" $97 $98 $98 $97))) '-1073741824 (lambda '($106 $107) $106) (lambda '($108 $109 $110) (IfPresent $110 $16 $18)) (lambda '($111 $112 $113 $114) (block '(
    (let $115 (IfPresent $113 $16 $18))
    (return (IfPresent $114 (lambda '($116) (IfPresent $113 (lambda '($117) (Just (NamedApply $21 '($116 (Convert $117 $12)) (AsStruct) $15))) (Just $116))) $115))
  ))) $99))
))) $38))
(let $40 (DqCnParallelUnionAll (TDqOutput $34 '0)))
(let $41 (DqCnParallelUnionAll (TDqOutput $39 '0)))
(let $42 '('('"_logical_id" '12010) '('"_id" '"2075c4d-62999995-f6bfc4e2-252ad7a6") $32))
(let $43 (DqPhyStage '($40 $41) (lambda '($120 $121) (FromFlow (Extend (ToFlow (WideFromBlocks $120)) (ToFlow (WideFromBlocks $121))))) $42))
(let $44 (DqCnHashShuffle (TDqOutput $43 '0) $9 '0 '"HashV2"))
(let $45 (StructType '('"distinct_med" $14) '('"med" $14) '('"p80" $14)))
(let $46 '('('"_logical_id" '12239) '('"_id" '"e5bfb0f1-c9536161-7425d35a-63bd90b1") '('"_wide_channels" $45)))
(let $47 (DqPhyStage '($44) (lambda '($122) (block '(
  (let $123 (CallableType '() $11 $23))
  (let $124 (Udf '"Stat.TDigest_Deserialize" (Void) (VoidType) '"" $123 (VoidType) '"" '()))
  (let $125 (lambda '($143) (Just (Apply $124 $143))))
  (let $126 (lambda '($142) (Just (IfPresent $142 $125 $18))))
  (let $127 (Nothing (OptionalType $17)))
  (let $128 (lambda '($136 $137 $138 $139) (block '(
    (let $140 (IfPresent $137 $126 $127))
    (let $141 (IfPresent $138 $126 $127))
    (return $140 $141)
  ))))
  (let $129 (lambda '($144 $145 $146 $147 $148 $149) (block '(
    (let $150 (CallableType '() $11 $11 $11))
    (let $151 (Udf '"Stat.TDigest_Merge" (Void) (VoidType) '"" $150 (VoidType) '"" $20))
    (let $152 (IfPresent $145 (lambda '($154) (block '(
      (let $155 (IfPresent $145 $126 $127))
      (return (IfPresent $148 (lambda '($156) (Just (IfPresent $154 (lambda '($157) (block '(
        (let $158 (IfPresent $154 $125 $18))
        (return (IfPresent $156 (lambda '($159) (Just (Apply $151 (Apply $124 $157) $159))) $158))
      ))) $156))) $155))
    ))) $148))
    (let $153 (IfPresent $146 (lambda '($160) (block '(
      (let $161 (IfPresent $146 $126 $127))
      (return (IfPresent $149 (lambda '($162) (Just (IfPresent $160 (lambda '($163) (block '(
        (let $164 (IfPresent $160 $125 $18))
        (return (IfPresent $162 (lambda '($165) (Just (Apply $151 (Apply $124 $163) $165))) $164))
      ))) $162))) $161))
    ))) $149))
    (return $152 $153)
  ))))
  (let $130 (lambda '($166 $167 $168) (block '(
    (let $169 (CallableType '() $13 $11 $13))
    (let $170 (Udf '"Stat.TDigest_GetPercentile" (Void) (VoidType) '"" $169 (VoidType) '"" $20))
    (let $171 (Double '0.5))
    (let $172 (IfPresent (Unwrap $167) (lambda '($174) (block '(
      (let $175 (Apply $170 $174 $171))
      (let $176 (Apply $170 $174 (Double '"0.8")))
      (return (Just '($175 $176)))
    ))) (Nothing (OptionalType (TupleType $12 $12)))))
    (let $173 (IfPresent (Unwrap $168) (lambda '($177) (Just (Apply $170 $177 $171))) (Nothing $14)))
    (return (Nth $172 '0) $173 (Nth $172 '1))
  ))))
  (let $131 (WideCombiner (ToFlow $122) '"" (lambda '($133 $134 $135) $135) $128 $129 $130))
  (let $132 (lambda '($178 $179 $180) $179 $178 $180))
  (return (FromFlow (WideMap (WideSort $131 '('('0 (Bool 'true)))) $132)))
))) $46))
(let $48 (DqCnMerge (TDqOutput $47 '0) '('('1 '"Asc"))))
(let $49 (DqPhyStage '($48) (lambda '($181) (FromFlow (NarrowMap (ToFlow $181) (lambda '($182 $183 $184) (AsStruct '('"distinct_med" $182) '('"med" $183) '('"p80" $184)))))) '('('"_logical_id" '12251) '('"_id" '"7ead104b-53608e39-abb372ce-dcf10d10"))))
(let $50 '($34 $36 $39 $43 $47 $49))
(let $51 '('"med" '"distinct_med" '"p80"))
(let $52 (DqCnResult (TDqOutput $49 '0) $51))
(return (KqpPhysicalQuery '((KqpPhysicalTx $50 '($52) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $45) '0 '0)) '('('"type" '"query"))))
)
