@@ -341,8 +341,48 @@ public void percentileAggregationTest() throws SqlParseException, SQLFeatureNotS
341
341
Assert .assertEquals ("32.0,32.0,34.0,36.0,38.0,40.0,40.0" ,lines .get (0 ));
342
342
}
343
343
344
+ @ Test
345
+ public void includeTypeAndNotScore () throws SqlParseException , SQLFeatureNotSupportedException , Exception {
346
+ String query = String .format ("select age , firstname from %s/account where age > 31 limit 2" , TEST_INDEX );
347
+ CSVResult csvResult = getCsvResult (false , query ,false ,true );
348
+ List <String > headers = csvResult .getHeaders ();
349
+ Assert .assertEquals (3 ,headers .size ());
350
+ Assert .assertTrue (headers .contains ("age" ));
351
+ Assert .assertTrue (headers .contains ("firstname" ));
352
+ Assert .assertTrue (headers .contains ("_type" ));
353
+ List <String > lines = csvResult .getLines ();
354
+ Assert .assertTrue (lines .get (0 ).contains (",account" ));
355
+ Assert .assertTrue (lines .get (1 ).contains (",account" ));
356
+ }
344
357
358
+ @ Test
359
+ public void includeScoreAndNotType () throws SqlParseException , SQLFeatureNotSupportedException , Exception {
360
+ String query = String .format ("select age , firstname from %s/account where age > 31 limit 2" , TEST_INDEX );
361
+ CSVResult csvResult = getCsvResult (false , query ,true ,false );
362
+ List <String > headers = csvResult .getHeaders ();
363
+ Assert .assertEquals (3 ,headers .size ());
364
+ Assert .assertTrue (headers .contains ("age" ));
365
+ Assert .assertTrue (headers .contains ("firstname" ));
366
+ Assert .assertTrue (headers .contains ("_score" ));
367
+ List <String > lines = csvResult .getLines ();
368
+ Assert .assertTrue (lines .get (0 ).contains (",1.0" ));
369
+ Assert .assertTrue (lines .get (1 ).contains (",1.0" ));
370
+ }
345
371
372
+ @ Test
373
+ public void includeScoreAndType () throws SqlParseException , SQLFeatureNotSupportedException , Exception {
374
+ String query = String .format ("select age , firstname from %s/account where age > 31 limit 2" , TEST_INDEX );
375
+ CSVResult csvResult = getCsvResult (false , query ,true ,true );
376
+ List <String > headers = csvResult .getHeaders ();
377
+ Assert .assertEquals (4 ,headers .size ());
378
+ Assert .assertTrue (headers .contains ("age" ));
379
+ Assert .assertTrue (headers .contains ("firstname" ));
380
+ Assert .assertTrue (headers .contains ("_score" ));
381
+ Assert .assertTrue (headers .contains ("_type" ));
382
+ List <String > lines = csvResult .getLines ();
383
+ Assert .assertTrue (lines .get (0 ).contains (",account,1.0" ));
384
+ Assert .assertTrue (lines .get (1 ).contains (",account,1.0" ));
385
+ }
346
386
/* todo: more tests:
347
387
* filter/nested and than metric
348
388
* histogram
@@ -351,12 +391,14 @@ public void percentileAggregationTest() throws SqlParseException, SQLFeatureNotS
351
391
352
392
353
393
private CSVResult getCsvResult (boolean flat , String query ) throws SqlParseException , SQLFeatureNotSupportedException , Exception , CsvExtractorException {
394
+ return getCsvResult (flat ,query ,false ,false );
395
+ }
396
+
397
+ private CSVResult getCsvResult (boolean flat , String query ,boolean includeScore , boolean includeType ) throws SqlParseException , SQLFeatureNotSupportedException , Exception , CsvExtractorException {
354
398
SearchDao searchDao = MainTestSuite .getSearchDao ();
355
399
QueryAction queryAction = searchDao .explain (query );
356
400
Object execution = QueryActionElasticExecutor .executeAnyAction (searchDao .getClient (), queryAction );
357
- return new CSVResultsExtractor ().extractResults (execution , flat , "," );
401
+ return new CSVResultsExtractor (includeScore , includeType ).extractResults (execution , flat , "," );
358
402
}
359
403
360
-
361
-
362
404
}
0 commit comments