Spark-edshift 介绍
Spark-edshift 是可以从 Amazon Redshift 加载数据到 Spark sql DataFrames 中的库,并且还可以写回到
Redshift 列表中。Amazon S3 可以让数据高效地转入或转出 Redshift,并且可以自动触发 Redshift 相应的 copY 和
UNLOAD 指令。
示例代码:
import org.apache.spark.sql._val sc = // existing SparkContextval sqlContext = new sqlContext(sc)// Get some data from a Redshift tableval df: DataFrame = sqlContext.read .format("com.databricks.spark.redshift") .option("url", "jdbc:redshift://redshifthost:5439/database?user=username&password=pass") .option("dbtable", "my_table") .option("tempdir", "s3n://path/for/temp/data") .load()// Can also load data from a Redshift queryval df: DataFrame = sqlContext.read .format("com.databricks.spark.redshift") .option("url", "jdbc:redshift://redshifthost:5439/database?user=username&password=pass") .option("query", "select x, count(*) my_table group by x") .option("tempdir", "s3n://path/for/temp/data") .load()// Apply some transformations to the data as per normal, then you can use the// Data Source API to write the data back to another tabledf.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-edshift 官网
https://github.com/databricks/spark-redshift
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。