Skip to content

Conversation

@jonahgao
Copy link
Member

@jonahgao jonahgao commented Jun 5, 2024

Which issue does this PR close?

Closes #10791.

Rationale for this change

When the args are empty, they panic at display_name, due to "index out of bounds".

fn display_name(&self, args: &[Expr]) -> Result<String> {
let args_name: Vec<String> = args.iter().map(|e| e.to_string()).collect();
Ok(format!("{}[{}]", args_name[0], args_name[1..].join(":")))
}

The fix is to use an empty string as the arg name if it is out of bounds, allow display_name to pass through, and subsequently generating an error by checking the signature.

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jun 5, 2024
@jonahgao jonahgao marked this pull request as draft June 5, 2024 13:35
@jonahgao jonahgao marked this pull request as ready for review June 5, 2024 13:55
Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

[6.0] [6.0] [] []

# Testing with empty arguments should result in an error
query error DataFusion error: Error during planning: Error during planning: \[data_types_with_scalar_udf\] signature VariadicAny does not support zero arguments.
Copy link
Contributor

Choose a reason for hiding this comment

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

It is handled by signature!

fn display_name(&self, args: &[Expr]) -> Result<String> {
let args_name: Vec<String> = args.iter().map(|e| e.to_string()).collect();
Ok(format!("{}[{}]", args_name[0], args_name[1]))
Ok(format!(
Copy link
Contributor

Choose a reason for hiding this comment

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

that is a nice drive by cleanup

@alamb alamb merged commit 9b1a6f3 into apache:main Jun 5, 2024
@alamb
Copy link
Contributor

alamb commented Jun 5, 2024

Thanks @jonahgao and @jayzhan211

@jonahgao
Copy link
Member Author

jonahgao commented Jun 5, 2024

Thank you for the review @jayzhan211 @alamb

@jonahgao jonahgao deleted the fix_array_panic branch June 5, 2024 14:40
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
…#10804)

* fix: `array_slice` and `array_element` panicked on empty args

* Use single-line error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_slice panicked when called with empty args

3 participants