cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

ERROR: Writing to Unity Catalog from Remote Spark using JDBC

DumbBeaver
New Contributor II
This is my code here.
 
df = spark.createDataFrame([[1,1,2]], schema=['id','first_name','last_name'])

(df.write.format("jdbc")

    .option("url",  <jdbc-url>)

    .option("dbtable","hive_metastore.default.test")

    .option("driver", "com.databricks.client.jdbc.Driver")

    .mode("overwrite")

    # .saveAsTable("test")

    .save()

)

The Error

An error occurred while calling o273.save.
: java.sql.SQLException: [Databricks][JDBCDriver](500051) ERROR processing query/statement. Error Code: 0, SQL state: 42601,
Query: CREATE TAB***, Error message from Server: org.apache.hive.service.cli.HiveSQLException:
Error running query: [PARSE_SYNTAX_ERROR]
org.apache.spark.sql.catalyst.parser.ParseException:
[PARSE_SYNTAX_ERROR] Syntax error at or near '\"id\"'.(line 1, pos 19)

== SQL ==
CREATE TABLE test (\"id\" BIGINT , \"first_name\" BIGINT , \"last_name\" BIGINT )
1 ACCEPTED SOLUTION

Accepted Solutions

feiyun0112
Honored Contributor

 

%scala
import org.apache.spark.sql.jdbc.{JdbcDialect, JdbcDialects}

JdbcDialects.registerDialect(new JdbcDialect() {
    override
    def canHandle(url: String): Boolean = url.toLowerCase.startsWith("jdbc:databricks:")
    override
    def quoteIdentifier(column: String): String = column
})

 

you need register a JDBC Spark dialect to remove quote in column name

 

View solution in original post

2 REPLIES 2

feiyun0112
Honored Contributor

 

%scala
import org.apache.spark.sql.jdbc.{JdbcDialect, JdbcDialects}

JdbcDialects.registerDialect(new JdbcDialect() {
    override
    def canHandle(url: String): Boolean = url.toLowerCase.startsWith("jdbc:databricks:")
    override
    def quoteIdentifier(column: String): String = column
})

 

you need register a JDBC Spark dialect to remove quote in column name

 

Thanks, it worked!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group