use of org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal in project cassandra by apache.
the class SinglePartitionSliceCommandTest method testPartitionDeletionRowDeletionTie.
/**
* Partition deletion should remove row deletion when tie
*/
@Test
public void testPartitionDeletionRowDeletionTie() {
QueryProcessor.executeOnceInternal("CREATE TABLE ks.partition_row_deletion (k int, c int, v int, primary key (k, c))");
TableMetadata metadata = Schema.instance.getTableMetadata("ks", "partition_row_deletion");
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(metadata.id);
cfs.disableAutoCompaction();
BiFunction<Boolean, Boolean, List<Unfiltered>> tester = (flush, multiSSTable) -> {
cfs.truncateBlocking();
// timestamp and USING TIMESTAMP have different values to ensure the correct timestamp (the one specified in the
// query) is the one being picked up. For safety reason we want to be able to ensure that further to its main goal
// the test can also detect wrongful change of the code. The current timestamp retrieved from the ClientState is
// ignored but nowInSeconds is retrieved from it and used for the DeletionTime. It shows the difference between the
// time at which the record was marked for deletion and the time at which it truly happened.
final long timestamp = FBUtilities.timestampMicros();
final int nowInSec = FBUtilities.nowInSeconds();
QueryProcessor.executeOnceInternalWithNowAndTimestamp(nowInSec, timestamp, "DELETE FROM ks.partition_row_deletion USING TIMESTAMP 10 WHERE k=1");
if (flush && multiSSTable)
cfs.forceBlockingFlush();
QueryProcessor.executeOnceInternalWithNowAndTimestamp(nowInSec, timestamp, "DELETE FROM ks.partition_row_deletion USING TIMESTAMP 10 WHERE k=1 and c=1");
if (flush)
cfs.forceBlockingFlush();
QueryProcessor.executeOnceInternal("INSERT INTO ks.partition_row_deletion(k,c,v) VALUES(1,1,1) using timestamp 11");
if (flush) {
cfs.forceBlockingFlush();
try {
cfs.forceMajorCompaction();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
try (UnfilteredRowIterator partition = getIteratorFromSinglePartition("SELECT * FROM ks.partition_row_deletion where k=1 and c=1")) {
assertEquals(10, partition.partitionLevelDeletion().markedForDeleteAt());
return toUnfiltereds(partition);
}
};
List<Unfiltered> memtableUnfiltereds = tester.apply(false, false);
List<Unfiltered> singleSSTableUnfiltereds = tester.apply(true, false);
List<Unfiltered> multiSSTableUnfiltereds = tester.apply(true, true);
assertEquals(1, singleSSTableUnfiltereds.size());
String errorMessage = String.format("Expected %s but got %s", toString(memtableUnfiltereds, metadata), toString(singleSSTableUnfiltereds, metadata));
assertEquals(errorMessage, memtableUnfiltereds, singleSSTableUnfiltereds);
errorMessage = String.format("Expected %s but got %s", toString(singleSSTableUnfiltereds, metadata), toString(multiSSTableUnfiltereds, metadata));
assertEquals(errorMessage, singleSSTableUnfiltereds, multiSSTableUnfiltereds);
memtableUnfiltereds.forEach(u -> assertTrue("Expected no row deletion, but got " + u.toString(metadata, true), ((Row) u).deletion().isLive()));
}
use of org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal in project cassandra by apache.
the class SASIIndexTest method testConditionalsWithReversedType.
@Test
public void testConditionalsWithReversedType() {
final String TABLE_NAME = "reversed_clustering";
QueryProcessor.executeOnceInternal(String.format("CREATE TABLE IF NOT EXISTS %s.%s (pk text, ck int, v int, PRIMARY KEY (pk, ck)) " + "WITH CLUSTERING ORDER BY (ck DESC);", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (ck) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 1, 1);", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 2, 2);", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 3, 3);", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 1, 1);", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 2, 2);", KS_NAME, TABLE_NAME));
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 3, 3);", KS_NAME, TABLE_NAME));
UntypedResultSet resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2;", KS_NAME, TABLE_NAME));
CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 1, 1), CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 1, 1), CQLTester.row("Tom", 2, 2));
resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2 AND v > 1 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 2, 2));
resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck < 2;", KS_NAME, TABLE_NAME));
CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 1, 1), CQLTester.row("Tom", 1, 1));
resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2;", KS_NAME, TABLE_NAME));
CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Alex", 3, 3), CQLTester.row("Tom", 2, 2), CQLTester.row("Tom", 3, 3));
resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2 AND v < 3 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 2, 2));
resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck > 2;", KS_NAME, TABLE_NAME));
CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 3, 3), CQLTester.row("Tom", 3, 3));
}
use of org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal in project cassandra by apache.
the class SASIIndexTest method testLIKEAndEQSemanticsWithDifferenceKindsOfIndexes.
private void testLIKEAndEQSemanticsWithDifferenceKindsOfIndexes(String containsTable, String prefixTable, String analyzedPrefixTable, String tokenizedContainsTable, boolean forceFlush) {
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, containsTable), 0, "Pavel");
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, prefixTable), 0, "Jean-Claude");
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, analyzedPrefixTable), 0, "Jean-Claude");
QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, tokenizedContainsTable), 0, "Pavel");
if (forceFlush) {
Keyspace keyspace = Keyspace.open(KS_NAME);
for (String table : Arrays.asList(containsTable, prefixTable, analyzedPrefixTable)) keyspace.getColumnFamilyStore(table).forceBlockingFlush();
}
UntypedResultSet results;
// CONTAINS
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(0, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav%%';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pavel';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Pav';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(0, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Pavel';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
try {
QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Pav';", KS_NAME, tokenizedContainsTable));
Assert.fail();
} catch (InvalidRequestException e) {
// expected since CONTAINS + analyzed indexes only support LIKE
}
try {
QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav%%';", KS_NAME, tokenizedContainsTable));
Assert.fail();
} catch (InvalidRequestException e) {
// expected since CONTAINS + analyzed only support LIKE
}
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav%%';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Pav';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(0, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Pav%%';", KS_NAME, containsTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
// PREFIX
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Jean';", KS_NAME, prefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(0, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Jean-Claude';", KS_NAME, prefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jea';", KS_NAME, prefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(0, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jea%%';", KS_NAME, prefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
try {
QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Jea';", KS_NAME, prefixTable));
Assert.fail();
} catch (InvalidRequestException e) {
// expected since PREFIX indexes only support LIKE '<term>%'
}
try {
QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Jea%%';", KS_NAME, prefixTable));
Assert.fail();
} catch (InvalidRequestException e) {
// expected since PREFIX indexes only support LIKE '<term>%'
}
try {
QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Jean';", KS_NAME, analyzedPrefixTable));
Assert.fail();
} catch (InvalidRequestException e) {
// expected since PREFIX indexes only support EQ without tokenization
}
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jean';", KS_NAME, analyzedPrefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Claude';", KS_NAME, analyzedPrefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jean-Claude';", KS_NAME, analyzedPrefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jean%%';", KS_NAME, analyzedPrefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Claude%%';", KS_NAME, analyzedPrefixTable));
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
try {
QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Jean';", KS_NAME, analyzedPrefixTable));
Assert.fail();
} catch (InvalidRequestException e) {
// expected since PREFIX indexes only support LIKE '<term>%' and LIKE '<term>'
}
try {
QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Claude%%';", KS_NAME, analyzedPrefixTable));
Assert.fail();
} catch (InvalidRequestException e) {
// expected since PREFIX indexes only support LIKE '<term>%' and LIKE '<term>'
}
for (String table : Arrays.asList(containsTable, prefixTable, analyzedPrefixTable)) QueryProcessor.executeOnceInternal(String.format("TRUNCATE TABLE %s.%s", KS_NAME, table));
}
use of org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal in project cassandra by apache.
the class SinglePartitionSliceCommandTest method testPartitionDeletionRangeDeletionTie.
/**
* Partition deletion should remove range deletion when tie
*/
@Test
public void testPartitionDeletionRangeDeletionTie() {
QueryProcessor.executeOnceInternal("CREATE TABLE ks.partition_range_deletion (k int, c1 int, c2 int, v int, primary key (k, c1, c2))");
TableMetadata metadata = Schema.instance.getTableMetadata("ks", "partition_range_deletion");
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(metadata.id);
cfs.disableAutoCompaction();
BiFunction<Boolean, Boolean, List<Unfiltered>> tester = (flush, multiSSTable) -> {
cfs.truncateBlocking();
// timestamp and USING TIMESTAMP have different values to ensure the correct timestamp (the one specified in the
// query) is the one being picked up. For safety reason we want to be able to ensure that further to its main goal
// the test can also detect wrongful change of the code. The current timestamp retrieved from the ClientState is
// ignored but nowInSeconds is retrieved from it and used for the DeletionTime. It shows the difference between the
// time at which the record was marked for deletion and the time at which it truly happened.
final long timestamp = FBUtilities.timestampMicros();
final int nowInSec = FBUtilities.nowInSeconds();
QueryProcessor.executeOnceInternalWithNowAndTimestamp(nowInSec, timestamp, "DELETE FROM ks.partition_range_deletion USING TIMESTAMP 10 WHERE k=1");
if (flush && multiSSTable)
cfs.forceBlockingFlush();
QueryProcessor.executeOnceInternalWithNowAndTimestamp(nowInSec, timestamp, "DELETE FROM ks.partition_range_deletion USING TIMESTAMP 10 WHERE k=1 and c1=1");
if (flush)
cfs.forceBlockingFlush();
QueryProcessor.executeOnceInternal("INSERT INTO ks.partition_range_deletion(k,c1,c2,v) VALUES(1,1,1,1) using timestamp 11");
if (flush) {
cfs.forceBlockingFlush();
try {
cfs.forceMajorCompaction();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
try (UnfilteredRowIterator partition = getIteratorFromSinglePartition("SELECT * FROM ks.partition_range_deletion where k=1 and c1=1 and c2=1")) {
assertEquals(10, partition.partitionLevelDeletion().markedForDeleteAt());
return toUnfiltereds(partition);
}
};
List<Unfiltered> memtableUnfiltereds = tester.apply(false, false);
List<Unfiltered> singleSSTableUnfiltereds = tester.apply(true, false);
List<Unfiltered> multiSSTableUnfiltereds = tester.apply(true, true);
assertEquals(1, singleSSTableUnfiltereds.size());
String errorMessage = String.format("Expected %s but got %s", toString(memtableUnfiltereds, metadata), toString(singleSSTableUnfiltereds, metadata));
assertEquals(errorMessage, memtableUnfiltereds, singleSSTableUnfiltereds);
errorMessage = String.format("Expected %s but got %s", toString(singleSSTableUnfiltereds, metadata), toString(multiSSTableUnfiltereds, metadata));
assertEquals(errorMessage, singleSSTableUnfiltereds, multiSSTableUnfiltereds);
memtableUnfiltereds.forEach(u -> assertTrue("Expected row, but got " + u.toString(metadata, true), u.isRow()));
}
Aggregations