0

Created a sample Dataframe with string data and trying to write that row into the google spanner table which is already created in the database(Google SQL dialect Spanner DB)

Trying to write as below:

data.write.format("jdbc")
    .option("url", jdbcUrl)
    .option("driver", "com.google.cloud.spanner.jdbc.JdbcDriver")
    .option("dbtable", tableName)
    .mode("append")
    .save()

sample Dataframe(data) schema:

root
11:42:27   |-- sampleNumber: string (nullable = true)

Error:

Caused by: repackaged.com.google.google.cloud.spanner.SpannerBatchUpdateException: Syntax error: Unexpected string literal \"sampleNumber\" [at 1:37]\nINSERT INTO Account (\"sampleNumber\") VALUES (@p1)\n                                    ^
at repackaged.com.google.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.batchException(JdbcSqlExceptionFactory.java:325)

Table Schema:

11:42:27   |-- sampleNumber: string (nullable = true)

Tried with different df schema and types but still could not pass through that error

Islam Elbanna
  • 1,438
  • 2
  • 9
  • 15
  • What does tablename contains in your snippet ? – parisni Aug 23 '23 at 05:44
  • Looks like an issue with the tableName passed to the df. You can also look at a code reference here - https://github.com/GoogleCloudPlatform/dataproc-templates/blob/main/java/src/main/java/com/google/cloud/dataproc/templates/jdbc/JDBCToSpanner.java#L78 – Manit Gupta Aug 24 '23 at 08:52
  • Where you able to fix this? – Manit Gupta Sep 01 '23 at 04:58

0 Answers0