gpt4 book ai didi

apache-spark - 从 Redshift 读取时获取无效的 S3 URI 错误

转载 作者:行者123 更新时间:2023-12-04 17:53:54 24 4
gpt4 key购买 nike

我正在尝试将 Redshift 表中的数据读取到 Spark 2.0 数据帧中。我的电话看起来像这样:

 df = spark.read \
.format("com.databricks.spark.redshift") \
.option("url", "jdbc:redshift://hostname:5439/dbname?user=myuser&password=pwd&ssl=true&sslfactory=com.amazon.redshift.ssl.NonValidatingFactory") \
.option("dbtable", "myschema.mytable") \
.option('forward_spark_s3_credentials',"true") \
.option("tempdir", "s3a://mybucket/tmp2") \
.option("region", "us-east-1") \
.load()

这会返回 ok,没有错误。但是,当我运行

df.collect()

我得到以下错误:

17/02/07 17:37:36 WARN Utils$: An error occurred while trying to read 
the S3 bucket lifecycle configuration
java.lang.IllegalArgumentException: Invalid S3 URI: hostname does not
appear to be a valid S3 endpoint: s3://mybucket/tmp2
at com.amazonaws.services.s3.AmazonS3URI.<init>(AmazonS3URI.java:65)
at com.amazonaws.services.s3.AmazonS3URI.<init>(AmazonS3URI.java:42)
at com.databricks.spark.redshift.Utils$.checkThatBucketHasObjectLifecycleConfiguration(Utils.scala:72)
at com.databricks.spark.redshift.RedshiftRelation.buildScan(RedshiftRelation.scala:76)
at org.apache.spark.sql.execution.datasources.DataSourceStrategy$anonfun$11.apply(DataSourceStrategy.scala:336)
at org.apache.spark.sql.execution.datasources.DataSourceStrategy$anonfun$11.apply(DataSourceStrategy.scala:336)
at org.apache.spark.sql.execution.datasources.DataSourceStrategy$anonfun$pruneFilterProject$1.apply(DataSourceStrategy.scala:384)
at ...

随后返回数据...

Out[2]: [Row(col1=1, col2=u'yyyyy', col3=datetime.date(2015, 1, 6), col4=datetime.date(2017, 1, 6), col5=Decimal('21'), col6=u'ABCDEF',...)]

注意事项:

  • spark-submit 和 pyspark 都会出现这个错误
  • 的版本Spark 是 2.1,jars 目录包含这些相关文件:

    RedshiftJDBC4-1.2.1.1001.jar

    aws-java-sdk-1.7.4.jar

    spark-redshift_2.11-0.5.0.jar

    hadoop-aws-2.7.3.jar

我已经尝试过其他组合,尤其是 aws-java,但在这种情况下,我什至没有得到要返回的数据框。我从 spark.read 调用中收到错误消息。

  • S3中的tmp2 bucket目录存在,并被拆分写入包含 Redshift 结果的文件。
  • 这是在联合登录下运行的,无需提供凭据明确地。

如有任何帮助/建议,我们将不胜感激。

最佳答案

检查 bucket 和 redshift DB 是否在同一个 aws 区域?

关于apache-spark - 从 Redshift 读取时获取无效的 S3 URI 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42116052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com