Skip to content
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

[SPARK-48351] JDBC Connectors - Add cast suite and fix found issue #46669

Conversation

urosstan-db
Copy link
Contributor

Some cast that are supported on spark, are not supported on external database.
For example, spark supports casting from float to timestamp, but many other databases does not support that.

Add new cast suite that can be reused by any connector (even non JDBC connectors)
Add suites for MySQL and Postgres.
Fix found issues for MySQL, Postgres and Snowflake.

Why are the changes needed?

To avoid exception because illegal cast was tried on remote data source.

Does this PR introduce any user-facing change?

Yes, type mapping is a little bit changed for Postgres connector.

How was this patch tested?

Integration suites.

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the SQL label May 20, 2024
import com.databricks.sql.connector.JDBCConnectorCastSuiteBase

import org.apache.spark.sql.connector.catalog.{Identifier, TableCatalog}
import org.apache.spark.sql.execution.datasources.v2.jdbc.MysqlTableCatalog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that there are some imports in this file that do not exist in Apache Spark, such as com.databricks.sql.connector.JDBCConnectorCastSuiteBase and org.apache.spark.sql.execution.datasources.v2.jdbc.MysqlTableCatalog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will fix it.

override def visitCast(expr: String, exprDataType: DataType, dataType: DataType): String = {
dataType match {
case _: IntegralType =>
// MySQL does not support cast to SHORT INT, BIGINT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: SHORT, INT

@urosstan-db urosstan-db deleted the SPARK-48351-JDBC-connectors-Add-cast-suite branch May 20, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants