Skip to content

[SPARK-51987][SQL] DSv2 expressions in column defaults on write #51002

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aokolnychyi
Copy link
Contributor

What changes were proposed in this pull request?

This PR allows connectors to expose expression-based defaults on write.

Why are the changes needed?

These changes are needed to avoid the requirement of producing Spark SQL dialect in connectors.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

This PR comes with tests.

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

No.

@github-actions github-actions bot added the SQL label May 23, 2025
sealed class Metadata private[types] (private[types] val map: Map[String, Any])
sealed class Metadata private[types] (
private[types] val map: Map[String, Any],
@transient private[types] val runtimeMap: Map[String, Any])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am adding a runtime-only map of configs that is not serialized or exposed to the user. It will allow me to store alternative in-memory representations for certain configs. In particular, it would allow me to store SQL as well as the expression itself for default values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Below is an example of how it is being used:

val existsDefault = extractExistsDefault(default)
val (sql, expr) = extractCurrentDefault(default)
val newMetadata = new MetadataBuilder()
  .withMetadata(f.metadata)
  .putString(EXISTS_DEFAULT_COLUMN_METADATA_KEY, existsDefault)
  .putExpression(CURRENT_DEFAULT_COLUMN_METADATA_KEY, sql, expr)
  .build()
f.copy(metadata = newMetadata)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows me to use the expression directly without generating/parsing SQL for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant