开发者社区> 问答> 正文

从Redshift读入Spark Dataframe(Spark-Redshift模块)

我正在按照spark-redshift教程阅读redshift到spark(databricks)。我有以下代码:

val tempDir = "s3n://{my-s3-bucket-here}"

val jdbcUsername = "usernameExample"
val jdbcPassword = "samplePassword"
val jdbcHostname = "redshift.companyname.xyz"
val jdbcPort = 9293
val jdbcDatabase = "database"
val jdbcUrl = "sampleURL"

sc.hadoopConfiguration.set("fs.s3n.awsAccessKeyId", "SAMPLEAWSKEY")
sc.hadoopConfiguration.set("fs.s3n.awsSecretAccessKey", "SECRETKEYHERE")

val subs_dim = sqlContext.read.format("com.databricks.spark.redshift").option("url", jdbcUrl).option("tempdir", tempDir).option("dbtable", "example.exampledb").load()
现在,当我试图运行它时,我得到:

java.lang.IllegalArgumentException: requirement failed: You must specify a method for authenticating Redshift's connection to S3 (aws_iam_role, forward_spark_s3_credentials, or temporary_aws_*. For a discussion of the differences between these options, please see the README.
我有点困惑,因为我使用sc.hadoopConfiguration.set定义了awsAccesskeyID。=我想知道AWS密钥是错误的,还是我遗漏了什么?

展开
收起
社区小助手 2019-01-02 15:02:39 4377 0
1 条回答
写回答
取消 提交回答
  • 社区小助手是spark中国社区的管理员,我会定期更新直播回顾等资料和文章干货,还整合了大家在钉群提出的有关spark的问题及回答。

    我认为唯一的原因是,由于您尚未设置,因此未将S3凭据传递给Redshift连接forward_spark_s3_credentials。

    在你的调试中添加以下操作。

    option("forward_spark_s3_credentials", "true");

    将Spark的S3凭据转发到Redshift:如果forward_spark_s3_credentials选项设置为true,则此库将自动发现Spark用于连接到S3的凭据,并将这些凭据通过JDBC转发到Redshift。

    2019-07-17 23:24:24
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Hybrid Cloud and Apache Spark 立即下载
Scalable Deep Learning on Spark 立即下载
Comparison of Spark SQL with Hive 立即下载