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

IGNITE-21836: KeyValueView. GetNullable produces confusing error for a PoJo when field / column nullability do not match #3714

Merged
merged 11 commits into from May 14, 2024

Conversation

lowka
Copy link
Contributor

@lowka lowka commented May 7, 2024

https://issues.apache.org/jira/browse/IGNITE-21836


Thank you for submitting the pull request.

To streamline the review process of the patch and ensure better code quality
we ask both an author and a reviewer to verify the following:

The Review Checklist

  • Formal criteria: TC status, codestyle, mandatory documentation. Also make sure to complete the following:
    - There is a single JIRA ticket related to the pull request.
    - The web-link to the pull request is attached to the JIRA ticket.
    - The JIRA ticket has the Patch Available state.
    - The description of the JIRA ticket explains WHAT was made, WHY and HOW.
    - The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • Design: new code conforms with the design principles of the components it is added to.
  • Patch quality: patch cannot be split into smaller pieces, its size must be reasonable.
  • Code quality: code is clean and readable, necessary developer documentation is added if needed.
  • Tests code quality: test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.

Notes

@lowka lowka force-pushed the ignite-21836 branch 7 times, most recently from ce785f5 to 9d03cb4 Compare May 9, 2024 09:25
…a PoJo when field / column nullability do not match
@lowka lowka marked this pull request as ready for review May 9, 2024 14:04
@@ -229,6 +235,11 @@ public CompletableFuture<Void> putAllAsync(@Nullable Transaction tx, Map<K, V> p
return nullCompletedFuture();
}

for (Entry<K, V> e : pairs.entrySet()) {
Objects.requireNonNull(e.getKey());
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add some message to help a user identify a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should. But all assertions in this classes and their siblings do not return any message.

*/
public static void validateNullableOperation(Class<?> valueType) {
if (!Mapper.nativelySupported(valueType)) {
String message = format("`getNullable`* methods cannot be used when a value is not mapped to a simple type");
Copy link
Contributor

Choose a reason for hiding this comment

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

the method is utility and isn't linked to concrete classes that will be used. Maybe better to pass a method name as a parameter to form the message

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 code uses already established pattern see ClientKeyValueView::throwIfNull its callers.

throw new UnexpectedNullValueException("Got unexpected null value: use getNullable sibling method instead.");

Table table = ignite().tables().table("T1");
KeyValueView<Integer, Boolean> view = table.keyValueView(Mapper.of(Integer.class), Mapper.of(Boolean.class));

assertEquals(NullableValue.of(null), view.getNullable(null, 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can make NullableValue.NULL is public

}

private static void expectNullNotAllowed(Executable exec) {
NullPointerException err = assertThrows(NullPointerException.class, exec);
Copy link
Contributor

Choose a reason for hiding this comment

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

we have IgniteTestUtils.assert* methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

K key = entry.getKey();
V val = entry.getValue();

Objects.requireNonNull(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

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 variable names to requireNonNull calls.

lowka added 6 commits May 10, 2024 17:51
…a PoJo when field / column nullability do not match
…a PoJo when field / column nullability do not match
…a PoJo when field / column nullability do not match
…a PoJo when field / column nullability do not match
…a PoJo when field / column nullability do not match
…a PoJo when field / column nullability do not match
/**
* Embedded client nulls in operations test.
*/
public class ItThinClientNullsEmbeddedTest extends ItThinClientNullsTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

client is either thin or embedded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

lowka added 2 commits May 13, 2024 15:24
…a PoJo when field / column nullability do not match

rename.
…a PoJo when field / column nullability do not match

fix tests.
Objects.requireNonNull(key);
Objects.requireNonNull(key, "key");

return doGet(tx, key, "getNullableAsync");
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be a

Suggested change
return doGet(tx, key, "getNullableAsync");
return doGet(tx, key, "getAsync");

?

Copy link
Contributor

Choose a reason for hiding this comment

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

there are a few such places

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, it should not. It reports what method should be used instead.

@ygerzhedovich ygerzhedovich merged commit 38d13fc into apache:main May 14, 2024
1 check passed
@ygerzhedovich ygerzhedovich deleted the ignite-21836 branch May 14, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants