Skip to content

added support for negative scale for log decimal32/64 and power - #19409

Merged
comphead merged 5 commits into
apache:mainfrom
shifluxxc:support-negative-scale-log-for-decimal32/64-and-power
Dec 22, 2025
Merged

comphead merged 5 commits into
apache:mainfrom
shifluxxc:support-negative-scale-log-for-decimal32/64-and-power

Conversation

@shifluxxc

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

This PR enables support for the power() function with negative scale decimals (e.g., 1e4 represented as 1 with scale -4) and log for decimal32 decimal64 .

What changes are included in this PR?

  • Updated pow_decimal_int logic: Added support for negative scaling factors. When the adjustment factor is negative, the function now multiplies by instead of dividing.
  • For decimals with negative scale, the value is first converted to f64 to compute the logarithm.

Are these changes tested?

Yes.

  • Verified locally using sqllogictest.
  • Covers cases such as SELECT power(1e4, 2) which previously returned a "Negative scale is not supported" error.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Dec 19, 2025

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shifluxxc Can we have slt tests for

support for the power() function with negative scale decimals (e.g., 1e4 represented as 1 with scale -4) and log for decimal32 decimal64 .

Currently I can see

SELECT power(1e4 ,2)

which might not be covering all edge cases declared in this PR

Comment thread datafusion/sqllogictest/test_files/decimal.slt Outdated
shifluxxc and others added 2 commits December 19, 2025 23:01
@shifluxxc

Copy link
Copy Markdown
Contributor Author

I have added slts for other edge cases , please review .

Ok(actual_value.log(base))
} else {
let unscaled_value = decimal32_to_i32(value, scale)?;
let log_value: u32 = unscaled_value.ilog(base as i32);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

decimal32_to_i32() could return 0 and then 0.ilog() will fail

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added basic check to validate that case . It returns Neg infinity now .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought we return NaN for these cases?

Could we also add a test to check this behaviour

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I do think returning NaN is better , I have also added two sqllogic tests to check this behavior .

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shifluxxc nice PR
Thanks @Jefffrey and @martin-g for the review

@comphead
comphead added this pull request to the merge queue Dec 22, 2025
Merged via the queue into apache:main with commit a886b9e Dec 22, 2025
27 checks passed
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.

4 participants