45
45
46
46
public class SingleRestrictionEstimatedRowCountTest extends SAITester
47
47
{
48
- static protected Map <Map .Entry <Version , CQL3Type .Native >, ColumnFamilyStore > map = new HashMap <>();
48
+ static protected Map <Map .Entry <Version , CQL3Type .Native >, ColumnFamilyStore > tables = new HashMap <>();
49
+ static Version [] versions = new Version []{ Version .DB , Version .EB };
50
+ static CQL3Type .Native [] types = new CQL3Type .Native []{ INT , DECIMAL , VARINT };
49
51
50
52
static protected Object getFilterValue (CQL3Type .Native type , int value )
51
53
{
@@ -62,66 +64,74 @@ static protected Object getFilterValue(CQL3Type.Native type, int value)
62
64
return null ;
63
65
}
64
66
67
+ static Map .Entry <Version , CQL3Type .Native > tablesEntrykey (Version version , CQL3Type .Native type )
68
+ {
69
+ return new AbstractMap .SimpleEntry <>(version , type );
70
+ }
71
+
65
72
@ Test
66
- public void testInequality ()
73
+ public void testMemtablesSAI ()
67
74
{
75
+ createTables ();
76
+
68
77
var test = new RowCountTest (Operator .NEQ , 25 );
69
78
test .doTest (Version .DB , INT , 97.0 );
70
79
test .doTest (Version .EB , INT , 97.0 );
71
80
// Truncated numeric types planned differently
72
81
test .doTest (Version .DB , DECIMAL , 97.0 );
73
82
test .doTest (Version .EB , DECIMAL , 97.0 );
74
83
test .doTest (Version .EB , VARINT , 97.0 );
75
- }
76
84
77
- @ Test
78
- public void testHalfRangeMiddle ()
79
- {
80
- var test = new RowCountTest (Operator .LT , 50 );
85
+ test = new RowCountTest (Operator .LT , 50 );
81
86
test .doTest (Version .DB , INT , 48 );
82
87
test .doTest (Version .EB , INT , 48 );
83
88
test .doTest (Version .DB , DECIMAL , 48 );
84
89
test .doTest (Version .EB , DECIMAL , 48 );
85
- }
86
90
87
- @ Test
88
- public void testHalfRangeEverything ()
89
- {
90
- var test = new RowCountTest (Operator .LT , 150 );
91
+ test = new RowCountTest (Operator .LT , 150 );
91
92
test .doTest (Version .DB , INT , 97 );
92
93
test .doTest (Version .EB , INT , 97 );
93
94
test .doTest (Version .DB , DECIMAL , 97 );
94
95
test .doTest (Version .EB , DECIMAL , 97 );
95
- }
96
96
97
- @ Test
98
- public void testEquality ()
99
- {
100
- var test = new RowCountTest (Operator .EQ , 31 );
97
+ test = new RowCountTest (Operator .EQ , 31 );
101
98
test .doTest (Version .DB , INT , 15 );
102
99
test .doTest (Version .EB , INT , 0 );
103
100
test .doTest (Version .DB , DECIMAL , 15 );
104
101
test .doTest (Version .EB , DECIMAL , 0 );
105
102
}
106
103
107
- protected ColumnFamilyStore prepareTable (CQL3Type .Native type )
104
+
105
+ void createTables ()
108
106
{
109
- createTable ("CREATE TABLE %s (pk text PRIMARY KEY, age " + type + ')' );
110
- createIndex ("CREATE CUSTOM INDEX ON %s(age) USING 'StorageAttachedIndex'" );
111
- ColumnFamilyStore cfs = getCurrentColumnFamilyStore ();
107
+ for (Version version : versions )
108
+ {
109
+ SAIUtil .setLatestVersion (version );
110
+ for (CQL3Type .Native type : types )
111
+ {
112
+ createTable ("CREATE TABLE %s (pk text PRIMARY KEY, age " + type + ')' );
113
+ createIndex ("CREATE CUSTOM INDEX ON %s(age) USING 'StorageAttachedIndex'" );
114
+ tables .put (tablesEntrykey (version , type ), getCurrentColumnFamilyStore ());
115
+ }
116
+ }
117
+ flush ();
118
+ for (ColumnFamilyStore cfs : tables .values ())
119
+ populateTable (cfs );
120
+ }
112
121
113
- // Avoid race condition of flushing after the index creation
122
+ void populateTable (ColumnFamilyStore cfs )
123
+ {
124
+ // Avoid race condition of starting before flushing completed
114
125
cfs .unsafeRunWithoutFlushing (() -> {
115
126
for (int i = 0 ; i < 100 ; i ++)
116
127
{
117
- execute ("INSERT INTO %s (pk, age) VALUES (?," + i + ')' , "key" + i );
128
+ String query = String .format ("INSERT INTO %s (pk, age) VALUES (?, " + i + ')' , cfs .keyspace .getName () + '.' + cfs .name );
129
+ executeFormattedQuery (query , "key" + i );
118
130
}
119
131
});
120
-
121
- return cfs ;
122
132
}
123
133
124
- class RowCountTest
134
+ static class RowCountTest
125
135
{
126
136
final Operator op ;
127
137
final int filterValue ;
@@ -134,15 +144,8 @@ class RowCountTest
134
144
135
145
void doTest (Version version , CQL3Type .Native type , double expectedRows )
136
146
{
137
- Version latest = Version .latest ();
138
- SAIUtil .setLatestVersion (version );
139
-
140
- var key = new AbstractMap .SimpleEntry <>(version , type );
141
- ColumnFamilyStore cfs = map .computeIfAbsent (key , k -> prepareTable (type ));
142
-
143
- // ColumnFamilyStore cfs = prepareTable(type);
147
+ ColumnFamilyStore cfs = tables .get (new AbstractMap .SimpleEntry <>(version , type ));
144
148
Object filter = getFilterValue (type , filterValue );
145
-
146
149
ReadCommand rc = Util .cmd (cfs )
147
150
.columns ("age" )
148
151
.filterOn ("age" , op , filter )
@@ -152,6 +155,7 @@ void doTest(Version version, CQL3Type.Native type, double expectedRows)
152
155
version .onDiskFormat ().indexFeatureSet (),
153
156
new QueryContext (),
154
157
null );
158
+
155
159
long totalRows = controller .planFactory .tableMetrics .rows ;
156
160
assertEquals (0 , cfs .metrics ().liveSSTableCount .getValue ().intValue ());
157
161
assertEquals (97 , totalRows );
@@ -165,8 +169,6 @@ void doTest(Version version, CQL3Type.Native type, double expectedRows)
165
169
assertEquals (expectedRows , root .expectedRows (), 0.1 );
166
170
assertEquals (expectedRows , planNode .expectedKeys (), 0.1 );
167
171
assertEquals (expectedRows / totalRows , planNode .selectivity (), 0.001 );
168
-
169
- SAIUtil .setLatestVersion (latest );
170
172
}
171
173
}
172
174
}
0 commit comments