Class LimitAndSortHelper
- java.lang.Object
-
- com.amazonaws.athena.connector.substrait.util.LimitAndSortHelper
-
public final class LimitAndSortHelper extends Object
Utility class that extracts LIMIT and ORDER BY information from Substrait plans to enable pushdown of these operations to the underlying data source.This helper parses
Planobjects to extract:- LIMIT values from
FetchRelnodes, falling back toConstraintswhen no plan is available - ORDER BY sort fields from
SortRelnodes, mapped to column names via table metadata
Connectors can use the extracted
LimitAndSortHelper.GenericSortFieldrepresentations to build data-source-specific sort clauses (e.g., MongoDB sort documents, SQL ORDER BY clauses). - LIMIT values from
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLimitAndSortHelper.GenericSortFieldA data-source-agnostic representation of a sort field, containing the column name and sort direction.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<Integer>getLimit(io.substrait.proto.Plan plan, Constraints constraints)Determines if a LIMIT can be applied and extracts the limit value.static Optional<List<LimitAndSortHelper.GenericSortField>>getSortFromPlan(io.substrait.proto.Plan plan)Extracts sort field information from a Substrait plan for ORDER BY pushdown.
-
-
-
Method Detail
-
getLimit
public static Optional<Integer> getLimit(io.substrait.proto.Plan plan, Constraints constraints)
Determines if a LIMIT can be applied and extracts the limit value.When a Substrait
Planis provided, the limit is extracted from itsFetchRelnode. Otherwise, falls back to the limit defined inConstraints.- Parameters:
plan- the Substrait plan to extract the limit from, ornullto use constraintsconstraints- the query constraints containing a fallback limit value- Returns:
- an
Optionalcontaining the limit value if one can be applied, or empty otherwise
-
getSortFromPlan
public static Optional<List<LimitAndSortHelper.GenericSortField>> getSortFromPlan(io.substrait.proto.Plan plan)
Extracts sort field information from a Substrait plan for ORDER BY pushdown.Parses the
SortRelnode in the plan to produce a list ofLimitAndSortHelper.GenericSortFieldobjects, each containing a column name and sort direction. If the plan isnull, has no relations, or contains no sort relation, returns empty.- Parameters:
plan- the Substrait plan to extract sort information from, ornull- Returns:
- an
Optionalcontaining the list of sort fields, or empty if no sort is present
-
-