Skip to content

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

Closed

Description

@Yury-Fridlyand

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.

Activity

  1. added
    bug
    on Jan 16, 2023
  2. Yury-Fridlyand commented on Jan 17, 2023

    @Yury-Fridlyand
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions