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

[HUDI-8783] Add tests for decimal data type #12519

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

linliu-code
Copy link
Contributor

Change Logs

Add a test to insert/update/delete/read data for a MOR table

Impact

Verify that decimal data type workflow works.

Risk level (write none, low medium or high below)

Low.

Documentation Update

Describe any necessary documentation update if there is any new feature, config, or user-facing change. If not, put "none".

  • The config description must be updated if new configs are added or the default value of the configs are changed
  • Any new feature or user-facing change requires updating the Hudi website. Please create a Jira ticket, attach the
    ticket number here and follow the instruction to make
    changes to the website.

Contributor's checklist

  • Read through contributor's guide
  • Change Logs and Impact were stated clearly
  • Adequate tests were added if applicable
  • CI passed

val opts = sparkOpts ++ fgReaderOpts

@Test
def testDecimalInsertUpdateDeleteRead(): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add various precisions so we can test the different possible representations in parquet?
https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#decimal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sg

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, let's test at least 3 cases:

  1. precision <= 10
  2. precision > 10 && precision < 18
  3. precision > 18

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already did.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ParameterizedTest @CsvSource(value = Array("10,2", "20,10", "38,18", "5,0"))
So, let me add one more (15, 10)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now:
@ParameterizedTest @CsvSource(value = Array("10,2", "15,5", "20,10", "38,18", "5,0"))

@github-actions github-actions bot added the size:M PR with lines of changes in (100, 300] label Dec 19, 2024
@linliu-code linliu-code force-pushed the add_test_for_decimal_configs branch from a4d87e6 to aad4dd7 Compare December 19, 2024 22:58
@linliu-code linliu-code changed the title [HUDI-8783] Add test for decimal data type [HUDI-8783] Add tests for decimal data type Dec 19, 2024
@linliu-code linliu-code force-pushed the add_test_for_decimal_configs branch from aad4dd7 to bba29bd Compare December 20, 2024 08:20
case v: Integer => newType match {
case Type.INT => v
case Type.LONG => v.longValue()
case Type.FLOAT => v.floatValue()
case Type.DOUBLE => v.doubleValue()
case Type.STRING => UTF8String.fromString(v.toString)
case Type.FIXED => BigDecimal(v)
Copy link
Contributor

@danny0405 danny0405 Dec 21, 2024

Choose a reason for hiding this comment

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

I see a special handling for Spark decimal data type for precision < 18 in the UnsafeRow decimal getter:

public Decimal getDecimal(int ordinal, int precision, int scale) {
    if (isNullAt(ordinal)) {
      return null;
    }
    if (precision <= Decimal.MAX_LONG_DIGITS()) {
      return Decimal.createUnsafe(getLong(ordinal), precision, scale);
    } else {
      byte[] bytes = getBinary(ordinal);
      BigInteger bigInteger = new BigInteger(bytes);
      BigDecimal javaDecimal = new BigDecimal(bigInteger, scale);
      return Decimal.apply(javaDecimal, precision, scale);
    }
  }

Should we do it here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. let me add it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danny0405 , I tried to cast it, but I think we so far we have lost the precision and scale information from FIXED type here. So we can not do the special treatment.

@linliu-code linliu-code force-pushed the add_test_for_decimal_configs branch from bba29bd to 77e9370 Compare December 27, 2024 20:07
@hudi-bot
Copy link

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M PR with lines of changes in (100, 300]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants