Skip to content

Conversation

@manuzhang
Copy link
Member

What changes were proposed in this pull request?

Before this PR, store assignment policy is validated for V2Write command when v2Write.table.resolved && v2Write.query.resolved && !v2Write.outputResolved is true. However, !v2Write.outputResolved doesn't hold for DataFrameWriterV2 API and the policy is not validated. This PR validates store assignment policy for V2Write command without any conditions.

Why are the changes needed?

LEGACY store assignment policy should not be allowed writing to v2 table with DataFrameWriterV2 API.

Does this PR introduce any user-facing change?

An AnalysisError will be thrown when users write to v2 table with DataFrameWriterV2 API and spark.sql.storeAssignmentPolicy=LEGACY

How was this patch tested?

UT.

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

No.

@github-actions github-actions bot added the SQL label Oct 15, 2024
@manuzhang
Copy link
Member Author

@cloud-fan @yaooqinn @wangyum The following is allowed with legacy store assignment policy after #47082

CREATE TABLE testcat.ns.t1 (d1 string, d2 varchar(200)) USING parquet;
CREATE TABLE testcat.ns.t2 USING foo as select * from testcat.ns.t1;

I'm wondering to what extent is the policy allowed in data source v2.

checkError(
exception = intercept[AnalysisException] {
spark.range(10)
.writeTo("table_name")
Copy link
Contributor

Choose a reason for hiding this comment

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

what was the behavior before? Do we add hard cast for the input query?

Copy link
Member Author

Choose a reason for hiding this comment

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

This test passes on master branch. I was wrong about what's allowed with LEGACY store assignment policy.

The following is allowed with either SQL or DataFrameWriteV2 API when source has the same schema as v2Table.

insert into v2Table select * from source;
val df = spark.table("source")
df.writeTo("v2Table").append()

Copy link
Contributor

@cloud-fan cloud-fan Oct 18, 2024

Choose a reason for hiding this comment

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

OK so the current logic is: if Spark needs to adjust the input query before writing to the table (type coercion), then we disallow LEGACY store assignment. Otherwise, we don't check store assignment mode at all. This is consistent across all APIs and seems fine?

@manuzhang manuzhang closed this Oct 18, 2024
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