Skip to content

Commit

Permalink
fix(interactive): Give extra params such as snapshot id in the physic…
Browse files Browse the repository at this point in the history
…al plan (#3999)

Co-authored-by: Zhang Lei <[email protected]>
  • Loading branch information
BingqingLyu and zhanglei1949 authored Jul 8, 2024
1 parent 7ab99ec commit 8e9f741
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.graphscope.common.config.Configs;
import com.alibaba.graphscope.common.ir.meta.IrMeta;
import com.alibaba.graphscope.common.ir.meta.SnapshotId;
import com.alibaba.graphscope.common.ir.meta.schema.CommonOptTable;
import com.alibaba.graphscope.common.ir.rel.CommonTableScan;
import com.alibaba.graphscope.common.ir.rel.GraphShuttle;
Expand All @@ -37,6 +38,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -61,12 +63,14 @@ public GraphRelProtoPhysicalBuilder(
super(logicalPlan);
this.physicalBuilder = GraphAlgebraPhysical.PhysicalPlan.newBuilder();
this.relToCommons = createRelToCommons(logicalPlan);

this.relShuttle =
new GraphRelToProtoConverter(
irMeta.getSchema().isColumnId(),
graphConfig,
this.physicalBuilder,
this.relToCommons);
this.relToCommons,
createExtraParams(irMeta));
}

@Override
Expand Down Expand Up @@ -150,6 +154,16 @@ private IdentityHashMap<RelNode, List<CommonTableScan>> createRelToCommons(
return relToCommons;
}

private HashMap<String, String> createExtraParams(IrMeta irMeta) {
HashMap<String, String> extraParams = new HashMap<>();
// prepare extra params for physical plan, e.g. snapshot id
SnapshotId snapshotId = irMeta.getSnapshotId();
if (snapshotId.isAcquired()) {
extraParams.put("SID", String.valueOf(snapshotId.getId()));
}
return extraParams;
}

/**
* find the lowest common ancestor (union/join...) of a list of common table scans
* @param top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.commons.lang3.ObjectUtils;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -71,20 +72,23 @@ public class GraphRelToProtoConverter extends GraphShuttle {
private boolean preCacheEdgeProps;
private final IdentityHashMap<RelNode, List<CommonTableScan>> relToCommons;
private final int depth;
private final HashMap<String, String> extraParams = new HashMap<>();

public GraphRelToProtoConverter(
boolean isColumnId,
Configs configs,
GraphAlgebraPhysical.PhysicalPlan.Builder physicalBuilder,
IdentityHashMap<RelNode, List<CommonTableScan>> relToCommons) {
this(isColumnId, configs, physicalBuilder, relToCommons, 0);
IdentityHashMap<RelNode, List<CommonTableScan>> relToCommons,
HashMap<String, String> extraParams) {
this(isColumnId, configs, physicalBuilder, relToCommons, extraParams, 0);
}

public GraphRelToProtoConverter(
boolean isColumnId,
Configs configs,
GraphAlgebraPhysical.PhysicalPlan.Builder physicalBuilder,
IdentityHashMap<RelNode, List<CommonTableScan>> relToCommons,
HashMap<String, String> extraParams,
int depth) {
this.isColumnId = isColumnId;
this.rexBuilder = GraphPlanner.rexBuilderFactory.apply(configs);
Expand All @@ -97,6 +101,7 @@ public GraphRelToProtoConverter(
// precache edge properties.
this.preCacheEdgeProps = true;
this.relToCommons = relToCommons;
this.extraParams.putAll(extraParams);
this.depth = depth;
}

Expand Down Expand Up @@ -496,7 +501,12 @@ private GraphAlgebraPhysical.Apply.Builder buildApply(
GraphAlgebraPhysical.PhysicalPlan.newBuilder();
query.rel.accept(
new GraphRelToProtoConverter(
isColumnId, graphConfig, applyPlanBuilder, this.relToCommons, depth + 1));
isColumnId,
graphConfig,
applyPlanBuilder,
this.relToCommons,
this.extraParams,
depth + 1));
GraphAlgebraPhysical.Apply.Builder applyBuilder =
GraphAlgebraPhysical.Apply.newBuilder()
.setSubPlan(applyPlanBuilder)
Expand Down Expand Up @@ -793,11 +803,21 @@ public RelNode visit(LogicalJoin join) {
RelNode left = join.getLeft();
left.accept(
new GraphRelToProtoConverter(
isColumnId, graphConfig, leftPlanBuilder, this.relToCommons, depth + 1));
isColumnId,
graphConfig,
leftPlanBuilder,
this.relToCommons,
this.extraParams,
depth + 1));
RelNode right = join.getRight();
right.accept(
new GraphRelToProtoConverter(
isColumnId, graphConfig, rightPlanBuilder, this.relToCommons, depth + 1));
isColumnId,
graphConfig,
rightPlanBuilder,
this.relToCommons,
this.extraParams,
depth + 1));
if (isPartitioned) {

Map<Integer, Set<GraphNameOrId>> leftTagColumns =
Expand Down Expand Up @@ -838,6 +858,7 @@ public RelNode visit(LogicalUnion union) {
graphConfig,
commonPlanBuilder,
this.relToCommons,
this.extraParams,
depth + 1));
}
physicalBuilder.addAllPlan(commonPlanBuilder.getPlanList());
Expand All @@ -861,6 +882,7 @@ public RelNode visit(LogicalUnion union) {
graphConfig,
inputPlanBuilder,
this.relToCommons,
this.extraParams,
depth + 1));
unionBuilder.addSubPlans(inputPlanBuilder);
}
Expand All @@ -886,6 +908,7 @@ public RelNode visit(MultiJoin multiJoin) {
graphConfig,
commonPlanBuilder,
this.relToCommons,
this.extraParams,
depth + 1));
}
physicalBuilder.addAllPlan(commonPlanBuilder.getPlanList());
Expand Down Expand Up @@ -922,7 +945,12 @@ public RelNode visit(MultiJoin multiJoin) {
GraphAlgebraPhysical.PhysicalPlan.newBuilder();
input.accept(
new GraphRelToProtoConverter(
isColumnId, graphConfig, subPlanBuilder, this.relToCommons, depth + 1));
isColumnId,
graphConfig,
subPlanBuilder,
this.relToCommons,
this.extraParams,
depth + 1));
intersectBuilder.addSubPlans(subPlanBuilder);
}
intersectOprBuilder.setOpr(
Expand Down Expand Up @@ -1032,6 +1060,9 @@ private GraphAlgebra.QueryParams.Builder defaultQueryParams() {
GraphAlgebra.QueryParams.Builder paramsBuilder = GraphAlgebra.QueryParams.newBuilder();
// TODO: currently no sample rate fused into tableScan, so directly set 1.0 as default.
paramsBuilder.setSampleRatio(1.0);
if (!this.extraParams.isEmpty()) {
paramsBuilder.putAllExtra(extraParams);
}
return paramsBuilder;
}

Expand Down

0 comments on commit 8e9f741

Please sign in to comment.