A query like
select *
from table
where col1 = 'val'
and col2 = 'val2'
and col3 != 'val3'
returns empty result even if I have data in my table which satisfies these conditions. <col1, col2> are the partition keys and col3 is the clustering key for the cassandra table.
I debugged this and was able to find this in the log
com.facebook.presto.cassandra.CassandraRecordSetProvider Creating record set:
SELECT col1,col2,col3 FROM keyspace.table
WHERE col1 = 'val'
AND col2 = 'val2'
AND col3 < 'val3' AND col3 > 'val3'
What is the type of col1, col2 and col3? Are those char types?
col1 and col2 are partition keys and a mix of integer, text, col3 is the clustering key and is text.
Following are steps to reproduce.
-- Prepare data (cqlsh)
CREATE TABLE t10783 (
col1 int,
col2 text,
col3 text,
PRIMARY KEY ((col1, col2), col3)
) WITH CLUSTERING ORDER BY (col3 DESC)
;
insert into t10783 (col1, col2, col3) values (1, 'val2', 'val3')
;
insert into t10783 (col1, col2, col3) values (1, 'val2', 'expect hit')
;
-- Reproduce an issue (presto-cli)
select
*
from t10783
where col1 = 1
and col2 = 'val2'
and col3 != 'val3'
;
Workaround example. A Part of and trim(col3) != 'val3' are executed on presto side.
select
*
from t10783
where col1 = 1
and col2 = 'val2'
and trim(col3) != 'val3'
;