From cb9e2ee00a176064cc4458df9aa0312359697e2f Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Fri, 22 Jan 2021 01:38:55 +0200 Subject: [PATCH] cql-pytest: tests for fromJson() setting a map The fromJson() function can take a map JSON and use it to set a map column. However, the specific example of a map doesn't work in Scylla (it does work in Cassandra). The xfailing tests in this patch demonstrate this. Although the tests use perfectly legal ASCII, scylla fails the fromJson() function, with a misleading error. Refs #7949. Signed-off-by: Nadav Har'El Message-Id: <20210121233855.100640-1-nyh@scylladb.com> --- test/cql-pytest/test_json.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/cql-pytest/test_json.py b/test/cql-pytest/test_json.py index ca831913da..9bc6bfde2f 100644 --- a/test/cql-pytest/test_json.py +++ b/test/cql-pytest/test_json.py @@ -34,7 +34,7 @@ import random @pytest.fixture(scope="session") def table1(cql, test_keyspace): table = test_keyspace + "." + unique_name() - cql.execute(f"CREATE TABLE {table} (p int PRIMARY KEY, v int, a ascii, b boolean, vi varint)") + cql.execute(f"CREATE TABLE {table} (p int PRIMARY KEY, v int, a ascii, b boolean, vi varint, mai map)") yield table cql.execute("DROP TABLE " + table) @@ -176,3 +176,18 @@ def test_fromjson_null_prepared(cql, table1): stmt = cql.prepare(f"INSERT INTO {table1} (p, v) VALUES (?, fromJson(?))") cql.execute(stmt, [p, None]) assert list(cql.execute(f"SELECT p, v from {table1} where p = {p}")) == [(p, None)] + +# Test that fromJson can parse a map. Strangely Scylla had a bug +# setting a map with fromJson(), while map worked well. +# Reproduces #7949. +@pytest.mark.xfail(reason="issue #7949") +def test_fromjson_map_ascii_unprepared(cql, table1): + p = random.randint(1,1000000000) + cql.execute("INSERT INTO " + table1 + " (p, mai) VALUES (" + str(p) + ", fromJson('{\"a\": 1, \"b\": 2}'))") + assert list(cql.execute(f"SELECT p, mai from {table1} where p = {p}")) == [(p, {'a': 1, 'b': 2})] +@pytest.mark.xfail(reason="issue #7949") +def test_fromjson_map_ascii_prepared(cql, table1): + p = random.randint(1,1000000000) + stmt = cql.prepare(f"INSERT INTO {table1} (p, mai) VALUES (?, fromJson(?))") + cql.execute(stmt, [p, '{"a": 1, "b": 2}']) + assert list(cql.execute(f"SELECT p, mai from {table1} where p = {p}")) == [(p, {'a': 1, 'b': 2})]