无法使用 Spark 2.4.3 写入 Redshift
Posted
技术标签:
【中文标题】无法使用 Spark 2.4.3 写入 Redshift【英文标题】:Unable to write to Redshift using Spark 2.4.3 【发布时间】:2019-06-18 19:55:27 【问题描述】:我在本地模式下运行 Spark 2.4.3 并且能够下载文件但是我无法将它们写回 Redshift。我需要知道这样做的正确依赖关系。
我发现历史上存在 avro 依赖项的问题,但是我无法确定 spark 2.4.3 的正确依赖项。我尝试了各种组合,但没有一个允许我写回 redshift。
spark = SparkSession.builder.master("local").appName("Test")\
.config("spark.jars", 'RedshiftJDBC4-1.2.1.1001.jar,jets3t-0.9.0.jar,spark-avro_2.11-4.0.0.jar,hadoop-aws-2.7.4.jar')\
.config("spark.jars.packages", 'com.databricks:spark-redshift_2.10:0.5.0,com.amazonaws:aws-java-sdk:1.10.34,org.apache.hadoop:hadoop-aws:2.7.4')\
.config("driver.memory", '5g')\
.getOrCreate()
...
fact_table.write \
.format("com.databricks.spark.redshift") \
.option("url", jdbcUrl) \
.option("dbtable", "my_table") \
.option("tempdir", tempDir) \
.option('forward_spark_s3_credentials',True) \
.mode("error") \
.save()
我收到以下错误:
: java.lang.AbstractMethodError: com.databricks.spark.redshift.DefaultSource.createRelation(Lorg/apache/spark/sql/SQLContext;Lorg/apache/spark/sql/SaveMode;Lscala/collection/immutable/Map;Lorg/apache/spark/sql/Dataset;)Lorg/apache/spark/sql/sources/BaseRelation;
at org.apache.spark.sql.execution.datasources.SaveIntoDataSourceCommand.run(SaveIntoDataSourceCommand.scala:45)
at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:70)
at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:68)
at org.apache.spark.sql.execution.command.ExecutedCommandExec.doExecute(commands.scala:86)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:131)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:127)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$executeQuery$1.apply(SparkPlan.scala:155)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
at org.apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:152)
at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:127)
at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:80)
at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:80)
at org.apache.spark.sql.DataFrameWriter$$anonfun$runCommand$1.apply(DataFrameWriter.scala:676)
at org.apache.spark.sql.DataFrameWriter$$anonfun$runCommand$1.apply(DataFrameWriter.scala:676)
at org.apache.spark.sql.execution.SQLExecution$$anonfun$withNewExecutionId$1.apply(SQLExecution.scala:78)
at org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:125)
at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:73)
at org.apache.spark.sql.DataFrameWriter.runCommand(DataFrameWriter.scala:676)
at org.apache.spark.sql.DataFrameWriter.saveToV1Source(DataFrameWriter.scala:285)
at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:271)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
【问题讨论】:
开源spark-redshift
已在多年前停止使用。支持最新 Spark 版本的当前版本是专有的,仅通过 Databricks 平台提供。
【参考方案1】:
如 cmets 中所述,开源 databricks/spark-redshift 不再维护。
但是..
我们最近将该项目分叉并升级到 spark 2.4 - 我们本着社区协作的精神将其命名为 spark_redshift_community。请随时试用并报告您可能发现的任何问题。
【讨论】:
以上是关于无法使用 Spark 2.4.3 写入 Redshift的主要内容,如果未能解决你的问题,请参考以下文章
无法从使用 mongo spark 连接器读取的 spark DF 中显示/写入。
无法使用 spark(sqlContext) 在 aws redshift 中写入 csv 数据
无法使用Spark Structured Streaming在Parquet文件中写入数据