Skip to content

Commit

Permalink
cql.g: make the parser reject INSERT JSON without a JSON value
Browse files Browse the repository at this point in the history
We allow inserting column values using a JSON value, eg:
```cql
INSERT INTO mytable JSON '{ "\"myKey\"": 0, "value": 0}';
```

When no JSON value is specified, the query should be rejected.

Scylla used to crash in such cases. A recent change fixed the crash
(#14706), it now fails
on unwrapping an uninitialized value, but really it should
be rejected at the parsing stage, so let's fix the grammar so that
it doesn't allow JSON queries without JSON values.

A unit test is added to prevent regressions.

Refs: #14707
Fixes: #14709

Signed-off-by: Jan Ciolek <jan.ciolek@scylladb.com>

Closes #14785
  • Loading branch information
cvybhu authored and nyh committed Jul 21, 2023
1 parent 37ceef2 commit cbc97b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cql3/Cql.g
Expand Up @@ -479,8 +479,7 @@ orderByClause[raw::select_statement::parameters::orderings_type& orderings]
;
jsonValue returns [uexpression value]
:
| s=STRING_LITERAL { $value = untyped_constant{untyped_constant::string, $s.text}; }
: s=STRING_LITERAL { $value = untyped_constant{untyped_constant::string, $s.text}; }
| m=marker { $value = std::move(m); }
;
Expand Down
6 changes: 6 additions & 0 deletions test/cql-pytest/test_bad_grammar.py
Expand Up @@ -22,3 +22,9 @@ def test_limit_empty(cql, table1):
cql.execute(f'SELECT * FROM {table1} LIMIT')
with pytest.raises(SyntaxException):
cql.execute(f'SELECT * FROM {table1} PER PARTITION LIMIT')

# INSERT JSON should require a JSON value
# Reproduces https://github.com/scylladb/scylladb/issues/14709
def test_json_empty(cql, table1):
with pytest.raises(SyntaxException):
cql.execute(f'INSERT INTO {table1} JSON')

0 comments on commit cbc97b4

Please sign in to comment.