Skip to content

Commit

Permalink
Add cost based decision log for scaled writer optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
feilong-liu committed Oct 19, 2023
1 parent 4225f39 commit 70ecc39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,7 @@ public static boolean shouldInferInequalityPredicates(Session session)
return session.getSystemProperty(INFER_INEQUALITY_PREDICATES, Boolean.class);
}

public static boolean useHBOForScaledWriters(Session session)
public static boolean useHistoryBasedScaledWriters(Session session)
{
return session.getSystemProperty(ENABLE_HISTORY_BASED_SCALED_WRITER, Boolean.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@

import java.util.Optional;

import static com.facebook.presto.SystemSessionProperties.useHBOForScaledWriters;
import static com.facebook.presto.SystemSessionProperties.useHistoryBasedScaledWriters;
import static com.facebook.presto.sql.planner.plan.Patterns.tableWriterNode;
import static com.google.common.base.Preconditions.checkState;

public class ScaledWriterRule
implements Rule<TableWriterNode>
{
private String statsSource;

@Override
public Pattern<TableWriterNode> getPattern()
{
Expand All @@ -37,13 +39,26 @@ public Pattern<TableWriterNode> getPattern()
@Override
public boolean isEnabled(Session session)
{
return useHBOForScaledWriters(session);
return useHistoryBasedScaledWriters(session);
}

@Override
public boolean isCostBased(Session session)
{
return true;
}

@Override
public String getStatsSource()
{
return statsSource;
}

@Override
public Result apply(TableWriterNode node, Captures captures, Context context)
{
double taskNumber = context.getStatsProvider().getStats(node).getTableWriterNodeStatsEstimate().getTaskCountIfScaledWriter();
statsSource = context.getStatsProvider().getStats(node).getSourceInfo().getSourceInfoName();
if (Double.isNaN(taskNumber)) {
return Result.empty();
}
Expand Down

0 comments on commit 70ecc39

Please sign in to comment.