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

Stefan Miklosovic edited comment on CASSANDRA-20161 at 1/31/25 4:51 PM:
------------------------------------------------------------------------

Another problem is that I am not sure how to select on keys which are strings. 
Check this:
{noformat}
cassandra@cqlsh> DESCRIBE ks.tb2;

CREATE TABLE ks.tb2 (id text PRIMARY KEY) ...

cassandra@cqlsh> select * from ks.tb2;

       id
----------
        a
 O'Reilly(2 rows)

cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb2' and key = 'a';
SyntaxException: Failed parsing CQL term: [a] reason: SyntaxException line 0:-1 
no viable alternative at input '<EOF>'
cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb2' and key = 'O''Reilly';
SyntaxException: Failed parsing CQL term: [O'Reilly] reason: SyntaxException 
line 1:8 mismatched character '<EOF>' expecting '''
{noformat}
Huh? it works when key is int:
{noformat}
cassandra@cqlsh> DESCRIBE ks.tb;
CREATE TABLE ks.tb (
    id int PRIMARY KEY,
    val text
) ..

cassandra@cqlsh> select * from ks.tb;

 id | val
----+-----
  1 |   a

(1 rows)

cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb' and key = '1';

 keyspace_name | table_name | token_value          | key | size_estimate | 
sstables
---------------+------------+----------------------+-----+---------------+----------
            ks |         tb | -4069959284402364209 |   1 |            15 |      
  1

(1 rows)
{noformat}
 

EDIT:

OK, so this works:
{noformat}
cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb2' and key = '''a''';

 keyspace_name | table_name | token_value          | key | size_estimate | 
sstables
---------------+------------+----------------------+-----+---------------+----------
            ks |        tb2 | -8839064797231613815 | 'a' |             9 |      
  1
 {noformat}
That is a little bit  ... yikes.

Also for tables like this:
{noformat}
CREATE TABLE ks.tb3 (
    id1 text,
    id2 text,
    val int,
    PRIMARY KEY ((id1, id2))
)  {noformat}
I was not able to do that, all I could do is to do select on vtable without any 
key and then do this:
{code:java}
cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb3' and key = '0x0001610000016200'; 

 keyspace_name | table_name | token_value         | key                | 
size_estimate | sstables
---------------+------------+---------------------+--------------------+---------------+----------
            ks |        tb3 | 7470152180878494447 | 0x0001610000016200 |        
    21 |        1
 {code}
 


was (Author: smiklosovic):
Another problem is that I am not sure how to select on keys which are strings. 
Check this:
{noformat}
cassandra@cqlsh> DESCRIBE ks.tb2;

CREATE TABLE ks.tb2 (id text PRIMARY KEY) ...

cassandra@cqlsh> select * from ks.tb2;

       id
----------
        a
 O'Reilly(2 rows)

cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb2' and key = 'a';
SyntaxException: Failed parsing CQL term: [a] reason: SyntaxException line 0:-1 
no viable alternative at input '<EOF>'
cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb2' and key = 'O''Reilly';
SyntaxException: Failed parsing CQL term: [O'Reilly] reason: SyntaxException 
line 1:8 mismatched character '<EOF>' expecting '''
{noformat}
Huh? it works when key is int:
{noformat}
cassandra@cqlsh> DESCRIBE ks.tb;
CREATE TABLE ks.tb (
    id int PRIMARY KEY,
    val text
) ..

cassandra@cqlsh> select * from ks.tb;

 id | val
----+-----
  1 |   a

(1 rows)

cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb' and key = '1';

 keyspace_name | table_name | token_value          | key | size_estimate | 
sstables
---------------+------------+----------------------+-----+---------------+----------
            ks |         tb | -4069959284402364209 |   1 |            15 |      
  1(1 rows)
{noformat}
 

EDIT:

OK, so this works:
{noformat}
cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb2' and key = '''a''';

 keyspace_name | table_name | token_value          | key | size_estimate | 
sstables
---------------+------------+----------------------+-----+---------------+----------
            ks |        tb2 | -8839064797231613815 | 'a' |             9 |      
  1
 {noformat}
That is a little bit  ... yikes.

Also for tables like this:
{noformat}
CREATE TABLE ks.tb3 (
    id1 text,
    id2 text,
    val int,
    PRIMARY KEY ((id1, id2))
)  {noformat}
I was not able to do that, all I could do is to do select on vtable without any 
key and then do this:
{code:java}
cassandra@cqlsh> select * from system_views.primary_ids where keyspace_name = 
'ks' and table_name = 'tb3' and key = '0x0001610000016200'; 

 keyspace_name | table_name | token_value         | key                | 
size_estimate | sstables
---------------+------------+---------------------+--------------------+---------------+----------
            ks |        tb3 | 7470152180878494447 | 0x0001610000016200 |        
    21 |        1
 {code}
 

> Virtual table to query partition keys in a table
> ------------------------------------------------
>
>                 Key: CASSANDRA-20161
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-20161
>             Project: Apache Cassandra
>          Issue Type: New Feature
>          Components: Feature/Virtual Tables
>            Reporter: Chris Lohfink
>            Assignee: Chris Lohfink
>            Priority: Low
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Introduce a new virtual table, {{{}PrimaryIdTable{}}}, to allow users to 
> query partition keys and related metadata for a specific table within a 
> keyspace. This feature provides insights into SSTable-level details, such as 
> token values, size estimates, and SSTable counts, without requiring expensive 
> disk-based operations.



--
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