File tree 3 files changed +7
-12
lines changed
plugin/trino-elasticsearch/src/main/java/io/trino/plugin/elasticsearch
3 files changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -717,14 +717,15 @@ public Optional<TopNApplicationResult<ConnectorTableHandle>> applyTopN(
717
717
return Optional .empty ();
718
718
}
719
719
720
- TopN topN = TopN . fromLimit ( topNCount );
720
+ ImmutableList . Builder < TopN . TopNSortItem > topNSortItems = ImmutableList . builder ( );
721
721
for (SortItem sortItem : sortItems ) {
722
722
ElasticsearchColumnHandle ch = (ElasticsearchColumnHandle ) assignments .get (sortItem .getName ());
723
723
if (!ch .supportsPredicates ()) {
724
724
return Optional .empty ();
725
725
}
726
- topN . addSortItem (TopN .TopNSortItem .sortBy (ch .name (), sortItem .getSortOrder ()));
726
+ topNSortItems . add (TopN .TopNSortItem .sortBy (ch .name (), sortItem .getSortOrder ()));
727
727
}
728
+ TopN topN = new TopN (topNCount , topNSortItems .build ());
728
729
729
730
ElasticsearchTableHandle newHandle = new ElasticsearchTableHandle (
730
731
handle .type (),
Original file line number Diff line number Diff line change @@ -103,10 +103,11 @@ public ScanQueryPageSource(
103
103
104
104
Optional <TopN > topN = table .topN ();
105
105
if (topN .isEmpty ()) {
106
- topN = Optional .of (TopN .fromLimit (NO_LIMIT ));
107
106
if (table .query ().isEmpty ()) {
108
- // sorting by _doc (index order) get special treatment in Elasticsearch and is more efficient
109
- topN .get ().addSortItem (DEFAULT_SORT_BY_DOC );
107
+ topN = Optional .of (new TopN (NO_LIMIT , ImmutableList .of (DEFAULT_SORT_BY_DOC )));
108
+ }
109
+ else {
110
+ topN = Optional .of (TopN .fromLimit (NO_LIMIT ));
110
111
}
111
112
}
112
113
Original file line number Diff line number Diff line change 25
25
public record TopN (long limit , List <TopNSortItem > topNSortItems )
26
26
{
27
27
public static final long NO_LIMIT = -1 ;
28
- public static final TopN EMPTY = fromLimit (NO_LIMIT );
29
28
30
29
public static TopN fromLimit (long limit )
31
30
{
@@ -37,12 +36,6 @@ public static TopN fromLimit(long limit)
37
36
requireNonNull (topNSortItems , "topNSortItems is null" );
38
37
}
39
38
40
- public TopN addSortItem (TopNSortItem sortItem )
41
- {
42
- topNSortItems .add (sortItem );
43
- return this ;
44
- }
45
-
46
39
public boolean isOnlyLimit ()
47
40
{
48
41
return limit != NO_LIMIT && topNSortItems .isEmpty ();
You can’t perform that action at this time.
0 commit comments