Skip to content

[SPARK-53348] [SQL] Always persist ANSI value when creating a view or assume it when querying if not stored #52092

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
wants to merge 1 commit into from

Conversation

mihailoale-db
Copy link
Contributor

What changes were proposed in this pull request?

I propose that we always store ANSI value when creating a view because otherwise users can be affected by unwanted behavior. For example if user creates a view on version that has ANSI = false by default he expects this not to fail.

CREATE VIEW view AS SELECT CAST('abc' AS INT) AS a;
SELECT * FROM view;

But if user queries the view on the version which has ANSI = true by default, above query is going to fail (because when we don't store the value, and we store it only if explicitly set, we use the default one). Number of this and similar use cases is huge, because ANSI impact area is huge and thus I propose that we always store the value.

If the value is not stored, I propose that we use createVersion field to determine whether the ANSI value should be true (Spark 4.0.0 and above) or false (lower than Spark 4.0.0). If the createVersion field wasn't stored during view creation, I propose that we assume that the ANSI = false because number of those views is incomparable larger than the ones expecting ANSI = true

Why are the changes needed?

To improve user experience.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added suite.

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

No.

@github-actions github-actions bot added the SQL label Aug 21, 2025
@mihailoale-db mihailoale-db force-pushed the ansiview branch 3 times, most recently from b1a5ff1 to d86b348 Compare August 21, 2025 17:47
@mihailoale-db
Copy link
Contributor Author

@cloud-fan PTAL when you have time. Thanks!

*/
def sqlConfigsToProps(conf: SQLConf): Map[String, String] = {
val modifiedConfs = ViewHelper.getModifiedConf(conf)
modifiedConfs.map { case (key, value) => s"$SQL_CONFIG_PREFIX$key" -> value }

val alwaysCaptured = Seq(SQLConf.ANSI_ENABLED)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should unify it with the view code. We can do it later in a followup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wanted to do that in a followup. We also don't store SESSION_LOCAL_TIMEZONE for UDFs which is a gap.

@cloud-fan
Copy link
Contributor

thanks, merging to master/4.0!

@cloud-fan cloud-fan closed this in a322e0c Aug 22, 2025
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.

2 participants