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

[CALCITE-6352] The map_contains_key function may return true when the key and mapkeytype types are different #3786

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

caicancai
Copy link
Member

@caicancai caicancai commented May 3, 2024

return map.containsKey(key);
}

private static boolean isNumericEqual(Object obj1, Object obj2) {
if (obj1 instanceof Number && obj2 instanceof Number) {
double num1 = ((Number) obj1).doubleValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

this may not work for some decimal values which cannot be represented exactly as doubles
in general, it is not recommended to compare floating point values for equality, e.g, https://www.jetbrains.com/help/resharper/CompareOfFloatsByEqualityOperator.html

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right

Copy link
Member Author

Choose a reason for hiding this comment

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

@mihaibudiu Should I add a layer of explicit conversion in case to convert the types in map and key to the biggest type

Copy link
Member Author

@caicancai caicancai May 4, 2024

Choose a reason for hiding this comment

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

Or convert BigDecimal for comparison, what do you think

Copy link

sonarcloud bot commented May 5, 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
2 participants