Skip to content

Add Databricks to sql-error-codes #34640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MelleD opened this issue Mar 24, 2025 · 4 comments
Closed

Add Databricks to sql-error-codes #34640

MelleD opened this issue Mar 24, 2025 · 4 comments
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@MelleD
Copy link

MelleD commented Mar 24, 2025

I would like to use Databricks directly for the SQL error codes without creating a custom file:
https://github.com/spring-projects/spring-framework/blob/main/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml

The SQL code states are declared here:

https://docs.databricks.com/aws/en/error-messages/sqlstates

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 24, 2025
@bclozel bclozel changed the title [FR] Add Databricks to sql-error-codes Add Databricks to sql-error-codes Mar 24, 2025
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Mar 24, 2025
@jhoeller
Copy link
Contributor

jhoeller commented Mar 24, 2025

Note that we actually use SQLExceptionSubclassTranslator by default now, ignoring our internally shipped sql-error-codes.xml file. SQLErrorCodeSQLExceptionTranslator only kicks in for a user-declared sql-error-codes.xml file in the root of the classpath.

So our default mapping file is effectively legacy. From that perspective, there is limited value in us extending that default sql-error-codes.xml with a further database. This would not apply on its own anymore but just as a base definition for a user-declared file. In other words, you will still have to create a custom file in the root of the classpath (it may remain empty though if all you want to is to rely on the default sql-error-codes.xml mapping in spring-jdbc.jar).

Is there specific error detection that you would expect for Databricks that you do not get out of SQLException subclass analysis already? Additionally, SQLExceptionSubclassTranslator is standards-based but has a couple of extra checks for common cannot-acquire-lock and duplicate-key error codes as well. This is usually sufficient for common exception differentiation purposes, with no actual need for SQL error code mappings for a specific database.

As far as I can tell, Databricks supports 23505 for duplicate-key scenarios which our SQLExceptionSubclassTranslator detects already. And Databricks does not have any specific locking error codes, so there is nothing to specifically detect in that area.

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Mar 24, 2025
@MelleD
Copy link
Author

MelleD commented Mar 24, 2025

Thanks for the quick explanation and detailed answer. I haven't had an SQL translator yet, but I discovered the file and wondered if I needed to handle it for Databricks.

I saw also this here :).

	public SQLErrorCodes getErrorCodes(String databaseName) {
		Assert.notNull(databaseName, "Database product name must not be null");

		SQLErrorCodes sec = this.errorCodesMap.get(databaseName);
		if (sec == null) {
			for (SQLErrorCodes candidate : this.errorCodesMap.values()) {
				if (PatternMatchUtils.simpleMatch(candidate.getDatabaseProductNames(), databaseName)) {
					sec = candidate;
					break;
				}
			}
		}
		if (sec != null) {
			checkCustomTranslatorRegistry(databaseName, sec);
			if (logger.isDebugEnabled()) {
				logger.debug("SQL error codes for '" + databaseName + "' found");
			}
			return sec;
		}

		// Could not find the database among the defined ones.
		if (logger.isDebugEnabled()) {
			logger.debug("SQL error codes for '" + databaseName + "' not found");
		}
		return new SQLErrorCodes();
	}

I would use the default SQLErrorCodes for now and create a ticket if a special case occurs again.

@MelleD MelleD closed this as completed Mar 24, 2025
@MelleD
Copy link
Author

MelleD commented Mar 24, 2025

@jhoeller maybe i figured out the issue. Iam using jOOQ and this is directly using only the sql state error translator for Databricks, because the db name is null therefore
https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/DefaultExceptionTranslatorExecuteListener.java#L116

Maybe this looks like an bug, because also when the db name is not provided it should be using the the default SQLErrorCodeSQLExceptionTranslator which has an fallback to SQLExceptionSubclassTranslator. And SQLExceptionSubclassTranslator has an fallback then to SQLStateSQLExceptionTranslator and then it could work with the complete fallback chain.

Also the javadoc gives the hin
"This translator is commonly used as a fallback behind a primary translator such as SQLErrorCodeSQLExceptionTranslator or SQLExceptionSubclassTranslator.
"

So IMHO this line should changed to:

		return (dbName != null) ? new SQLErrorCodeSQLExceptionTranslator(dbName)
					: new SQLErrorCodeSQLExceptionTranslator();

What do you think?

and maybe the default contructor could provide a empty new SQLErrorCodes() if it is null, or this should also be handled in the auto config

@jhoeller
Copy link
Contributor

jhoeller commented Mar 24, 2025

@MelleD I wasn't ware that there was such a special error translation setup for JOOQ. Indeed, that line in Spring Boot's auto-configured translator should change as follows, matching the core Spring fallback chain:

return (dbName != null) ? new SQLErrorCodeSQLExceptionTranslator(dbName) : new SQLExceptionSubclassTranslator();

Without a database name given, SQLErrorCodeSQLExceptionTranslator itself cannot perform any meaningful lookup, so it effectively falls back to SQLExceptionSubclassTranslator. For that reason, the code should choose that fallback directly like core Spring does.

FWIW we used to fall back to SQLStateSQLExceptionTranslator in former times but changed this to SQLExceptionSubclassTranslator a few years ago for all core Spring JDBC exception translation setups.

Please report the suggestion above to the Spring Boot project: https://github.com/spring-projects/spring-boot/issues

@jhoeller jhoeller added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

5 participants