Search code examples
eclipseapache-sparkcassandraspark-cassandra-connector

Getting error while running spark job for cassandra connector - Caused by: java.io.IOException: Failed to write statements to test.events


I am trying to insert data to Cassandra using a Apache Spark job in eclipse. I am able to run my sample code but facing issue with complex table design.

Can someone please help how to resolve this issue?

Caused by: java.io.IOException: Failed to write statements to test.events.
    at com.datastax.spark.connector.writer.TableWriter$$anonfun$write$1.apply(TableWriter.scala:167)
    at com.datastax.spark.connector.writer.TableWriter$$anonfun$write$1.apply(TableWriter.scala:135)
    at com.datastax.spark.connector.cql.CassandraConnector$$anonfun$withSessionDo$1.apply(CassandraConnector.scala:111)
    at com.datastax.spark.connector.cql.CassandraConnector$$anonfun$withSessionDo$1.apply(CassandraConnector.scala:110)
    at com.datastax.spark.connector.cql.CassandraConnector.closeResourceAfterUse(CassandraConnector.scala:140)
    at com.datastax.spark.connector.cql.CassandraConnector.withSessionDo(CassandraConnector.scala:110)
    at com.datastax.spark.connector.writer.TableWriter.write(TableWriter.scala:135)
    at com.datastax.spark.connector.streaming.DStreamFunctions$$anonfun$saveToCassandra$1$$anonfun$apply$1.apply(DStreamFunctions.scala:54)
    at com.datastax.spark.connector.streaming.DStreamFunctions$$anonfun$saveToCassandra$1$$anonfun$apply$1.apply(DStreamFunctions.scala:54)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
    at org.apache.spark.scheduler.Task.run(Task.scala:99)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:282)
    ... 3 more

Solution

  • Try removing the keys first and see if only one key works or not. I can see you are using date, so then it can be unique, just try to insert few records at first, If that does not work, see in date, If there is any problem with the date formatting you are using, because it can cause you many problem, I once had a similar issue, and I checked my date, somehow during manipulation, it became 12-00-2012, so because of that cassandra was throwing error.

    If sample code works that means there should not be any issue with the configuration.