From 8e9f7410ab80c08cedb59e6b175673ded641fd3a Mon Sep 17 00:00:00 2001 From: BingqingLyu Date: Mon, 8 Jul 2024 10:59:10 +0800 Subject: [PATCH] fix(interactive): Give extra params such as snapshot id in the physical plan (#3999) Co-authored-by: Zhang Lei --- .../proto/GraphRelProtoPhysicalBuilder.java | 16 ++++++- .../proto/GraphRelToProtoConverter.java | 43 ++++++++++++++++--- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java index b056aeaff89d..67a8a22b9e7d 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelProtoPhysicalBuilder.java @@ -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; @@ -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; @@ -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 @@ -150,6 +154,16 @@ private IdentityHashMap> createRelToCommons( return relToCommons; } + private HashMap createExtraParams(IrMeta irMeta) { + HashMap 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 diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelToProtoConverter.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelToProtoConverter.java index 9dc5490701fb..c2835eee2274 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelToProtoConverter.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/GraphRelToProtoConverter.java @@ -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; @@ -71,13 +72,15 @@ public class GraphRelToProtoConverter extends GraphShuttle { private boolean preCacheEdgeProps; private final IdentityHashMap> relToCommons; private final int depth; + private final HashMap extraParams = new HashMap<>(); public GraphRelToProtoConverter( boolean isColumnId, Configs configs, GraphAlgebraPhysical.PhysicalPlan.Builder physicalBuilder, - IdentityHashMap> relToCommons) { - this(isColumnId, configs, physicalBuilder, relToCommons, 0); + IdentityHashMap> relToCommons, + HashMap extraParams) { + this(isColumnId, configs, physicalBuilder, relToCommons, extraParams, 0); } public GraphRelToProtoConverter( @@ -85,6 +88,7 @@ public GraphRelToProtoConverter( Configs configs, GraphAlgebraPhysical.PhysicalPlan.Builder physicalBuilder, IdentityHashMap> relToCommons, + HashMap extraParams, int depth) { this.isColumnId = isColumnId; this.rexBuilder = GraphPlanner.rexBuilderFactory.apply(configs); @@ -97,6 +101,7 @@ public GraphRelToProtoConverter( // precache edge properties. this.preCacheEdgeProps = true; this.relToCommons = relToCommons; + this.extraParams.putAll(extraParams); this.depth = depth; } @@ -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) @@ -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> leftTagColumns = @@ -838,6 +858,7 @@ public RelNode visit(LogicalUnion union) { graphConfig, commonPlanBuilder, this.relToCommons, + this.extraParams, depth + 1)); } physicalBuilder.addAllPlan(commonPlanBuilder.getPlanList()); @@ -861,6 +882,7 @@ public RelNode visit(LogicalUnion union) { graphConfig, inputPlanBuilder, this.relToCommons, + this.extraParams, depth + 1)); unionBuilder.addSubPlans(inputPlanBuilder); } @@ -886,6 +908,7 @@ public RelNode visit(MultiJoin multiJoin) { graphConfig, commonPlanBuilder, this.relToCommons, + this.extraParams, depth + 1)); } physicalBuilder.addAllPlan(commonPlanBuilder.getPlanList()); @@ -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( @@ -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; }