on 09-27-2022 8:41 AM
When using the HANA JDBC driver (downloaded from here) to write data to a HANA DB table from Apache Spark I'm getting a 'sql syntax error: incorrect syntax near "TEXT"' error which appears completely unrelated to what I'm doing.
Following the "JDBC To Other Databases" Spark documentation and the "Calling HANA Views from Apache Spark" blog post I tried
(df.write
.format('jdbc')
.option('url', f'jdbc:sap://{HANA_HOST}:{HANA_PORT}')
.option('dbtable', f'{HANA_SCHEMA}.{HANA_TABLE}')
.option('user', HANA_USER)
.option('password', HANA_PWD)
.mode('overwrite')
.save())
with a Spark dataframe that I created by loading a csv file via
df = (spark.read
.option('delimiter', ',')
.option('header', True)
.csv(file))
However, I'm getting this exception when running the Spark job:
com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [257] (at 60): sql syntax error: incorrect syntax near "TEXT": line 1 col 60 (at pos 60)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB._newInstance(SQLExceptionSapDB.java:209)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.newInstance(SQLExceptionSapDB.java:42)
at com.sap.db.jdbc.packet.HReplyPacket._buildExceptionChain(HReplyPacket.java:837)
at com.sap.db.jdbc.packet.HReplyPacket.getSQLExceptionChain(HReplyPacket.java:195)
at com.sap.db.jdbc.packet.HPartInfo.getSQLExceptionChain(HPartInfo.java:39)
at com.sap.db.jdbc.ConnectionSapDB._receive(ConnectionSapDB.java:5436)
at com.sap.db.jdbc.ConnectionSapDB.exchange(ConnectionSapDB.java:2528)
at com.sap.db.jdbc.StatementSapDB._executeDirect(StatementSapDB.java:2249)
at com.sap.db.jdbc.StatementSapDB._execute(StatementSapDB.java:2223)
at com.sap.db.jdbc.StatementSapDB._execute(StatementSapDB.java:2184)
at com.sap.db.jdbc.StatementSapDB._executeUpdate(StatementSapDB.java:2152)
at com.sap.db.jdbc.StatementSapDB.executeUpdate(StatementSapDB.java:253)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.executeStatement(JdbcUtils.scala:1060)
...
I'm using spark-3.3.0 with Python (pyspark-3.3.0) and the ngdbc-2.13.9 JDBC driver.
print(df)
df.show()
displays
DataFrame[a: string, b: string, c: string]
+---+---+---+
| a| b| c|
+---+---+---+
| 1| 2| 3|
| 2| 3| 4|
| 3| 4| 5|
+---+---+---+
The target table is created by doing
CREATE TABLE "<HANA_SCHEMA>"."<HANA_TABLE>"(
"a" NVARCHAR(10),
"b" NVARCHAR(10),
"c" NVARCHAR(10)
);
The 'incorrect syntax near "TEXT"' error message seems to indicate that the DB connection is working but something's wrong with the generated SQL INSERT statement. I've tried running the job with "DEBUG" log level but that didn't provide any additional clues.
Why am I getting an 'incorrect syntax near "TEXT"' error which appears to be completely unrelated to what I'm doing?
Ways to fix Syntax Errors
Check keyword spelling by referring to the documentation for the type of SQL you are using.
Check table spelling by referring to the database schema.
Check column spelling by referring to the database schema or doing SELECT * FROM the table you are trying to check the column name on.
Greeting,
Rachel Gomez
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
10 | |
8 | |
6 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.