이번 포스팅에서는 Azure Event hub를 통해 streaming ingest 중인 Azure Data Explorer 테이블에 컬럼을 추가하는 방안에 대해서 정리.

 

이 문서는 아래 두개의 포스팅과 이어지는 내용을 포함.

개발자 커뮤니티 SQLER.com - Azure Event Hubs로 kafka message 전송 처리

개발자 커뮤니티 SQLER.com - Azure Event Hubs의 데이터를 Azure Data Explorer로 전송

 

Azure Data Explorer - Event Hub 스트리밍 ingest 중 컬럼추가

 

간략히, ADX(Azure Data Explorer, 이하 ADX) 테이블에 컬럼을 추가하고, table mapping에 컬럼 정의를 추가하면 해결된다.

 

ADX 테이블에 컬럼 추가

지난 포스팅에서 ADX 테이블을 생성하였다. 생성한 테이블에 컬럼을 아래 .alter table 구문으로 수행.

// add column
.alter-merge table dw_evthub_ingest (ColumnX:string) 

// .show table dw_evthub_ingest

이렇게 수행하고 이어서 현재 streaming ingest 중이기 때문에 mapping을 추가

 

ADX 테이블에 table mapping 추가

// alter mapping
.alter table dw_evthub_ingest ingestion json mapping 'evthub_ingest_mapping' '[{"column":"product_num", "Properties": {"Path": "$.product_num", "datatype":"int"}}, {"column":"product_price", "Properties": {"Path":"$.product_price", "datatype":"int"}} ,{"column":"product_description", "Properties": {"Path":"$.product_description", "datatype":"string"}}, {"column":"product_production_dt", "Properties": {"Path":"$.product_production_dt", "datatype":"datetime"}}, {"column":"ColumnX", "Properties": {"Path":"$.ColumnX", "datatype":"string"}}]'

// .show table dw_evthub_ingest ingestion mappings

ColumnX 라는 컬럼의 mapping을 이렇게 수정한다.

 

ADX 테이블에 추가된 컬럼 확인

컬럼을 추가하고 쿼리해 보면, 이렇게 테이블에 컬럼이 추가되었고, 값은 null 로 지정된다.

adx-add-column.png

 

어플리케이션 코드에서 json 데이터에 ColumnX 데이터 추가

지난 포스팅에서 json 데이터를 이용해 event hub로 sink 했다. 이 json 데이터에 컬럼을 추가한다.

def build_message():
    msg = {}
    msg["product_num"] = round(random.uniform(1, 10))
    msg["product_price"] = round(random.uniform(100, 10000))
    msg["product_description"] = ''.join(random.SystemRandom().choice(string.ascii_letters+string.digits) for _ in range(10))
    msg["product_production_dt"] = str(datetime.utcnow())
    msg["ColumnX"] = ''.join(random.SystemRandom().choice(string.ascii_letters+string.digits) for _ in range(5))
    return json.dumps(msg)

Azure Event hub로 kafka message를 json으로 전송하는 Github 코드 링크

 

이렇게 ColumnX를 추가하고, 잠시 기다렸다가 다시 쿼리해 보면, 아래처럼 추가된 column에 데이터가 들어온 것을 확인 가능하다.

adx-add-column02.png

 

============================================================================

2021년 10월 19일 추가

만약, 자동적으로 새로 추가된 ADX 테이블 컬럼으로 event hub의 message가 sink 되지 않는다면, cache 삭제를 해본다.

Clearing cached schema for streaming ingestion - Azure Data Explorer | Microsoft Docs

 

.clear database cache streamingingestion schema
.show table 테이블명 cache streamingingestion schema

 

 

참고링크

.alter-merge table - Azure Data Explorer | Microsoft Docs

개발자 커뮤니티 SQLER.com - Azure Event Hubs로 kafka message 전송 처리

개발자 커뮤니티 SQLER.com - Azure Event Hubs의 데이터를 Azure Data Explorer로 전송

CloudBreadPaPa/azure-eventhub-kafka-python: produce messages to event hub for kafka protocol (github.com)

No. Subject Author Date Views
Notice SQL강좌: 챗GPT와 함께 배우는 SQL Server 무료 강좌 목차와 소개 (2023년 9월 업데이트) 코난(김대우) 2023.08.18 38698
Notice Python 무료 강좌 - 기초, 중급, 머신러닝(2023년 6월 업데이트) 코난(김대우) 2021.01.01 20797
338 Azure Data Explorer - SELECT INTO(CTAS) 또는 INSERT SELECT 쿼리 수행 코난(김대우) 2021.10.26 339
337 Azure Data Explorer에서 Trigger 기능 구현 - update policy file 코난(김대우) 2021.10.22 291
336 vscode에서 일관된 팀 단위 개발 환경 구성 - devcontainer file 코난(김대우) 2021.10.19 585
335 Bicep - Azure 클라우드 리소스 배포를 위한 언어 file 코난(김대우) 2021.10.19 149
» Azure Data Explorer - Event Hub 스트리밍 ingest 중 컬럼추가 file 코난(김대우) 2021.10.18 150
333 SonarQube 리뷰 및 Azure DevOps 연결 file 코난(김대우) 2021.10.01 246
332 PySpark, koalas와 pandas dataframe file 코난(김대우) 2021.09.29 268
331 Apache Spark, pyspark 설치 후 jupyter notebook 실행 file 코난(김대우) 2021.09.29 397
330 Azure Data Explorer의 데이터를 Python Pandas Dataframe과 CSV로 변환 코난(김대우) 2021.09.28 183
329 Azure Blob Storage SAS token 생성 코난(김대우) 2021.09.17 228
328 Azure Data Factory를 이용해 ADX에서 SQL로 900만건의 데이터 전송 file 코난(김대우) 2021.09.16 279
327 Azure Data Explorer에서 SQL서버 데이터베이스 테이블 조회/삽입 - sql_request plugin file 코난(김대우) 2021.09.16 172
326 Azure Data Explorer에 대량 CSV 파일 ingest 코난(김대우) 2021.09.15 170
325 Azure Event Hubs의 데이터를 Azure Data Explorer로 전송 file 코난(김대우) 2021.09.15 223
324 Azure Event Hubs로 kafka message 전송 처리 file 코난(김대우) 2021.09.15 272
323 Service Principal과 Azure 리소스 접근/사용을 위한 인증 방법 3+1가지 file 코난(김대우) 2020.12.26 641
322 Azure storage 관리 도구 - storage explorer 설치와 사용 방법 코난(김대우) 2020.12.25 425
321 Azure cli - command line interface 명령줄 인터페이스 도구를 쓰는 이유와 방법 코난(김대우) 2020.12.25 367
320 클라우드 오픈소스 개발환경 - WSL [1] file 코난(김대우) 2020.12.20 1249
319 Cloud RoadShow 세션 발표 자료 코난(김대우) 2016.05.04 11433





XE Login