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