This is an automated email from the ASF dual-hosted git repository.
adelapena pushed a commit to branch cassandra-5.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-5.0 by this push:
new 5eba52feb8 Add cqlsh autocompletion for the vector data type
5eba52feb8 is described below
commit 5eba52feb83d5cc68b7c2dea39eb64cad2e5338d
Author: Andrés de la Peña <[email protected]>
AuthorDate: Fri Oct 20 13:31:25 2023 +0100
Add cqlsh autocompletion for the vector data type
patch by Andrés de la Peña; reviewed by Brandon Williams for CASSANDRA-18946
---
CHANGES.txt | 1 +
pylib/cqlshlib/cql3handling.py | 20 +++++++++-------
pylib/cqlshlib/test/test_cqlsh_completion.py | 36 ++++++++++++++++++++++++----
pylib/cqlshlib/test/test_cqlsh_output.py | 12 ++++++----
pylib/cqlshlib/test/test_keyspace_init.cql | 30 ++++++++++++++++-------
5 files changed, 73 insertions(+), 26 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 517a20cdb8..317954aafb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.0-alpha2
+ * Add cqlsh autocompletion for the vector data type (CASSANDRA-18946)
* Fix nodetool tablehistograms output to avoid printing repeated information
and ensure at most two arguments (CASSANDRA-18955)
* Change the checksum algorithm SAI-related files use from CRC32 to CRC32C
(CASSANDRA-18836)
* Correctly remove Index.Group from IndexRegistry (CASSANDRA-18905)
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 39b08fcb1b..3c6518a0b9 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -21,7 +21,7 @@ from cqlshlib.cqlhandling import CqlParsingRuleSet, Hint
simple_cql_types = {'ascii', 'bigint', 'blob', 'boolean', 'counter', 'date',
'decimal', 'double', 'duration', 'float',
'inet', 'int', 'smallint', 'text', 'time', 'timestamp',
'timeuuid', 'tinyint', 'uuid', 'varchar',
'varint'}
-simple_cql_types.difference_update(('set', 'map', 'list'))
+simple_cql_types.difference_update(('set', 'map', 'list', 'vector'))
cqldocs = helptopics.CQL3HelpTopics()
@@ -305,7 +305,7 @@ JUNK ::= /([
\t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ;
<userType> ::= utname=<cfOrKsName> ;
-<storageType> ::= ( <simpleStorageType> | <collectionType> |
<frozenCollectionType> | <userType> ) ( <column_mask> )? ;
+<storageType> ::= ( <simpleStorageType> | <collectionType> |
<frozenCollectionType> | <vectorType> | <userType> ) ( <column_mask> )? ;
<column_mask> ::= "MASKED" "WITH" ( "DEFAULT" | <functionName>
<selectionFunctionArguments> );
@@ -321,6 +321,8 @@ JUNK ::= /([
\t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ;
| "frozen" "<" "set" "<" <storageType> ">" ">"
;
+<vectorType> ::= "vector" "<" <storageType> "," <wholenumber> ">" ;
+
<columnFamilyName> ::= ( ksname=<cfOrKsName> dot="." )? cfname=<cfOrKsName> ;
<materializedViewName> ::= ( ksname=<cfOrKsName> dot="." )?
mvname=<cfOrKsName> ;
@@ -922,9 +924,9 @@ def insert_newval_completer(ctxt, cass):
return []
curcol = insertcols[len(valuesdone)]
coltype = layout.columns[curcol].cql_type
- if coltype in ('map', 'set'):
+ if coltype.startswith('map<') or coltype.startswith('set<'):
return ['{']
- if coltype == 'list':
+ if coltype.startswith('list<') or coltype.startswith('vector<'):
return ['[']
if coltype == 'boolean':
return ['true', 'false']
@@ -999,10 +1001,10 @@ def update_countername_completer(ctxt, cass):
coltype = layout.columns[curcol].cql_type
if coltype == 'counter':
return [maybe_escape_name(curcol)]
- if coltype in ('map', 'set'):
- return ["{"]
- if coltype == 'list':
- return ["["]
+ if coltype.startswith('map<') or coltype.startswith('set<'):
+ return ['{']
+ if coltype.startswith('list<') or coltype.startswith('vector<'):
+ return ['[']
return [Hint('<term (%s)>' % coltype)]
@@ -1065,7 +1067,7 @@ def assignment_udt_field_completer(ctxt, cass):
def _is_usertype(layout, curcol):
coltype = layout.columns[curcol].cql_type
- return coltype not in simple_cql_types and coltype not in ('map', 'set',
'list')
+ return coltype not in simple_cql_types and coltype not in ('map', 'set',
'list', 'vector')
def _usertype_fields(ctxt, cass, layout, curcol):
diff --git a/pylib/cqlshlib/test/test_cqlsh_completion.py
b/pylib/cqlshlib/test/test_cqlsh_completion.py
index db59297a97..3fe46e878f 100644
--- a/pylib/cqlshlib/test/test_cqlsh_completion.py
+++ b/pylib/cqlshlib/test/test_cqlsh_completion.py
@@ -210,17 +210,17 @@ class TestCqlshCompletion(CqlshCompletionCase):
self.trycompletions(
'INSERT INTO twenty_rows_composite_table (a, b, c) VALUES (',
- ['<value for a (text)>'],
+ choices=['<value for a (text)>'],
split_completed_lines=False)
self.trycompletions(
"INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ('",
- ['<value for a (text)>'],
+ choices=['<value for a (text)>'],
split_completed_lines=False)
self.trycompletions(
"INSERT INTO twenty_rows_composite_table (a, b, c) VALUES ( 'eggs",
- ['<value for a (text)>'],
+ choices=['<value for a (text)>'],
split_completed_lines=False)
self.trycompletions(
@@ -230,7 +230,7 @@ class TestCqlshCompletion(CqlshCompletionCase):
self.trycompletions(
("INSERT INTO twenty_rows_composite_table (a, b, c) "
"VALUES ( 'eggs',"),
- ['<value for b (text)>'],
+ choices=['<value for b (text)>'],
split_completed_lines=False)
self.trycompletions(
@@ -323,6 +323,22 @@ class TestCqlshCompletion(CqlshCompletionCase):
"VALUES ( 'eggs', 'sausage', 'spam') USING TTL 0 AND TIMESTAMP 0
AND "),
choices=[])
+ self.trycompletions(
+ ("INSERT INTO has_all_types (num, setcol) VALUES (0, "),
+ immediate="{ ")
+
+ self.trycompletions(
+ ("INSERT INTO has_all_types (num, mapcol) VALUES (0, "),
+ immediate="{ ")
+
+ self.trycompletions(
+ ("INSERT INTO has_all_types (num, listcol) VALUES (0, "),
+ immediate="[ ")
+
+ self.trycompletions(
+ ("INSERT INTO has_all_types (num, vectorcol) VALUES (0, "),
+ immediate="[ ")
+
def test_complete_in_update(self):
self.trycompletions("UPD", immediate="ATE ")
self.trycompletions("UPDATE ",
@@ -631,6 +647,18 @@ class TestCqlshCompletion(CqlshCompletionCase):
self.trycompletions(prefix + ' new_table (col_a int PRIMARY KEY ',
choices=[')', ','])
+ self.trycompletions(prefix + ' new_table (col_a v',
+ choices=['varchar', 'varint', 'vector'])
+ self.trycompletions(prefix + ' new_table (col_a ve',
+ immediate='ctor ')
+ self.trycompletions(prefix + ' new_table (col_a vector<',
+ choices=['address', 'boolean', 'duration', 'list'],
+ other_choices_ok=True)
+ self.trycompletions(prefix + ' new_table (col_a vector<float, ',
+ choices=['<wholenumber>'])
+ self.trycompletions(prefix + ' new_table (col_a vector<float, 2 ',
+ immediate='>')
+
self.trycompletions(prefix + ' new_table (col_a int PRIMARY KEY,',
choices=['<identifier>', '<quotedName>'])
self.trycompletions(prefix + ' new_table (col_a int PRIMARY KEY)',
diff --git a/pylib/cqlshlib/test/test_cqlsh_output.py
b/pylib/cqlshlib/test/test_cqlsh_output.py
index 75f272b348..c17def624a 100644
--- a/pylib/cqlshlib/test/test_cqlsh_output.py
+++ b/pylib/cqlshlib/test/test_cqlsh_output.py
@@ -307,9 +307,9 @@ class TestCqlshOutput(BaseTestCase):
# same query should show up as empty in cql 3
self.assertQueriesGiveColoredOutput((
(q, """
- num | asciicol | bigintcol | blobcol | booleancol | decimalcol |
doublecol | durationcol | floatcol | intcol | smallintcol | textcol |
timestampcol | tinyintcol | uuidcol | varcharcol | varintcol
- RRR MMMMMMMM MMMMMMMMM MMMMMMM MMMMMMMMMM MMMMMMMMMM
MMMMMMMMM MMMMMMMMMMM MMMMMMMM MMMMMM MMMMMMMMMMM MMMMMMM
MMMMMMMMMMMM MMMMMMMMMM MMMMMMM MMMMMMMMMM MMMMMMMMM
-
-----+----------+-----------+---------+------------+------------+-----------+-------------+----------+--------+-------------+---------+--------------+------------+---------+------------+-----------
+ num | asciicol | bigintcol | blobcol | booleancol | decimalcol |
doublecol | durationcol | floatcol | intcol | listcol | mapcol | setcol |
smallintcol | textcol | timestampcol | tinyintcol | uuidcol | varcharcol |
varintcol | vectorcol
+ RRR MMMMMMMM MMMMMMMMM MMMMMMM MMMMMMMMMM MMMMMMMMMM
MMMMMMMMM MMMMMMMMMMM MMMMMMMM MMMMMM MMMMMMM MMMMMM MMMMMM
MMMMMMMMMMM MMMMMMM MMMMMMMMMMMM MMMMMMMMMM MMMMMMM MMMMMMMMMM
MMMMMMMMM MMMMMMMMM
+
-----+----------+-----------+---------+------------+------------+-----------+-------------+----------+--------+---------+--------+--------+-------------+---------+--------------+------------+---------+------------+-----------+-----------
(0 rows)
@@ -675,7 +675,11 @@ class TestCqlshOutput(BaseTestCase):
tinyintcol tinyint,
uuidcol uuid,
varcharcol text,
- varintcol varint
+ varintcol varint,
+ vectorcol vector<float, 3>,
+ listcol list<text>,
+ mapcol map<text, int>,
+ setcol set<text>
) WITH additional_write_policy = '99p'
AND allow_auto_snapshot = true
AND bloom_filter_fp_chance = 0.01
diff --git a/pylib/cqlshlib/test/test_keyspace_init.cql
b/pylib/cqlshlib/test/test_keyspace_init.cql
index 9eea478be3..6862413581 100644
--- a/pylib/cqlshlib/test/test_keyspace_init.cql
+++ b/pylib/cqlshlib/test/test_keyspace_init.cql
@@ -33,38 +33,50 @@ CREATE TABLE has_all_types (
tinyintcol tinyint,
uuidcol uuid,
varcharcol varchar,
- varintcol varint
+ varintcol varint,
+ listcol list<text>,
+ setcol set<text>,
+ mapcol map<text, int>,
+ vectorcol vector<float, 3>,
) WITH compression = {'class':'LZ4Compressor'};
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol,
booleancol,
decimalcol, doublecol, durationcol, floatcol,
smallintcol, textcol,
- timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol)
+ timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol,
+ listcol, setcol, mapcol, vectorcol)
VALUES (0, -12, 'abcdefg', 1234567890123456789, 0x000102030405fffefd, true,
19952.11882, 1.0, 12h, -2.1, 32767, 'Voilá!',
- '2012-05-14 12:53:20+0000', 127, bd1924e1-6af8-44ae-b5e1-f24131dbd460,
'"', 10000000000000000000000000);
+ '2012-05-14 12:53:20+0000', 127, bd1924e1-6af8-44ae-b5e1-f24131dbd460,
'"', 10000000000000000000000000,
+ ['a', 'b', 'c'], {'a', 'b', 'c'}, {'a': 1, 'b': 2, 'c': 3}, [1.0, 2.0,
3.0]);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol,
booleancol,
decimalcol, doublecol, durationcol, floatcol,
smallintcol, textcol,
- timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol)
+ timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol,
+ listcol, setcol, mapcol, vectorcol)
VALUES (1, 2147483647, '__!''$#@!~"', 9223372036854775807,
0xffffffffffffffffff, true,
0.00000000000001, 9999999.999, 12h30m, 99999.999, 32767, '∭Ƕ⑮ฑ➳❏''',
'1950-01-01+0000', 127, ffffffff-ffff-ffff-ffff-ffffffffffff,
'newline->
-<-', 9);
+<-', 9,
+['__!''$#@!~"'], {'__!''$#@!~"'}, {'__!''$#@!~"': 2147483647}, [1, -2.0, NaN]);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol,
booleancol,
decimalcol, doublecol, durationcol, floatcol,
smallintcol, textcol,
- timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol)
+ timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol,
+ listcol, setcol, mapcol, vectorcol)
VALUES (2, 0, '', 0, 0x, false,
0.0, 0.0, 12h30m30s, 0.0, 0, '',
- 0, 0, 00000000-0000-0000-0000-000000000000, '', 0);
+ 0, 0, 00000000-0000-0000-0000-000000000000, '', 0,
+ [], {}, {}, [0.0, 0.0, 0.0]);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol,
booleancol,
decimalcol, doublecol, durationcol, floatcol,
smallintcol, textcol,
- timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol)
+ timestampcol, tinyintcol, uuidcol, varcharcol,
varintcol,
+ listcol, setcol, mapcol, vectorcol)
VALUES (3, -2147483648, '''''''', -9223372036854775808, 0x80, false,
10.0000000000000, -1004.10, 12h30m30s250ms, 100000000.9, 32767, '龍馭鬱',
'2038-01-19T03:14-1200', 127, ffffffff-ffff-1fff-8fff-ffffffffffff,
- '''', -10000000000000000000000000);
+ '''', -10000000000000000000000000,
+ ['龍馭鬱'], {'龍馭鬱'}, {'龍馭鬱': -2147483648}, [100000000.9, 100000000.9,
100000000.9]);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol,
booleancol,
decimalcol, doublecol, floatcol, smallintcol,
textcol,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]