(
(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 (Int32 '1))
(let $10 '('"2"))
(let $11 (ResourceType '"Stat.TDigestResource"))
(let $12 '($11))
(let $13 (DataType 'Double))
(let $14 '($13))
(let $15 (OptionalType $13))
(let $16 (DependsOn (Uint32 '0)))
(let $17 (lambda '($60) (block '(
  (let $61 '($15))
  (let $62 (CallableType $10 $12 $14 $61 $61))
  (let $63 (Udf '"Stat.TDigest_Create" (Void) (VoidType) '"" $62 (VoidType) '"" '()))
  (return (Just (NamedApply $63 '((Convert $60 $13)) (AsStruct) $16)))
))))
(let $18 (OptionalType $11))
(let $19 (Nothing $18))
(let $20 (CallableType '() $12 $12 $14))
(let $21 '('('"strict")))
(let $22 (Udf '"Stat.TDigest_AddValue" (Void) (VoidType) '"" $20 (VoidType) '"" $21))
(let $23 (DataType 'String))
(let $24 '($23))
(let $25 (lambda '($74) (block '(
  (let $75 (CallableType '() $24 $12))
  (let $76 (Udf '"Stat.TDigest_Serialize" (Void) (VoidType) '"" $75 (VoidType) '"" $21))
  (return (Just (Apply $76 $74)))
))))
(let $26 (OptionalType $23))
(let $27 (Nothing $26))
(let $28 (OptionalType $26))
(let $29 (Nothing $28))
(let $30 '('"_logical_id" '15657))
(let $31 '('"key" $23))
(let $32 (StructType '('_yql_agg_0 $28) '('_yql_agg_1 $28) $31))
(let $33 '('"_wide_channels" $32))
(let $34 '($30 '('"_id" '"fc31e8f2-79d2b1ea-e0c47647-555688ff") $33))
(let $35 (DqPhyStage '() (lambda '() (block '(
  (let $54 (lambda '($72 $73) (Just (IfPresent $73 $25 $27)) $29 $72))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow $7)) '-1073741824 (lambda '($55 $56) $55) (lambda '($57 $58 $59) (IfPresent (+ (SafeCast $59 $8) $9) $17 $19)) (lambda '($64 $65 $66 $67) (block '(
    (let $68 (+ (SafeCast $66 $8) $9))
    (let $69 (IfPresent $68 $17 $19))
    (return (IfPresent $67 (lambda '($70) (IfPresent $68 (lambda '($71) (Just (NamedApply $22 '($70 (Convert $71 $13)) (AsStruct) $16))) (Just $70))) $69))
  ))) $54))
))) $34))
(let $36 '($30 '('"_id" '"9acb43fb-8926157c-cb161d8b-83e40fa8") '('"_wide_channels" (StructType '('_yql_preagg_Median0 $8) $31))))
(let $37 (DqPhyStage '() (lambda '() (block '(
  (let $77 (lambda '($81 $82) (+ (SafeCast $82 $8) $9) $81))
  (let $78 (lambda '($83 $84 $85 $86) $83 $84))
  (let $79 (lambda '($87 $88 $89 $90 $91 $92) $91 $92))
  (let $80 (lambda '($93 $94 $95 $96) $95 $96))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow $7)) '-1073741824 $77 $78 $79 $80))
))) $36))
(let $38 (DqCnHashShuffle (TDqOutput $37 '0) '('0 '1) '0 '"HashV2"))
(let $39 '('('"_logical_id" '15831) '('"_id" '"cfe95c63-c690fcd6-aaeb7d3d-86b37d8a") $33))
(let $40 (DqPhyStage '($38) (lambda '($97) (block '(
  (let $98 (lambda '($101 $102) $101 $102))
  (let $99 (lambda '($103 $104 $105 $106)))
  (let $100 (lambda '($119 $120) $29 (Just (IfPresent $120 $25 $27)) $119))
  (return (DqPhyHashCombine (WideToBlocks (FromFlow (WideCombiner (ToFlow (WideFromBlocks $97)) '"" $98 $99 $99 $98))) '-1073741824 (lambda '($107 $108) $108) (lambda '($109 $110 $111) (IfPresent $110 $17 $19)) (lambda '($112 $113 $114 $115) (block '(
    (let $116 (IfPresent $113 $17 $19))
    (return (IfPresent $115 (lambda '($117) (IfPresent $113 (lambda '($118) (Just (NamedApply $22 '($117 (Convert $118 $13)) (AsStruct) $16))) (Just $117))) $116))
  ))) $100))
))) $39))
(let $41 (DqCnParallelUnionAll (TDqOutput $35 '0)))
(let $42 (DqCnParallelUnionAll (TDqOutput $40 '0)))
(let $43 '('('"_logical_id" '15933) '('"_id" '"f4212d7a-2a0bd673-cf6b2ef-56d7e4f3") $33))
(let $44 (DqPhyStage '($41 $42) (lambda '($121 $122) (FromFlow (Extend (ToFlow (WideFromBlocks $121)) (ToFlow (WideFromBlocks $122))))) $43))
(let $45 (DqCnHashShuffle (TDqOutput $44 '0) $10 '0 '"HashV2"))
(let $46 (StructType '('"distinct_med" $15) '('"med" $15) '('"p80" $15)))
(let $47 '('('"_logical_id" '16162) '('"_id" '"cf7d3cab-db4bf4db-c9c55f88-245184cc") '('"_wide_channels" $46)))
(let $48 (DqPhyStage '($45) (lambda '($123) (block '(
  (let $124 (CallableType '() $12 $24))
  (let $125 (Udf '"Stat.TDigest_Deserialize" (Void) (VoidType) '"" $124 (VoidType) '"" '()))
  (let $126 (lambda '($144) (Just (Apply $125 $144))))
  (let $127 (lambda '($143) (Just (IfPresent $143 $126 $19))))
  (let $128 (Nothing (OptionalType $18)))
  (let $129 (lambda '($137 $138 $139 $140) (block '(
    (let $141 (IfPresent $138 $127 $128))
    (let $142 (IfPresent $139 $127 $128))
    (return $141 $142)
  ))))
  (let $130 (lambda '($145 $146 $147 $148 $149 $150) (block '(
    (let $151 (CallableType '() $12 $12 $12))
    (let $152 (Udf '"Stat.TDigest_Merge" (Void) (VoidType) '"" $151 (VoidType) '"" $21))
    (let $153 (IfPresent $146 (lambda '($155) (block '(
      (let $156 (IfPresent $146 $127 $128))
      (return (IfPresent $149 (lambda '($157) (Just (IfPresent $155 (lambda '($158) (block '(
        (let $159 (IfPresent $155 $126 $19))
        (return (IfPresent $157 (lambda '($160) (Just (Apply $152 (Apply $125 $158) $160))) $159))
      ))) $157))) $156))
    ))) $149))
    (let $154 (IfPresent $147 (lambda '($161) (block '(
      (let $162 (IfPresent $147 $127 $128))
      (return (IfPresent $150 (lambda '($163) (Just (IfPresent $161 (lambda '($164) (block '(
        (let $165 (IfPresent $161 $126 $19))
        (return (IfPresent $163 (lambda '($166) (Just (Apply $152 (Apply $125 $164) $166))) $165))
      ))) $163))) $162))
    ))) $150))
    (return $153 $154)
  ))))
  (let $131 (lambda '($167 $168 $169) (block '(
    (let $170 (Unwrap $168))
    (let $171 (CallableType '() $14 $12 $14))
    (let $172 (Udf '"Stat.TDigest_GetPercentile" (Void) (VoidType) '"" $171 (VoidType) '"" $21))
    (let $173 (lambda '($178) (Just (Apply $172 $178 (Double '0.5)))))
    (let $174 (Nothing $15))
    (let $175 (IfPresent $170 $173 $174))
    (let $176 (IfPresent (Unwrap $169) $173 $174))
    (let $177 (IfPresent $170 (lambda '($179) (Just (Apply $172 $179 (Double '"0.8")))) $174))
    (return $175 $176 $177)
  ))))
  (let $132 (WideCombiner (ToFlow $123) '"" (lambda '($134 $135 $136) $136) $129 $130 $131))
  (let $133 (lambda '($180 $181 $182) $181 $180 $182))
  (return (FromFlow (WideMap (WideSort $132 '('('0 (Bool 'true)))) $133)))
))) $47))
(let $49 (DqCnMerge (TDqOutput $48 '0) '('('1 '"Asc"))))
(let $50 (DqPhyStage '($49) (lambda '($183) (FromFlow (NarrowMap (ToFlow $183) (lambda '($184 $185 $186) (AsStruct '('"distinct_med" $184) '('"med" $185) '('"p80" $186)))))) '('('"_logical_id" '16174) '('"_id" '"b908c694-3b826a39-ec0a1756-bc0b30d0"))))
(let $51 '($35 $37 $40 $44 $48 $50))
(let $52 '('"med" '"distinct_med" '"p80"))
(let $53 (DqCnResult (TDqOutput $50 '0) $52))
(return (KqpPhysicalQuery '((KqpPhysicalTx $51 '($53) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $46) '0 '0)) '('('"type" '"query"))))
)
