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

Added 'long' as a target type for 'convert_entry_type' processor #4359

Merged
merged 8 commits into from
Apr 4, 2024
Merged

Conversation

Utkarsh-Aga
Copy link
Contributor

@Utkarsh-Aga Utkarsh-Aga commented Mar 30, 2024

Description

Added the following type conversions -

  • String/Double/Boolean/Integer to Long

Issues Resolved

Resolves #4120

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

@Utkarsh-Aga , Thank you for this contribution. I have a couple comments. One is that the build itself is failing.

void testInvalidStringConversion() {
IntegerConverter converter = new IntegerConverter();
assertThrows(IllegalArgumentException.class, () -> converter.convert(new Object()));
IntegerConverter converter = new IntegerConverter();
Copy link
Member

Choose a reason for hiding this comment

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

I'm seeing the following failure:

/home/runner/work/data-prepper/data-prepper/data-prepper-api/src/test/java/org/opensearch/dataprepper/typeconverter/LongConverterTests.java:51: error: variable converter is already defined in method testInvalidStringConversion()
         IntegerConverter converter = new IntegerConverter();

I think you can remove lines 51 and 52 and they repeat the same tests from 49-50.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was a mistake on my part of using IntegerConverter in LongConverterTests. Fixed it.

@Test
void testDoubleToLongConversion() {
LongConverter converter = new LongConverter();
final Double doubleConstant = (double)12345678.12345678;
Copy link
Member

Choose a reason for hiding this comment

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

It may be good to have a test that converts a value which is larger than the maximum integer in addition to this one. You could make a large double constant like 2.0 * Integer.MAX_INT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a test case testDoubleToLongConversionWithBigValue for it.

@Utkarsh-Aga
Copy link
Contributor Author

Thanks a lot @dlvenable for the review. I have made the changes to the commit and tried to address the comments.
Would request another set of review.

graytaylor0
graytaylor0 previously approved these changes Apr 3, 2024
final Double doubleConstant = (double)12345678.12345678;
assertThat(converter.convert(doubleConstant), equalTo((long)(double)doubleConstant));
}
@Test
Copy link
Member

Choose a reason for hiding this comment

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

These test cases look good. One thing you could do to make it easier to add more tests would be to use @ParameterizedTest with an Arguments source. An example of that can be found here (

void testArithmeticExpressionEvaluatorInvalidInput(final String expression, final Event event) {
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the ParameterizedTest for all the test except for testInvalidStringConversion as had to create a MethodSource.

@graytaylor0 graytaylor0 dismissed their stale review April 3, 2024 05:01

Build failing

@graytaylor0
Copy link
Member

Looks like build is failing due to jacoco test coverage reaching .9 only and being set at 1. Are you able to see the report to see which instructions are being missed in the tests to fill that gap?

@Utkarsh-Aga
Copy link
Contributor Author

Sure, I was not sure why the build was failing but let me check more on it.

@Utkarsh-Aga Utkarsh-Aga requested a review from dlvenable April 3, 2024 06:47
@Utkarsh-Aga
Copy link
Contributor Author

The build failure was because of missing test for testIntToLongConverstion. Added that.
Thanks a lot @graytaylor0 for pointing the steps to fix that.

@Utkarsh-Aga Utkarsh-Aga requested a review from graytaylor0 April 3, 2024 06:50
@dlvenable dlvenable merged commit 24bbbf1 into opensearch-project:main Apr 4, 2024
47 checks passed
@dlvenable
Copy link
Member

@Utkarsh-Aga , thank you for this contribution!

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.

Add long as a target type for convert_entry_type processor
3 participants