From a3a3c35f0a4bab2a0627fcb01b0b5c6acd0e3919 Mon Sep 17 00:00:00 2001 From: Jaimee Date: Sat, 2 Dec 2023 02:04:21 +0800 Subject: [PATCH] add Quantile Sketch for aggregator and postaggregator (#287) Co-authored-by: jaimelyn.maico --- .pre-commit-config.yaml | 1 + pydruid/utils/aggregators.py | 4 ++++ pydruid/utils/postaggregator.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fee7b2a5..98959275 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ repos: rev: 19.10b0 hooks: - id: black + additional_dependencies: ['click<8.1'] language_version: python3 - repo: https://github.com/asottile/seed-isort-config diff --git a/pydruid/utils/aggregators.py b/pydruid/utils/aggregators.py index 23caa826..4516e912 100644 --- a/pydruid/utils/aggregators.py +++ b/pydruid/utils/aggregators.py @@ -25,6 +25,10 @@ def thetasketch(raw_column, isinputthetasketch=False, size=16384): } +def quantilesDoublesSketch(raw_column, k=128): + return {"type": "quantilesDoublesSketch", "fieldName": raw_column, "k": k} + + def min(raw_metric): """ .. note:: Deprecated use `longMin`, `doubleMin' instead diff --git a/pydruid/utils/postaggregator.py b/pydruid/utils/postaggregator.py index 16c4087c..82cb10f5 100644 --- a/pydruid/utils/postaggregator.py +++ b/pydruid/utils/postaggregator.py @@ -53,6 +53,20 @@ def rename_postagg(new_name, post_aggregator): ] +class QuantilesDoublesSketchToQuantile(Postaggregator): + def __init__(self, name: str, field_name: str, fraction: float): + self.post_aggregator = { + "type": "quantilesDoublesSketchToQuantile", + "name": name, + "fraction": fraction, + "field": { + "fieldName": field_name, + "name": field_name, + "type": "fieldAccess", + }, + } + + class Quantile(Postaggregator): def __init__(self, name, probability): Postaggregator.__init__(self, None, None, name)