(
(let $1 (Configure! world (DataSource '"config") '"DqEngine" '"force"))
(let $2 (Configure! $1 (DataSource '"dq" '"$all") '"Attr" '"maxtasksperstage" '"2"))
(let $3 (Configure! $2 (DataSource '"pq" '"$all") '"Attr" '"consumer" '"test_client"))
(let $4 (DataSource '"pq" '"pq"))
(let $5 '('('"PartitionsCount" '1)))
(let $6 (DataType 'String))
(let $7 (StructType '('"Data" $6)))
(let $8 (PqTopic '"pq" '"local" '"test_topic_input" $5 '() $7))
(let $9 '('"Endpoint" '"<pq_pq_endpoint>"))
(let $10 '('"SharedReading" '1))
(let $11 '('"UseSsl" '1))
(let $12 '('('"Consumer" '"test_client") $9 $10 '('"ReconnectPeriod" '"") '('"Format" '"raw") '('"ReadGroup" '"fqrun") $11))
(let $13 (SecureParam '"cluster:default_pq"))
(let $14 (DqPqTopicSource $3 $8 '('"Data") $12 $13 '"" $7 '""))
(let $15 (ResourceType '"Yson2.Node"))
(let $16 '('"2"))
(let $17 '('"strict"))
(let $18 '($17))
(let $19 (DataType 'Yson))
(let $20 '($15 '"" '1))
(let $21 (CallableType '() '($19) $20))
(let $22 (DataType 'Uint64))
(let $23 (OptionalType $22))
(let $24 '($6))
(let $25 '($15))
(let $26 (DqStage '((DqSource $4 $14)) (lambda '($30) (block '(
  (let $31 '('('"format" '"raw") '('"formatSettings" '('('"data.datetime.formatname" '"POSIX") '('"data.timestamp.formatname" '"POSIX"))) '('"settings" '($10))))
  (let $32 (DqSourceWideWrap $30 $4 $7 $31))
  (return (FlatMap (NarrowMap $32 (lambda '($33) (AsStruct '('"Data" $33)))) (lambda '($34) (block '(
    (let $35 (ResourceType '"Yson2.Options"))
    (let $36 (TupleType (TupleType $6 $35) (StructType) (TupleType)))
    (let $37 '('1))
    (let $38 '($6 '"" '1))
    (let $39 '((OptionalType $35)))
    (let $40 (CallableType $37 '((OptionalType $15)) $38 $39))
    (let $41 (Udf '"Yson2.Parse" (Void) $36 '"" $40 (VoidType) '"" '()))
    (let $42 (OptionalType (DataType 'Bool)))
    (let $43 (CallableType $16 '($35) '($42 '"AutoConvert") '($42 '"Strict")))
    (let $44 (Udf '"Yson2.Options" (Void) (VoidType) '"" $43 (VoidType) '"" $18))
    (let $45 (Just (NamedApply $44 '() (AsStruct '('"AutoConvert" (Just (Bool '"false"))) '('"Strict" (Just (Bool 'true)))))))
    (let $46 (Apply $41 (Member $34 '"Data") $45))
    (let $47 (FlatMap $46 (lambda '($52) (block '(
      (let $53 (Udf '"Yson2.Serialize" (Void) (VoidType) '"" $21 (VoidType) '"" $18))
      (return (Just (Apply $53 $52)))
    )))))
    (let $48 (TupleType (TupleType $19) (StructType) (TupleType)))
    (let $49 '($19 '"" '1))
    (let $50 (CallableType $37 $25 $49 $39))
    (let $51 (Udf '"Yson2.Parse" (Void) $48 '"" $50 (VoidType) '"" $18))
    (return (Just (AsStruct '('"t" (FlatMap $47 (lambda '($54) (block '(
      (let $55 (CallableType $37 '($23) $20 $24 $39))
      (let $56 (Udf '"Yson2.LookupUint64" (Void) (VoidType) '"" $55 (VoidType) '"" '()))
      (return (Apply $56 (Apply $51 $54) (String '"time") $45))
    ))))) '('"v" (FlatMap $47 (lambda '($57) (block '(
      (let $58 (CallableType $37 '((OptionalType (DataType 'Int64))) $20 $24 $39))
      (let $59 (Udf '"Yson2.LookupInt64" (Void) (VoidType) '"" $58 (VoidType) '"" '()))
      (return (Apply $59 (Apply $51 $57) (String '"val") $45))
    ))))))))
  )))))
))) '('('"_logical_id" '0))))
(let $27 (DataSink '"pq" '"pq"))
(let $28 (PqTopic '"pq" '"local" '"test_topic_output" $5 '() $7))
(let $29 (DqPqTopicSink $28 '($9 $11) $13))
(return (Commit! (DqQuery! $3 '((DqStage '((DqCnUnionAll (TDqOutput $26 '0))) (lambda '($60) (block '(
  (let $61 (Uint32 '0))
  (let $62 (Interval '10000))
  (let $63 '"Percentile0_Percentile1_")
  (let $64 '((ResourceType '"Stat.TDigestResource")))
  (let $65 (DataType 'Double))
  (let $66 '($65))
  (let $67 (OptionalType $65))
  (let $68 (DependsOn $61))
  (let $69 (lambda '($78) (block '(
    (let $79 '($67))
    (let $80 (CallableType $16 $64 $66 $79 $79))
    (let $81 (Udf '"Stat.TDigest_Create" (Void) (VoidType) '"" $80 (VoidType) '"" '()))
    (return (Just (NamedApply $81 '((Convert $78 $65)) (AsStruct) $68)))
  ))))
  (let $70 (MultiHoppingCore (FromFlow $60) (lambda '($71) $61) (lambda '($72) (FlatMap (SafeCast (Unwrap (Member (SafeCast $72 (StructType '('"t" $23))) '"t")) (OptionalType (DataType 'Uint32))) (lambda '($73) (block '(
    (let $74 '($22 '"" '1))
    (let $75 (CallableType '() '((OptionalType (DataType 'Timestamp))) $74))
    (let $76 (Udf '"DateTime2.FromMilliseconds" (Void) (VoidType) '"" $75 (VoidType) '"" '('('"blocks") $17)))
    (return (Apply $76 (Convert $73 $22)))
  ))))) (Interval '5000) $62 $62 'true (lambda '($77) (AsStruct '($63 (FlatMap (Member $77 '"v") $69)))) (lambda '($82 $83) (block '(
    (let $84 (Member $82 '"v"))
    (let $85 (IfPresent (Member $83 $63) (lambda '($86) (IfPresent $84 (lambda '($87) (block '(
      (let $88 (CallableType '() $64 $64 $66))
      (let $89 (Udf '"Stat.TDigest_AddValue" (Void) (VoidType) '"" $88 (VoidType) '"" $18))
      (return (Just (NamedApply $89 '($86 (Convert $87 $65)) (AsStruct) $68)))
    ))) (Just $86))) (FlatMap $84 $69)))
    (return (AsStruct '($63 $85)))
  ))) (lambda '($90) (AsStruct '($63 (FlatMap (Member $90 $63) (lambda '($91) (block '(
    (let $92 (CallableType '() $24 $64))
    (let $93 (Udf '"Stat.TDigest_Serialize" (Void) (VoidType) '"" $92 (VoidType) '"" $18))
    (return (Just (Apply $93 $91)))
  ))))))) (lambda '($94) (AsStruct '($63 (FlatMap (Member $94 $63) (lambda '($95) (block '(
    (let $96 (CallableType '() $64 $24))
    (let $97 (Udf '"Stat.TDigest_Deserialize" (Void) (VoidType) '"" $96 (VoidType) '"" '()))
    (return (Just (Apply $97 $95)))
  ))))))) (lambda '($98 $99) (block '(
    (let $100 (OptionalReduce (Member $98 $63) (Member $99 $63) (lambda '($101 $102) (block '(
      (let $103 (CallableType '() $64 $64 $64))
      (let $104 (Udf '"Stat.TDigest_Merge" (Void) (VoidType) '"" $103 (VoidType) '"" $18))
      (return (Apply $104 $101 $102))
    )))))
    (return (AsStruct '($63 $100)))
  ))) (lambda '($105 $106 $107) (block '(
    (let $108 (Member $106 $63))
    (let $109 (CallableType '() $66 $64 $66))
    (let $110 (Udf '"Stat.TDigest_GetPercentile" (Void) (VoidType) '"" $109 (VoidType) '"" $18))
    (return (AsStruct '('Percentile0 (FlatMap $108 (lambda '($111) (Just (Apply $110 $111 (Double '"0.75")))))) '('Percentile1 (FlatMap $108 (lambda '($112) (Just (Apply $110 $112 (Double '"0.9")))))) '('"_yql_time" $107)))
  ))) '0 '"_yql_time"))
  (return (FlatMap (ExtractMembers $70 '('Percentile0 'Percentile1)) (lambda '($113) (block '(
    (let $114 (Udf '"Yson2.SerializeText" (Void) (VoidType) '"" $21 (VoidType) '"" $18))
    (let $115 (StructType '('"p75" $67) '('"p90" $67)))
    (let $116 (TupleType (TupleType $115) (StructType) (TupleType)))
    (let $117 (CallableType '() $25 '($115)))
    (let $118 (Udf '"Yson2.From" (Void) $116 '"" $117 (VoidType) '"" $18))
    (return (Just (AsStruct '('"column0" (Apply $114 (Apply $118 (AsStruct '('"p75" (Member $113 'Percentile0)) '('"p90" (Member $113 'Percentile1)))))))))
  )))))
))) '('('"_logical_id" '0)) '((DqSink '0 $27 $29))))) $27))
)
