1717 */
1818package org .apache .drill .exec .store .kafka ;
1919
20+ import org .apache .drill .PlanTestBase ;
2021import org .apache .drill .categories .KafkaStorageTest ;
2122import org .apache .drill .categories .SlowTest ;
2223import org .apache .kafka .common .serialization .StringSerializer ;
23-
2424import org .junit .BeforeClass ;
2525import org .junit .Test ;
2626import org .junit .experimental .categories .Category ;
3232@ Category ({KafkaStorageTest .class , SlowTest .class })
3333public class KafkaFilterPushdownTest extends KafkaTestBase {
3434 private static final int NUM_PARTITIONS = 5 ;
35- private static final String expectedSubStr = " \" kafkaScanSpec\" : {\n " +
36- " \" topicName\" : \" drill-pushdown-topic\" \n " +
37- " },\n " +
38- " \" cost\" " ;
35+ private static final String expectedPattern = "kafkaScanSpec.*\\ n.*\" topicName\" : \" drill-pushdown-topic\" \\ n(" +
36+ ".*\\ n)?(.*\\ n)?(.*\\ n)?.*cost\" (.*\\ n)(.*\\ n).*outputRowCount\" : (%s.0)" ;
3937
4038 @ BeforeClass
4139 public static void setup () throws Exception {
@@ -63,7 +61,9 @@ public void testPushdownOnOffset() throws Exception {
6361 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 );
6462
6563 runKafkaSQLVerifyCount (queryString , expectedRowCount );
66- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
64+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
65+ new String [] {String .format (expectedPattern , expectedRowCount )},
66+ new String []{});
6767 }
6868
6969 /**
@@ -79,7 +79,9 @@ public void testPushdownOnPartition() throws Exception {
7979 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate );
8080
8181 runKafkaSQLVerifyCount (queryString , expectedRowCount );
82- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
82+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
83+ new String [] {String .format (expectedPattern , expectedRowCount )},
84+ new String []{});
8385 }
8486
8587 /**
@@ -95,7 +97,9 @@ public void testPushdownOnTimestamp() throws Exception {
9597 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate );
9698
9799 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
98- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
100+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
101+ new String [] {String .format (expectedPattern , expectedRowCount )},
102+ new String []{});
99103 }
100104
101105 /**
@@ -112,7 +116,9 @@ public void testPushdownUnorderedTimestamp() throws Exception {
112116 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate );
113117
114118 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
115- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowInPlan ));
119+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
120+ new String [] {String .format (expectedPattern , expectedRowInPlan )},
121+ new String []{});
116122 }
117123
118124 /**
@@ -128,7 +134,9 @@ public void testPushdownWhenTimestampDoesNotExist() throws Exception {
128134 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate );
129135
130136 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
131- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
137+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
138+ new String [] {String .format (expectedPattern , expectedRowCount )},
139+ new String []{});
132140 }
133141
134142 /**
@@ -144,7 +152,9 @@ public void testPushdownWhenPartitionDoesNotExist() throws Exception {
144152 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate );
145153
146154 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
147- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
155+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
156+ new String [] {String .format (expectedPattern , expectedRowCount )},
157+ new String []{});
148158 }
149159
150160 /**
@@ -161,7 +171,9 @@ public void testPushdownForEmptyScanSpec() throws Exception {
161171 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 );
162172
163173 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
164- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
174+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
175+ new String [] {String .format (expectedPattern , expectedRowCount )},
176+ new String []{});
165177 }
166178
167179 /**
@@ -178,42 +190,54 @@ public void testPushdownOffsetNoRecordsReturnedWithBoundaryConditions() throws E
178190 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset = 10" );
179191
180192 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
181- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
193+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
194+ new String [] {String .format (expectedPattern , expectedRowCount )},
195+ new String []{});
182196
183197 //"equal" such that value < startOffset
184198 queryString = String .format (TestQueryConstants .QUERY_TEMPLATE_BASIC ,
185199 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset = -1" );
186200
187201 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
188- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
202+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
203+ new String [] {String .format (expectedPattern , expectedRowCount )},
204+ new String []{});
189205
190206 //"greater_than" such that value = endOffset-1
191207 queryString = String .format (TestQueryConstants .QUERY_TEMPLATE_BASIC ,
192208 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset > 9" );
193209
194210 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
195- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
211+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
212+ new String [] {String .format (expectedPattern , expectedRowCount )},
213+ new String []{});
196214
197215 //"greater_than_or_equal" such that value = endOffset
198216 queryString = String .format (TestQueryConstants .QUERY_TEMPLATE_BASIC ,
199217 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset >= 10" );
200218
201219 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
202- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
220+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
221+ new String [] {String .format (expectedPattern , expectedRowCount )},
222+ new String []{});
203223
204224 //"less_than" such that value = startOffset
205225 queryString = String .format (TestQueryConstants .QUERY_TEMPLATE_BASIC ,
206226 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset < 0" );
207227
208228 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
209- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
229+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
230+ new String [] {String .format (expectedPattern , expectedRowCount )},
231+ new String []{});
210232
211233 //"less_than_or_equal" such that value < startOffset
212234 queryString = String .format (TestQueryConstants .QUERY_TEMPLATE_BASIC ,
213235 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset <= -1" );
214236
215237 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
216- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
238+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
239+ new String [] {String .format (expectedPattern , expectedRowCount )},
240+ new String []{});
217241 }
218242
219243 /**
@@ -230,21 +254,27 @@ public void testPushdownOffsetOneRecordReturnedWithBoundaryConditions() throws E
230254 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset = 9" );
231255
232256 runKafkaSQLVerifyCount (queryString , expectedRowCount );
233- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
257+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
258+ new String [] {String .format (expectedPattern , expectedRowCount )},
259+ new String []{});
234260
235261 //"greater_than" such that value = endOffset-2
236262 queryString = String .format (TestQueryConstants .QUERY_TEMPLATE_BASIC ,
237263 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset > 8" );
238264
239265 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
240- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
266+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
267+ new String [] {String .format (expectedPattern , expectedRowCount )},
268+ new String []{});
241269
242270 //"greater_than_or_equal" such that value = endOffset-1
243271 queryString = String .format (TestQueryConstants .QUERY_TEMPLATE_BASIC ,
244272 TestQueryConstants .JSON_PUSHDOWN_TOPIC , "kafkaMsgOffset >= 9" );
245273
246274 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
247- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
275+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
276+ new String [] {String .format (expectedPattern , expectedRowCount )},
277+ new String []{});
248278 }
249279
250280 /**
@@ -262,7 +292,9 @@ public void testPushdownWithOr() throws Exception {
262292 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 );
263293
264294 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
265- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
295+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
296+ new String [] {String .format (expectedPattern , expectedRowCount )},
297+ new String []{});
266298 }
267299
268300 /**
@@ -280,7 +312,9 @@ public void testPushdownWithOr1() throws Exception {
280312 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 );
281313
282314 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
283- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowInPlan ));
315+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
316+ new String [] {String .format (expectedPattern , expectedRowInPlan )},
317+ new String []{});
284318 }
285319
286320 /**
@@ -299,7 +333,9 @@ public void testPushdownWithAndOrCombo() throws Exception {
299333 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 , predicate3 );
300334
301335 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
302- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCount ));
336+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
337+ new String [] {String .format (expectedPattern , expectedRowCount )},
338+ new String []{});
303339 }
304340
305341 /**
@@ -319,7 +355,9 @@ public void testPushdownWithAndOrCombo2() throws Exception {
319355 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 , predicate3 , predicate4 );
320356
321357 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
322- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCountInPlan ));
358+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
359+ new String [] {String .format (expectedPattern , expectedRowCountInPlan )},
360+ new String []{});
323361 }
324362
325363 /**
@@ -338,7 +376,9 @@ public void testPushdownTimestampWithNonMetaField() throws Exception {
338376 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 );
339377
340378 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
341- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCountInPlan ));
379+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
380+ new String [] {String .format (expectedPattern , expectedRowCountInPlan )},
381+ new String []{});
342382 }
343383
344384 /**
@@ -358,7 +398,9 @@ public void testNoPushdownOfOffsetWithNonMetadataField() throws Exception {
358398 TestQueryConstants .JSON_PUSHDOWN_TOPIC , predicate1 , predicate2 , predicate3 );
359399
360400 runKafkaSQLVerifyCount (queryString ,expectedRowCount );
361- testPhysicalPlan (queryString , String .format (expectedSubStr , expectedRowCountInPlan ));
401+ PlanTestBase .testPlanMatchingPatterns (queryString , JSON_FORMAT ,
402+ new String [] {String .format (expectedPattern , expectedRowCountInPlan )},
403+ new String []{});
362404 }
363405
364406}
0 commit comments