Skip to content

Commit c85c5eb

Browse files
Removed TopN addSortItem and changed Top.topNSortItems as immutable
1 parent 4adf598 commit c85c5eb

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

Diff for: plugin/trino-elasticsearch/src/main/java/io/trino/plugin/elasticsearch/ElasticsearchMetadata.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,15 @@ public Optional<TopNApplicationResult<ConnectorTableHandle>> applyTopN(
717717
return Optional.empty();
718718
}
719719

720-
TopN topN = TopN.fromLimit(topNCount);
720+
ImmutableList.Builder<TopN.TopNSortItem> topNSortItems = ImmutableList.builder();
721721
for (SortItem sortItem : sortItems) {
722722
ElasticsearchColumnHandle ch = (ElasticsearchColumnHandle) assignments.get(sortItem.getName());
723723
if (!ch.supportsPredicates()) {
724724
return Optional.empty();
725725
}
726-
topN.addSortItem(TopN.TopNSortItem.sortBy(ch.name(), sortItem.getSortOrder()));
726+
topNSortItems.add(TopN.TopNSortItem.sortBy(ch.name(), sortItem.getSortOrder()));
727727
}
728+
TopN topN = new TopN(topNCount, topNSortItems.build());
728729

729730
ElasticsearchTableHandle newHandle = new ElasticsearchTableHandle(
730731
handle.type(),

Diff for: plugin/trino-elasticsearch/src/main/java/io/trino/plugin/elasticsearch/ScanQueryPageSource.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ public ScanQueryPageSource(
103103

104104
Optional<TopN> topN = table.topN();
105105
if (topN.isEmpty()) {
106-
topN = Optional.of(TopN.fromLimit(NO_LIMIT));
107106
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));
110111
}
111112
}
112113

Diff for: plugin/trino-elasticsearch/src/main/java/io/trino/plugin/elasticsearch/expression/TopN.java

-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
public record TopN(long limit, List<TopNSortItem> topNSortItems)
2626
{
2727
public static final long NO_LIMIT = -1;
28-
public static final TopN EMPTY = fromLimit(NO_LIMIT);
2928

3029
public static TopN fromLimit(long limit)
3130
{
@@ -37,12 +36,6 @@ public static TopN fromLimit(long limit)
3736
requireNonNull(topNSortItems, "topNSortItems is null");
3837
}
3938

40-
public TopN addSortItem(TopNSortItem sortItem)
41-
{
42-
topNSortItems.add(sortItem);
43-
return this;
44-
}
45-
4639
public boolean isOnlyLimit()
4740
{
4841
return limit != NO_LIMIT && topNSortItems.isEmpty();

0 commit comments

Comments
 (0)