DistinctCount Aggregator

DistinctCount Aggregator (고유값 집계기)

druid-distinctcount 확장은 드루이드 네이티브 질의에서 고유값(distinct count)을 계산할 수 있는 집계기를 제공해요. 정확한 결과를 얻으려면 파티셔닝과 granularity 설정에 몇 가지 조건을 지켜야 해요.

출처: 문서

본문

이 Apache Druid 확장을 사용하려면 extensions load list에 druid-distinctcount를 포함해 주세요.

druid-distinctcount

추가로 다음 단계를 따라야 해요.

첫째, 단일 dimension 해시 기반 파티션 스펙(single dimension hash-based partition spec)을 사용해 단일 dimension(예: visitor_id)으로 데이터를 파티셔닝해요. 이렇게 하면 해당 dimension의 특정 값을 가진 모든 행이 같은 세그먼트에 들어가게 돼요. 그렇지 않으면 과다 집계(over count)될 수 있어요.

둘째, distinctCount로 고유값을 계산할 때 queryGranularity가 segmentGranularity로 정확히 나눠지는지 확인해요. 그렇지 않으면 결과가 틀려요.

몇 가지 제한 사항이 있어요. groupBy에서 사용할 때 groupBy 키의 수가 각 세그먼트의 maxIntermediateRows를 초과하면 안 돼요. 초과하면 결과가 틀려요. topN에서 사용할 때 numValuesPerPass가 너무 크면 안 돼요. 너무 크면 distinctCount가 많은 메모리를 사용해서 JVM이 메모리 부족(out of memory)으로 죽을 수 있어요.

예시: Timeseries query

{
  "queryType": "timeseries",
  "dataSource": "sample_datasource",
  "granularity": "day",
  "aggregations": [
    {
      "type": "distinctCount",
      "name": "uv",
      "fieldName": "visitor_id"
    }
  ],
  "intervals": [
    "2016-03-01T00:00:00.000/2013-03-20T00:00:00.000"
  ]
}

예시: TopN query

{
  "queryType": "topN",
  "dataSource": "sample_datasource",
  "dimension": "sample_dim",
  "threshold": 5,
  "metric": "uv",
  "granularity": "all",
  "aggregations": [
    {
      "type": "distinctCount",
      "name": "uv",
      "fieldName": "visitor_id"
    }
  ],
  "intervals": [
    "2016-03-06T00:00:00/2016-03-06T23:59:59"
  ]
}

예시: GroupBy query

{
  "queryType": "groupBy",
  "dataSource": "sample_datasource",
  "dimensions": ["sample_dim"],
  "granularity": "all",
  "aggregations": [
    {
      "type": "distinctCount",
      "name": "uv",
      "fieldName": "visitor_id"
    }
  ],
  "intervals": [
    "2016-03-06T00:00:00/2016-03-06T23:59:59"
  ]
}

더 알아보기 (Learn more)