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

[BUG] Serialization failure - some math function return NaN instead of NULL #1280

Closed
Yury-Fridlyand opened this issue Jan 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Yury-Fridlyand
Copy link
Collaborator

What is the bug?

Some math functions return ±NaN instead of NULL. NaN is not serializable by GSON lib.
For example, LN uses Math.log which returns -NaN for negative values.

How can one reproduce the bug?

opensearchsql> select LN(-12.34567);
{'reason': 'Invalid SQL query', 'details': 'NaN is not a valid double value as per JSON specification. To override this behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method.', 'type': 'IllegalArgumentException'}

What is the expected behavior?

mysql> select LN(-12.34567);
+---------------+
| LN(-12.34567) |
+---------------+
|          NULL |
+---------------+

What is your host/environment?

main @ 9d4a841

Do you have any additional context?

Fix all math functions or patch serializer callee in protocol module to replace all ±NaN by NULLs.

@Yury-Fridlyand Yury-Fridlyand added the bug Something isn't working label Jan 16, 2023
@Yury-Fridlyand
Copy link
Collaborator Author

Legacy engine fails as well:

$ curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -d '{"query": "SELECT LN(0)"}'
{
  "error": {
    "reason": "Invalid SQL query",
    "details": "-Infinity is not a valid double value as per JSON specification. To override this behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method.",
    "type": "IllegalArgumentException"
  },
  "status": 400
}

$ curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -d '{"query": "SELECT LN(0) from books", "fetch_size": 10}'
JSON does not allow non-finite numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants