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

propagate error instead of panicking on out of bounds in physical-expr/src/analysis.rs #10992

Merged
merged 2 commits into from
Jun 20, 2024
Merged

propagate error instead of panicking on out of bounds in physical-expr/src/analysis.rs #10992

merged 2 commits into from
Jun 20, 2024

Conversation

LorrensP-2158466
Copy link
Contributor

Which issue does this PR close?

Closes #10536.

Rationale for this change

In

let field = &schema.fields()[col_index];

The function panics when col_index is out of bounds when returning an internal error with extra context is much more convenient.

What changes are included in this PR?

Propagate the error as en DataFusionError::Internal.

Are these changes tested?

Are there any user-facing changes?

Users may need to handle that error case

@LorrensP-2158466 LorrensP-2158466 changed the title propogate error instead of panicking propagate error instead of panicking Jun 19, 2024
@LorrensP-2158466 LorrensP-2158466 changed the title propagate error instead of panicking propagate error instead of panicking on out of bounds in physical-expr/src/analysis.rs Jun 19, 2024
let field = schema.fields()
.get(col_index)
.ok_or_else(|| DataFusionError::Internal(
format!("Could not create `ExprBoundaries`: in `try_from_column` `col_index` has gone out of bounds with a value of {col_index}, the schema has {} columns while.", schema.fields.len())
Copy link
Member

Choose a reason for hiding this comment

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

Using internal_datafusion_err could simplify it.

 let field = schema.fields().get(col_index).ok_or_else(|| {
            internal_datafusion_err!(
                "Could not create `ExprBoundaries`: in `try_from_column` `col_index` 
                has gone out of bounds with a value of {col_index}, the schema has {} columns while.",
                schema.fields.len()
            )
        })?;

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 yes, that's much more nicer. Thanks!

@github-actions github-actions bot added the physical-expr Physical Expressions label Jun 20, 2024
Copy link
Member

@jonahgao jonahgao left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks @LorrensP-2158466

@jonahgao jonahgao merged commit 5316278 into apache:main Jun 20, 2024
23 checks passed
@LorrensP-2158466 LorrensP-2158466 deleted the analysis-bound-check branch June 20, 2024 18:22
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jun 22, 2024
…r/src/analysis.rs (apache#10992)

* propogate error instead of panicking

* use macro for creating internal df error
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jun 22, 2024
…r/src/analysis.rs (apache#10992)

* propogate error instead of panicking

* use macro for creating internal df error
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
…r/src/analysis.rs (apache#10992)

* propogate error instead of panicking

* use macro for creating internal df error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

analysis.rs bounds check panic
2 participants