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-50463][SQL] Fix ConstantColumnVector with Columnar to Row conversion #49021

Closed

Conversation

richardc-db
Copy link
Contributor

What changes were proposed in this pull request?

800faf0 frees column vector resources between batches in columnar to row conversion. However, like WritableColumnVector, ConstantColumnVector should not free resources between batches because the same data is used across batches

Why are the changes needed?

Without this change, ConstantColumnVectors with string values, for example, will fail if used with column->row conversion. For instance, reading a parquet table partitioned by a string column with multiple batches.

Does this PR introduce any user-facing change?

How was this patch tested?

added UT that failed before and now passes

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

no

@github-actions github-actions bot added the SQL label Dec 2, 2024
@richardc-db richardc-db changed the title [SPARK-50463][SQL] FIx ConstantColumnVector with Columnar to Row conversion [SPARK-50463][SQL] Fix ConstantColumnVector with Columnar to Row conversion Dec 2, 2024
@richardc-db
Copy link
Contributor Author

hey @viirya mind taking a quick look at this one? Fixes using ConstantColumnVectors with the col->row memory leak fix you merged a bit ago

@@ -77,6 +77,11 @@ public ConstantColumnVector(int numRows, DataType type) {
}
}

public void closeIfFreeable() {
Copy link
Member

Choose a reason for hiding this comment

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

closeIfNotWritable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah my apologies - do you think closeIfNotWritable still makes sense given that the ConstantColumnVector is not a WritableColumnVector?

Do you think closeIfFreeable makes sense? If so, I'll change the method name in ColumnVector.java in this PR as well.

Or do you have a preference for a different name?

Copy link
Member

Choose a reason for hiding this comment

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

Ok for closeIfFreeable. I just wondered why you only changed in ConstantColumnVector.

viirya
viirya previously approved these changes Dec 2, 2024
Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

Good catch. Thanks.

@viirya viirya dismissed their stale review December 2, 2024 00:56

Method name incorrect

@richardc-db richardc-db force-pushed the col_to_row_const_col_vec_fix branch from 3ee4f29 to 9e453bf Compare December 2, 2024 02:55
@richardc-db richardc-db requested a review from viirya December 2, 2024 02:56
public void closeIfNotWritable() {
// By default, we just call close() for all column vectors. If a column vector is writable, it
// should override this method and do nothing.
public void closeIfFreeable() {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm ColumnVector is an API actually. Can we avoid direct renaming here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original PR which added this method 800faf0 was merged ~a month ago. is it too late to now change the method name?

If so, how do you suggest we go about this? I think closeIfNotWritable doesn't represent the purpose of the method well, so one option is to deprecate closeIfNotWritable and directly call closeIfFreeable inside it. This is pretty ugly, though, so I'm open to any suggestions

Copy link
Member

Choose a reason for hiding this comment

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

ah okie dokie then should be fine

Copy link
Member

Choose a reason for hiding this comment

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

Yea, it is a new API just added recently and not released yet.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM. Thank you, @richardc-db , @viirya , @HyukjinKwon .
Merged to master for Apache Spark 4.0.0 on February 2025.

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-50463][SQL] Fix ConstantColumnVector with Columnar to Row conversion [SPARK-50463][SQL] Fix ConstantColumnVector with Columnar to Row conversion Dec 3, 2024
LuciferYang pushed a commit to LuciferYang/spark that referenced this pull request Dec 10, 2024
…nversion

### What changes were proposed in this pull request?

apache@800faf0 frees column vector resources between batches in columnar to row conversion. However, like `WritableColumnVector`, `ConstantColumnVector` should not free resources between batches because the same data is used across batches

### Why are the changes needed?

Without this change, ConstantColumnVectors with string values, for example, will fail if used with column->row conversion. For instance, reading a parquet table partitioned by a string column with multiple batches.

### Does this PR introduce _any_ user-facing change?

### How was this patch tested?

added UT that failed before and now passes

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

no

Closes apache#49021 from richardc-db/col_to_row_const_col_vec_fix.

Authored-by: Richard Chen <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
@LuciferYang
Copy link
Contributor

@dongjoon-hyun I found that the previous PR of this one, which is #48767, was merged into both master and branch-3.5, but this pr was only merged into master. Then I manually copied the new test cases from this pr and found that they fail in branch-3.5.

So should we backport this patch to branch-3.5? I have created a backporting: #49131

@dongjoon-hyun
Copy link
Member

Oh, is this a regression then, @LuciferYang ?

@LuciferYang
Copy link
Contributor

Oh, is this a regression then, @LuciferYang ?

I think so...

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.

5 participants