YotpoLtd/metorikku

Failed when writing dataFrame to Oracle

Closed this issue · 5 comments

Hi , I construct a ETL job which reads data from Oracle and writes data to Oracle.

Oracle version: 11g
Oracle jar: ojdbc6-11.2.0.1.0.jar

The job.yaml:

output:
  jdbc:
    connectionUrl: "jdbc:oracle:thin:@192.168.3.132:1521/renxiang"
    user: qdgakk3
    password: qdgakk
    driver: "oracle.jdbc.driver.OracleDriver"
inputs:
  t_customer:
    jdbc:
      password: "qdgakk"
      options:
        driver: "oracle.jdbc.driver.OracleDriver"
      connectionUrl: "jdbc:oracle:thin:@192.168.3.132:1521/renxiang"
      user: "qdgakk3"
      table: "customer"
metrics:
- "metric.yaml"

The metric.yaml:

output:
- outputType: "JDBC"
  outputOptions:
     saveMode: Overwrite
     dbTable: customer2
  dataFrameName: "table_1"
steps:
- dataFrameName: "table_1"
  sql: "select * from t_customer"

When executing this job, some exceptions occurs:

Exception in thread "main" com.yotpo.metorikku.exceptions.MetorikkuWriteFailedException: Failed to write dataFrame: table_1 to output: JDBC on metric: metric4
	at com.yotpo.metorikku.metric.Metric.com$yotpo$metorikku$metric$Metric$$writeBatch(Metric.scala:101)
	at com.yotpo.metorikku.metric.Metric$$anonfun$write$1.apply(Metric.scala:136)
	at com.yotpo.metorikku.metric.Metric$$anonfun$write$1.apply(Metric.scala:125)
	at scala.collection.immutable.List.foreach(List.scala:381)
	at com.yotpo.metorikku.metric.Metric.write(Metric.scala:125)
	at com.yotpo.metorikku.metric.MetricSet$$anonfun$run$1.apply(MetricSet.scala:44)
	at com.yotpo.metorikku.metric.MetricSet$$anonfun$run$1.apply(MetricSet.scala:39)
	at scala.collection.immutable.List.foreach(List.scala:381)
	at com.yotpo.metorikku.metric.MetricSet.run(MetricSet.scala:39)
	at com.yotpo.metorikku.Metorikku$$anonfun$runMetrics$1.apply(Metorikku.scala:17)
	at com.yotpo.metorikku.Metorikku$$anonfun$runMetrics$1.apply(Metorikku.scala:15)
	at scala.collection.immutable.List.foreach(List.scala:381)
	at com.yotpo.metorikku.Metorikku$.runMetrics(Metorikku.scala:15)
	at com.yotpo.metorikku.Metorikku$.delayedEndpoint$com$yotpo$metorikku$Metorikku$1(Metorikku.scala:11)
	at com.yotpo.metorikku.Metorikku$delayedInit$body.apply(Metorikku.scala:7)
	at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.collection.immutable.List.foreach(List.scala:381)
	at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
	at scala.App$class.main(App.scala:76)
	at com.yotpo.metorikku.Metorikku$.main(Metorikku.scala:7)
	at com.yotpo.metorikku.Metorikku.main(Metorikku.scala)
	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 org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
	at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:879)
	at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:197)
	at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:227)
	at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:136)
	at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.InstantiationException: org.apache.spark.sql.execution.datasources.jdbc.DriverWrapper
	at java.lang.Class.newInstance(Class.java:427)
	at org.apache.spark.sql.execution.datasources.jdbc.DriverRegistry$.register(DriverRegistry.scala:53)
	at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$1.apply(JdbcUtils.scala:55)
	at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$1.apply(JdbcUtils.scala:54)
	at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:63)
	at org.apache.spark.sql.execution.datasources.SaveIntoDataSourceCommand.run(SaveIntoDataSourceCommand.scala:46)
	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:654)
	at org.apache.spark.sql.DataFrameWriter$$anonfun$runCommand$1.apply(DataFrameWriter.scala:654)
	at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:77)
	at org.apache.spark.sql.DataFrameWriter.runCommand(DataFrameWriter.scala:654)
	at org.apache.spark.sql.DataFrameWriter.saveToV1Source(DataFrameWriter.scala:273)
	at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:267)
	at org.apache.spark.sql.DataFrameWriter.jdbc(DataFrameWriter.scala:499)
	at com.yotpo.metorikku.output.writers.jdbc.JDBCOutputWriter.write(JDBCOutputWriter.scala:28)
	at com.yotpo.metorikku.metric.Metric.com$yotpo$metorikku$metric$Metric$$writeBatch(Metric.scala:97)
	... 33 more
Caused by: java.lang.NoSuchMethodException: org.apache.spark.sql.execution.datasources.jdbc.DriverWrapper.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 58 more

NoSuchMethodException is usually caused by class version incompatibility. What should I do to solve this problem ? Any suggestion would be appreciated. Thanks,

hi, can you provide your full spark-submit command? and also where are you running this in? (spark versions as well)
Thanks

/home/spark-2.1.1-bin-hadoop2.6/bin/spark-submit --jars ojdbc6-11.2.0.1.0.jar --class com.yotpo.metorikku.Metorikku metorikku.jar -c job.yaml

is this your own cluster? are you running on managed? (emr/cloudera?)
Did you check this:
https://stackoverflow.com/questions/52818195/error-while-writing-pyspark-dataframe-to-mysql-database

I think maybe the problem is we're not setting the driver here:

Since I don't have an oracle here and in mysql it works quite well, can you add a line there to add to the properties the driver name and try writing again?

it works after setting dirver, thanks @lyogev