You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Caleb Rackliffe (Jira)" <ji...@apache.org> on 2024/08/26 18:33:00 UTC
[jira] [Comment Edited] (CASSANDRA-19688) SAI support for BETWEEN operator
[ https://issues.apache.org/jira/browse/CASSANDRA-19688?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17876819#comment-17876819 ]
Caleb Rackliffe edited comment on CASSANDRA-19688 at 8/26/24 6:32 PM:
----------------------------------------------------------------------
We've added some additional testing w/ {{IndexQuerySupport}} for descending clustering orders w/ BETWEEEN, and we're getting some strange results. A simple set of tests that indicates the problem would be the following:
{noformat}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.index.sai.cql;
import com.datastax.driver.core.ResultSet;
import org.apache.cassandra.cql3.UntypedResultSet;
import org.apache.cassandra.index.sai.SAITester;
import org.junit.Test;
public class DescClusteringRangeQueryTest extends SAITester
{
@Test
public void testReverseAndBetweenMemtable()
{
// -Dcassandra.test.random.seed=-2111569943044846907 (TrieMemtable)
// -Dcassandra.test.random.seed=2908580607432529589 (ShardedSkipListMemtable)
// -Dcassandra.test.random.seed=336757681742614926 (SkipListMemtable)
createTable("CREATE TABLE %s(p int, c int, abbreviation ascii, PRIMARY KEY (p, c)) WITH CLUSTERING ORDER BY (c DESC)");
createIndex("CREATE INDEX clustering_test_index ON %s(c) USING 'sai'");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 1, 'CA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 2, 'MA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 3, 'MS')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 4, 'TX')");
UntypedResultSet rangeRows = execute("SELECT * FROM %s WHERE c >= 2 AND c <= 3");
assertRows(rangeRows, row (0, 3, "MS"), row (0, 2, "MA"));
ResultSet rangeRowsNet = executeNet("SELECT * FROM %s WHERE c >= 2 AND c <= 3");
assertRowsNet(rangeRowsNet, row (0, 3, "MS"), row (0, 2, "MA"));
UntypedResultSet betweenRows = execute("SELECT * FROM %s WHERE c BETWEEN 2 AND 3");
assertRows(betweenRows, row (0, 3, "MS"), row (0, 2, "MA"));
ResultSet betweenRowsNet = executeNet("SELECT * FROM %s WHERE c BETWEEN 2 AND 3");
assertRowsNet(betweenRowsNet, row (0, 3, "MS"), row (0, 2, "MA"));
}
@Test
public void testReverseAndBetweenSSTable()
{
// -Dcassandra.test.random.seed=-3481171747941629309 (bti)
// -Dcassandra.test.random.seed=-4375377577732286980 (big)
createTable("CREATE TABLE %s(p int, c int, abbreviation ascii, PRIMARY KEY (p, c)) WITH CLUSTERING ORDER BY (c DESC)");
createIndex("CREATE INDEX clustering_test_index ON %s(c) USING 'sai'");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 1, 'CA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 2, 'MA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 3, 'MS')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 4, 'TX')");
flush();
UntypedResultSet rangeRows = execute("SELECT * FROM %s WHERE c >= 2 AND c <= 3");
assertRows(rangeRows, row (0, 3, "MS"), row (0, 2, "MA"));
ResultSet rangeRowsNet = executeNet("SELECT * FROM %s WHERE c >= 2 AND c <= 3");
assertRowsNet(rangeRowsNet, row (0, 3, "MS"), row (0, 2, "MA"));
UntypedResultSet betweenRows = execute("SELECT * FROM %s WHERE c BETWEEN 2 AND 3");
assertRows(betweenRows, row (0, 3, "MS"), row (0, 2, "MA"));
ResultSet betweenRowsNet = executeNet("SELECT * FROM %s WHERE c BETWEEN 2 AND 3");
assertRowsNet(betweenRowsNet, row (0, 3, "MS"), row (0, 2, "MA"));
}
}
{noformat}
Two things are very odd here. First, identical range queries pass without any trouble. Second, the BETWEEN queries only fail when using a real driver session rather than hitting {{QueryProcessor}} directly via {{CQLTester}}.
was (Author: maedhroz):
We've added some additional testing w/ {{IndexQuerySupport}} for descending clustering orders w/ BETWEEEN, and we're getting some strange results. A simple set of tests that indicates the problem would be the following:
{noformat}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.index.sai.cql;
import com.datastax.driver.core.ResultSet;
import org.apache.cassandra.index.sai.SAITester;
import org.junit.Test;
public class DescClusteringRangeQueryTest extends SAITester
{
@Test
public void testReverseAndBetweenMemtable()
{
// -Dcassandra.test.random.seed=-2111569943044846907 (TrieMemtable)
// -Dcassandra.test.random.seed=2908580607432529589 (ShardedSkipListMemtable)
// -Dcassandra.test.random.seed=336757681742614926 (SkipListMemtable)
createTable("CREATE TABLE %s(p int, c int, abbreviation ascii, PRIMARY KEY (p, c)) WITH CLUSTERING ORDER BY (c DESC)");
createIndex("CREATE INDEX clustering_test_index ON %s(c) USING 'sai'");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 1, 'CA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 2, 'MA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 3, 'MS')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 4, 'TX')");
ResultSet rangeRows = executeNet("SELECT * FROM %s WHERE c >= 2 AND c <= 3");
assertRowsNet(rangeRows, row (0, 3, "MS"), row (0, 2, "MA"));
ResultSet betweenRows = executeNet("SELECT * FROM %s WHERE c BETWEEN 2 AND 3");
assertRowsNet(betweenRows, row (0, 3, "MS"), row (0, 2, "MA"));
}
@Test
public void testReverseAndBetweenSSTable()
{
// -Dcassandra.test.random.seed=-3481171747941629309 (bti)
// -Dcassandra.test.random.seed=-4375377577732286980 (big)
createTable("CREATE TABLE %s(p int, c int, abbreviation ascii, PRIMARY KEY (p, c)) WITH CLUSTERING ORDER BY (c DESC)");
createIndex("CREATE INDEX clustering_test_index ON %s(c) USING 'sai'");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 1, 'CA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 2, 'MA')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 3, 'MS')");
execute("INSERT INTO %s(p, c, abbreviation) VALUES (0, 4, 'TX')");
flush();
ResultSet rangeRows = executeNet("SELECT * FROM %s WHERE c >= 2 AND c <= 3");
assertRowsNet(rangeRows, row (0, 3, "MS"), row (0, 2, "MA"));
ResultSet betweenRows = executeNet("SELECT * FROM %s WHERE c BETWEEN 2 AND 3");
assertRowsNet(betweenRows, row (0, 3, "MS"), row (0, 2, "MA"));
}
}
{noformat}
> SAI support for BETWEEN operator
> --------------------------------
>
> Key: CASSANDRA-19688
> URL: https://issues.apache.org/jira/browse/CASSANDRA-19688
> Project: Cassandra
> Issue Type: New Feature
> Components: CQL/Syntax, Feature/SAI
> Reporter: Caleb Rackliffe
> Assignee: Arun Ganesh
> Priority: Normal
> Fix For: 5.x
>
> Time Spent: 50m
> Remaining Estimate: 0h
>
> The new CQL BETWEEN operator should map pretty neatly to SAI’s internal RANGE operator for numeric indexes. There’s no reason we shouldn’t support it.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org