본문 바로가기
학습장/Data Engineering

spark dataframe to vertica

by daedoo_ 2021. 6. 29.

pyspark 상에서 Dataframe을 Vertica로 적재 할 때 활용할 수 있는 두가지 방법

  1. vertica-spark 커넥터 활용
  2. jdbc Driver 활용
  1. You can use Vertica's Spark Connector.
    • This is generally the preferred way and faster.
    • But it has a dependency on HDFS as a temporary location to land the data before it is written to Vertica. Vertica & Spark must be able to access HDFS
    • No support for Kerberos Authentication (yet) without hacky workarounds
       
  2. You can use the Vertica JDBC Driver
    • A little slower but no dependency on HDFS
    • You potentially may be able to define Kerberos params in the jdbc connection string.
    • May require writing a custom SQL Dialect (depending on what you want to do)

참고 - https://forum.vertica.com/discussion/241120/unable-to-write-spark-df-in-vertica-using-api 

 

Unable to write spark DF in Vertica using API

Hi Team Getting below error when trying to save spark DF in vertica,this is blocking my work ,any help will be really appreciated ,couple of things here a) we have kereberosed cloudera and kerberosed vertica ,all necessary xml files are copied already in v

forum.vertica.com

 

연동을 위한 사전 준비사항

0. 공통 

HDFS -> Vertica 방화벽 허용 설정

 

1. vertica-spark 커넥터

  • vertica-spark 커넥터 파일
  • df.save()호출 시 타겟테이블에 적재 전 임시경로 ('hdfs_url' 값으로 지정) 에 .orc 포맷으로 write 한 후 Vertica가 클라이언트로서 HDFS에 접근하여 COPY구문으로 적재하는 방식이어서, Vertica -> HDFS 로의 방화벽 허용 필요
  • 버티카 전체 노드의 /etc/hadoop/conf 폴더에 core-site.xml, hdfs-site.xml 파일 필요
    • select VERIFY_HADOOP_CONF_DIR() 하여 validation 체크
  • 버티카 전체 노드의 /etc/hosts에 목적지 HDFS 노드 정보 추가
    • 노드 정보 누락 있을 경우 아래 에러가 랜덤하게 발생
      • Could not connect to HDFS cluster (Namenode:port): No endpoints provided
  • 참고: 2021.04.05 - [학습장/Hadoop] - vertica-spark 연동

2. jdbc Drvier

  • jdbc Driver jar 파일

 

save()시 mode별 특이사항

(mode 관련 참고 https://spark.apache.org/docs/1.6.2/api/java/org/apache/spark/sql/SaveMode.html )

1. vertica-spark 커넥터

  • 적재시 null 값에 대한 별도 처리 불필요

2. jdbc Driver

  • Dataframe 상에 String 필드 있으면 overwrite 불가
    • Dataframe에서 String 타입의 컬럼은 타겟테이블 생성시 TEXT로 생성 하려함
      • [Vertica][VJDBC](5108) ERROR: Type "TEXT" does not exist 에러 발생
  • append 시 String 필드에 null 값 있으면 에러 발생하여 Dataframe에서 빈값('') 등으로 치환 필요

 

댓글