[SPARK-46370][SQL] Fix bug when querying from table after changing column defaults#44302
[SPARK-46370][SQL] Fix bug when querying from table after changing column defaults#44302dtenedor wants to merge 3 commits intoapache:masterfrom
Conversation
|
cc @cloud-fan |
| // TODO: support change column name/dataType/metadata/position. | ||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| catalog.refreshTable(tableName) |
There was a problem hiding this comment.
let's add some code comments to explain the reason: this command may change column default values and we need to refresh the table relation cache so that DML commands can resolve default values correctly.
There was a problem hiding this comment.
Shall we call catalog.refreshTable(tableName) after check the default values changed?
There was a problem hiding this comment.
Hi @beliefer thanks for your comment, I think we have to check it before calling catalog.getTableRawMetadata so that method performs a catalog lookup as expected rather than reading from the cache (which may be stale). There's only one call to catalog.getTableRawMetadata in this function so we should be OK here, but thanks for keeping this question in mind :)
|
Can you retrigger the test? The failed test seems unrelated. |
beliefer
left a comment
There was a problem hiding this comment.
LGTM except one comment.
| // TODO: support change column name/dataType/metadata/position. | ||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| catalog.refreshTable(tableName) |
There was a problem hiding this comment.
Shall we call catalog.refreshTable(tableName) after check the default values changed?
@cloud-fan I started this, it is in progress now: |
|
@cloud-fan all tests are passing now: |
|
thanks, merging to master/3.5! |


What changes were proposed in this pull request?
This PR fixes a bug when querying from table after changing defaults:
The bug is related to the relation cache, and the fix involves adding a manual refresh to the cache to make sure we use the right table schema.
Why are the changes needed?
This PR fixes a correctness bug.
Does this PR introduce any user-facing change?
Yes, see above.
How was this patch tested?
This PR adds test coverage.
Was this patch authored or co-authored using generative AI tooling?
No.