Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ private case class DatabricksDialect() extends JdbcDialect with NoLegacyJDBCErro
case _ => None
}

// See https://docs.databricks.com/aws/en/error-messages/sqlstates
// See https://docs.databricks.com/aws/en/error-messages/sqlstates.
// The driver may report syntax errors with a non-class-42 SQLState.
override def isSyntaxErrorBestEffort(exception: SQLException): Boolean = {
Option(exception.getSQLState).exists(_.startsWith("42"))
Option(exception.getSQLState).exists(_.startsWith("42")) ||
Option(exception.getMessage)
.exists(_.toUpperCase(Locale.ROOT).contains("SYNTAX_ERROR"))
}

override def quoteIdentifier(colName: String): String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.spark.sql.jdbc

import java.math.BigDecimal
import java.sql.{Connection, Date, DriverManager, ResultSet, Statement, Timestamp}
import java.sql.{Connection, Date, DriverManager, ResultSet, SQLException, Statement, Timestamp}
import java.time.{Instant, LocalDate, LocalDateTime}
import java.time.format.DateTimeFormatter
import java.util.{Calendar, GregorianCalendar, Properties, TimeZone}
Expand Down Expand Up @@ -2608,6 +2608,13 @@ class JDBCSuite extends SharedSparkSession {
.getJDBCType(BinaryType).map(_.databaseTypeDefinition).get == "BINARY")
}

test("SPARK-58193: DatabricksDialect syntax error detection") {
val dialect = DatabricksDialect()
assert(dialect.isSyntaxErrorBestEffort(
new SQLException("[parse_syntax_error] Syntax error at or near 'SQL'", "07000")))
assert(!dialect.isSyntaxErrorBestEffort(new SQLException("Connection reset", "08001")))
}

test("SPARK-45425: Mapped TINYINT to ShortType for MsSqlServerDialect") {
val msSqlServerDialect = JdbcDialects.get("jdbc:sqlserver")
val metadata = new MetadataBuilder().putLong("scale", 1)
Expand Down