DataSketches HLL Sketch 모듈
DataSketches HLL Sketch 모듈
Apache DataSketches 라이브러리의 HLL sketch를 기반으로 고유값(distinct) 개수 세기(counting)를 위한 Druid 애그리게이터를 제공하는 모듈이에요. 어떤 컬럼의 카디널리티도 근사적으로 추정할 수 있어요.
출처: 문서
본문
이 모듈은 Apache DataSketches 라이브러리의 HLL sketch를 기반으로 고유값 개수 세기를 위한 Apache Druid 애그리게이터를 제공해요. 인제이션 시점에 이 애그리게이터는 Druid 세그먼트에 저장할 HLL sketch 객체를 만들어요. 기본적으로 Druid는 쿼리 시점에 sketch를 읽고 병합해요. 기본 결과는 sketch에 제시된 고유 값 수의 추정치예요. 또한 post aggregator를 사용해 같은 행의 sketch 컬럼들의 union을 만들 수도 있어요. HLL sketch 애그리게이터는 어떤 컬럼에서든 그 카디널리티를 추정하는 데 사용할 수 있어요.
이 애그리게이터를 사용하려면 config 파일에 확장 기능을 포함하세요:
druid.extensions.loadList=["druid-datasketches"]
Druid가 지원하는 추가 sketch 유형은 DataSketches extension을 참고하세요.
애그리게이터 (Aggregators)
| Property | Description | Required? | | type | Either HLLSketchBuild or HLLSketchMerge . | yes | | name | String representing the output column to store sketch values. | yes | | fieldName | The name of the input field. | yes | | lgK | log2 of K that is the number of buckets in the sketch, parameter that controls the size and the accuracy. Must be between 4 and 21 inclusively. | no, defaults to 12 | | tgtHllType | The type of the target HLL sketch. Must be HLL_4 , HLL_6 or HLL_8 | no, defaults to HLL_4 | | round | Round off values to whole numbers. Only affects query-time behavior and is ignored at ingestion-time. | no, defaults to false | | shouldFinalize | Return the final double type representing the estimate rather than the intermediate sketch type itself. In addition to controlling the finalization of this aggregator, you can control whether all aggregators are finalized with the query context parameters finalize and sqlFinalizeOuterSketches . | no, defaults to true |
info
기본 lgK 값은 대부분의 사용 사례에 충분한 것으로 입증되었어요. 정상적인 상황에서는 16 이상의 lgK 값으로 정확도 향상은 매우 미미할 거예요.
HLLSketchBuild 애그리게이터
{
"type": "HLLSketchBuild",
"name": <output name>,
"fieldName": <metric name>,
"lgK": <size and accuracy parameter>,
"tgtHllType": <target HLL type>,
"round": <false | true>
}
HLLSketchBuild 애그리게이터는 지정된 입력 컬럼에서 HLL sketch 객체를 만들어요. 인제이션 중에 사용되면 Druid는 입력 컬럼의 원시 데이터 대신 미리 생성된 HLL sketch 객체를 데이터소스에 저장해요. 기존 차원에 쿼리 시점에 적용되면 post-aggregator에 의해 결과 컬럼을 중간 차원으로 사용할 수 있어요.
info
높은 카디널리티 컬럼에 메트릭을 만들기 위해 HLLSketchBuild를 rollup과 조합해 사용하는 것은 매우 흔해요. 이 예제에서 userid_hll이라는 메트릭이 metricsSpec에 포함돼요. 이는 인제이션 시점에 userid 필드에 HLL sketch를 수행해 매우 고성능의 근사 COUNT DISTINCT 쿼리 연산을 가능하게 하고, userid가 dimensionsSpec에서 제외될 때 roll-up 비율을 개선해요.
"metricsSpec": [
{
"type": "HLLSketchBuild",
"name": "userid_hll",
"fieldName": "userid",
"lgK": 12,
"tgtHllType": "HLL_4"
}
]
HLLSketchMerge 애그리게이터
{
"type": "HLLSketchMerge",
"name": <output name>,
"fieldName": <metric name>,
"lgK": <size and accuracy parameter>,
"tgtHllType": <target HLL type>,
"round": <false | true>
}
HLLSketchMerge 애그리게이터를 사용해 입력 데이터 세트에서 미리 생성된 sketch를 인제스트할 수 있어요. 예를 들어 데이터를 Druid로 보내기 전에 sketch를 생성하는 배치 처리 작업을 설정할 수 있어요. 입력 데이터 세트의 sketch를 Base64로 인코딩된 바이트로 직렬화해야 해요. 그런 다음 네이티브 인제이션 metricsSpec에서 입력 컬럼에 HLLSketchMerge를 지정하세요.
Post aggregator (Post aggregators)
Estimate
고유 개수 추정치를 double로 반환해요.
{
"type": "HLLSketchEstimate",
"name": <output name>,
"field": <post aggregator that returns an HLL Sketch>,
"round": <if true, round the estimate. Default is false>
}
Estimate with bounds
HLL sketch에서 고유 개수 추정치와 오차 경계를 반환해요. 결과는 estimate, lower bound, upper bound의 세 double 값을 포함하는 배열이에요. 경계는 주어진 표준편차 수(선택 사항, 기본 1)에서 제공돼요. 이는 대략 68.3%, 95.4%, 99.7% 신뢰 구간에 해당하는 정수 값 1, 2 또는 3이어야 해요.
{
"type": "HLLSketchEstimateWithBounds",
"name": <output name>,
"field": <post aggregator that returns an HLL Sketch>,
"numStdDev": <number of standard deviations: 1 (default), 2 or 3>
}
Union
{
"type": "HLLSketchUnion",
"name": <output name>,
"fields": <array of post aggregators that return HLL sketches>,
"lgK": <log2 of K for the target sketch>,
"tgtHllType": <target HLL type>
}
Sketch to string
디버깅을 위한 사람이 읽을 수 있는 sketch 요약.
{
"type": "HLLSketchToString",
"name": <output name>,
"field": <post aggregator that returns an HLL Sketch>
}