2016-07-22 3 views
0

私はマージ形式でS3にあるデータをpysparkを使ってaws redshiftにロードしようとしています。私はこれを行うことができますが、テーブル定義内の列のエンコーディングを見ると一貫しています。私はそれを一貫して作りたいと思っています。特に私はそれらのすべてをlzoにしたいと思います。以下は、不一致のある単一テーブルのデータ型のリストです。PySparkからRedshiftにデータをロードするときに列エンコーディングを実行する方法

+-------------------------------+-------------------+ 
| data_type     | encoding   | 
+-------------------------------+-------------------+ 
| bigint      | delta    | 
| bigint      | delta32k   | 
| character varying(256)  | lzo    | 
| bigint      | runlength   | 
| bigint      | bytedict   | 
| timestamp without time zone | bytedict   | 
| integer      | runlength   | 
+-------------------------------+-------------------+ 

pysparkでこれを実行する方法を教えてもらえますか?火花redshift_2.10:私はcom.databricksの列エンコーディングのいずれかのオプションが表示されない1.0.0

x.write.format("com.databricks.spark.redshift") 
.option("url","jdbc:redshift://<url>:<port>/<schema>?user=<user>&password=<pass>") 
.option("dbtable","<tbl_nm>") 
.option("diststyle","KEY").option("distkey","<key>") 
.option("sortkeyspec","SORTKEY(<sort1>)") 
.option("tempdir","<path>") 
.mode("error").save() 

答えて

1

私はPR 178で列エンコーディングを指定するための該当ビットを発見しました。

したがって、.read.option('encoding', 'lzo')などでエンコードを指定しないでください。データフレーム作成時のエンコーディングを指定するメタデータを含むスキーマオブジェクトを作成する必要があります。 Pythonでは、例えば:

%pyspark 

from pyspark.sql.types import IntegerType, StringType, StructType, StructField 

metadata = {'encoding':'LZO'} 

schema = StructType([ 
    StructField("id", IntegerType(), True, metadata), 
    StructField("name", StringType(), True, metadata)]) 

df = spark.createDataFrame([(1, 'Alice')], schema) 

df.write \ 
    .format("com.databricks.spark.redshift") \ 
    .option("url", "jdbc:redshift://example.com:5439/db_foo?user=user_bar&password=pass_baz") \ 
    .option("dbtable", "foo") \ 
    .option("tempdir", "s3a://foo/bar") \ 
    .mode("error") \ 
    .save() 

検証:

select "column", "encoding" from pg_table_def where tablename = 'foo'; 
column | encoding 
--------+---------- 
id  | lzo 
name | lzo 
(2 rows) 
関連する問題