Skip to content

Conversation

@goldmedal
Copy link
Contributor

Which issue does this PR close?

Closes #12012 .

Rationale for this change

What changes are included in this PR?

If the percentile or t-digest is invalid for approx_percentile_cont, throw no_impl_err with a readable message instead of internal_error.

Are these changes tested?

yes

Are there any user-facing changes?

no

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Aug 23, 2024
@alamb alamb changed the title Throw no_impl_error for approx_percentile_cont parameters validation Throw not_impl_error for approx_percentile_cont parameters validation Aug 23, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @goldmedal -- this looks like an improvement to me

I had another suggestion on how to simplify the code, but it is certainly not required

fn validate_input_percentile_expr(expr: &Arc<dyn PhysicalExpr>) -> Result<f64> {
let percentile = match get_scalar_value(expr)? {
ScalarValue::Float32(Some(value)) => {
let percentile = match get_scalar_value(expr).ok() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Another way to express this for your consideration that might make the error handling more obvious is

      let scalar = match get_scalar_value(expr)
        .map_err(not_impl_err!("Percentile value for 'APPROX_PERCENTILE_CONT' must be a litera, got: {expr}l")?
      match scalar { 
          ScalarValue::Float32(Some(value)) => {
 ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks nice. Thanks for the suggestions!

@jayzhan211
Copy link
Contributor

Thanks @goldmedal @alamb

@jayzhan211 jayzhan211 merged commit 31adb08 into apache:main Aug 24, 2024
@goldmedal
Copy link
Contributor Author

Thanks @alamb @jayzhan211

@goldmedal goldmedal deleted the bugfix/12012-fix-approx_percentile_cont branch August 24, 2024 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal error in approx_percentile_cont() aggregate function (SQLancer)

3 participants