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

fix: skip negative scale checks for creating decimals #723

Merged
merged 5 commits into from
Aug 1, 2024

Conversation

kazuyukitanimura
Copy link
Contributor

Which issue does this PR close?

Part of #679 and #670

Rationale for this change

This PR improves the getDecimal performance

What changes are included in this PR?

The new createDecimal method skips the negative scale check

How are these changes tested?

Existing tests

@@ -30,7 +30,7 @@ public class CometDictionary implements AutoCloseable {
private final int numValues;

/** Decoded dictionary values. We only need to copy values for decimal type. */
private ByteArrayWrapper[] binaries;
private volatile ByteArrayWrapper[] binaries;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not directly related but forgot to add based on #705 (comment)

@kazuyukitanimura kazuyukitanimura marked this pull request as ready for review July 26, 2024 18:38
@kazuyukitanimura
Copy link
Contributor Author

SF=100

getDecimal(Long)

Before

Screenshot 2024-07-26 at 11 39 30 AM

After

Screenshot 2024-07-26 at 11 39 51 AM

getDecimal(128)

Before

Screenshot 2024-07-26 at 11 40 13 AM

After

Screenshot 2024-07-26 at 11 40 29 AM

}
}

/** This method skips the negative scale check, otherwise the same as Decimal.createUnsafe(). */
private Decimal createDecimal(long unscaled, int precision, int scale) {
Decimal dec = new Decimal();
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems the check for negative scale is a feature for ANSI correctness? https://issues.apache.org/jira/browse/SPARK-30252

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 does not need to do the check every read, we are running ANSI tests in spark_sql_test_ansi.yml

/** This method skips a few checks, otherwise the same as Decimal.apply(). */
private Decimal createDecimal(BigDecimal value, int precision, int scale) {
Decimal dec = new Decimal();
Platform.putObjectVolatile(dec, decimalValOffset, new scala.math.BigDecimal(value));
Copy link
Contributor

Choose a reason for hiding this comment

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

The spark version has some additional checks for rounding and precision. Do we not need those?

    this.decimalVal = decimal.setScale(scale, ROUND_HALF_UP)
    if (decimalVal.precision > precision) {
      throw QueryExecutionErrors.decimalPrecisionExceedsMaxPrecisionError(
        decimalVal.precision, precision)
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No we do not need the precision check because it is done in advance

Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my knowledge, where?

@kazuyukitanimura
Copy link
Contributor Author

@andygrove @comphead @huaxingao @parthchandra @viirya
Any other feedbacks?

Copy link
Contributor

@parthchandra parthchandra left a comment

Choose a reason for hiding this comment

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

lgtm

/** This method skips a few checks, otherwise the same as Decimal.apply(). */
private Decimal createDecimal(BigDecimal value, int precision, int scale) {
Decimal dec = new Decimal();
Platform.putObjectVolatile(dec, decimalValOffset, new scala.math.BigDecimal(value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my knowledge, where?

@andygrove andygrove merged commit fbe86d0 into apache:main Aug 1, 2024
74 checks passed
himadripal pushed a commit to himadripal/datafusion-comet that referenced this pull request Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants