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

Replace if-return with Assume API from Junit in DecimalParquetInputTest #16436

Merged
merged 3 commits into from
May 14, 2024

Conversation

Codegass
Copy link
Contributor

Fixes #12926.

Description

This PR improves the test cases in DecimalParquetInputTest by replacing the if-return blocks that check for unsupported parser types with assumeFalse-- Assume API from Junit.

Replaced if-return blocks with assumeFalse

The existing test cases used if-return blocks like this to skip tests for unsupported parser types:

// parquet-avro does not correctly convert decimal types
if (parserType.equals(ParquetExtensionsModule.PARQUET_AVRO_INPUT_PARSER_TYPE)) {  
  return;
}

This made the test logic implicit. It's preferable to make unsupported preconditions explicit using JUnit's assume methods. The assume function, introduced after JUnit 4, is designed to check for test pre-condition. As mentioned in the document:

Assume functions is a set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information.

I replaced the if-return blocks with equivalent assumeFalse assertions:

// parquet-avro does not correctly convert decimal types
assumeFalse(parserType.equals(ParquetExtensionsModule.PARQUET_AVRO_INPUT_PARSER_TYPE));

A failed assumption will cause the test to be skipped, while still allowing the test to run for supported parser types. This makes the preconditions clearer without changing the test behavior.

This refactoring resolves the silent quit issue by using the Assume API to provide explicit output when tests are skipped.

I applied this change to all three test cases in DecimalParquetInputTest:

  • testReadParquetDecimalFixedLen
  • testReadParquetDecimali32
  • testReadParquetDecimali64

This is a straightforward refactoring that improves test readability without altering functionality. No other code changes were made.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@Codegass Codegass changed the title Replace if return with Assume API from Junit Replace if return with Assume API from Junit in DecimalParquetInputTest May 13, 2024
@Codegass Codegass changed the title Replace if return with Assume API from Junit in DecimalParquetInputTest Replace if-return with Assume API from Junit in DecimalParquetInputTest May 13, 2024
Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, @Codegass . I have left some comments.

if (parserType.equals(ParquetExtensionsModule.PARQUET_AVRO_INPUT_PARSER_TYPE)) {
return;
}
assumeFalse(parserType.equals(ParquetExtensionsModule.PARQUET_AVRO_INPUT_PARSER_TYPE));
Copy link
Contributor

Choose a reason for hiding this comment

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

Druid code doesn't use the import static style.

Suggested change
assumeFalse(parserType.equals(ParquetExtensionsModule.PARQUET_AVRO_INPUT_PARSER_TYPE));
Assume.assumeFalse(parserType.equals(ParquetExtensionsModule.PARQUET_AVRO_INPUT_PARSER_TYPE));

"example/decimals/dec_in_i64.json",
parserType,
true
"example/decimals/dec_in_i64.json",
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes are not needed as this code is already formatted correctly according to the formatting style used by this project. Same comment for the other formatting changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for the suggestions! I just updated the pr based on them.

@kfaraz kfaraz merged commit 621525a into apache:master May 14, 2024
54 checks passed
@kfaraz
Copy link
Contributor

kfaraz commented May 14, 2024

Thanks a lot for your first contribution to Druid, @Codegass !

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.

A Minor Improvement to the test cases inDecimalParquetInputTest
2 participants