use of io.trino.spi.connector.SortItem in project trino by trinodb.
the class PushTopNIntoTableScan method apply.
@Override
public Result apply(TopNNode topNNode, Captures captures, Context context) {
TableScanNode tableScan = captures.get(TABLE_SCAN);
long topNCount = topNNode.getCount();
List<SortItem> sortItems = topNNode.getOrderingScheme().toSortItems();
Map<String, ColumnHandle> assignments = tableScan.getAssignments().entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().getName(), Map.Entry::getValue));
return metadata.applyTopN(context.getSession(), tableScan.getTable(), topNCount, sortItems, assignments).map(result -> {
PlanNode node = new TableScanNode(context.getIdAllocator().getNextId(), result.getHandle(), tableScan.getOutputSymbols(), tableScan.getAssignments(), TupleDomain.all(), deriveTableStatisticsForPushdown(context.getStatsProvider(), context.getSession(), result.isPrecalculateStatistics(), result.isTopNGuaranteed() ? topNNode : tableScan), tableScan.isUpdateTarget(), // table scan partitioning might have changed with new table handle
Optional.empty());
if (!result.isTopNGuaranteed()) {
node = topNNode.replaceChildren(ImmutableList.of(node));
}
return Result.ofPlanNode(node);
}).orElseGet(Result::empty);
}
Aggregations