본문 바로가기
Splunk/Search Command

Splunk SPL에서의 JOIN 연산: LEFT, INNER, OUTER JOIN

by drinkdog 2025. 1. 21.
반응형
Splunk Search Processing Language(SPL)에서
"데이터를 결합하는 JOIN 연산은 강력한 분석 도구입니다."

여러 데이터 소스나 검색 결과를 효과적으로 결합하는 방법에 대해 공부했습니다.

1. SPL JOIN의 기본 개념

SPL에서 JOIN은 두 개의 검색 결과를 특정 필드를 기준으로 결합하는 연산입니다.

 

예를 들어,

  • 서버 로그와 사용자 정보를 결합하거나
  • 보안 이벤트와 자산 정보를 매칭할 때 사용됩니다.

2. 샘플 데이터로 보는 JOIN 타입

두 개의 CSV 파일로 예시를 들어보겠습니다.

  • 서버 정보 (servers.csv)
hostname, ip_address, os_type
webserver1, 192.168.1.10, Linux
webserver2, 192.168.1.11, Linux
dbserver1, 192.168.1.20, Windows
appserver1, 192.168.1.30, Windows
  • 보안 이벤트 (security_events.csv)
timestamp, hostname, event_type, severity
2024-01-21 10:00:00, webserver1, login_failed, high
2024-01-21 10:05:00, webserver1, breach_attempt, critical
2024-01-21 10:10:00, dbserver1, unauthorized_access, high
2024-01-21 10:15:00, unknown_host, malware_detected, critical

 

2-1. LEFT JOIN (type=left)

왼쪽(첫 번째) 검색 결과의 모든 레코드를 포함하며, 매칭되지 않는 경우 null을 표시합니다.

| inputlookup servers.csv
| join type=left hostname
    [| inputlookup security_events.csv
    | table hostname, event_type, severity]
  • 결과:
hostname   | ip_address    | os_type | event_type      | severity
webserver1 | 192.168.1.10  | Linux   | login_failed    | high
webserver1 | 192.168.1.10  | Linux   | breach_attempt  | critical
webserver2 | 192.168.1.11  | Linux   | null            | null
dbserver1  | 192.168.1.20  | Windows | unauthorized_access | high
appserver1 | 192.168.1.30  | Windows | null            | null

 

2-2. INNER JOIN (type=inner)

양쪽 검색 결과에 모두 존재하는 데이터만 반환합니다.

| inputlookup servers.csv
| join type=inner hostname
    [| inputlookup security_events.csv
    | table hostname, event_type, severity]
  • 결과:
hostname   | ip_address    | os_type | event_type      | severity
webserver1 | 192.168.1.10  | Linux   | login_failed    | high
webserver1 | 192.168.1.10  | Linux   | breach_attempt  | critical
dbserver1  | 192.168.1.20  | Windows | unauthorized_access | high

2-3. OUTER JOIN (type=outer)

양쪽 검색 결과의 모든 데이터를 포함합니다.

| inputlookup servers.csv
| join type=outer hostname
    [| inputlookup security_events.csv
    | table hostname, event_type, severity]
  • 결과:
hostname     | ip_address    | os_type | event_type      | severity
webserver1   | 192.168.1.10  | Linux   | login_failed    | high
webserver1   | 192.168.1.10  | Linux   | breach_attempt  | critical
webserver2   | 192.168.1.11  | Linux   | null            | null
dbserver1    | 192.168.1.20  | Windows | unauthorized_access | high
appserver1   | 192.168.1.30  | Windows | null            | null
unknown_host | null          | null    | malware_detected | critical

3. JOIN 사용 시 주의사항

  • 성능 고려사항:
    • JOIN 전에 필요한 필드만 선택 (table 명령어 사용)
    • 가능한 데이터를 필터링 후 JOIN
    • 큰 데이터셋 JOIN 시 시스템 리소스 고려
  • 필드 매칭:
    • JOIN 키로 사용할 필드명이 정확히 일치하는지 확인
    • 필요시 rename 명령어로 필드명 조정
  • NULL 처리:
    • fillnull 명령어로 NULL 값 처리 가능
    • 조건문에서 NULL 고려

4. 결론

Splunk SPL의 JOIN은 데이터 분석의 핵심 도구로 상황에 맞는 JOIN 타입을 선택하고 성능을 고려한 쿼리 작성이 중요합니다.
특히 보안, 모니터링, 분석 등 다양한 분야에서 활용될 수 있으며, 효율적인 데이터 통합을 가능하게 합니다.

 

출처

https://docs.splunk.com/Documentation/Splunk/9.4.0/SearchReference/Join

 

 

 

 

반응형