prestodb / presto

The official home of the Presto distributed SQL query engine for big data
http://prestodb.io
Apache License 2.0
15.98k stars 5.36k forks source link

Inequality on clustering key returns empty results in cassandra #10783

Open aandis opened 6 years ago

aandis commented 6 years ago

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.

aandis commented 6 years ago

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'
sopel39 commented 6 years ago

What is the type of col1, col2 and col3? Are those char types?

aandis commented 6 years ago

col1 and col2 are partition keys and a mix of integer, text, col3 is the clustering key and is text.

ebyhr commented 6 years ago

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