-
Notifications
You must be signed in to change notification settings - Fork 179
Merge paginated plan optimizer into the regular optimizer. #1516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
eb23fda
18aa5d8
dd8486a
44f45dc
0de447a
1ddd311
ba0b7a9
31315dc
9df41c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,45 +5,66 @@ | |
|
|
||
| package org.opensearch.sql.planner.optimizer.rule; | ||
|
|
||
| import static org.opensearch.sql.planner.optimizer.pattern.Patterns.table; | ||
|
|
||
| import com.facebook.presto.matching.Capture; | ||
| import com.facebook.presto.matching.Captures; | ||
| import com.facebook.presto.matching.Pattern; | ||
| import java.util.ArrayDeque; | ||
| import java.util.Deque; | ||
| import java.util.List; | ||
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
| import org.opensearch.sql.planner.logical.LogicalPaginate; | ||
| import org.opensearch.sql.planner.logical.LogicalPlan; | ||
| import org.opensearch.sql.planner.logical.LogicalRelation; | ||
| import org.opensearch.sql.planner.optimizer.Rule; | ||
| import org.opensearch.sql.storage.Table; | ||
| import org.opensearch.sql.storage.read.TableScanBuilder; | ||
|
|
||
| /** | ||
| * Rule to create a paged TableScanBuilder in pagination request. | ||
| */ | ||
| public class CreatePagingTableScanBuilder implements Rule<LogicalRelation> { | ||
| /** Capture the table inside matched logical relation operator. */ | ||
| private final Capture<Table> capture; | ||
|
|
||
| public class CreatePagingTableScanBuilder implements Rule<LogicalPaginate> { | ||
| /** Capture the table inside matched logical paginate operator. */ | ||
| private LogicalPlan relationParent = null; | ||
| /** Pattern that matches logical relation operator. */ | ||
| @Accessors(fluent = true) | ||
| @Getter | ||
| private final Pattern<LogicalRelation> pattern; | ||
| private final Pattern<LogicalPaginate> pattern; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| */ | ||
| public CreatePagingTableScanBuilder() { | ||
| this.capture = Capture.newCapture(); | ||
| this.pattern = Pattern.typeOf(LogicalRelation.class) | ||
| .with(table().capturedAs(capture)); | ||
| this.pattern = Pattern.typeOf(LogicalPaginate.class).matching(this::findLogicalRelation); | ||
| } | ||
|
|
||
| /** | ||
| * Finds an instance of LogicalRelation and saves a reference in relationParent variable. | ||
| * @param logicalPaginate An instance of LogicalPaginate | ||
| * @return true if {@link LogicalRelation} node was found among the descendents of | ||
| * {@link this.logicalPaginate}, false otherwise. | ||
| */ | ||
| private boolean findLogicalRelation(LogicalPaginate logicalPaginate) { | ||
| Deque<LogicalPlan> plans = new ArrayDeque<>(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you could create ArrayDeque with logicalPagination
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly, I cannot -- that constructor expects a collection. Compared to adding a conversion to collection, just calling |
||
| plans.push(logicalPaginate); | ||
| do { | ||
| var plan = plans.pop(); | ||
| if (plan.getChild().stream().anyMatch(LogicalRelation.class::isInstance)) { | ||
| if (plan.getChild().size() > 1) { | ||
| throw new UnsupportedOperationException(); | ||
|
||
| } | ||
| relationParent = plan; | ||
| return true; | ||
| } | ||
| plan.getChild().forEach(plans::push); | ||
|
||
| } while (!plans.isEmpty()); | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public LogicalPlan apply(LogicalRelation plan, Captures captures) { | ||
| TableScanBuilder scanBuilder = captures.get(capture) | ||
| .createPagedScanBuilder(plan.getPageSize()); | ||
| // TODO: Remove this after Prometheus refactored to new table scan builder too | ||
| return (scanBuilder == null) ? plan : scanBuilder; | ||
| public LogicalPlan apply(LogicalPaginate plan, Captures captures) { | ||
| var logicalRelation = (LogicalRelation) relationParent.getChild().get(0); | ||
| var scan = logicalRelation.getTable().createPagedScanBuilder(plan.getPageSize()); | ||
| relationParent.replaceChildPlans(List.of(scan)); | ||
|
|
||
| return plan; | ||
| } | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.