您可以使用 Spark SQL/Hive/Presto 从 Parquet/S3 直接复制到 Redshift 吗? [英] Can you copy straight from Parquet/S3 to Redshift using Spark SQL/Hive/Presto?

查看:43
本文介绍了您可以使用 Spark SQL/Hive/Presto 从 Parquet/S3 直接复制到 Redshift 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将大量服务器数据存储在 S3(即将采用 Parquet 格式)中.数据需要一些转换,因此它不能是 S3 的直接副本.我将使用 Spark 来访问数据,但我想知道是否不是用 Spark 操作它,而是写回 S3,然后复制到 Redshift,如果我可以跳过一个步骤和运行查询以提取/转换数据,然后将其直接复制到 Redshift?

We have huge amounts of server data stored in S3 (soon to be in a Parquet format). The data needs some transformation, and so it can't be a straight copy from S3. I'll be using Spark to access the data, but I'm wondering if instead of manipulating it with Spark, writing back out to S3, and then copying to Redshift if I can just skip a step and run a query to pull/transform the data and then copy it straight to Redshift?

推荐答案

当然,完全有可能.

读取 parquet 的 Scala 代码(取自 此处)

Scala code to read parquet (taken from here)

val people: RDD[Person] = ... 
people.write.parquet("people.parquet")
val parquetFile = sqlContext.read.parquet("people.parquet") //data frame

写入 redshift 的 Scala 代码(取自此处)

Scala code to write to redshift (taken from here)

parquetFile.write
.format("com.databricks.spark.redshift")
.option("url", "jdbc:redshift://redshifthost:5439/database?user=username&password=pass")
.option("dbtable", "my_table_copy")
.option("tempdir", "s3n://path/for/temp/data")
.mode("error")
.save()

这篇关于您可以使用 Spark SQL/Hive/Presto 从 Parquet/S3 直接复制到 Redshift 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆