@@ -57,20 +57,60 @@ public void testTwoIndexes()
57
57
assertInvalidMessage ("BM25 ordering on column v requires an analyzed index" ,
58
58
"SELECT k FROM %s WHERE v : 'apple' ORDER BY v BM25 OF 'apple' LIMIT 3" );
59
59
60
- // create analyzed index
61
- analyzeIndex ();
60
+ createAnalyzedIndex ();
62
61
// BM25 query should work now
63
62
var result = execute ("SELECT k FROM %s WHERE v : 'apple' ORDER BY v BM25 OF 'apple' LIMIT 3" );
64
63
assertRows (result , row (1 ));
65
64
}
66
65
66
+ @ Test
67
+ public void testDeletedRow () throws Throwable
68
+ {
69
+ createTable ("CREATE TABLE %s (k int PRIMARY KEY, v text)" );
70
+ createAnalyzedIndex ();
71
+ execute ("INSERT INTO %s (k, v) VALUES (1, 'apple')" );
72
+ execute ("INSERT INTO %s (k, v) VALUES (2, 'apple juice')" );
73
+ var result = execute ("SELECT k FROM %s ORDER BY v BM25 OF 'apple' LIMIT 3" );
74
+ assertThat (result ).hasSize (2 );
75
+ execute ("DELETE FROM %s WHERE k=2" );
76
+ String select = "SELECT k FROM %s ORDER BY v BM25 OF 'apple' LIMIT 3" ;
77
+ beforeAndAfterFlush (() -> assertRows (execute (select ), row (1 )));
78
+ }
79
+
80
+ @ Test
81
+ public void testDeletedColumn () throws Throwable
82
+ {
83
+ createTable ("CREATE TABLE %s (k int PRIMARY KEY, v text)" );
84
+ createAnalyzedIndex ();
85
+ execute ("INSERT INTO %s (k, v) VALUES (1, 'apple')" );
86
+ execute ("INSERT INTO %s (k, v) VALUES (2, 'apple juice')" );
87
+ String select = "SELECT k FROM %s ORDER BY v BM25 OF 'apple' LIMIT 3" ;
88
+ assertRows (execute (select ), row (1 ), row (2 ));
89
+ execute ("DELETE v FROM %s WHERE k = 2" );
90
+ beforeAndAfterFlush (() -> assertRows (execute (select ), row (1 )));
91
+ }
92
+
93
+ @ Test
94
+ public void testDeletedRowWithPredicate () throws Throwable
95
+ {
96
+ createTable ("CREATE TABLE %s (k int PRIMARY KEY, v text, n int)" );
97
+ createIndex ("CREATE CUSTOM INDEX ON %s(n) USING 'org.apache.cassandra.index.sai.StorageAttachedIndex'" );
98
+ createAnalyzedIndex ();
99
+ execute ("INSERT INTO %s (k, v, n) VALUES (1, 'apple', 0)" );
100
+ execute ("INSERT INTO %s (k, v, n) VALUES (2, 'apple juice', 0)" );
101
+ String select = "SELECT k FROM %s WHERE n = 0 ORDER BY v BM25 OF 'apple' LIMIT 3" ;
102
+ assertRows (execute (select ), row (1 ), row (2 ));
103
+ execute ("DELETE FROM %s WHERE k=2" );
104
+ beforeAndAfterFlush (() -> assertRows (execute (select ), row (1 )));
105
+ }
106
+
67
107
@ Test
68
108
public void testTwoIndexesAmbiguousPredicate () throws Throwable
69
109
{
70
110
createTable ("CREATE TABLE %s (k int PRIMARY KEY, v text)" );
71
111
72
- // Create analyzed and un-analyzed indexes
73
- analyzeIndex ();
112
+ createAnalyzedIndex ();
113
+ // Create un-analyzed indexes
74
114
createIndex ("CREATE CUSTOM INDEX ON %s(v) USING 'org.apache.cassandra.index.sai.StorageAttachedIndex'" );
75
115
76
116
execute ("INSERT INTO %s (k, v) VALUES (1, 'apple')" );
@@ -368,10 +408,10 @@ public void testIrrelevantRowsWithCompaction()
368
408
private void createSimpleTable ()
369
409
{
370
410
createTable ("CREATE TABLE %s (k int PRIMARY KEY, v text)" );
371
- analyzeIndex ();
411
+ createAnalyzedIndex ();
372
412
}
373
413
374
- private String analyzeIndex ()
414
+ private String createAnalyzedIndex ()
375
415
{
376
416
return createIndex ("CREATE CUSTOM INDEX ON %s(v) " +
377
417
"USING 'org.apache.cassandra.index.sai.StorageAttachedIndex' " +
@@ -387,7 +427,7 @@ private String analyzeIndex()
387
427
public void testWithPredicate () throws Throwable
388
428
{
389
429
createTable ("CREATE TABLE %s (k int PRIMARY KEY, p int, v text)" );
390
- analyzeIndex ();
430
+ createAnalyzedIndex ();
391
431
execute ("CREATE CUSTOM INDEX ON %s(p) USING 'StorageAttachedIndex'" );
392
432
393
433
// Insert documents with varying frequencies of the term "apple"
@@ -412,7 +452,7 @@ public void testWithPredicate() throws Throwable
412
452
public void testWidePartition () throws Throwable
413
453
{
414
454
createTable ("CREATE TABLE %s (k1 int, k2 int, v text, PRIMARY KEY (k1, k2))" );
415
- analyzeIndex ();
455
+ createAnalyzedIndex ();
416
456
417
457
// Insert documents with varying frequencies of the term "apple"
418
458
execute ("INSERT INTO %s (k1, k2, v) VALUES (0, 1, 'apple')" );
@@ -434,7 +474,7 @@ public void testWidePartition() throws Throwable
434
474
public void testWidePartitionWithPkPredicate () throws Throwable
435
475
{
436
476
createTable ("CREATE TABLE %s (k1 int, k2 int, v text, PRIMARY KEY (k1, k2))" );
437
- analyzeIndex ();
477
+ createAnalyzedIndex ();
438
478
439
479
// Insert documents with varying frequencies of the term "apple"
440
480
execute ("INSERT INTO %s (k1, k2, v) VALUES (0, 1, 'apple')" );
@@ -458,7 +498,7 @@ public void testWidePartitionWithPkPredicate() throws Throwable
458
498
public void testWidePartitionWithPredicate () throws Throwable
459
499
{
460
500
createTable ("CREATE TABLE %s (k1 int, k2 int, p int, v text, PRIMARY KEY (k1, k2))" );
461
- analyzeIndex ();
501
+ createAnalyzedIndex ();
462
502
execute ("CREATE CUSTOM INDEX ON %s(p) USING 'StorageAttachedIndex'" );
463
503
464
504
// Insert documents with varying frequencies of the term "apple"
@@ -519,7 +559,7 @@ public void testQueryEmptyTable()
519
559
public void testBM25RaceConditionConcurrentQueriesInInvertedIndexSearcher () throws Throwable
520
560
{
521
561
createTable ("CREATE TABLE %s (pk int, v text, PRIMARY KEY (pk))" );
522
- analyzeIndex ();
562
+ createAnalyzedIndex ();
523
563
524
564
// Create 3 docs that have the same BM25 score and will be our top docs
525
565
execute ("INSERT INTO %s (pk, v) VALUES (1, 'apple apple apple')" );
@@ -552,7 +592,7 @@ public void testBM25RaceConditionConcurrentQueriesInInvertedIndexSearcher() thro
552
592
public void testWildcardSelection ()
553
593
{
554
594
createTable ("CREATE TABLE %s (k int, c int, v text, PRIMARY KEY (k, c))" );
555
- analyzeIndex ();
595
+ createAnalyzedIndex ();
556
596
execute ("INSERT INTO %s (k, c, v) VALUES (1, 1, 'apple')" );
557
597
558
598
var result = execute ("SELECT * FROM %s ORDER BY v BM25 OF 'apple' LIMIT 3" );
0 commit comments