FILLNULL 명령어
FILLNULL 명령어
fillnull 명령어는 검색 결과의 하나 이상의 필드에서 null 값을 지정된 값으로 대체해요.
출처: 문서
본문
fillnull 명령어는 검색 결과의 하나 이상의 필드에서 null 값을 지정된 값으로 대체해요.
fillnull 명령어는 쿼리 도메인 특화 언어(DSL, query domain-specific language)로 다시 작성되지 않아요. 코디네이팅(coordinating) 노드에서만 실행돼요.
구문 (Syntax)
fillnull 명령어의 구문은 다음과 같아요:
fillnull with <replacement> [in <field-list>]
fillnull using <field> = <replacement> [, <field> = <replacement>]
fillnull value=<replacement> [<field-list>]
다음과 같은 구문 변형이 가능해요:
with <replacement> in <field-list>– 지정된 필드에 동일한 값을 적용해요.using <field>=<replacement>, ...– 각각 다른 필드에 다른 값을 적용해요.value=<replacement> [<field-list>]– 선택적인 공백으로 구분된 필드 목록이 있는 대체 구문이에요.
매개변수 (Parameters)
fillnull 명령어는 다음 매개변수를 지원해요.
| 매개변수 | 필수/선택 | 설명 |
|---|---|---|
<replacement> |
필수 | null 값을 대체하는 값이에요. |
<field> |
필수 (using 구문에서) | 특정 대체 값이 적용되는 필드의 이름이에요. |
<field-list> |
선택 | null 값이 대체되는 필드 목록이에요. 목록을 쉼표로 구분(using 또는 with 구문)하거나 공백으로 구분(value= 구문)해서 지정할 수 있어요. 기본적으로 모든 필드가 처리돼요. |
예제 1: 필드별로 다른 값으로 null 값 대체하기
다음 쿼리는 누락된 instrumentation scope 이름을 기본값으로 채워요:
source=otellogs
| where severityText IN ('ERROR', 'WARN')
| fields severityText, `resource.attributes.service.name`, instrumentationScope.name
| fillnull using instrumentationScope.name = 'unknown'
| sort `resource.attributes.service.name`
쿼리는 다음과 같은 결과를 반환해요:
| severityText | resource.attributes.service.name | instrumentationScope.name |
|---|---|---|
| ERROR | checkout | unknown |
| ERROR | checkout | unknown |
| ERROR | frontend-proxy | unknown |
| WARN | frontend-proxy | unknown |
| WARN | frontend-proxy | unknown |
| ERROR | payment | @opentelemetry/instrumentation-http |
| ERROR | payment | unknown |
| WARN | product-catalog | go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc |
| WARN | product-catalog | unknown |
| ERROR | product-catalog | unknown |
| ERROR | recommendation | unknown |
예제 2: value= 구문으로 null 값 대체하기
다음 쿼리는 value= 구문을 사용해 null인 instrumentation scope 이름을 채워요. 인스트루먼테이션되지 않은 서비스를 식별하는 데 도움이 돼요:
source=otellogs
| where severityText = 'ERROR'
| fields severityText, `resource.attributes.service.name`, instrumentationScope.name
| fillnull value='unknown' instrumentationScope.name
| sort `resource.attributes.service.name`
쿼리는 다음과 같은 결과를 반환해요:
| severityText | resource.attributes.service.name | instrumentationScope.name |
|---|---|---|
| ERROR | checkout | unknown |
| ERROR | checkout | unknown |
| ERROR | frontend-proxy | unknown |
| ERROR | payment | @opentelemetry/instrumentation-http |
| ERROR | payment | unknown |
| ERROR | product-catalog | unknown |
| ERROR | recommendation | unknown |
제한 사항 (Limitations)
fillnull 명령어는 다음과 같은 제한 사항이 있어요:
- 필드 이름을 지정하지 않고 모든 필드에 동일한 값을 적용할 때는 모든 필드가 같은 타입이어야 해요. 혼합 타입이라면 별도의 fillnull 명령어를 사용하거나 필드를 명시적으로 지정해요.
- 대체 값 타입은 필드 목록의 모든 필드 타입과 일치해야 해요. 여러 필드에 동일한 값을 적용할 때는 모든 필드가 같은 타입(모두 문자열 또는 모두 숫자)이어야 해요. 다음 쿼리는 이 규칙을 위반할 때 발생하는 오류를 보여줘요:
# This FAILS - same value for mixed-type fields
source = accounts
| fillnull value = 0 firstname, age
# ERROR: fillnull failed: replacement value type INTEGER is not compatible with field 'firstname' (type: VARCHAR).
# The replacement value type must match the field type.