[ 
https://issues.apache.org/jira/browse/CASSANDRA-15458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17654193#comment-17654193
 ] 

Yaman Ziadeh commented on CASSANDRA-15458:
------------------------------------------

Created a PR ([https://github.com/apache/cassandra/pull/2063)] to standardize 
all formatting in pylib/cqlshlib/formatting.py to be unquoted (quote=False) and 
escaped. Previously, collections formatting was not consistent with text 
formatting as mentioned above. With these proposed changes, retrieved text, 
map, set, list, tuple, and UDT data will be escaped and unquoted. 

For example,
{code:java}
CREATE KEYSPACE test WITH replication = {'class': 'NetworkTopologyStrategy', 
'datacenter1': 3};
USE test;
CREATE TABLE t1 (id int, data map<int, text>, PRIMARY KET (id));
INSERT INTO t1 (id, data) values (1, 'I''m newb');{code}
When fetching Map data from table t1, this would have been the output prior to 
these changes:
{code:java}
 id | data
----+---------------
  1 | {1: 'I''m newb'} {code}
Now, the data will be escaped and unquoted as such:
{code:java}
 id | data
----+---------------
  1 | {1: I'm newb} {code}
Previously for Sets:
{code:java}
 id | data
----+------------
  1 | {'I''m newb'} {code}
and now:
{code:java}
 id | data
----+------------
  1 | {I'm newb}{code}
Previously for UDTs:
{code:java}
CREATE TYPE random (data text);
CREATE TABLE t5 (id int, data random, PRIMARY KEY(id));
INSERT INTO t5 (id, data) values (1, {data: 'I''m newb'});
SELECT * FROM t5;

 id | data
----+------------------
  1 | {data: 'I''m newb'} {code}
and now:
{code:java}
 id | data
----+------------------
  1 | {data: I'm newb} {code}

Let me know what you think!




 

 

> CQL: Unable to escape single quote in a map<int,text> attribute
> ---------------------------------------------------------------
>
>                 Key: CASSANDRA-15458
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-15458
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL/Interpreter, CQL/Semantics
>            Reporter: Abhijeet Singh
>            Assignee: Yaman Ziadeh
>            Priority: Normal
>              Labels: AdventCalendar2021, lhf
>         Attachments: cass-screen.png
>
>
> h3. Overview
> For {{text}} attributes, CQL allows escaping single quote [using additional 
> single 
> quote|http://mail-archives.apache.org/mod_mbox/cassandra-user/201108.mbox/%3c20110803152250.294...@gmx.net%3E].
>  But applying the same syntax for a {{map<int,text>}} attribute does not 
> work. Inconsistent behavior was observed between {{text}} datatype and 
> {{map<int,text>}} datatype.
> h3. CQL semantic proposal
> Cassandra (CQL) should apply same escaping semantics on {{text}} and 
> text-within-map {{map<int,text>}} datatypes.
> h3. Reproducing the bug:
> CREATE query: 
> {code:java}
> CREATE TABLE university.test (id int, data map<int, text>, PRIMARY KEY 
> (id));{code}
>  INSERT query: 
> {code:java}
> insert into university.test (id, data) values(1, {1:'I''m newb'});{code}
> On running the aforementioned INSERT query, Cassandra inserts and returns 
> {{\{1: 'I''m newb'}}} while the expected result is {{\{1: 'I'm newb'}}}
> h3. Technical details 
> OS: CentOS 7
> Kernel: Linux 3.10.0-1062.9.1.el7.x86_64
> Cassandra version: 3.11.5
> Screenshot: [Output after SELECT query|https://i.stack.imgur.com/PLAan.png]
>   
> +Additional information for newcomers:+
> The issue seems to come from the ANTLR Lexer logic for {{STRING_LITERAL}}. A 
> unit test should also be added in {{SelectTest}}



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

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to