我使用spark-sql连接到oracle数据库并将数据作为数据帧获取。我想将这个检索到的数据写入avro文件。写给avro时,我看到了多个问题,你能帮助我们吗?
这是代码 -
val df = sqlContext.read.format("jdbc")
.options(Map( "driver"->"oracle.jdbc.driver.OracleDriver",
"url" -> "jdbc:oracle:thin:user/password@host/service"
, "numPartitions" -> "1", "dbtable"-> "
(Select * from schema.table WHERE STAGE_NUM <=39 and
guid='I284ba1f9cdba11dea82ab9f4ee295c21')"))
.load()
df.write.format("com.databricks.spark.avro").save("Outputfile")
我项目中存在的依赖关系 -
<dependency><br> <groupId>org.apache.spark</groupId><br> <artifactId>spark-sql_2.10</artifactId><br> <version>1.5.1</version><br></dependency><br><dependency><br> <groupId>com.databricks</groupId><br> <artifactId>spark-avro_2.10</artifactId><br> <version>2.0.1</version><br></dependency><br><dependency><br> <groupId>org.apache.avro</groupId><br> <artifactId>avro</artifactId><br> <version>1.7.7</version><br></dependency><br><dependency><br> <groupId>org.apache.avro</groupId><br> <artifactId>avro-mapred</artifactId><br> <version>1.7.7</version><br></dependency>
以下是例外信息 -
java.lang.RuntimeException:com.databricks.spark.avro.DefaultSource不允许将create table作为select
如果我使用 - df.write.avro("headnotes")
,我会收到以下异常。
java.lang.IllegalAccessError:尝试从类com.databricks.spark.avro.SchemaConverters $$ anonfun $ convertStructToAvro $ 1
访问类org.apache.avro.SchemaBuilder $ FieldDefault