sqoop export 를 이용하여 타겟테이블에 통으로 적재하고자 하는데, 일반적인 ETL 툴 처럼 Truncate & Insert가 불가할 것으로 생각되었음.
sqoop export에서 아래와 같은 파라미터를 추가하면 upsert 유사한 기능을 제공함.
--update-key column_name \
--update-mode allowinsert
--update-mode를 명시하지 않으면 (디폴트: updateonly) update-key 컬럼 기준 변경된 부분이 없으면, insert 되지 않고 종료됨.
그러나, 해당 기능은 일부 타겟 DB에 한정됨 ( 가능 : Oracle, Mysql, Postresql )
ex) 타겟DB - Vertica 경우 아래와 같은 에러 발생
Mixed update/insert is not supported against the target database yet
MySQL 처럼 INSERT INTO xxx UPDATE ON DUPLICATE KEY 구문이 DB에서 가능해야 해당 기능이 에러 없이 동작함.
그리하여, pyspark를 통해서 적재하는게 맞는가 싶음..
pyspark - DB(Vertica) 연동 관련하여 리서치&테스트 중인데, 추후에 정리하여 포스팅 예정
야매로 sqoop으로도 Truncate&Insert가 가능할 거 같음..
아래 두 명령어를 하나의 스크립트로 수행 가능
- sqoop eval 활용하여 Truncate 구문 실행
- sqoop export 수행
우선 급한대로 위 방법으로라도 테스트 예정임..
# 참고
Sqoop : Truncate SQL Server table before exporting data from Hadoop
We are using Sqoop to export data from the hive to SQL Server. The new data is always appended to the existing data in SQL Server. Is it possible to truncate the SQL Server table via Sqoop before
stackoverflow.com
'학습장 > Data Engineering' 카테고리의 다른 글
DataStage 쿼리 결과값을 파라미터로 활용 (0) | 2021.04.20 |
---|---|
vertica-spark 연동 (0) | 2021.04.05 |
sqoop export 시 org.apache.parquet.io.ParquetDecodingException (0) | 2021.04.02 |
까먹었을때 참고할 linux 명령어 정리 (0) | 2021.03.13 |
sqoop export (0) | 2021.03.12 |
댓글