Nadav Har'El created CASSANDRA-21745:
----------------------------------------

             Summary: INSERT JSON and fromJson() inconsistently accept an empty 
string as a value of non-string types
                 Key: CASSANDRA-21745
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-21745
             Project: Apache Cassandra
          Issue Type: Bug
            Reporter: Nadav Har'El


In INSERT JSON and in the fromJson() function, a JSON string can be used as the 
value of many non-string types - e.g., "123" for an {{int}} column. But the 
*empty* string {{""}} is handled inconsistently between types: for some types 
it is silently accepted and writes an "empty value" (a zero-length value, 
different from null), and for other types it is rejected.

Tested on Cassandra 5.0.9 and 6.0-alpha2 (same behavior), with a table having 
one column of each type, using

INSERT INTO t JSON '\{"k": 1, "v": ""}'

and

{{{}INSERT INTO t (k, v) VALUES (1, fromJson('""')){}}}:
||Type||INSERT JSON with ""||fromJson('""')||
|int, bigint, boolean, decimal, double, float, uuid, timeuuid|accepted (empty 
value)|accepted (empty value)|
|smallint, tinyint, duration|accepted (empty value)|server error 
(RuntimeException, see below)|
|varint|InvalidRequest ("Value '' is not a valid representation of a varint 
value")|FunctionFailure|
|blob|InvalidRequest|FunctionFailure|

An empty string is not a valid integer, float, UUID or boolean, so I think it 
should be rejected for all these types, as it already is for {{varint}} and 
{{blob}} - the user most likely made a mistake, and almost certainly didn't 
intend to write an empty value. As CASSANDRA-8354 explains, empty values of 
these types exist only for historical reasons and are a nuisance; they 
shouldn't be this easy to write by accident.

The server errors for smallint, tinyint and duration happen because fromJson() 
returns an empty value, which these types don't accept, so FunctionCall's check 
of the return value throws a RuntimeException ("Return of function 
system.fromjson : (text) -> smallint () is not a valid value for its declared 
return type smallint") - an instance of CASSANDRA-18484.

The same behavior for date, time, inet and timestamp (which also have string 
literal forms) may deserve a separate discussion: on the tested versions, "" is 
rejected for date and time but accepted for inet and timestamp.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to