Having 필터

Having 필터 (groupBy)

Apache Druid는 Druid SQL과 네이티브 쿼리 두 가지 쿼리 언어를 지원해요. 이 문서는 네이티브 언어를 설명합니다. having 절은 집계된 값에 조건을 지정해 groupBy 쿼리에서 어떤 행을 반환할지 식별하는 JSON 객체입니다. 기본적으로 SQL의 HAVING 절과 동등해요.

출처: 문서

본문

having 절은 집계된 값에 조건을 지정해 groupBy 쿼리에서 어떤 행을 반환할지 식별하는 JSON 객체입니다. 기본적으로 SQL의 HAVING 절과 동등합니다. Apache Druid는 다음 유형의 having 절을 지원합니다.

쿼리 필터(Query filters)

Query filter HavingSpec은 모든 Druid 쿼리 필터를 쿼리의 Having 부분에서 사용할 수 있게 해줍니다. query filter HavingSpec의 문법은 다음과 같아요:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
            "type" : "filter",
            "filter" : <any Druid query filter>
        }
}

예를 들어 selector 필터를 사용하려면:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
            "type" : "filter",
            "filter" : {
              "type": "selector",
              "dimension" : "<dimension>",
              "value" : "<dimension_value>"
            }
        }
}

"filter" HavingSpec을 사용해 "__time" 컬럼에 필터를 적용하면 결과 행의 타임스탬프로 필터링할 수 있습니다.

숫자 필터(Numeric filters)

가장 간단한 having 절은 숫자 필터입니다. 숫자 필터는 더 복잡한 boolean 필터 표현식의 기본 필터로 사용될 수 있어요. having-절 숫자 필터의 예시는 다음과 같습니다:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
            "type": "greaterThan",
            "aggregation": "<aggregate_metric>",
            "value": <numeric_value>
        }
}

Equal To

equalTo 필터는 특정 집계 값을 가진 행과 매칭됩니다. equalTo 필터의 문법은 다음과 같아요:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
            "type": "equalTo",
            "aggregation": "<aggregate_metric>",
            "value": <numeric_value>
        }
}

이것은 HAVING <aggregate> = <value>와 동등합니다.

Greater Than

greaterThan 필터는 집계 값이 주어진 값보다 큰 행과 매칭됩니다. greaterThan 필터의 문법은 다음과 같고, HAVING <aggregate> > <value>와 동등합니다.

Less Than

lessThan 필터는 집계 값이 지정된 값보다 작은 행과 매칭됩니다. greaterThan 필터의 문법은 다음과 같아요:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
            "type": "lessThan",
            "aggregation": "<aggregate_metric>",
            "value": <numeric_value>
        }
}

이것은 HAVING <aggregate> < <value>와 동등합니다.

차원 선택기 필터(Dimension Selector Filter)

dimSelector

dimSelector 필터는 차원 값이 지정된 값과 같은 행과 매칭됩니다. dimSelector 필터의 문법은 다음과 같아요:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
       {
            "type": "dimSelector",
            "dimension": "<dimension>",
            "value": <dimension_value>
        }
}

논리 표현식 필터(Logical expression filters)

AND

AND 필터의 문법은 다음과 같아요:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
            "type": "and",
            "havingSpecs": [
                {
                    "type": "greaterThan",
                    "aggregation": "<aggregate_metric>",
                    "value": <numeric_value>
                },
                {
                    "type": "lessThan",
                    "aggregation": "<aggregate_metric>",
                    "value": <numeric_value>
                }
            ]
        }
}

OR

OR 필터의 문법은 다음과 같아요:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
            "type": "or",
            "havingSpecs": [
                {
                    "type": "greaterThan",
                    "aggregation": "<aggregate_metric>",
                    "value": <numeric_value>
                },
                {
                    "type": "equalTo",
                    "aggregation": "<aggregate_metric>",
                    "value": <numeric_value>
                }
            ]
        }
}

NOT

NOT 필터의 문법은 다음과 같아요:

{
    "queryType": "groupBy",
    "dataSource": "sample_datasource",
    ...
    "having":
        {
        "type": "not",
        "havingSpec":
            {
                "type": "equalTo",
                "aggregation": "<aggregate_metric>",
                "value": <numeric_value>
            }
        }
}

더 알아보기 (Learn more)

  • groupBy 쿼리: having 절이 사용되는 그룹바이 쿼리 문서.
  • Query filters: Druid 쿼리 필터 종류.