From 4c9911f5c6c73f15978658822be79a16c0114ede Mon Sep 17 00:00:00 2001 From: shirly121 Date: Fri, 20 Sep 2024 19:44:45 +0800 Subject: [PATCH 01/17] [GIE Compiler] integrate procedure call into physical plan --- interactive_engine/compiler/build_ir_core.sh | 20 ++-- .../compiler/src/main/antlr4/CypherGS.g4 | 2 +- .../ir/meta/schema/GSDataTypeConvertor.java | 2 + .../common/ir/planner/GraphHepPlanner.java | 5 + .../common/ir/rel/GraphProcedureCall.java | 93 +++++++++++++++++++ .../common/ir/rel/GraphShuttle.java | 4 + .../ir/runtime/ProcedurePhysicalBuilder.java | 42 +++------ .../proto/GraphRelToProtoConverter.java | 24 +++++ .../common/ir/runtime/proto/Utils.java | 29 ++++++ .../common/ir/tools/GraphPlanner.java | 2 +- .../antlr4/visitor/GraphBuilderVisitor.java | 36 ++++++- .../antlr4/visitor/LogicalPlanVisitor.java | 5 +- .../antlr4/visitor/ProcedureCallVisitor.java | 3 +- .../common/ir/runtime/FfiLogicalPlanTest.java | 3 +- .../graphscope/cypher/antlr4/MatchTest.java | 70 ++++++++++++++ .../test/resources/config/modern/graph.yaml | 32 +++++++ .../executor/ir/proto/physical.proto | 6 ++ .../executor/ir/proto/stored_procedure.proto | 7 +- 18 files changed, 336 insertions(+), 49 deletions(-) create mode 100644 interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphProcedureCall.java diff --git a/interactive_engine/compiler/build_ir_core.sh b/interactive_engine/compiler/build_ir_core.sh index 532e2f0a5f64..3a27f9725c6d 100755 --- a/interactive_engine/compiler/build_ir_core.sh +++ b/interactive_engine/compiler/build_ir_core.sh @@ -1,12 +1,12 @@ #!/bin/bash -set -e -set -x - -if $(! command -v cargo &> /dev/null) -then - echo "cargo not exit, skip compile" -else - cd ../executor/ir/core - cargo build --release -fi +#set -e +#set -x +# +#if $(! command -v cargo &> /dev/null) +#then +# echo "cargo not exit, skip compile" +#else +# cd ../executor/ir/core +# cargo build --release +#fi diff --git a/interactive_engine/compiler/src/main/antlr4/CypherGS.g4 b/interactive_engine/compiler/src/main/antlr4/CypherGS.g4 index 30f6777fbe98..b4b1180ace41 100644 --- a/interactive_engine/compiler/src/main/antlr4/CypherGS.g4 +++ b/interactive_engine/compiler/src/main/antlr4/CypherGS.g4 @@ -52,7 +52,7 @@ CALL : ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ; YIELD : ( 'Y' | 'y' ) ( 'I' | 'i' ) ( 'E' | 'e' ) ( 'L' | 'l' ) ( 'D' | 'd' ) ; oC_RegularQuery - : oC_Match ( SP? ( oC_Match | oC_With ) )* ( SP oC_Return ) ; + : oC_Match ( SP? ( oC_Match | oC_With | oC_StandaloneCall ) )* ( SP oC_Return ) ; oC_Match : ( OPTIONAL SP )? MATCH SP? oC_Pattern ( SP? oC_Where )? ; diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/GSDataTypeConvertor.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/GSDataTypeConvertor.java index c8e89f7f2e5d..f12a70e8caf8 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/GSDataTypeConvertor.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/schema/GSDataTypeConvertor.java @@ -108,6 +108,8 @@ public RelDataType convert(GSDataTypeDesc from) { Object value; if ((value = typeMap.get("primitive_type")) != null) { switch (value.toString()) { + case "DT_ANY": + return typeFactory.createSqlType(SqlTypeName.ANY); case "DT_SIGNED_INT32": return typeFactory.createSqlType(SqlTypeName.INTEGER); case "DT_SIGNED_INT64": diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/planner/GraphHepPlanner.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/planner/GraphHepPlanner.java index 5ec5e479e702..4963c8e6e3fc 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/planner/GraphHepPlanner.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/planner/GraphHepPlanner.java @@ -145,6 +145,11 @@ public RelNode visit(LogicalJoin join) { return findBestIfRoot(join, visitChildren(join)); } + @Override + public RelNode visit(GraphProcedureCall procedureCall) { + return findBestIfRoot(procedureCall, visitChildren(procedureCall)); + } + @Override public RelNode visit(CommonTableScan tableScan) { RelOptTable optTable = tableScan.getTable(); diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphProcedureCall.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphProcedureCall.java new file mode 100644 index 000000000000..f49bc68eb8f4 --- /dev/null +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphProcedureCall.java @@ -0,0 +1,93 @@ +/* + * + * * Copyright 2020 Alibaba Group Holding Limited. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package com.alibaba.graphscope.common.ir.rel; + +import com.alibaba.graphscope.common.ir.tools.AliasInference; + +import org.apache.calcite.plan.GraphOptCluster; +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelShuttle; +import org.apache.calcite.rel.RelWriter; +import org.apache.calcite.rel.SingleRel; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.rel.type.RelDataTypeFieldImpl; +import org.apache.calcite.rel.type.RelRecordType; +import org.apache.calcite.rex.RexNode; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class GraphProcedureCall extends SingleRel { + private final RexNode procedure; + + public GraphProcedureCall( + RelOptCluster optCluster, RelTraitSet traitSet, RelNode input, RexNode procedure) { + super(optCluster, traitSet, input); + this.procedure = procedure; + } + + @Override + public RelWriter explainTerms(RelWriter pw) { + return super.explainTerms(pw).item("procedure", procedure); + } + + @Override + public RelNode accept(RelShuttle shuttle) { + if (shuttle instanceof GraphShuttle) { + return ((GraphShuttle) shuttle).visit(this); + } + return shuttle.visit(this); + } + + @Override + public RelDataType deriveRowType() { + Set uniqueNameList = AliasInference.getUniqueAliasList(input, true); + List reOrgFields = + this.procedure.getType().getFieldList().stream() + .map( + k -> { + // ensure the name is unique in the query + String checkName = + AliasInference.inferDefault( + k.getName(), uniqueNameList); + uniqueNameList.add(checkName); + return new RelDataTypeFieldImpl( + checkName, + ((GraphOptCluster) getCluster()) + .getIdGenerator() + .generate(checkName), + k.getType()); + }) + .collect(Collectors.toList()); + return new RelRecordType(reOrgFields); + } + + @Override + public GraphProcedureCall copy(RelTraitSet traitSet, List inputs) { + return new GraphProcedureCall(getCluster(), traitSet, sole(inputs), procedure); + } + + public RexNode getProcedure() { + return procedure; + } +} diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphShuttle.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphShuttle.java index bb95b5eb2c89..2662b7385c37 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphShuttle.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphShuttle.java @@ -101,6 +101,10 @@ public RelNode visit(LogicalJoin join) { return visitChildren(join); } + public RelNode visit(GraphProcedureCall procedureCall) { + return visitChildren(procedureCall); + } + @Override public RelNode visit(RelNode other) { if (other instanceof MultiJoin) { diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/ProcedurePhysicalBuilder.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/ProcedurePhysicalBuilder.java index a7b2b3dda339..add9393f0c17 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/ProcedurePhysicalBuilder.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/ProcedurePhysicalBuilder.java @@ -16,46 +16,28 @@ package com.alibaba.graphscope.common.ir.runtime; +import com.alibaba.graphscope.common.config.Configs; +import com.alibaba.graphscope.common.ir.meta.IrMeta; +import com.alibaba.graphscope.common.ir.runtime.proto.RexToProtoConverter; import com.alibaba.graphscope.common.ir.runtime.proto.Utils; +import com.alibaba.graphscope.common.ir.tools.GraphPlanner; import com.alibaba.graphscope.common.ir.tools.LogicalPlan; -import com.alibaba.graphscope.gaia.proto.Common; import com.alibaba.graphscope.gaia.proto.StoredProcedure; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.util.JsonFormat; -import org.apache.calcite.rex.*; -import org.apache.calcite.sql.SqlOperator; - -import java.util.List; - public class ProcedurePhysicalBuilder extends PhysicalBuilder { private final StoredProcedure.Query.Builder builder; - public ProcedurePhysicalBuilder(LogicalPlan logicalPlan) { + public ProcedurePhysicalBuilder(Configs configs, IrMeta irMeta, LogicalPlan logicalPlan) { super(logicalPlan); - this.builder = StoredProcedure.Query.newBuilder(); - RexCall procedureCall = (RexCall) logicalPlan.getProcedureCall(); - setStoredProcedureName(procedureCall, builder); - setStoredProcedureArgs(procedureCall, builder); - } - - private void setStoredProcedureName( - RexCall procedureCall, StoredProcedure.Query.Builder builder) { - SqlOperator operator = procedureCall.getOperator(); - builder.setQueryName(Common.NameOrId.newBuilder().setName(operator.getName()).build()); - } - - private void setStoredProcedureArgs( - RexCall procedureCall, StoredProcedure.Query.Builder builder) { - List operands = procedureCall.getOperands(); - for (int i = 0; i < operands.size(); ++i) { - builder.addArguments( - StoredProcedure.Argument.newBuilder() - // param name is omitted - .setParamInd(i) - .setValue(Utils.protoValue((RexLiteral) operands.get(i))) - .build()); - } + this.builder = + Utils.protoProcedure( + logicalPlan.getProcedureCall(), + new RexToProtoConverter( + true, + irMeta.getSchema().isColumnId(), + GraphPlanner.rexBuilderFactory.apply(configs))); } @Override 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 69184c613934..7055102edf1e 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 @@ -105,6 +105,30 @@ public GraphRelToProtoConverter( this.depth = depth; } + @Override + public RelNode visit(GraphProcedureCall procedureCall) { + visitChildren(procedureCall); + physicalBuilder.addPlan( + GraphAlgebraPhysical.PhysicalOpr.newBuilder() + .setOpr( + GraphAlgebraPhysical.PhysicalOpr.Operator.newBuilder() + .setProcedureCall( + GraphAlgebraPhysical.ProcedureCall.newBuilder() + .setQuery( + Utils.protoProcedure( + procedureCall + .getProcedure(), + new RexToProtoConverter( + true, + isColumnId, + this.rexBuilder)))) + .build()) + .addAllMetaData( + Utils.physicalProtoRowType(procedureCall.getRowType(), isColumnId)) + .build()); + return procedureCall; + } + @Override public RelNode visit(GraphLogicalSource source) { GraphAlgebraPhysical.PhysicalOpr.Builder oprBuilder = diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/Utils.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/Utils.java index 41955150c9a6..bf6c6ba35056 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/Utils.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/runtime/proto/Utils.java @@ -36,6 +36,7 @@ import org.apache.calcite.rel.core.JoinRelType; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexLiteral; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; @@ -776,4 +777,32 @@ public static void removeEdgeProperties( } tagColumns.keySet().removeAll(removeKeys); } + + public static final StoredProcedure.Query.Builder protoProcedure( + RexNode procedure, RexToProtoConverter converter) { + RexCall procedureCall = (RexCall) procedure; + StoredProcedure.Query.Builder builder = StoredProcedure.Query.newBuilder(); + SqlOperator operator = procedureCall.getOperator(); + builder.setQueryName(Common.NameOrId.newBuilder().setName(operator.getName()).build()); + List operands = procedureCall.getOperands(); + for (int i = 0; i < operands.size(); ++i) { + // param name is omitted + StoredProcedure.Argument.Builder paramBuilder = + StoredProcedure.Argument.newBuilder().setParamInd(i); + OuterExpression.ExprOpr protoValue = operands.get(i).accept(converter).getOperators(0); + switch (protoValue.getItemCase()) { + case VAR: + paramBuilder.setVar(protoValue.getVar()); + break; + case CONST: + paramBuilder.setConst(protoValue.getConst()); + break; + default: + throw new IllegalArgumentException( + "cannot set value=" + protoValue + " to any parameter in procedure"); + } + builder.addArguments(paramBuilder); + } + return builder; + } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java index cb69a5d6f987..e130ccf77a53 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java @@ -168,7 +168,7 @@ public PhysicalPlan planPhysical(LogicalPlan logicalPlan) { } } } else { - return new ProcedurePhysicalBuilder(logicalPlan).build(); + return new ProcedurePhysicalBuilder(graphConfig, irMeta, logicalPlan).build(); } } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/GraphBuilderVisitor.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/GraphBuilderVisitor.java index 936f21ad321c..3a33d686a487 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/GraphBuilderVisitor.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/GraphBuilderVisitor.java @@ -19,6 +19,7 @@ import com.alibaba.graphscope.common.antlr4.ExprUniqueAliasInfer; import com.alibaba.graphscope.common.antlr4.ExprVisitorResult; import com.alibaba.graphscope.common.ir.rel.GraphLogicalAggregate; +import com.alibaba.graphscope.common.ir.rel.GraphProcedureCall; import com.alibaba.graphscope.common.ir.rel.type.group.GraphAggCall; import com.alibaba.graphscope.common.ir.rex.RexTmpVariableConverter; import com.alibaba.graphscope.common.ir.rex.RexVariableAliasCollector; @@ -26,10 +27,13 @@ import com.alibaba.graphscope.common.ir.tools.config.GraphOpt; import com.alibaba.graphscope.grammar.CypherGSBaseVisitor; import com.alibaba.graphscope.grammar.CypherGSParser; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.common.base.Supplier; import com.google.common.collect.Lists; import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.plan.RelTraitSet; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexNode; @@ -47,15 +51,41 @@ public class GraphBuilderVisitor extends CypherGSBaseVisitor { private final GraphBuilder builder; private final ExpressionVisitor expressionVisitor; private final ExprUniqueAliasInfer aliasInfer; + private final Supplier procedureCallVisitorSupplier; - public GraphBuilderVisitor(GraphBuilder builder) { - this(builder, new ExprUniqueAliasInfer()); + public GraphBuilderVisitor( + GraphBuilder builder, Supplier procedureCallVisitorSupplier) { + this(builder, new ExprUniqueAliasInfer(), procedureCallVisitorSupplier); } - public GraphBuilderVisitor(GraphBuilder builder, ExprUniqueAliasInfer aliasInfer) { + public GraphBuilderVisitor( + GraphBuilder builder, + ExprUniqueAliasInfer aliasInfer, + Supplier procedureCallVisitorSupplier) { this.builder = Objects.requireNonNull(builder); this.aliasInfer = Objects.requireNonNull(aliasInfer); this.expressionVisitor = new ExpressionVisitor(this); + this.procedureCallVisitorSupplier = Objects.requireNonNull(procedureCallVisitorSupplier); + } + + @VisibleForTesting + public GraphBuilderVisitor(GraphBuilder builder) { + this(builder, new ExprUniqueAliasInfer(), () -> null); + } + + @Override + public GraphBuilder visitOC_StandaloneCall(CypherGSParser.OC_StandaloneCallContext ctx) { + ProcedureCallVisitor procedureCallVisitor = procedureCallVisitorSupplier.get(); + Preconditions.checkArgument( + procedureCallVisitor != null, + "cannot do procedure call without procedure call visitor"); + RexNode procedure = procedureCallVisitor.visitOC_StandaloneCall(ctx); + return builder.push( + new GraphProcedureCall( + builder.getCluster(), + RelTraitSet.createEmpty(), + builder.build(), + procedure)); } @Override diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/LogicalPlanVisitor.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/LogicalPlanVisitor.java index 8472fd682812..8033ad049a4f 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/LogicalPlanVisitor.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/LogicalPlanVisitor.java @@ -59,7 +59,10 @@ public LogicalPlan visitOC_Cypher(CypherGSParser.OC_CypherContext ctx) { @Override public LogicalPlan visitOC_Query(CypherGSParser.OC_QueryContext ctx) { if (ctx.oC_RegularQuery() != null) { - GraphBuilderVisitor builderVisitor = new GraphBuilderVisitor(this.builder); + GraphBuilderVisitor builderVisitor = + new GraphBuilderVisitor( + this.builder, + () -> new ProcedureCallVisitor(this.builder, this.irMeta)); RelNode regularQuery = builderVisitor.visitOC_RegularQuery(ctx.oC_RegularQuery()).build(); Map map = builderVisitor.getExpressionVisitor().getDynamicParams(); diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/ProcedureCallVisitor.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/ProcedureCallVisitor.java index b5d690d0751b..915ed3d04f18 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/ProcedureCallVisitor.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/antlr4/visitor/ProcedureCallVisitor.java @@ -40,7 +40,8 @@ public class ProcedureCallVisitor extends CypherGSBaseVisitor { public ProcedureCallVisitor(GraphBuilder builder, IrMeta irMeta) { this.builder = builder; - this.expressionVisitor = new ExpressionVisitor(new GraphBuilderVisitor(this.builder)); + this.expressionVisitor = + new ExpressionVisitor(new GraphBuilderVisitor(this.builder, () -> this)); this.irMeta = irMeta; } diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/FfiLogicalPlanTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/FfiLogicalPlanTest.java index fa2cc42c35e1..dcb3decb3899 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/FfiLogicalPlanTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/runtime/FfiLogicalPlanTest.java @@ -159,7 +159,8 @@ public void logical_plan_4_test() throws Exception { LogicalPlan logicalPlan = com.alibaba.graphscope.cypher.antlr4.Utils.evalLogicalPlan( "Call ldbc_ic2(10l, 20120112l)", "config/modern/graph.yaml"); - try (PhysicalBuilder ffiBuilder = new ProcedurePhysicalBuilder(logicalPlan)) { + try (PhysicalBuilder ffiBuilder = + new ProcedurePhysicalBuilder(Utils.configs, Utils.schemaMeta, logicalPlan)) { PhysicalPlan plan = ffiBuilder.build(); Assert.assertEquals( FileUtils.readJsonFromResource("call_procedure.json"), plan.explain()); diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java index 17ba8e808dc9..88fdbbf19059 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/antlr4/MatchTest.java @@ -19,18 +19,48 @@ import com.alibaba.graphscope.common.config.Configs; import com.alibaba.graphscope.common.config.FrontendConfig; import com.alibaba.graphscope.common.exception.FrontendException; +import com.alibaba.graphscope.common.ir.meta.IrMeta; +import com.alibaba.graphscope.common.ir.planner.GraphIOProcessor; +import com.alibaba.graphscope.common.ir.planner.GraphRelOptimizer; import com.alibaba.graphscope.common.ir.rel.graph.GraphLogicalSource; import com.alibaba.graphscope.common.ir.tools.GraphBuilder; import com.alibaba.graphscope.common.ir.tools.LogicalPlan; +import com.alibaba.graphscope.cypher.antlr4.parser.CypherAntlr4Parser; +import com.alibaba.graphscope.cypher.antlr4.visitor.LogicalPlanVisitor; import com.google.common.collect.ImmutableMap; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rex.RexCall; import org.apache.calcite.sql.type.SqlTypeName; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; public class MatchTest { + private static Configs configs; + private static IrMeta irMeta; + private static GraphRelOptimizer optimizer; + + @BeforeClass + public static void beforeClass() { + configs = + new Configs( + ImmutableMap.of( + "graph.planner.is.on", + "true", + "graph.planner.opt", + "CBO", + "graph.planner.rules", + "FilterIntoJoinRule, FilterMatchRule, ExtendIntersectRule," + + " ExpandGetVFusionRule")); + optimizer = new GraphRelOptimizer(configs); + irMeta = + com.alibaba.graphscope.common.ir.Utils.mockIrMeta( + "config/modern/graph.yaml", + "statistics/modern_statistics.json", + optimizer.getGlogueHolder()); + } + @Test public void match_1_test() { RelNode source = Utils.eval("Match (n) Return n").build(); @@ -524,4 +554,44 @@ public void property_exist_after_type_inference_test() { + " properties=[BIGINT creationDate]) h)", rel.getRowType().toString()); } + + @Test + public void shortest_path_test() { + GraphBuilder builder = + com.alibaba.graphscope.common.ir.Utils.mockGraphBuilder(optimizer, irMeta); + LogicalPlanVisitor logicalPlanVisitor = new LogicalPlanVisitor(builder, irMeta); + LogicalPlan logicalPlan = + logicalPlanVisitor.visit( + new CypherAntlr4Parser() + .parse( + "MATCH\n" + + "(person1:person {id:" + + " $person1Id})-[:knows]->(person2:person {id:" + + " $person2Id})\n" + + "CALL shortestPath.dijkstra.stream(\n" + + " person1, person2, 'KNOWS', 'BOTH', 'weight', 5)\n" + + "WITH person1, person2, totalCost\n" + + "WHERE person1.id <> $person2Id\n" + + "Return person1.id AS person1Id, totalCost AS" + + " totalWeight;")); + RelNode after = + optimizer.optimize( + logicalPlan.getRegularQuery(), new GraphIOProcessor(builder, irMeta)); + Assert.assertEquals( + "GraphLogicalProject(person1Id=[person1.id], totalWeight=[totalCost]," + + " isAppend=[false])\n" + + " LogicalFilter(condition=[<>(person1.id, ?1)])\n" + + " GraphLogicalProject(person1=[person1], person2=[person2]," + + " totalCost=[totalCost], isAppend=[false])\n" + + " GraphProcedureCall(procedure=[shortestPath.dijkstra.stream(person1," + + " person2, _UTF-8'KNOWS', _UTF-8'BOTH', _UTF-8'weight', 5)])\n" + + " GraphPhysicalGetV(tableConfig=[{isAll=false, tables=[person]}]," + + " alias=[person2], fusedFilter=[[=(_.id, ?1)]], opt=[END]," + + " physicalOpt=[ITSELF])\n" + + " GraphPhysicalExpand(tableConfig=[{isAll=false, tables=[knows]}]," + + " alias=[_], startAlias=[person1], opt=[OUT], physicalOpt=[VERTEX])\n" + + " GraphLogicalSource(tableConfig=[{isAll=false, tables=[person]}]," + + " alias=[person1], opt=[VERTEX], uniqueKeyFilters=[=(_.id, ?0)])", + after.explain().trim()); + } } diff --git a/interactive_engine/compiler/src/test/resources/config/modern/graph.yaml b/interactive_engine/compiler/src/test/resources/config/modern/graph.yaml index 85a94f9077c1..72a261cdceb7 100644 --- a/interactive_engine/compiler/src/test/resources/config/modern/graph.yaml +++ b/interactive_engine/compiler/src/test/resources/config/modern/graph.yaml @@ -19,6 +19,38 @@ stored_procedures: query: "MATCH(n: PERSON ${personId2}) WHERE n.creationDate < ${maxDate} RETURN n.firstName AS name LIMIT 10;" library: libquery_ic2.so encoding: string + - name: shortestPath.dijkstra.stream + description: "" + type: x_cypher + params: + - name: person1 + type: + primitive_type: DT_ANY + - name: person2 + type: + primitive_type: DT_ANY + - name: label + type: + string: + long_text: + - name: direction + type: + string: + long_text: + - name: property + type: + string: + long_text: + - name: iterations + type: + primitive_type: DT_SIGNED_INT32 + returns: + - name: totalCost + type: + primitive_type: DT_FLOAT + query: "" + library: libquery_shortest_path.so + encoding: string schema: vertex_types: - type_name: person diff --git a/interactive_engine/executor/ir/proto/physical.proto b/interactive_engine/executor/ir/proto/physical.proto index 8e4f30d40ac4..3cafff2ebe94 100644 --- a/interactive_engine/executor/ir/proto/physical.proto +++ b/interactive_engine/executor/ir/proto/physical.proto @@ -24,6 +24,7 @@ import "expr.proto"; import "schema.proto"; import "type.proto"; import "algebra.proto"; +import "stored_procedure.proto"; import "google/protobuf/wrappers.proto"; // To project a relation on certain attributes or further their properties @@ -277,6 +278,10 @@ message Repartition { // A dummy node to delegate a source opr for multiple scan cases. message Root {} +message ProcedureCall { + procedure.Query query = 1; +} + message PhysicalOpr { message Operator { oneof op_kind { @@ -300,6 +305,7 @@ message PhysicalOpr { GetV vertex = 30; EdgeExpand edge = 31; PathExpand path = 32; + ProcedureCall procedure_call = 33; } } message MetaData { diff --git a/interactive_engine/executor/ir/proto/stored_procedure.proto b/interactive_engine/executor/ir/proto/stored_procedure.proto index 51bd7d64c431..48446b077233 100644 --- a/interactive_engine/executor/ir/proto/stored_procedure.proto +++ b/interactive_engine/executor/ir/proto/stored_procedure.proto @@ -20,11 +20,16 @@ option java_package = "com.alibaba.graphscope.gaia.proto"; option java_outer_classname = "StoredProcedure"; import "common.proto"; +import "expr.proto"; message Argument { string param_name = 1; // param name int32 param_ind = 2; // index of param - common.Value value = 3; // real value + + oneof value { + common.Value const = 3; // real value + common.Variable var = 4; + } } message Query { From 764a05bc276f2c7ca83e416b3e119b4b335cf425 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 15 Oct 2024 15:42:21 +0800 Subject: [PATCH 02/17] impl call_proc Committed-by: xiaolei.zl from Dev container --- flex/engines/graph_db/database/graph_db.cc | 9 +- .../graph_db/database/graph_db_session.cc | 9 + .../graph_db/database/graph_db_session.h | 2 + .../runtime/adhoc/operators/operators.h | 5 + .../runtime/adhoc/operators/procedure_call.cc | 317 ++++++++++++++++++ .../engines/graph_db/runtime/adhoc/runtime.cc | 9 + .../runtime/common/columns/i_context_column.h | 24 ++ .../runtime/common/columns/value_columns.cc | 1 + .../runtime/common/columns/value_columns.h | 200 +++++++---- .../graph_db/runtime/common/leaf_utils.h | 4 + .../engines/graph_db/runtime/common/rt_any.cc | 31 +- flex/engines/graph_db/runtime/common/rt_any.h | 15 + flex/engines/graph_db/runtime/common/types.cc | 5 + flex/engines/graph_db/runtime/common/types.h | 2 + .../hqps_db/app/interactive_app_base.h | 7 +- .../gs_interactive/tests/test_robustness.py | 9 + flex/storages/rt_mutable_graph/schema.cc | 13 + 17 files changed, 585 insertions(+), 77 deletions(-) create mode 100644 flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc diff --git a/flex/engines/graph_db/database/graph_db.cc b/flex/engines/graph_db/database/graph_db.cc index 2f3ad08306c8..ed27fac9b825 100644 --- a/flex/engines/graph_db/database/graph_db.cc +++ b/flex/engines/graph_db/database/graph_db.cc @@ -428,9 +428,14 @@ void GraphDB::initApps( size_t valid_plugins = 0; for (auto& path_and_index : plugins) { auto path = path_and_index.second.first; + auto name = path_and_index.first; auto index = path_and_index.second.second; - if (registerApp(path, index)) { - ++valid_plugins; + if (!Schema::IsBuiltinPlugin(name)) { + if (registerApp(path, index)) { + ++valid_plugins; + } + } else { + valid_plugins++; } } LOG(INFO) << "Successfully registered stored procedures : " << valid_plugins diff --git a/flex/engines/graph_db/database/graph_db_session.cc b/flex/engines/graph_db/database/graph_db_session.cc index 96e51f2d70f2..6b77bbafc4a7 100644 --- a/flex/engines/graph_db/database/graph_db_session.cc +++ b/flex/engines/graph_db/database/graph_db_session.cc @@ -216,6 +216,15 @@ int64_t GraphDBSession::query_num() const { return query_num_.load(); } #define likely(x) __builtin_expect(!!(x), 1) +AppBase* GraphDBSession::GetApp(const std::string& app_name) { + auto& app_name_to_path_index = db_.schema().GetPlugins(); + if (app_name_to_path_index.count(app_name) <= 0) { + LOG(ERROR) << "Query name is not registered: " << app_name; + return nullptr; + } + return GetApp(app_name_to_path_index.at(app_name).second); +} + AppBase* GraphDBSession::GetApp(int type) { // create if not exist if (type >= GraphDBSession::MAX_PLUGIN_NUM) { diff --git a/flex/engines/graph_db/database/graph_db_session.h b/flex/engines/graph_db/database/graph_db_session.h index 918e22d62514..e4ed13f74990 100644 --- a/flex/engines/graph_db/database/graph_db_session.h +++ b/flex/engines/graph_db/database/graph_db_session.h @@ -105,6 +105,8 @@ class GraphDBSession { AppBase* GetApp(int idx); + AppBase* GetApp(const std::string& name); + private: Result> parse_query_type_from_cypher_json(const std::string_view& input); diff --git a/flex/engines/graph_db/runtime/adhoc/operators/operators.h b/flex/engines/graph_db/runtime/adhoc/operators/operators.h index 395d94acae9c..9b1a81e51dc5 100644 --- a/flex/engines/graph_db/runtime/adhoc/operators/operators.h +++ b/flex/engines/graph_db/runtime/adhoc/operators/operators.h @@ -78,6 +78,11 @@ bl::result eval_join(const physical::Join& opr, Context&& ctx, bl::result eval_limit(const algebra::Limit& opr, Context&& ctx); +bl::result eval_procedure_call(std::vector alias, + const physical::ProcedureCall& opr, + const ReadTransaction& txn, + Context&& ctx); + void eval_sink(const Context& ctx, const ReadTransaction& txn, Encoder& output); } // namespace runtime diff --git a/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc new file mode 100644 index 000000000000..7bba6af61993 --- /dev/null +++ b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc @@ -0,0 +1,317 @@ +/** Copyright 2020 Alibaba Group Holding Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "flex/engines/graph_db/database/graph_db.h" +#include "flex/engines/graph_db/database/graph_db_session.h" +#include "flex/engines/graph_db/runtime/adhoc/operators/operators.h" +#include "flex/engines/graph_db/runtime/common/leaf_utils.h" +#include "flex/proto_generated_gie/algebra.pb.h" + +namespace gs { +namespace runtime { + +std::shared_ptr any_vec_to_column( + const std::vector& any_vec) { + if (any_vec.empty()) { + return nullptr; + } + auto first = any_vec[0].type(); + if (first == RTAnyType::kBoolValue) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_bool()); + } + return builder.finish(); + } else if (first == RTAnyType::kI32Value) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_int32()); + } + return builder.finish(); + } else if (first == RTAnyType::kI64Value) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_int64()); + } + return builder.finish(); + } else if (first == RTAnyType::kF64Value) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_double()); + } + return builder.finish(); + } else if (first == RTAnyType::kStringValue) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(std::string(any.as_string())); + } + return builder.finish(); + } else if (first == RTAnyType::kStdStringValue) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_std_string()); + } + return builder.finish(); + } else { + LOG(FATAL) << "Unsupported RTAny type: " + << static_cast(first.type_enum_); + } +} + +RTAny vertex_to_rt_any(const results::Vertex& vertex) { + auto label_id = vertex.label().id(); + auto label_id_vid = decode_unique_vertex_id(vertex.id()); + CHECK(label_id == label_id_vid.first) << "Inconsistent label id."; + return RTAny::from_vertex(label_id, label_id_vid.second); +} + +RTAny edge_to_rt_any(const results::Edge& edge) { + LOG(FATAL) << "Not implemented."; + return RTAny(); +} + +RTAny object_to_rt_any(const common::Value& val) { + if (val.item_case() == common::Value::kBoolean) { + return RTAny::from_bool(val.boolean()); + } else if (val.item_case() == common::Value::kI32) { + return RTAny::from_int32(val.i32()); + } else if (val.item_case() == common::Value::kI64) { + return RTAny::from_int64(val.i64()); + } else if (val.item_case() == common::Value::kF64) { + return RTAny::from_double(val.f64()); + } else if (val.item_case() == common::Value::kStr) { + return RTAny::from_string(val.str()); + } else { + LOG(FATAL) << "Unsupported value type: " << val.item_case(); + } +} + +RTAny element_to_rt_any(const results::Element& element) { + if (element.inner_case() == results::Element::kVertex) { + return vertex_to_rt_any(element.vertex()); + } else if (element.inner_case() == results::Element::kEdge) { + return edge_to_rt_any(element.edge()); + } else if (element.inner_case() == results::Element::kObject) { + return object_to_rt_any(element.object()); + } else { + LOG(FATAL) << "Unsupported element type: " << element.inner_case(); + } +} + +RTAny collection_to_rt_any(const results::Collection& collection) { + std::vector values; + for (const auto& element : collection.collection()) { + values.push_back(element_to_rt_any(element)); + } + return RTAny::from_tuple(std::move(values)); +} + +RTAny map_to_rt_any(const results::KeyValues& map) { + LOG(FATAL) << "Not implemented."; +} + +RTAny column_to_rt_any(const results::Column& column) { + auto& entry = column.entry(); + if (entry.has_element()) { + return element_to_rt_any(entry.element()); + } else if (entry.has_collection()) { + return collection_to_rt_any(entry.collection()); + } else { + return map_to_rt_any(entry.map()); + } +} + +std::vector result_to_rt_any(const results::Results& result) { + auto& record = result.record(); + if (record.columns_size() == 0) { + LOG(WARNING) << "Empty result."; + return {}; + } else { + std::vector tuple; + for (int32_t i = 0; i < record.columns_size(); ++i) { + tuple.push_back(column_to_rt_any(record.columns(i))); + } + return tuple; + } +} + +std::pair>, std::vector> +collective_result_vec_to_column( + int32_t expect_col_num, + const std::vector& collective_results_vec) { + std::vector offsets; + offsets.push_back(0); + size_t record_cnt = 0; + for (size_t i = 0; i < collective_results_vec.size(); ++i) { + record_cnt += collective_results_vec[i].results_size(); + offsets.push_back(record_cnt); + } + LOG(INFO) << "record_cnt: " << record_cnt; + std::vector> any_vec(expect_col_num); + for (size_t i = 0; i < collective_results_vec.size(); ++i) { + for (int32_t j = 0; j < collective_results_vec[i].results_size(); ++j) { + auto tuple = result_to_rt_any(collective_results_vec[i].results(j)); + CHECK(tuple.size() == (size_t) expect_col_num) + << "Inconsistent column number."; + for (int32_t k = 0; k < expect_col_num; ++k) { + any_vec[k].push_back(tuple[k]); + } + } + } + std::vector> columns; + for (int32_t i = 0; i < expect_col_num; ++i) { + columns.push_back(any_vec_to_column(any_vec[i])); + } + return std::make_pair(columns, offsets); +} + +procedure::Query fill_in_query(const procedure::Query& query, + const Context& ctx, size_t idx) { + procedure::Query real_query; + real_query.mutable_query_name()->CopyFrom(query.query_name()); + for (auto& param : query.arguments()) { + auto argument = real_query.add_arguments(); + if (param.value_case() == procedure::Argument::kVar) { + auto& var = param.var(); + auto tag = var.tag().id(); + auto col = ctx.get(tag); + if (col == nullptr) { + LOG(ERROR) << "Tag not found: " << tag; + continue; + } + auto val = col->get_elem(idx); + auto const_value = argument->mutable_const_(); + if (val.type() == gs::runtime::RTAnyType::kVertex) { + LOG(FATAL) << "Not implemented yet"; + } else if (val.type() == gs::runtime::RTAnyType::kEdge) { + LOG(FATAL) << "Not implemented yet"; + } else if (val.type() == gs::runtime::RTAnyType::kI64Value) { + const_value->set_i64(val.as_int64()); + } else if (val.type() == gs::runtime::RTAnyType::kI32Value) { + const_value->set_i32(val.as_int32()); + } else if (val.type() == gs::runtime::RTAnyType::kStringValue) { + const_value->set_str(std::string(val.as_string())); + } else { + LOG(ERROR) << "Unsupported type: " + << static_cast(val.type().type_enum_); + } + } else { + argument->CopyFrom(param); + } + } + return real_query; +} + +/** + * @brief Evaluate the ProcedureCall operator. + * The ProcedureCall operator is used to call a stored procedure, which is + * already registered in the system. The return value of the stored procedure is + * a result::CollectiveResults object, we need to convert it to a Column, and + * append to the current context. + * + * + * @param opr The ProcedureCall operator. + * @param txn The read transaction. + * @param ctx The input context. + * + * @return bl::result The output context. + * + * + */ +bl::result eval_procedure_call(std::vector aliases, + const physical::ProcedureCall& opr, + const ReadTransaction& txn, + Context&& ctx) { + auto& query = opr.query(); + auto& proc_name = query.query_name(); + + if (proc_name.item_case() == common::NameOrId::kName) { + // TODO: avoid calling graphDB here. + auto& db = gs::GraphDB::get(); + //------------------------------------------ + // FIXME: sess id is hard coded to 0 + auto& sess = db.GetSession(0); + + AppBase* app = sess.GetApp(proc_name.name()); + if (!app) { + RETURN_BAD_REQUEST_ERROR("Stored procedure not found: " + + proc_name.name()); + } + ReadAppBase* read_app = dynamic_cast(app); + if (!app) { + RETURN_BAD_REQUEST_ERROR("Stored procedure is not a read procedure: " + + proc_name.name()); + } + + std::vector results; + // Iterate over current context. + for (size_t i = 0; i < ctx.row_num(); ++i) { + // Call the procedure. + // Use real values from the context to replace the placeholders in the + // query. + auto real_query = fill_in_query(query, ctx, i); + // We need to serialize the protobuf-based arguments to the input format + // that a cypher procedure can accept. + auto query_str = real_query.SerializeAsString(); + // append CYPHER_PROTO as the last byte as input_format + query_str.push_back(static_cast( + GraphDBSession::InputFormat::kCypherProtoProcedure)); + std::vector buffer; + Encoder encoder(buffer); + Decoder decoder(query_str.data(), query_str.size()); + if (!read_app->run(sess, decoder, encoder)) { + RETURN_CALL_PROCEDURE_ERROR("Failed to call procedure: "); + } + // Decode the result from the encoder. + Decoder result_decoder(buffer.data(), buffer.size()); + if (result_decoder.size() < 4) { + LOG(ERROR) << "Unexpected result size: " << result_decoder.size(); + RETURN_CALL_PROCEDURE_ERROR("Unexpected result size"); + } + std::string collective_results_str(result_decoder.get_string()); + results::CollectiveResults collective_results; + if (!collective_results.ParseFromString(collective_results_str)) { + LOG(ERROR) << "Failed to parse CollectiveResults"; + RETURN_CALL_PROCEDURE_ERROR("Failed to parse procedure's result"); + } + results.push_back(collective_results); + } + + auto column_and_offsets = + collective_result_vec_to_column(aliases.size(), results); + auto& columns = column_and_offsets.first; + auto& offsets = column_and_offsets.second; + if (columns.size() != aliases.size()) { + LOG(ERROR) << "Column size mismatch: " << columns.size() << " vs " + << aliases.size(); + RETURN_CALL_PROCEDURE_ERROR("Column size mismatch"); + } + LOG(INFO) << "Procedure call returns " << columns.size() << " columns"; + if (columns.size() >= 1) { + ctx.set_with_reshuffle(aliases[0], columns[0], offsets); + } + for (size_t i = 1; i < columns.size(); ++i) { + ctx.set(aliases[i], columns[i]); + } + return std::move(ctx); + } else { + LOG(ERROR) << "Currently only support calling stored procedure by name"; + RETURN_UNSUPPORTED_ERROR( + "Currently only support calling stored procedure by name"); + } +} + +} // namespace runtime +} // namespace gs diff --git a/flex/engines/graph_db/runtime/adhoc/runtime.cc b/flex/engines/graph_db/runtime/adhoc/runtime.cc index 48f35b9b2992..b0d9e27ba78f 100644 --- a/flex/engines/graph_db/runtime/adhoc/runtime.cc +++ b/flex/engines/graph_db/runtime/adhoc/runtime.cc @@ -229,6 +229,15 @@ bl::result runtime_eval_impl( case physical::PhysicalOpr_Operator::OpKindCase::kLimit: { BOOST_LEAF_ASSIGN(ret, eval_limit(opr.opr().limit(), std::move(ret))); } break; + case physical::PhysicalOpr_Operator::OpKindCase::kProcedureCall: { + std::vector aliases; + for (int32_t i = 0; i < opr.meta_data_size(); ++i) { + aliases.push_back(opr.meta_data(i).alias()); + } + BOOST_LEAF_ASSIGN( + ret, eval_procedure_call(aliases, opr.opr().procedure_call(), txn, + std::move(ret))); + } break; default: LOG(ERROR) << "Unknown operator type: " diff --git a/flex/engines/graph_db/runtime/common/columns/i_context_column.h b/flex/engines/graph_db/runtime/common/columns/i_context_column.h index c35f97f19378..cdacb8d5fd24 100644 --- a/flex/engines/graph_db/runtime/common/columns/i_context_column.h +++ b/flex/engines/graph_db/runtime/common/columns/i_context_column.h @@ -110,6 +110,30 @@ class SigColumn : public ISigColumn { std::vector sig_list_; }; +template <> +class SigColumn : public ISigColumn { + public: + SigColumn(const std::vector& data) { + std::unordered_map table; + sig_list_.reserve(data.size()); + for (auto& str : data) { + auto iter = table.find(str); + if (iter == table.end()) { + size_t idx = table.size(); + table.emplace(str, idx); + sig_list_.push_back(idx); + } else { + sig_list_.push_back(iter->second); + } + } + } + ~SigColumn() = default; + size_t get_sig(size_t idx) const override { return sig_list_[idx]; } + + private: + std::vector sig_list_; +}; + template <> class SigColumn> : public ISigColumn { public: diff --git a/flex/engines/graph_db/runtime/common/columns/value_columns.cc b/flex/engines/graph_db/runtime/common/columns/value_columns.cc index 8a1c23ac8dfc..f136e9f44348 100644 --- a/flex/engines/graph_db/runtime/common/columns/value_columns.cc +++ b/flex/engines/graph_db/runtime/common/columns/value_columns.cc @@ -14,6 +14,7 @@ */ #include "flex/engines/graph_db/runtime/common/columns/value_columns.h" +#include "flex/proto_generated_gie/results.pb.h" namespace gs { diff --git a/flex/engines/graph_db/runtime/common/columns/value_columns.h b/flex/engines/graph_db/runtime/common/columns/value_columns.h index 1547ab7b91fb..bc0372bb2d49 100644 --- a/flex/engines/graph_db/runtime/common/columns/value_columns.h +++ b/flex/engines/graph_db/runtime/common/columns/value_columns.h @@ -47,24 +47,31 @@ class ValueColumn : public IValueColumn { size_t size() const override { return data_.size(); } std::string column_info() const override { - return "ValueColumn<" + TypedConverter::name() + ">[" + std::to_string(size()) + "]"; + return "ValueColumn<" + TypedConverter::name() + ">[" + + std::to_string(size()) + "]"; + } + ContextColumnType column_type() const override { + return ContextColumnType::kValue; } - ContextColumnType column_type() const override { return ContextColumnType::kValue; } std::shared_ptr builder() const override { return std::make_shared>(); } - std::shared_ptr optional_builder() const override { + std::shared_ptr optional_builder() + const override { return std::dynamic_pointer_cast( std::make_shared>()); } std::shared_ptr dup() const override; - std::shared_ptr shuffle(const std::vector& offsets) const override; + std::shared_ptr shuffle( + const std::vector& offsets) const override; RTAnyType elem_type() const override { return TypedConverter::type(); } - RTAny get_elem(size_t idx) const override { return TypedConverter::from_typed(data_[idx]); } + RTAny get_elem(size_t idx) const override { + return TypedConverter::from_typed(data_[idx]); + } T get_value(size_t idx) const override { return data_[idx]; } @@ -82,22 +89,25 @@ class ValueColumn : public IValueColumn { for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { - // data_[a] == data_[b] - if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), + [this](size_t a, size_t b) { + // data_[a] == data_[b] + if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { - if (i == 0 || ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || - (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { + if (i == 0 || + ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || + (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { offsets.push_back(origin_offsets[i]); } } } - std::shared_ptr union_col(std::shared_ptr other) const override; + std::shared_ptr union_col( + std::shared_ptr other) const override; private: template @@ -117,7 +127,9 @@ class ValueColumn : public IValueColumn { return "ValueColumn<" + TypedConverter::name() + ">[" + std::to_string(size()) + "]"; } - ContextColumnType column_type() const override { return ContextColumnType::kValue; } + ContextColumnType column_type() const override { + return ContextColumnType::kValue; + } std::shared_ptr builder() const override { return std::dynamic_pointer_cast( @@ -125,26 +137,34 @@ class ValueColumn : public IValueColumn { } RTAnyType elem_type() const override { return RTAnyType::kStringValue; } - std::shared_ptr shuffle(const std::vector& offsets) const override; + std::shared_ptr shuffle( + const std::vector& offsets) const override; std::shared_ptr dup() const override; - RTAny get_elem(size_t idx) const override { return RTAny::from_string(data_[idx]); } + RTAny get_elem(size_t idx) const override { + return RTAny::from_string(data_[idx]); + } - std::string_view get_value(size_t idx) const override { return std::string_view(data_[idx]); } + std::string_view get_value(size_t idx) const override { + return std::string_view(data_[idx]); + } - ISigColumn* generate_signature() const override { return new SigColumn(data_); } + ISigColumn* generate_signature() const override { + return new SigColumn(data_); + } void generate_dedup_offset(std::vector& offsets) const override { std::vector origin_offsets(data_.size()); for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { - if (data_[a] == data_[b]) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), + [this](size_t a, size_t b) { + if (data_[a] == data_[b]) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { if (i == 0 || data_[origin_offsets[i]] != data_[origin_offsets[i - 1]]) { offsets.push_back(origin_offsets[i]); @@ -194,7 +214,9 @@ class ListValueColumn : public IValueColumn { std::string column_info() const override { return "ListValueColumn[" + std::to_string(size()) + "]"; } - ContextColumnType column_type() const override { return ContextColumnType::kValue; } + ContextColumnType column_type() const override { + return ContextColumnType::kValue; + } std::shared_ptr builder() const override { auto builder = std::make_shared>(); @@ -204,12 +226,15 @@ class ListValueColumn : public IValueColumn { } std::shared_ptr dup() const override; - std::shared_ptr shuffle(const std::vector& offsets) const override; + std::shared_ptr shuffle( + const std::vector& offsets) const override; RTAnyType elem_type() const override { auto type = RTAnyType::kList; return type; } - RTAny get_elem(size_t idx) const override { return RTAny::from_list(data_[idx]); } + RTAny get_elem(size_t idx) const override { + return RTAny::from_list(data_[idx]); + } List get_value(size_t idx) const override { return data_[idx]; } @@ -223,16 +248,18 @@ class ListValueColumn : public IValueColumn { for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { - // data_[a] == data_[b] - if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), + [this](size_t a, size_t b) { + // data_[a] == data_[b] + if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { - if (i == 0 || ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || - (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { + if (i == 0 || + ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || + (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { offsets.push_back(origin_offsets[i]); } } @@ -260,11 +287,14 @@ class ListValueColumnBuilder : public IContextColumnBuilder { void push_back_opt(const List& val) { data_.emplace_back(val); } - void set_list_impls(const std::vector>& list_impls) { + void set_list_impls( + const std::vector>& list_impls) { list_impls_ = list_impls; } - void set_list_data(const std::vector>& list_data) { list_data_ = list_data; } + void set_list_data(const std::vector>& list_data) { + list_data_ = list_data; + } std::shared_ptr finish() override { auto ret = std::make_shared>(); @@ -317,13 +347,16 @@ class MapValueColumn : public IValueColumn { return "MapValueColumn[" + std::to_string(size()) + "]"; } - ContextColumnType column_type() const override { return ContextColumnType::kValue; } + ContextColumnType column_type() const override { + return ContextColumnType::kValue; + } std::shared_ptr builder() const override; std::shared_ptr dup() const override; - std::shared_ptr shuffle(const std::vector& offsets) const override; + std::shared_ptr shuffle( + const std::vector& offsets) const override; RTAnyType elem_type() const override { auto type = RTAnyType::kMap; @@ -375,7 +408,9 @@ class MapValueColumnBuilder : public IContextColumnBuilder { values_.push_back(std::move(values)); } - void push_back_opt(const std::vector& values) { values_.push_back(values); } + void push_back_opt(const std::vector& values) { + values_.push_back(values); + } void set_keys(const std::vector& keys) { keys_ = keys; } @@ -401,9 +436,12 @@ class OptionalValueColumn : public IValueColumn { size_t size() const override { return data_.size(); } std::string column_info() const override { - return "OptionalValueColumn<" + TypedConverter::name() + ">[" + std::to_string(size()) + "]"; + return "OptionalValueColumn<" + TypedConverter::name() + ">[" + + std::to_string(size()) + "]"; + } + ContextColumnType column_type() const override { + return ContextColumnType::kOptionalValue; } - ContextColumnType column_type() const override { return ContextColumnType::kOptionalValue; } std::shared_ptr dup() const override { OptionalValueColumnBuilder builder; @@ -413,7 +451,8 @@ class OptionalValueColumn : public IValueColumn { return builder.finish(); } - std::shared_ptr shuffle(const std::vector& offsets) const override { + std::shared_ptr shuffle( + const std::vector& offsets) const override { OptionalValueColumnBuilder builder; builder.reserve(offsets.size()); for (auto offset : offsets) { @@ -432,7 +471,9 @@ class OptionalValueColumn : public IValueColumn { type.null_able_ = true; return type; } - RTAny get_elem(size_t idx) const override { return TypedConverter::from_typed(data_[idx]); } + RTAny get_elem(size_t idx) const override { + return TypedConverter::from_typed(data_[idx]); + } T get_value(size_t idx) const override { return data_[idx]; } @@ -450,16 +491,18 @@ class OptionalValueColumn : public IValueColumn { for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { - // data_[a] == data_[b] - if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), + [this](size_t a, size_t b) { + // data_[a] == data_[b] + if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { - if (i == 0 || ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || - (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { + if (i == 0 || + ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || + (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { offsets.push_back(origin_offsets[i]); } } @@ -476,7 +519,8 @@ class OptionalValueColumn : public IValueColumn { }; template <> -class OptionalValueColumn : public IValueColumn { +class OptionalValueColumn + : public IValueColumn { public: OptionalValueColumn() = default; ~OptionalValueColumn() = default; @@ -484,10 +528,12 @@ class OptionalValueColumn : public IValueColumn::name() + ">[" + - std::to_string(size()) + "]"; + return "OptionalValueColumn<" + TypedConverter::name() + + ">[" + std::to_string(size()) + "]"; + } + ContextColumnType column_type() const override { + return ContextColumnType::kOptionalValue; } - ContextColumnType column_type() const override { return ContextColumnType::kOptionalValue; } std::shared_ptr builder() const override { return std::dynamic_pointer_cast( @@ -496,15 +542,20 @@ class OptionalValueColumn : public IValueColumn dup() const override; - std::shared_ptr shuffle(const std::vector& offsets) const override; + std::shared_ptr shuffle( + const std::vector& offsets) const override; RTAnyType elem_type() const override { auto type = RTAnyType::kStringValue; type.null_able_ = true; return type; } - RTAny get_elem(size_t idx) const override { return RTAny::from_string(data_[idx]); } + RTAny get_elem(size_t idx) const override { + return RTAny::from_string(data_[idx]); + } - std::string_view get_value(size_t idx) const override { return std::string_view(data_[idx]); } + std::string_view get_value(size_t idx) const override { + return std::string_view(data_[idx]); + } ISigColumn* generate_signature() const override { LOG(FATAL) << "not implemented for " << this->column_info(); @@ -516,12 +567,13 @@ class OptionalValueColumn : public IValueColumn -class OptionalValueColumnBuilder : public IOptionalContextColumnBuilder { +class OptionalValueColumnBuilder + : public IOptionalContextColumnBuilder { public: OptionalValueColumnBuilder() = default; ~OptionalValueColumnBuilder() = default; @@ -621,7 +674,9 @@ class ValueColumnBuilder : public IContextColumnBuilder { ~ValueColumnBuilder() = default; void reserve(size_t size) override { data_.reserve(size); } - void push_back_elem(const RTAny& val) override { data_.push_back(std::string(val.as_string())); } + void push_back_elem(const RTAny& val) override { + data_.push_back(std::string(val.as_string())); + } void push_back_opt(const std::string& val) { data_.push_back(val); } @@ -636,7 +691,8 @@ class ValueColumnBuilder : public IContextColumnBuilder { }; template -std::shared_ptr ValueColumn::shuffle(const std::vector& offsets) const { +std::shared_ptr ValueColumn::shuffle( + const std::vector& offsets) const { ValueColumnBuilder builder; builder.reserve(offsets.size()); for (auto offset : offsets) { diff --git a/flex/engines/graph_db/runtime/common/leaf_utils.h b/flex/engines/graph_db/runtime/common/leaf_utils.h index e5be15bdd415..88fee5382789 100644 --- a/flex/engines/graph_db/runtime/common/leaf_utils.h +++ b/flex/engines/graph_db/runtime/common/leaf_utils.h @@ -39,4 +39,8 @@ namespace bl = boost::leaf; return ::boost::leaf::new_error( \ ::gs::Status(::gs::StatusCode::UNIMPLEMENTED, PREPEND_LINE_INFO(msg))) +#define RETURN_CALL_PROCEDURE_ERROR(msg) \ + return ::boost::leaf::new_error( \ + ::gs::Status(::gs::StatusCode::QUERY_FAILED, PREPEND_LINE_INFO(msg))) + #endif // RUNTIME_COMMON_LEAF_UTILS_H_ diff --git a/flex/engines/graph_db/runtime/common/rt_any.cc b/flex/engines/graph_db/runtime/common/rt_any.cc index e3cf4a1d55d8..d912126b255d 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.cc +++ b/flex/engines/graph_db/runtime/common/rt_any.cc @@ -35,6 +35,8 @@ const RTAnyType RTAnyType::kBoolValue = RTAnyType(RTAnyType::RTAnyTypeImpl::kBoolValue); const RTAnyType RTAnyType::kStringValue = RTAnyType(RTAnyType::RTAnyTypeImpl::kStringValue); +const RTAnyType RTAnyType::kStdStringValue = + RTAnyType(RTAnyType::RTAnyTypeImpl::kStdStringValue); const RTAnyType RTAnyType::kVertexSetValue = RTAnyType(RTAnyType::RTAnyTypeImpl::kVertexSetValue); const RTAnyType RTAnyType::kStringSetValue = @@ -140,6 +142,8 @@ RTAny::RTAny(const RTAny& rhs) : type_(rhs.type_) { value_.vertex = rhs.value_.vertex; } else if (type_ == RTAnyType::kStringValue) { value_.str_val = rhs.value_.str_val; + } else if (type_ == RTAnyType::kStdStringValue) { + value_.std_str_val = rhs.value_.std_str_val; } else if (type_ == RTAnyType::kNull) { // do nothing } else if (type_ == RTAnyType::kTuple) { @@ -167,6 +171,8 @@ RTAny& RTAny::operator=(const RTAny& rhs) { value_.vertex = rhs.value_.vertex; } else if (type_ == RTAnyType::kStringValue) { value_.str_val = rhs.value_.str_val; + } else if (type_ == RTAnyType::kStdStringValue) { + value_.std_str_val = rhs.value_.std_str_val; } else if (type_ == RTAnyType::kTuple) { value_.t = rhs.value_.t.dup(); } else if (type_ == RTAnyType::kList) { @@ -238,13 +244,14 @@ RTAny RTAny::from_int32(int v) { RTAny RTAny::from_string(const std::string& str) { RTAny ret; - ret.type_ = RTAnyType::kStringValue; - ret.value_.str_val = std::string_view(str); + ret.type_ = RTAnyType::kStdStringValue; + ret.value_.std_str_val = str; return ret; } RTAny RTAny::from_string(const std::string_view& str) { RTAny ret; + LOG(INFO) << "from_string: " << str; ret.type_ = RTAnyType::kStringValue; ret.value_.str_val = str; return ret; @@ -361,6 +368,17 @@ std::string_view RTAny::as_string() const { } } +std::string RTAny::as_std_string() const { + if (type_ == RTAnyType::kStdStringValue) { + return *(value_.std_str_val.ptr); + } else if (type_ == RTAnyType::kUnknown) { + return std::string(); + } else { + LOG(FATAL) << "unexpected type" << static_cast(type_.type_enum_); + return std::string(); + } +} + List RTAny::as_list() const { CHECK(type_ == RTAnyType::kList); return value_.list; @@ -444,6 +462,8 @@ bool RTAny::operator<(const RTAny& other) const { } else if (type_ == RTAnyType::kStringValue) { return value_.str_val < other.value_.str_val; + } else if (type_ == RTAnyType::kStdStringValue) { + return *(value_.std_str_val.ptr) < *(other.value_.std_str_val.ptr); } else if (type_ == RTAnyType::kDate32) { return value_.i64_val < other.value_.i64_val; } else if (type_ == RTAnyType::kF64Value) { @@ -470,6 +490,8 @@ bool RTAny::operator==(const RTAny& other) const { return value_.i32_val == other.value_.i32_val; } else if (type_ == RTAnyType::kStringValue) { return value_.str_val == other.value_.str_val; + } else if (type_ == RTAnyType::kStdStringValue) { + return *(value_.std_str_val.ptr) == *(other.value_.std_str_val.ptr); } else if (type_ == RTAnyType::kVertex) { return value_.vertex == other.value_.vertex; } else if (type_ == RTAnyType::kDate32) { @@ -554,6 +576,9 @@ void RTAny::sink_impl(common::Value* value) const { value->set_i64(value_.i64_val); } else if (type_ == RTAnyType::kStringValue) { value->set_str(value_.str_val.data(), value_.str_val.size()); + } else if (type_ == RTAnyType::kStdStringValue) { + value->set_str(value_.std_str_val.ptr->data(), + value_.std_str_val.ptr->size()); } else if (type_ == RTAnyType::kI32Value) { value->set_i32(value_.i32_val); } else if (type_ == RTAnyType::kStringSetValue) { @@ -742,6 +767,8 @@ std::string RTAny::to_string() const { return std::to_string(value_.i64_val); } else if (type_ == RTAnyType::kStringValue) { return std::string(value_.str_val); + } else if (type_ == RTAnyType::kStdStringValue) { + return std::string(*(value_.std_str_val.ptr)); } else if (type_ == RTAnyType::kI32Value) { return std::to_string(value_.i32_val); } else if (type_ == RTAnyType::kVertex) { diff --git a/flex/engines/graph_db/runtime/common/rt_any.h b/flex/engines/graph_db/runtime/common/rt_any.h index cc5371e4005f..5d831fc57c8d 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.h +++ b/flex/engines/graph_db/runtime/common/rt_any.h @@ -157,6 +157,7 @@ class RTAnyType { kF64Value, kBoolValue, kStringValue, + kStdStringValue, kVertexSetValue, kStringSetValue, kUnknown, @@ -175,6 +176,7 @@ class RTAnyType { static const RTAnyType kF64Value; static const RTAnyType kBoolValue; static const RTAnyType kStringValue; + static const RTAnyType kStdStringValue; static const RTAnyType kVertexSetValue; static const RTAnyType kStringSetValue; static const RTAnyType kUnknown; @@ -228,6 +230,7 @@ union RTAnyValue { const std::vector* vset; const std::set* str_set; std::string_view str_val; + StringPtr std_str_val; Path p; Tuple t; List list; @@ -278,6 +281,7 @@ class RTAny { const std::tuple& as_edge() const; const std::set& as_string_set() const; std::string_view as_string() const; + std::string as_std_string() const; const std::vector& as_vertex_list() const; Path as_path() const; Tuple as_tuple() const; @@ -361,6 +365,17 @@ struct TypedConverter { } }; +template <> +struct TypedConverter { + static RTAnyType type() { return RTAnyType::kStringValue; } + static std::string to_typed(const RTAny& val) { return val.as_std_string(); } + static RTAny from_typed(const std::string& val) { + return RTAny::from_string(val); + } + static const std::string name() { return "string"; } + static std::string typed_from_string(const std::string& str) { return str; } +}; + template <> struct TypedConverter { static RTAnyType type() { return RTAnyType::kU64Value; } diff --git a/flex/engines/graph_db/runtime/common/types.cc b/flex/engines/graph_db/runtime/common/types.cc index 4f0bf79a5b98..432be67c5ce0 100644 --- a/flex/engines/graph_db/runtime/common/types.cc +++ b/flex/engines/graph_db/runtime/common/types.cc @@ -24,6 +24,11 @@ uint64_t encode_unique_vertex_id(label_t label_id, vid_t vid) { return global_id.global_id; } +std::pair decode_unique_vertex_id(uint64_t unique_id) { + return std::pair{GlobalId::get_label_id(unique_id), + GlobalId::get_vid(unique_id)}; +} + uint32_t generate_edge_label_id(label_t src_label_id, label_t dst_label_id, label_t edge_label_id) { uint32_t unique_edge_label_id = src_label_id; diff --git a/flex/engines/graph_db/runtime/common/types.h b/flex/engines/graph_db/runtime/common/types.h index 28f2a5784bff..7f4014ee0949 100644 --- a/flex/engines/graph_db/runtime/common/types.h +++ b/flex/engines/graph_db/runtime/common/types.h @@ -26,6 +26,8 @@ namespace gs { namespace runtime { uint64_t encode_unique_vertex_id(label_t label_id, vid_t vid); +std::pair decode_unique_vertex_id(uint64_t unique_id); + uint32_t generate_edge_label_id(label_t src_label_id, label_t dst_label_id, label_t edge_label_id); int64_t encode_unique_edge_id(uint32_t label_id, vid_t src, vid_t dst); diff --git a/flex/engines/hqps_db/app/interactive_app_base.h b/flex/engines/hqps_db/app/interactive_app_base.h index 5186379ad948..987401bc895a 100644 --- a/flex/engines/hqps_db/app/interactive_app_base.h +++ b/flex/engines/hqps_db/app/interactive_app_base.h @@ -35,7 +35,12 @@ inline bool parse_input_argument_from_proto_impl( } else { auto& type = std::get(tuple); auto& argument = args.Get(I); - auto& value = argument.value(); + if (argument.value_case() != procedure::Argument::kConst) { + LOG(ERROR) << "Expect a const value for input param, but got " + << argument.value_case(); + return false; + } + auto& value = argument.const_(); auto item_case = value.item_case(); if (item_case == common::Value::kI32) { if constexpr (std::is_same 0 + +def test_call_proc_in_cypher(interactive_session, neo4j_session, create_modern_graph): + print("[Test call procedure in cypher]") + import_data_to_full_modern_graph(interactive_session, create_modern_graph) + result = neo4j_session.run('MATCH(p: person) with p.id as oid CALL k_neighbors("person", oid, 1) return label_name, vertex_oid;') + cnt = 0 + for record in result: + cnt += 1 + assert cnt == 8 diff --git a/flex/storages/rt_mutable_graph/schema.cc b/flex/storages/rt_mutable_graph/schema.cc index e6957c8514ca..01a272c3813f 100644 --- a/flex/storages/rt_mutable_graph/schema.cc +++ b/flex/storages/rt_mutable_graph/schema.cc @@ -1322,6 +1322,19 @@ bool Schema::EmplacePlugins( } } + // Emplace the built-in plugins + plugin_name_to_path_and_id_.emplace( + Schema::BUILTIN_COUNT_VERTICES_PLUGIN_NAME, + std::make_pair("", Schema::BUILTIN_COUNT_VERTICES_PLUGIN_ID)); + plugin_name_to_path_and_id_.emplace( + Schema::BUILTIN_PAGERANK_PLUGIN_NAME, + std::make_pair("", Schema::BUILTIN_PAGERANK_PLUGIN_ID)); + plugin_name_to_path_and_id_.emplace( + Schema::BUILTIN_K_DEGREE_NEIGHBORS_PLUGIN_NAME, + std::make_pair("", Schema::BUILTIN_K_DEGREE_NEIGHBORS_PLUGIN_ID)); + plugin_name_to_path_and_id_.emplace( + Schema::BUILTIN_TVSP_PLUGIN_NAME, + std::make_pair("", Schema::BUILTIN_TVSP_PLUGIN_ID)); LOG(INFO) << "Load " << plugin_name_to_path_and_id_.size() << " plugins"; return true; } From c09daa003864de55deda3507d2e01018738bc3ff Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 15 Oct 2024 15:46:02 +0800 Subject: [PATCH 03/17] format Committed-by: xiaolei.zl from Dev container --- .../graph_db/grin/src/property/property.cc | 2 +- flex/engines/hqps_db/core/base_engine.h | 76 +++---- .../hqps_db/core/operator/edge_expand.h | 9 +- flex/engines/hqps_db/core/operator/group_by.h | 21 +- flex/engines/hqps_db/core/operator/project.h | 12 +- flex/engines/hqps_db/core/utils/hqps_utils.h | 206 ++++++++++++------ 6 files changed, 196 insertions(+), 130 deletions(-) diff --git a/flex/engines/graph_db/grin/src/property/property.cc b/flex/engines/graph_db/grin/src/property/property.cc index 1a00e94aa134..aa008fad20bd 100644 --- a/flex/engines/graph_db/grin/src/property/property.cc +++ b/flex/engines/graph_db/grin/src/property/property.cc @@ -88,7 +88,7 @@ void grin_destroy_vertex_property(GRIN_GRAPH g, GRIN_VERTEX_PROPERTY vp) {} */ GRIN_DATATYPE grin_get_vertex_property_datatype(GRIN_GRAPH g, GRIN_VERTEX_PROPERTY vp) { - return (GRIN_DATATYPE)(vp >> 16); + return (GRIN_DATATYPE) (vp >> 16); } int grin_get_vertex_property_value_of_int32(GRIN_GRAPH g, GRIN_VERTEX v, diff --git a/flex/engines/hqps_db/core/base_engine.h b/flex/engines/hqps_db/core/base_engine.h index 8dca3c12a30b..fd56c4410b8d 100644 --- a/flex/engines/hqps_db/core/base_engine.h +++ b/flex/engines/hqps_db/core/base_engine.h @@ -109,14 +109,14 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ind_ele_t = std::remove_reference_t().GetAllIndexElement())>; - using ctx_y_all_data_t = std::remove_reference_t().GetAllData())>; + using ctx_x_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ind_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllIndexElement())>; + using ctx_y_all_data_t = std::remove_reference_t< + decltype(std::declval().GetAllData())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -222,14 +222,14 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ind_ele_t = std::remove_reference_t().GetAllIndexElement())>; - using ctx_y_all_data_t = std::remove_reference_t().GetAllData())>; + using ctx_x_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ind_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllIndexElement())>; + using ctx_y_all_data_t = std::remove_reference_t< + decltype(std::declval().GetAllData())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -461,12 +461,12 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_data_t = std::remove_reference_t().GetAllData())>; + using ctx_x_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_data_t = std::remove_reference_t< + decltype(std::declval().GetAllData())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -556,10 +556,10 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -651,10 +651,10 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -757,10 +757,10 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t real_x_ind = alias_x == -1 ? x_ele_num - 1 : alias_x - CTX_X::base_tag_id; @@ -808,10 +808,10 @@ class BaseEngine { using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; // the prev column (the last column in prev_tuple should be the same.) - using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t< + decltype(std::declval().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; diff --git a/flex/engines/hqps_db/core/operator/edge_expand.h b/flex/engines/hqps_db/core/operator/edge_expand.h index ce3e4b5c70f1..1f3ee240174c 100644 --- a/flex/engines/hqps_db/core/operator/edge_expand.h +++ b/flex/engines/hqps_db/core/operator/edge_expand.h @@ -465,10 +465,11 @@ class EdgeExpand { CHECK(edge_triplets.size() > 0); // result_set_t is the type of calling EdgeExpandV with cur_vertex_set // and edge_triplets[i] - using result_set_t = decltype( - EdgeExpandV(graph, cur_vertex_set, direction, edge_triplets[0][2], - edge_triplets[0][1], std::move(edge_filter)) - .first); + using result_set_t = + decltype(EdgeExpandV(graph, cur_vertex_set, direction, + edge_triplets[0][2], edge_triplets[0][1], + std::move(edge_filter)) + .first); using result_pair_t = std::pair>; std::vector result_pairs; for (size_t i = 0; i < edge_triplets.size(); ++i) { diff --git a/flex/engines/hqps_db/core/operator/group_by.h b/flex/engines/hqps_db/core/operator/group_by.h index 674c43cc0476..ff261a3f163e 100644 --- a/flex/engines/hqps_db/core/operator/group_by.h +++ b/flex/engines/hqps_db/core/operator/group_by.h @@ -36,8 +36,8 @@ struct CommonBuilderT; template struct CommonBuilderT> { - using set_t = std::remove_const_t().template GetNode())>>; + using set_t = std::remove_const_t().template GetNode())>>; using builder_t = typename set_t::builder_t; using result_t = typename builder_t::result_t; using result_ele_t = typename result_t::element_type; @@ -45,8 +45,8 @@ struct CommonBuilderT> { template struct CommonBuilderT> { - using set_t = std::remove_const_t().template GetNode())>>; + using set_t = std::remove_const_t().template GetNode())>>; using builder_t = CollectionBuilder; using result_t = typename builder_t::result_t; using result_ele_t = typename result_t::element_type; @@ -57,8 +57,8 @@ struct GroupKeyResT; template struct GroupKeyResT> { - using set_t = std::remove_const_t().template GetNode())>>; + using set_t = std::remove_const_t().template GetNode())>>; using result_t = typename KeyedT>::keyed_set_t; }; @@ -75,8 +75,9 @@ struct GroupValueResT, std::integer_sequence>, typename std::enable_if<(sizeof...(Is) == 1)>::type> { - using old_set_t = std::remove_const_t().template GetNode::value>())>>; + using old_set_t = std::remove_const_t() + .template GetNode::value>())>>; using result_t = typename GroupValueResTImpl>::result_t; @@ -89,8 +90,8 @@ struct GroupValueResT>, typename std::enable_if<(sizeof...(Is) > 1)>::type> { using old_set_tuple_t = - std::tuple().template GetNode())>>...>; + std::tuple().template GetNode())>>...>; using result_t = typename GroupValueResTImpl>::result_t; diff --git a/flex/engines/hqps_db/core/operator/project.h b/flex/engines/hqps_db/core/operator/project.h index d1681387ba2b..be7791dfc8fc 100644 --- a/flex/engines/hqps_db/core/operator/project.h +++ b/flex/engines/hqps_db/core/operator/project.h @@ -42,8 +42,8 @@ struct ResultOfContextKeyAlias< Context, IdentityMapper>> { using context_t = Context; - using ctx_node_t = std::remove_reference_t().template GetNode())>; + using ctx_node_t = std::remove_reference_t< + decltype(std::declval().template GetNode())>; using result_t = Collection; }; @@ -54,8 +54,8 @@ struct ResultOfContextKeyAlias< Context, IdentityMapper>> { using context_t = Context; - using ctx_node_t = std::remove_reference_t().template GetNode())>; + using ctx_node_t = std::remove_reference_t< + decltype(std::declval().template GetNode())>; using result_t = ctx_node_t; }; @@ -266,8 +266,8 @@ class ProjectOp { const GRAPH_INTERFACE& graph, CTX_T& ctx, IdentityMapper>& mapper) { auto& node = ctx.template GetNode(); - static_assert(std::remove_reference_t::is_vertex_set); // edge_set not supported + static_assert(std::remove_reference_t< + decltype(node)>::is_vertex_set); // edge_set not supported // Create a empty copy. auto offset_array = ctx.ObtainOffsetFromTag(in_col_id); auto repeat_array = offset_array_to_repeat_array(std::move(offset_array)); diff --git a/flex/engines/hqps_db/core/utils/hqps_utils.h b/flex/engines/hqps_db/core/utils/hqps_utils.h index efdfb68dc647..5cae552776e0 100644 --- a/flex/engines/hqps_db/core/utils/hqps_utils.h +++ b/flex/engines/hqps_db/core/utils/hqps_utils.h @@ -145,14 +145,16 @@ template struct group_key_on_property : public std::true_type {}; template -struct group_key_on_property> +struct group_key_on_property< + AliasTagProp> : public std::false_type {}; template struct group_key_on_property> : public std::true_type {}; template -struct group_key_on_property> : public std::false_type {}; +struct group_key_on_property> + : public std::false_type {}; // check edge_dir and vopt consistency inline bool check_edge_dir_consist_vopt(const Direction& dir, VOpt vopt) { @@ -167,18 +169,24 @@ inline bool check_edge_dir_consist_vopt(const Direction& dir, VOpt vopt) { return false; } -template ::type* = nullptr> -constexpr auto remove_nth_element_impl(std::index_sequence, std::index_sequence, +template < + std::size_t nth, std::size_t... Head, std::size_t... Tail, + typename... Types, + typename std::enable_if<(nth + 1 != sizeof...(Types))>::type* = nullptr> +constexpr auto remove_nth_element_impl(std::index_sequence, + std::index_sequence, const std::tuple& tup) { return std::tuple{std::get(tup)..., // We +1 to refer one element after the one removed std::get(tup)...}; } -template ::type* = nullptr> -constexpr auto remove_nth_element_impl(std::index_sequence, std::index_sequence, +template < + std::size_t nth, std::size_t... Head, std::size_t... Tail, + typename... Types, + typename std::enable_if<(nth + 1 == sizeof...(Types))>::type* = nullptr> +constexpr auto remove_nth_element_impl(std::index_sequence, + std::index_sequence, const std::tuple& tup) { return std::tuple{std::get(tup)...}; } @@ -186,8 +194,9 @@ constexpr auto remove_nth_element_impl(std::index_sequence, std::index_ template constexpr auto remove_nth_element(const std::tuple& tup) { static_assert(nth < sizeof...(Types)); - return remove_nth_element_impl(std::make_index_sequence(), - std::make_index_sequence(), tup); + return remove_nth_element_impl( + std::make_index_sequence(), + std::make_index_sequence(), tup); } template @@ -214,7 +223,8 @@ template struct remove_ith_type> { typedef decltype(std::tuple_cat( std::declval>(), - std::declval>::type>())) type; + std::declval>::type>())) + type; }; // I != J @@ -222,13 +232,15 @@ template struct remove_ith_jth_type {}; template -struct remove_ith_jth_type, typename std::enable_if<(I < J)>::type> { +struct remove_ith_jth_type, + typename std::enable_if<(I < J)>::type> { using first_type = typename remove_ith_type>::type; using type = typename remove_ith_type::type; }; template -struct remove_ith_jth_type, typename std::enable_if<(I > J)>::type> { +struct remove_ith_jth_type, + typename std::enable_if<(I > J)>::type> { using type = typename remove_ith_jth_type>::type; }; @@ -237,17 +249,20 @@ struct Edge; template < size_t Is, typename... PROP_T, - typename std::enable_if::type* = nullptr> void props_to_string_array( - std::tuple& props, - std::array>>& res) { + typename std::enable_if::type* = nullptr> void + props_to_string_array( + std::tuple& props, + std::array>>& + res) { res[Is] = std::get(props).property_name; props_to_string_array(props, res); } template ::type* = nullptr> -void props_to_string_array(std::tuple& props, - std::array>>& res) { +void props_to_string_array( + std::tuple& props, + std::array>>& res) { res[Is] = std::get(props).property_name; } template @@ -262,8 +277,8 @@ struct tuple_element; // recursive case template -struct tuple_element> : gs::tuple_element> { -}; +struct tuple_element> + : gs::tuple_element> {}; // base case template @@ -281,7 +296,8 @@ struct tuple_element<-1, std::tuple> { template auto unwrap_future_tuple(std::tuple&& tuple) { - return unwrap_future_tuple(std::move(tuple), std::make_index_sequence()); + return unwrap_future_tuple(std::move(tuple), + std::make_index_sequence()); } template auto unwrap_future_tuple(std::tuple&& tuple, std::index_sequence) { @@ -322,7 +338,9 @@ struct FirstElement { // Create a tuple of const references to the elements of a tuple. template auto make_tuple_of_const_refs(const std::tuple& t) { - return std::apply([](const Args&... args) { return std::make_tuple(std::cref(args)...); }, t); + return std::apply( + [](const Args&... args) { return std::make_tuple(std::cref(args)...); }, + t); } template @@ -340,8 +358,9 @@ struct first_n_impl; template struct first_n_impl, Out...> { - typedef typename first_n_impl, Out..., First>::type - type; // move first input to output. + typedef + typename first_n_impl, Out..., First>::type + type; // move first input to output. }; // need First, Other... here to resolve ambiguity on n = 0 @@ -377,34 +396,42 @@ constexpr auto tuple_slice_impl(T&& t, std::index_sequence) { template constexpr auto tuple_slice(T&& t) { static_assert(r >= l, "invalid slice"); - static_assert(std::tuple_size>::value >= r, "slice index out of bounds"); - return tuple_slice_impl(std::forward(t), std::make_index_sequence{}); + static_assert(std::tuple_size>::value >= r, + "slice index out of bounds"); + return tuple_slice_impl(std::forward(t), + std::make_index_sequence{}); } // [l, tuple_size - 1] template constexpr auto tuple_slice(T&& t) { - static_assert(std::tuple_size>::value > l, "slice index out of bounds"); + static_assert(std::tuple_size>::value > l, + "slice index out of bounds"); return tuple_slice_impl( - std::forward(t), std::make_index_sequence>::value - l>{}); + std::forward(t), + std::make_index_sequence>::value - l>{}); } -template = 0)>::type* = nullptr> +template = 0)>::type* = nullptr> inline auto get_from_tuple(std::tuple& tuple) { return std::get(tuple); } -template ::type* = nullptr> +template ::type* = nullptr> inline auto get_from_tuple(std::tuple& tuple) { static constexpr size_t num = sizeof...(T); return std::get(tuple); } -template = 0)>::type* = nullptr> +template = 0)>::type* = nullptr> inline const auto& get_from_tuple(const std::tuple& tuple) { return std::get(tuple); } -template ::type* = nullptr> +template ::type* = nullptr> inline const auto& get_from_tuple(const std::tuple& tuple) { static constexpr size_t num = sizeof...(T); return std::get(tuple); @@ -413,26 +440,30 @@ inline const auto& get_from_tuple(const std::tuple& tuple) { // vertex/edge property associate with type template ::type> -auto transform_array_impl(std::array&& array, FUNC_T&& func, std::index_sequence) { +auto transform_array_impl(std::array&& array, FUNC_T&& func, + std::index_sequence) { return std::array{std::move(func(std::move(array[Is])))...}; } template auto transform_array(std::array&& array, FUNC_T&& func) { - return transform_array_impl(std::move(array), std::move(func), std::make_index_sequence()); + return transform_array_impl(std::move(array), std::move(func), + std::make_index_sequence()); } template ::type> auto transform_tuple_impl(const std::tuple&& tuple, FUNC_T&& func, std::index_sequence) { - return std::make_tuple(std::move(func(Is, std::move(std::get(tuple))))...); + return std::make_tuple( + std::move(func(Is, std::move(std::get(tuple))))...); } template auto transform_tuple(const std::tuple&& tuple, FUNC_T&& func) { static constexpr size_t N = sizeof...(T); - return transform_tuple_impl(std::move(tuple), std::move(func), std::make_index_sequence()); + return transform_tuple_impl(std::move(tuple), std::move(func), + std::make_index_sequence()); } template @@ -443,28 +474,32 @@ bool apply_on_tuple_impl(const FUNC& func, const std::tuple& tuple, template bool apply_on_tuple(const FUNC& func, const std::tuple& tuple) { - return apply_on_tuple_impl(func, tuple, std::make_index_sequence()); + return apply_on_tuple_impl(func, tuple, + std::make_index_sequence()); } template ::type> -auto apply_array_impl(const std::array& array, FUNC_T&& func, std::index_sequence) { +auto apply_array_impl(const std::array& array, FUNC_T&& func, + std::index_sequence) { return std::array{std::move(func(array[Is]))...}; } template auto apply_array(const std::array& array, FUNC_T&& func) { - return apply_array_impl(array, std::move(func), std::make_index_sequence()); + return apply_array_impl(array, std::move(func), + std::make_index_sequence()); } template -void apply_tuple_impl(const std::tuple& tuple, const FUNC_T& func, std::index_sequence, - OTHER_ARGS&... other_args) { +void apply_tuple_impl(const std::tuple& tuple, const FUNC_T& func, + std::index_sequence, OTHER_ARGS&... other_args) { ((func(std::get(tuple), std::forward(other_args)...)), ...); } template -auto apply_tuple(const std::tuple& tuple, const FUNC_T& func, OTHER_ARGS&... other_args) { +auto apply_tuple(const std::tuple& tuple, const FUNC_T& func, + OTHER_ARGS&... other_args) { static constexpr size_t N = sizeof...(T); return apply_tuple_impl(tuple, func, std::make_index_sequence(), std::forward(other_args)...); @@ -473,8 +508,8 @@ auto apply_tuple(const std::tuple& tuple, const FUNC_T& func, OTHER_ARGS&. template constexpr auto make_array(Args&&... args) { if constexpr (std::is_same::value) { - return std::array...>, sizeof...(Args)>{ - {std::forward(args)...}}; + return std::array...>, + sizeof...(Args)>{{std::forward(args)...}}; } else { return std::array{{std::forward(args)...}}; } @@ -522,11 +557,13 @@ struct NumberLarger { }; template -using make_index_range = decltype(add(std::make_index_sequence())); +using make_index_range = + decltype(add(std::make_index_sequence())); template struct TupleCatT { - using tuple_cat_t = decltype(std::tuple_cat(std::declval(), std::declval())); + using tuple_cat_t = + decltype(std::tuple_cat(std::declval(), std::declval())); }; template @@ -540,7 +577,8 @@ struct TupleCatT> { }; template -auto make_getter_tuple(label_t label, std::tuple&& tuple, std::index_sequence) { +auto make_getter_tuple(label_t label, std::tuple&& tuple, + std::index_sequence) { return std::make_tuple(std::get(tuple).CreateGetter(label)...); } @@ -582,8 +620,9 @@ struct ColumnAccessorImpl {}; // Recursive template -struct ColumnAccessorImpl : public SingleColumn, - public ColumnAccessorImpl {}; +struct ColumnAccessorImpl + : public SingleColumn, + public ColumnAccessorImpl {}; // multiple single columns. @@ -641,8 +680,8 @@ std::vector array_to_vec(const std::array& array) { } template -static typename PRIORITY_QUEUE_T::container_type priority_queue_to_vec(PRIORITY_QUEUE_T& pq, - bool reversed = false) { +static typename PRIORITY_QUEUE_T::container_type priority_queue_to_vec( + PRIORITY_QUEUE_T& pq, bool reversed = false) { auto pq_size = pq.size(); typename PRIORITY_QUEUE_T::container_type res; res.reserve(pq_size); @@ -681,7 +720,8 @@ struct to_string_impl> { // map{key:value, ...} ss << "map{"; for (auto& [k, v] : vec) { - ss << to_string_impl::to_string(k) << ":" << to_string_impl::to_string(v) << ","; + ss << to_string_impl::to_string(k) << ":" + << to_string_impl::to_string(v) << ","; } ss << "}"; return ss.str(); @@ -701,7 +741,8 @@ struct to_string_impl> { template struct to_string_impl, M>> { - static inline std::string to_string(const std::array, M>& empty) { + static inline std::string to_string( + const std::array, M>& empty) { std::stringstream ss; ss << "["; for (auto i : empty) { @@ -729,7 +770,9 @@ struct to_string_impl { template <> struct to_string_impl { - static inline std::string to_string(const Dist& empty) { return std::to_string(empty.dist); } + static inline std::string to_string(const Dist& empty) { + return std::to_string(empty.dist); + } }; template <> @@ -741,12 +784,16 @@ struct to_string_impl { template <> struct to_string_impl { - static inline std::string to_string(const std::string_view& empty) { return std::string(empty); } + static inline std::string to_string(const std::string_view& empty) { + return std::string(empty); + } }; template <> struct to_string_impl { - static inline std::string to_string(const grape::EmptyType& empty) { return ""; } + static inline std::string to_string(const grape::EmptyType& empty) { + return ""; + } }; template <> @@ -758,37 +805,51 @@ struct to_string_impl { template <> struct to_string_impl { - static inline std::string to_string(const int64_t& empty) { return std::to_string(empty); } + static inline std::string to_string(const int64_t& empty) { + return std::to_string(empty); + } }; template <> struct to_string_impl { - static inline std::string to_string(const bool& empty) { return std::to_string(empty); } + static inline std::string to_string(const bool& empty) { + return std::to_string(empty); + } }; template <> struct to_string_impl { - static inline std::string to_string(const unsigned long& empty) { return std::to_string(empty); } + static inline std::string to_string(const unsigned long& empty) { + return std::to_string(empty); + } }; template <> struct to_string_impl { - static inline std::string to_string(const int32_t& empty) { return std::to_string(empty); } + static inline std::string to_string(const int32_t& empty) { + return std::to_string(empty); + } }; template <> struct to_string_impl { - static inline std::string to_string(const uint32_t& empty) { return std::to_string(empty); } + static inline std::string to_string(const uint32_t& empty) { + return std::to_string(empty); + } }; template <> struct to_string_impl { - static inline std::string to_string(const double& empty) { return std::to_string(empty); } + static inline std::string to_string(const double& empty) { + return std::to_string(empty); + } }; template <> struct to_string_impl { - static inline std::string to_string(const std::string& empty) { return empty; } + static inline std::string to_string(const std::string& empty) { + return empty; + } }; template <> @@ -874,8 +935,8 @@ struct to_string_impl> { std::apply( [&result](const auto&... v) { ((result += - (to_string_impl>>::to_string( - v)) + + (to_string_impl>>::to_string(v)) + ","), ...); }, @@ -904,9 +965,11 @@ template struct Edge { VID_T src, dst; const std::tuple& edata; - Edge(VID_T s, VID_T d, const std::tuple& data) : src(s), dst(d), edata(data) {} + Edge(VID_T s, VID_T d, const std::tuple& data) + : src(s), dst(d), edata(data) {} std::string to_string() const { - return std::to_string(src) + "->" + std::to_string(dst) + "(" + gs::to_string(edata) + ")"; + return std::to_string(src) + "->" + std::to_string(dst) + "(" + + gs::to_string(edata) + ")"; } }; @@ -924,7 +987,8 @@ template using DefaultEdge = Edge; template -inline bool operator==(const DefaultEdge& lhs, const DefaultEdge& rhs) { +inline bool operator==(const DefaultEdge& lhs, + const DefaultEdge& rhs) { return lhs.src == rhs.src && lhs.dst == rhs.dst; } @@ -958,9 +1022,9 @@ struct function_traits }; template -static std::tuple get_graph_label_pair(Direction& direction, - label_id_t query_src_label, - label_id_t query_dst_label) { +static std::tuple get_graph_label_pair( + Direction& direction, label_id_t query_src_label, + label_id_t query_dst_label) { label_id_t src_label, dst_label; if (direction == Direction::In) { src_label = query_dst_label; From 16a8ece4be95fb91557b047f0c07f69e690c0bf6 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 15 Oct 2024 15:50:32 +0800 Subject: [PATCH 04/17] format Committed-by: xiaolei.zl from Dev container --- .../graph_db/grin/src/property/property.cc | 2 +- .../runtime/common/columns/value_columns.h | 200 ++++++----------- flex/engines/hqps_db/core/base_engine.h | 76 +++---- .../hqps_db/core/operator/edge_expand.h | 9 +- flex/engines/hqps_db/core/operator/group_by.h | 21 +- flex/engines/hqps_db/core/operator/project.h | 12 +- flex/engines/hqps_db/core/utils/hqps_utils.h | 206 ++++++------------ flex/tests/hqps/context_test.cc | 8 +- 8 files changed, 206 insertions(+), 328 deletions(-) diff --git a/flex/engines/graph_db/grin/src/property/property.cc b/flex/engines/graph_db/grin/src/property/property.cc index aa008fad20bd..1a00e94aa134 100644 --- a/flex/engines/graph_db/grin/src/property/property.cc +++ b/flex/engines/graph_db/grin/src/property/property.cc @@ -88,7 +88,7 @@ void grin_destroy_vertex_property(GRIN_GRAPH g, GRIN_VERTEX_PROPERTY vp) {} */ GRIN_DATATYPE grin_get_vertex_property_datatype(GRIN_GRAPH g, GRIN_VERTEX_PROPERTY vp) { - return (GRIN_DATATYPE) (vp >> 16); + return (GRIN_DATATYPE)(vp >> 16); } int grin_get_vertex_property_value_of_int32(GRIN_GRAPH g, GRIN_VERTEX v, diff --git a/flex/engines/graph_db/runtime/common/columns/value_columns.h b/flex/engines/graph_db/runtime/common/columns/value_columns.h index bc0372bb2d49..1547ab7b91fb 100644 --- a/flex/engines/graph_db/runtime/common/columns/value_columns.h +++ b/flex/engines/graph_db/runtime/common/columns/value_columns.h @@ -47,31 +47,24 @@ class ValueColumn : public IValueColumn { size_t size() const override { return data_.size(); } std::string column_info() const override { - return "ValueColumn<" + TypedConverter::name() + ">[" + - std::to_string(size()) + "]"; - } - ContextColumnType column_type() const override { - return ContextColumnType::kValue; + return "ValueColumn<" + TypedConverter::name() + ">[" + std::to_string(size()) + "]"; } + ContextColumnType column_type() const override { return ContextColumnType::kValue; } std::shared_ptr builder() const override { return std::make_shared>(); } - std::shared_ptr optional_builder() - const override { + std::shared_ptr optional_builder() const override { return std::dynamic_pointer_cast( std::make_shared>()); } std::shared_ptr dup() const override; - std::shared_ptr shuffle( - const std::vector& offsets) const override; + std::shared_ptr shuffle(const std::vector& offsets) const override; RTAnyType elem_type() const override { return TypedConverter::type(); } - RTAny get_elem(size_t idx) const override { - return TypedConverter::from_typed(data_[idx]); - } + RTAny get_elem(size_t idx) const override { return TypedConverter::from_typed(data_[idx]); } T get_value(size_t idx) const override { return data_[idx]; } @@ -89,25 +82,22 @@ class ValueColumn : public IValueColumn { for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), - [this](size_t a, size_t b) { - // data_[a] == data_[b] - if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { + // data_[a] == data_[b] + if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { - if (i == 0 || - ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || - (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { + if (i == 0 || ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || + (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { offsets.push_back(origin_offsets[i]); } } } - std::shared_ptr union_col( - std::shared_ptr other) const override; + std::shared_ptr union_col(std::shared_ptr other) const override; private: template @@ -127,9 +117,7 @@ class ValueColumn : public IValueColumn { return "ValueColumn<" + TypedConverter::name() + ">[" + std::to_string(size()) + "]"; } - ContextColumnType column_type() const override { - return ContextColumnType::kValue; - } + ContextColumnType column_type() const override { return ContextColumnType::kValue; } std::shared_ptr builder() const override { return std::dynamic_pointer_cast( @@ -137,34 +125,26 @@ class ValueColumn : public IValueColumn { } RTAnyType elem_type() const override { return RTAnyType::kStringValue; } - std::shared_ptr shuffle( - const std::vector& offsets) const override; + std::shared_ptr shuffle(const std::vector& offsets) const override; std::shared_ptr dup() const override; - RTAny get_elem(size_t idx) const override { - return RTAny::from_string(data_[idx]); - } + RTAny get_elem(size_t idx) const override { return RTAny::from_string(data_[idx]); } - std::string_view get_value(size_t idx) const override { - return std::string_view(data_[idx]); - } + std::string_view get_value(size_t idx) const override { return std::string_view(data_[idx]); } - ISigColumn* generate_signature() const override { - return new SigColumn(data_); - } + ISigColumn* generate_signature() const override { return new SigColumn(data_); } void generate_dedup_offset(std::vector& offsets) const override { std::vector origin_offsets(data_.size()); for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), - [this](size_t a, size_t b) { - if (data_[a] == data_[b]) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { + if (data_[a] == data_[b]) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { if (i == 0 || data_[origin_offsets[i]] != data_[origin_offsets[i - 1]]) { offsets.push_back(origin_offsets[i]); @@ -214,9 +194,7 @@ class ListValueColumn : public IValueColumn { std::string column_info() const override { return "ListValueColumn[" + std::to_string(size()) + "]"; } - ContextColumnType column_type() const override { - return ContextColumnType::kValue; - } + ContextColumnType column_type() const override { return ContextColumnType::kValue; } std::shared_ptr builder() const override { auto builder = std::make_shared>(); @@ -226,15 +204,12 @@ class ListValueColumn : public IValueColumn { } std::shared_ptr dup() const override; - std::shared_ptr shuffle( - const std::vector& offsets) const override; + std::shared_ptr shuffle(const std::vector& offsets) const override; RTAnyType elem_type() const override { auto type = RTAnyType::kList; return type; } - RTAny get_elem(size_t idx) const override { - return RTAny::from_list(data_[idx]); - } + RTAny get_elem(size_t idx) const override { return RTAny::from_list(data_[idx]); } List get_value(size_t idx) const override { return data_[idx]; } @@ -248,18 +223,16 @@ class ListValueColumn : public IValueColumn { for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), - [this](size_t a, size_t b) { - // data_[a] == data_[b] - if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { + // data_[a] == data_[b] + if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { - if (i == 0 || - ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || - (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { + if (i == 0 || ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || + (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { offsets.push_back(origin_offsets[i]); } } @@ -287,14 +260,11 @@ class ListValueColumnBuilder : public IContextColumnBuilder { void push_back_opt(const List& val) { data_.emplace_back(val); } - void set_list_impls( - const std::vector>& list_impls) { + void set_list_impls(const std::vector>& list_impls) { list_impls_ = list_impls; } - void set_list_data(const std::vector>& list_data) { - list_data_ = list_data; - } + void set_list_data(const std::vector>& list_data) { list_data_ = list_data; } std::shared_ptr finish() override { auto ret = std::make_shared>(); @@ -347,16 +317,13 @@ class MapValueColumn : public IValueColumn { return "MapValueColumn[" + std::to_string(size()) + "]"; } - ContextColumnType column_type() const override { - return ContextColumnType::kValue; - } + ContextColumnType column_type() const override { return ContextColumnType::kValue; } std::shared_ptr builder() const override; std::shared_ptr dup() const override; - std::shared_ptr shuffle( - const std::vector& offsets) const override; + std::shared_ptr shuffle(const std::vector& offsets) const override; RTAnyType elem_type() const override { auto type = RTAnyType::kMap; @@ -408,9 +375,7 @@ class MapValueColumnBuilder : public IContextColumnBuilder { values_.push_back(std::move(values)); } - void push_back_opt(const std::vector& values) { - values_.push_back(values); - } + void push_back_opt(const std::vector& values) { values_.push_back(values); } void set_keys(const std::vector& keys) { keys_ = keys; } @@ -436,12 +401,9 @@ class OptionalValueColumn : public IValueColumn { size_t size() const override { return data_.size(); } std::string column_info() const override { - return "OptionalValueColumn<" + TypedConverter::name() + ">[" + - std::to_string(size()) + "]"; - } - ContextColumnType column_type() const override { - return ContextColumnType::kOptionalValue; + return "OptionalValueColumn<" + TypedConverter::name() + ">[" + std::to_string(size()) + "]"; } + ContextColumnType column_type() const override { return ContextColumnType::kOptionalValue; } std::shared_ptr dup() const override { OptionalValueColumnBuilder builder; @@ -451,8 +413,7 @@ class OptionalValueColumn : public IValueColumn { return builder.finish(); } - std::shared_ptr shuffle( - const std::vector& offsets) const override { + std::shared_ptr shuffle(const std::vector& offsets) const override { OptionalValueColumnBuilder builder; builder.reserve(offsets.size()); for (auto offset : offsets) { @@ -471,9 +432,7 @@ class OptionalValueColumn : public IValueColumn { type.null_able_ = true; return type; } - RTAny get_elem(size_t idx) const override { - return TypedConverter::from_typed(data_[idx]); - } + RTAny get_elem(size_t idx) const override { return TypedConverter::from_typed(data_[idx]); } T get_value(size_t idx) const override { return data_[idx]; } @@ -491,18 +450,16 @@ class OptionalValueColumn : public IValueColumn { for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), - [this](size_t a, size_t b) { - // data_[a] == data_[b] - if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { + // data_[a] == data_[b] + if (!(data_[a] < data_[b]) && !(data_[b] < data_[a])) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { - if (i == 0 || - ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || - (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { + if (i == 0 || ((data_[origin_offsets[i]] < data_[origin_offsets[i - 1]]) || + (data_[origin_offsets[i - 1]] < data_[origin_offsets[i]]))) { offsets.push_back(origin_offsets[i]); } } @@ -519,8 +476,7 @@ class OptionalValueColumn : public IValueColumn { }; template <> -class OptionalValueColumn - : public IValueColumn { +class OptionalValueColumn : public IValueColumn { public: OptionalValueColumn() = default; ~OptionalValueColumn() = default; @@ -528,12 +484,10 @@ class OptionalValueColumn size_t size() const override { return data_.size(); } std::string column_info() const override { - return "OptionalValueColumn<" + TypedConverter::name() + - ">[" + std::to_string(size()) + "]"; - } - ContextColumnType column_type() const override { - return ContextColumnType::kOptionalValue; + return "OptionalValueColumn<" + TypedConverter::name() + ">[" + + std::to_string(size()) + "]"; } + ContextColumnType column_type() const override { return ContextColumnType::kOptionalValue; } std::shared_ptr builder() const override { return std::dynamic_pointer_cast( @@ -542,20 +496,15 @@ class OptionalValueColumn std::shared_ptr dup() const override; - std::shared_ptr shuffle( - const std::vector& offsets) const override; + std::shared_ptr shuffle(const std::vector& offsets) const override; RTAnyType elem_type() const override { auto type = RTAnyType::kStringValue; type.null_able_ = true; return type; } - RTAny get_elem(size_t idx) const override { - return RTAny::from_string(data_[idx]); - } + RTAny get_elem(size_t idx) const override { return RTAny::from_string(data_[idx]); } - std::string_view get_value(size_t idx) const override { - return std::string_view(data_[idx]); - } + std::string_view get_value(size_t idx) const override { return std::string_view(data_[idx]); } ISigColumn* generate_signature() const override { LOG(FATAL) << "not implemented for " << this->column_info(); @@ -567,13 +516,12 @@ class OptionalValueColumn for (size_t i = 0; i < data_.size(); ++i) { origin_offsets[i] = i; } - std::sort(origin_offsets.begin(), origin_offsets.end(), - [this](size_t a, size_t b) { - if (data_[a] == data_[b]) { - return a < b; - } - return data_[a] < data_[b]; - }); + std::sort(origin_offsets.begin(), origin_offsets.end(), [this](size_t a, size_t b) { + if (data_[a] == data_[b]) { + return a < b; + } + return data_[a] < data_[b]; + }); for (size_t i = 0; i < data_.size(); ++i) { if (i == 0 || data_[origin_offsets[i]] != data_[origin_offsets[i - 1]]) { offsets.push_back(origin_offsets[i]); @@ -629,8 +577,7 @@ class OptionalValueColumnBuilder : public IOptionalContextColumnBuilder { }; template <> -class OptionalValueColumnBuilder - : public IOptionalContextColumnBuilder { +class OptionalValueColumnBuilder : public IOptionalContextColumnBuilder { public: OptionalValueColumnBuilder() = default; ~OptionalValueColumnBuilder() = default; @@ -674,9 +621,7 @@ class ValueColumnBuilder : public IContextColumnBuilder { ~ValueColumnBuilder() = default; void reserve(size_t size) override { data_.reserve(size); } - void push_back_elem(const RTAny& val) override { - data_.push_back(std::string(val.as_string())); - } + void push_back_elem(const RTAny& val) override { data_.push_back(std::string(val.as_string())); } void push_back_opt(const std::string& val) { data_.push_back(val); } @@ -691,8 +636,7 @@ class ValueColumnBuilder : public IContextColumnBuilder { }; template -std::shared_ptr ValueColumn::shuffle( - const std::vector& offsets) const { +std::shared_ptr ValueColumn::shuffle(const std::vector& offsets) const { ValueColumnBuilder builder; builder.reserve(offsets.size()); for (auto offset : offsets) { diff --git a/flex/engines/hqps_db/core/base_engine.h b/flex/engines/hqps_db/core/base_engine.h index fd56c4410b8d..8dca3c12a30b 100644 --- a/flex/engines/hqps_db/core/base_engine.h +++ b/flex/engines/hqps_db/core/base_engine.h @@ -109,14 +109,14 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ind_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllIndexElement())>; - using ctx_y_all_data_t = std::remove_reference_t< - decltype(std::declval().GetAllData())>; + using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ind_ele_t = std::remove_reference_t().GetAllIndexElement())>; + using ctx_y_all_data_t = std::remove_reference_t().GetAllData())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -222,14 +222,14 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ind_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllIndexElement())>; - using ctx_y_all_data_t = std::remove_reference_t< - decltype(std::declval().GetAllData())>; + using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ind_ele_t = std::remove_reference_t().GetAllIndexElement())>; + using ctx_y_all_data_t = std::remove_reference_t().GetAllData())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -461,12 +461,12 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_data_t = std::remove_reference_t< - decltype(std::declval().GetAllData())>; + using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_data_t = std::remove_reference_t().GetAllData())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -556,10 +556,10 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -651,10 +651,10 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; @@ -757,10 +757,10 @@ class BaseEngine { // get all tuples from two context. using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; - using ctx_x_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t real_x_ind = alias_x == -1 ? x_ele_num - 1 : alias_x - CTX_X::base_tag_id; @@ -808,10 +808,10 @@ class BaseEngine { using ctx_x_iter_t = typename CTX_X::iterator; using ctx_y_iter_t = typename CTX_Y::iterator; // the prev column (the last column in prev_tuple should be the same.) - using ctx_x_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; - using ctx_y_all_ele_t = std::remove_reference_t< - decltype(std::declval().GetAllElement())>; + using ctx_x_all_ele_t = std::remove_reference_t().GetAllElement())>; + using ctx_y_all_ele_t = std::remove_reference_t().GetAllElement())>; static constexpr size_t x_ele_num = std::tuple_size_v; static constexpr size_t y_ele_num = std::tuple_size_v; static constexpr int x_base_tag = CTX_X::base_tag_id; diff --git a/flex/engines/hqps_db/core/operator/edge_expand.h b/flex/engines/hqps_db/core/operator/edge_expand.h index 1f3ee240174c..ce3e4b5c70f1 100644 --- a/flex/engines/hqps_db/core/operator/edge_expand.h +++ b/flex/engines/hqps_db/core/operator/edge_expand.h @@ -465,11 +465,10 @@ class EdgeExpand { CHECK(edge_triplets.size() > 0); // result_set_t is the type of calling EdgeExpandV with cur_vertex_set // and edge_triplets[i] - using result_set_t = - decltype(EdgeExpandV(graph, cur_vertex_set, direction, - edge_triplets[0][2], edge_triplets[0][1], - std::move(edge_filter)) - .first); + using result_set_t = decltype( + EdgeExpandV(graph, cur_vertex_set, direction, edge_triplets[0][2], + edge_triplets[0][1], std::move(edge_filter)) + .first); using result_pair_t = std::pair>; std::vector result_pairs; for (size_t i = 0; i < edge_triplets.size(); ++i) { diff --git a/flex/engines/hqps_db/core/operator/group_by.h b/flex/engines/hqps_db/core/operator/group_by.h index ff261a3f163e..674c43cc0476 100644 --- a/flex/engines/hqps_db/core/operator/group_by.h +++ b/flex/engines/hqps_db/core/operator/group_by.h @@ -36,8 +36,8 @@ struct CommonBuilderT; template struct CommonBuilderT> { - using set_t = std::remove_const_t().template GetNode())>>; + using set_t = std::remove_const_t().template GetNode())>>; using builder_t = typename set_t::builder_t; using result_t = typename builder_t::result_t; using result_ele_t = typename result_t::element_type; @@ -45,8 +45,8 @@ struct CommonBuilderT> { template struct CommonBuilderT> { - using set_t = std::remove_const_t().template GetNode())>>; + using set_t = std::remove_const_t().template GetNode())>>; using builder_t = CollectionBuilder; using result_t = typename builder_t::result_t; using result_ele_t = typename result_t::element_type; @@ -57,8 +57,8 @@ struct GroupKeyResT; template struct GroupKeyResT> { - using set_t = std::remove_const_t().template GetNode())>>; + using set_t = std::remove_const_t().template GetNode())>>; using result_t = typename KeyedT>::keyed_set_t; }; @@ -75,9 +75,8 @@ struct GroupValueResT, std::integer_sequence>, typename std::enable_if<(sizeof...(Is) == 1)>::type> { - using old_set_t = std::remove_const_t() - .template GetNode::value>())>>; + using old_set_t = std::remove_const_t().template GetNode::value>())>>; using result_t = typename GroupValueResTImpl>::result_t; @@ -90,8 +89,8 @@ struct GroupValueResT>, typename std::enable_if<(sizeof...(Is) > 1)>::type> { using old_set_tuple_t = - std::tuple().template GetNode())>>...>; + std::tuple().template GetNode())>>...>; using result_t = typename GroupValueResTImpl>::result_t; diff --git a/flex/engines/hqps_db/core/operator/project.h b/flex/engines/hqps_db/core/operator/project.h index be7791dfc8fc..d1681387ba2b 100644 --- a/flex/engines/hqps_db/core/operator/project.h +++ b/flex/engines/hqps_db/core/operator/project.h @@ -42,8 +42,8 @@ struct ResultOfContextKeyAlias< Context, IdentityMapper>> { using context_t = Context; - using ctx_node_t = std::remove_reference_t< - decltype(std::declval().template GetNode())>; + using ctx_node_t = std::remove_reference_t().template GetNode())>; using result_t = Collection; }; @@ -54,8 +54,8 @@ struct ResultOfContextKeyAlias< Context, IdentityMapper>> { using context_t = Context; - using ctx_node_t = std::remove_reference_t< - decltype(std::declval().template GetNode())>; + using ctx_node_t = std::remove_reference_t().template GetNode())>; using result_t = ctx_node_t; }; @@ -266,8 +266,8 @@ class ProjectOp { const GRAPH_INTERFACE& graph, CTX_T& ctx, IdentityMapper>& mapper) { auto& node = ctx.template GetNode(); - static_assert(std::remove_reference_t< - decltype(node)>::is_vertex_set); // edge_set not supported + static_assert(std::remove_reference_t::is_vertex_set); // edge_set not supported // Create a empty copy. auto offset_array = ctx.ObtainOffsetFromTag(in_col_id); auto repeat_array = offset_array_to_repeat_array(std::move(offset_array)); diff --git a/flex/engines/hqps_db/core/utils/hqps_utils.h b/flex/engines/hqps_db/core/utils/hqps_utils.h index 5cae552776e0..efdfb68dc647 100644 --- a/flex/engines/hqps_db/core/utils/hqps_utils.h +++ b/flex/engines/hqps_db/core/utils/hqps_utils.h @@ -145,16 +145,14 @@ template struct group_key_on_property : public std::true_type {}; template -struct group_key_on_property< - AliasTagProp> +struct group_key_on_property> : public std::false_type {}; template struct group_key_on_property> : public std::true_type {}; template -struct group_key_on_property> - : public std::false_type {}; +struct group_key_on_property> : public std::false_type {}; // check edge_dir and vopt consistency inline bool check_edge_dir_consist_vopt(const Direction& dir, VOpt vopt) { @@ -169,24 +167,18 @@ inline bool check_edge_dir_consist_vopt(const Direction& dir, VOpt vopt) { return false; } -template < - std::size_t nth, std::size_t... Head, std::size_t... Tail, - typename... Types, - typename std::enable_if<(nth + 1 != sizeof...(Types))>::type* = nullptr> -constexpr auto remove_nth_element_impl(std::index_sequence, - std::index_sequence, +template ::type* = nullptr> +constexpr auto remove_nth_element_impl(std::index_sequence, std::index_sequence, const std::tuple& tup) { return std::tuple{std::get(tup)..., // We +1 to refer one element after the one removed std::get(tup)...}; } -template < - std::size_t nth, std::size_t... Head, std::size_t... Tail, - typename... Types, - typename std::enable_if<(nth + 1 == sizeof...(Types))>::type* = nullptr> -constexpr auto remove_nth_element_impl(std::index_sequence, - std::index_sequence, +template ::type* = nullptr> +constexpr auto remove_nth_element_impl(std::index_sequence, std::index_sequence, const std::tuple& tup) { return std::tuple{std::get(tup)...}; } @@ -194,9 +186,8 @@ constexpr auto remove_nth_element_impl(std::index_sequence, template constexpr auto remove_nth_element(const std::tuple& tup) { static_assert(nth < sizeof...(Types)); - return remove_nth_element_impl( - std::make_index_sequence(), - std::make_index_sequence(), tup); + return remove_nth_element_impl(std::make_index_sequence(), + std::make_index_sequence(), tup); } template @@ -223,8 +214,7 @@ template struct remove_ith_type> { typedef decltype(std::tuple_cat( std::declval>(), - std::declval>::type>())) - type; + std::declval>::type>())) type; }; // I != J @@ -232,15 +222,13 @@ template struct remove_ith_jth_type {}; template -struct remove_ith_jth_type, - typename std::enable_if<(I < J)>::type> { +struct remove_ith_jth_type, typename std::enable_if<(I < J)>::type> { using first_type = typename remove_ith_type>::type; using type = typename remove_ith_type::type; }; template -struct remove_ith_jth_type, - typename std::enable_if<(I > J)>::type> { +struct remove_ith_jth_type, typename std::enable_if<(I > J)>::type> { using type = typename remove_ith_jth_type>::type; }; @@ -249,20 +237,17 @@ struct Edge; template < size_t Is, typename... PROP_T, - typename std::enable_if::type* = nullptr> void - props_to_string_array( - std::tuple& props, - std::array>>& - res) { + typename std::enable_if::type* = nullptr> void props_to_string_array( + std::tuple& props, + std::array>>& res) { res[Is] = std::get(props).property_name; props_to_string_array(props, res); } template ::type* = nullptr> -void props_to_string_array( - std::tuple& props, - std::array>>& res) { +void props_to_string_array(std::tuple& props, + std::array>>& res) { res[Is] = std::get(props).property_name; } template @@ -277,8 +262,8 @@ struct tuple_element; // recursive case template -struct tuple_element> - : gs::tuple_element> {}; +struct tuple_element> : gs::tuple_element> { +}; // base case template @@ -296,8 +281,7 @@ struct tuple_element<-1, std::tuple> { template auto unwrap_future_tuple(std::tuple&& tuple) { - return unwrap_future_tuple(std::move(tuple), - std::make_index_sequence()); + return unwrap_future_tuple(std::move(tuple), std::make_index_sequence()); } template auto unwrap_future_tuple(std::tuple&& tuple, std::index_sequence) { @@ -338,9 +322,7 @@ struct FirstElement { // Create a tuple of const references to the elements of a tuple. template auto make_tuple_of_const_refs(const std::tuple& t) { - return std::apply( - [](const Args&... args) { return std::make_tuple(std::cref(args)...); }, - t); + return std::apply([](const Args&... args) { return std::make_tuple(std::cref(args)...); }, t); } template @@ -358,9 +340,8 @@ struct first_n_impl; template struct first_n_impl, Out...> { - typedef - typename first_n_impl, Out..., First>::type - type; // move first input to output. + typedef typename first_n_impl, Out..., First>::type + type; // move first input to output. }; // need First, Other... here to resolve ambiguity on n = 0 @@ -396,42 +377,34 @@ constexpr auto tuple_slice_impl(T&& t, std::index_sequence) { template constexpr auto tuple_slice(T&& t) { static_assert(r >= l, "invalid slice"); - static_assert(std::tuple_size>::value >= r, - "slice index out of bounds"); - return tuple_slice_impl(std::forward(t), - std::make_index_sequence{}); + static_assert(std::tuple_size>::value >= r, "slice index out of bounds"); + return tuple_slice_impl(std::forward(t), std::make_index_sequence{}); } // [l, tuple_size - 1] template constexpr auto tuple_slice(T&& t) { - static_assert(std::tuple_size>::value > l, - "slice index out of bounds"); + static_assert(std::tuple_size>::value > l, "slice index out of bounds"); return tuple_slice_impl( - std::forward(t), - std::make_index_sequence>::value - l>{}); + std::forward(t), std::make_index_sequence>::value - l>{}); } -template = 0)>::type* = nullptr> +template = 0)>::type* = nullptr> inline auto get_from_tuple(std::tuple& tuple) { return std::get(tuple); } -template ::type* = nullptr> +template ::type* = nullptr> inline auto get_from_tuple(std::tuple& tuple) { static constexpr size_t num = sizeof...(T); return std::get(tuple); } -template = 0)>::type* = nullptr> +template = 0)>::type* = nullptr> inline const auto& get_from_tuple(const std::tuple& tuple) { return std::get(tuple); } -template ::type* = nullptr> +template ::type* = nullptr> inline const auto& get_from_tuple(const std::tuple& tuple) { static constexpr size_t num = sizeof...(T); return std::get(tuple); @@ -440,30 +413,26 @@ inline const auto& get_from_tuple(const std::tuple& tuple) { // vertex/edge property associate with type template ::type> -auto transform_array_impl(std::array&& array, FUNC_T&& func, - std::index_sequence) { +auto transform_array_impl(std::array&& array, FUNC_T&& func, std::index_sequence) { return std::array{std::move(func(std::move(array[Is])))...}; } template auto transform_array(std::array&& array, FUNC_T&& func) { - return transform_array_impl(std::move(array), std::move(func), - std::make_index_sequence()); + return transform_array_impl(std::move(array), std::move(func), std::make_index_sequence()); } template ::type> auto transform_tuple_impl(const std::tuple&& tuple, FUNC_T&& func, std::index_sequence) { - return std::make_tuple( - std::move(func(Is, std::move(std::get(tuple))))...); + return std::make_tuple(std::move(func(Is, std::move(std::get(tuple))))...); } template auto transform_tuple(const std::tuple&& tuple, FUNC_T&& func) { static constexpr size_t N = sizeof...(T); - return transform_tuple_impl(std::move(tuple), std::move(func), - std::make_index_sequence()); + return transform_tuple_impl(std::move(tuple), std::move(func), std::make_index_sequence()); } template @@ -474,32 +443,28 @@ bool apply_on_tuple_impl(const FUNC& func, const std::tuple& tuple, template bool apply_on_tuple(const FUNC& func, const std::tuple& tuple) { - return apply_on_tuple_impl(func, tuple, - std::make_index_sequence()); + return apply_on_tuple_impl(func, tuple, std::make_index_sequence()); } template ::type> -auto apply_array_impl(const std::array& array, FUNC_T&& func, - std::index_sequence) { +auto apply_array_impl(const std::array& array, FUNC_T&& func, std::index_sequence) { return std::array{std::move(func(array[Is]))...}; } template auto apply_array(const std::array& array, FUNC_T&& func) { - return apply_array_impl(array, std::move(func), - std::make_index_sequence()); + return apply_array_impl(array, std::move(func), std::make_index_sequence()); } template -void apply_tuple_impl(const std::tuple& tuple, const FUNC_T& func, - std::index_sequence, OTHER_ARGS&... other_args) { +void apply_tuple_impl(const std::tuple& tuple, const FUNC_T& func, std::index_sequence, + OTHER_ARGS&... other_args) { ((func(std::get(tuple), std::forward(other_args)...)), ...); } template -auto apply_tuple(const std::tuple& tuple, const FUNC_T& func, - OTHER_ARGS&... other_args) { +auto apply_tuple(const std::tuple& tuple, const FUNC_T& func, OTHER_ARGS&... other_args) { static constexpr size_t N = sizeof...(T); return apply_tuple_impl(tuple, func, std::make_index_sequence(), std::forward(other_args)...); @@ -508,8 +473,8 @@ auto apply_tuple(const std::tuple& tuple, const FUNC_T& func, template constexpr auto make_array(Args&&... args) { if constexpr (std::is_same::value) { - return std::array...>, - sizeof...(Args)>{{std::forward(args)...}}; + return std::array...>, sizeof...(Args)>{ + {std::forward(args)...}}; } else { return std::array{{std::forward(args)...}}; } @@ -557,13 +522,11 @@ struct NumberLarger { }; template -using make_index_range = - decltype(add(std::make_index_sequence())); +using make_index_range = decltype(add(std::make_index_sequence())); template struct TupleCatT { - using tuple_cat_t = - decltype(std::tuple_cat(std::declval(), std::declval())); + using tuple_cat_t = decltype(std::tuple_cat(std::declval(), std::declval())); }; template @@ -577,8 +540,7 @@ struct TupleCatT> { }; template -auto make_getter_tuple(label_t label, std::tuple&& tuple, - std::index_sequence) { +auto make_getter_tuple(label_t label, std::tuple&& tuple, std::index_sequence) { return std::make_tuple(std::get(tuple).CreateGetter(label)...); } @@ -620,9 +582,8 @@ struct ColumnAccessorImpl {}; // Recursive template -struct ColumnAccessorImpl - : public SingleColumn, - public ColumnAccessorImpl {}; +struct ColumnAccessorImpl : public SingleColumn, + public ColumnAccessorImpl {}; // multiple single columns. @@ -680,8 +641,8 @@ std::vector array_to_vec(const std::array& array) { } template -static typename PRIORITY_QUEUE_T::container_type priority_queue_to_vec( - PRIORITY_QUEUE_T& pq, bool reversed = false) { +static typename PRIORITY_QUEUE_T::container_type priority_queue_to_vec(PRIORITY_QUEUE_T& pq, + bool reversed = false) { auto pq_size = pq.size(); typename PRIORITY_QUEUE_T::container_type res; res.reserve(pq_size); @@ -720,8 +681,7 @@ struct to_string_impl> { // map{key:value, ...} ss << "map{"; for (auto& [k, v] : vec) { - ss << to_string_impl::to_string(k) << ":" - << to_string_impl::to_string(v) << ","; + ss << to_string_impl::to_string(k) << ":" << to_string_impl::to_string(v) << ","; } ss << "}"; return ss.str(); @@ -741,8 +701,7 @@ struct to_string_impl> { template struct to_string_impl, M>> { - static inline std::string to_string( - const std::array, M>& empty) { + static inline std::string to_string(const std::array, M>& empty) { std::stringstream ss; ss << "["; for (auto i : empty) { @@ -770,9 +729,7 @@ struct to_string_impl { template <> struct to_string_impl { - static inline std::string to_string(const Dist& empty) { - return std::to_string(empty.dist); - } + static inline std::string to_string(const Dist& empty) { return std::to_string(empty.dist); } }; template <> @@ -784,16 +741,12 @@ struct to_string_impl { template <> struct to_string_impl { - static inline std::string to_string(const std::string_view& empty) { - return std::string(empty); - } + static inline std::string to_string(const std::string_view& empty) { return std::string(empty); } }; template <> struct to_string_impl { - static inline std::string to_string(const grape::EmptyType& empty) { - return ""; - } + static inline std::string to_string(const grape::EmptyType& empty) { return ""; } }; template <> @@ -805,51 +758,37 @@ struct to_string_impl { template <> struct to_string_impl { - static inline std::string to_string(const int64_t& empty) { - return std::to_string(empty); - } + static inline std::string to_string(const int64_t& empty) { return std::to_string(empty); } }; template <> struct to_string_impl { - static inline std::string to_string(const bool& empty) { - return std::to_string(empty); - } + static inline std::string to_string(const bool& empty) { return std::to_string(empty); } }; template <> struct to_string_impl { - static inline std::string to_string(const unsigned long& empty) { - return std::to_string(empty); - } + static inline std::string to_string(const unsigned long& empty) { return std::to_string(empty); } }; template <> struct to_string_impl { - static inline std::string to_string(const int32_t& empty) { - return std::to_string(empty); - } + static inline std::string to_string(const int32_t& empty) { return std::to_string(empty); } }; template <> struct to_string_impl { - static inline std::string to_string(const uint32_t& empty) { - return std::to_string(empty); - } + static inline std::string to_string(const uint32_t& empty) { return std::to_string(empty); } }; template <> struct to_string_impl { - static inline std::string to_string(const double& empty) { - return std::to_string(empty); - } + static inline std::string to_string(const double& empty) { return std::to_string(empty); } }; template <> struct to_string_impl { - static inline std::string to_string(const std::string& empty) { - return empty; - } + static inline std::string to_string(const std::string& empty) { return empty; } }; template <> @@ -935,8 +874,8 @@ struct to_string_impl> { std::apply( [&result](const auto&... v) { ((result += - (to_string_impl>>::to_string(v)) + + (to_string_impl>>::to_string( + v)) + ","), ...); }, @@ -965,11 +904,9 @@ template struct Edge { VID_T src, dst; const std::tuple& edata; - Edge(VID_T s, VID_T d, const std::tuple& data) - : src(s), dst(d), edata(data) {} + Edge(VID_T s, VID_T d, const std::tuple& data) : src(s), dst(d), edata(data) {} std::string to_string() const { - return std::to_string(src) + "->" + std::to_string(dst) + "(" + - gs::to_string(edata) + ")"; + return std::to_string(src) + "->" + std::to_string(dst) + "(" + gs::to_string(edata) + ")"; } }; @@ -987,8 +924,7 @@ template using DefaultEdge = Edge; template -inline bool operator==(const DefaultEdge& lhs, - const DefaultEdge& rhs) { +inline bool operator==(const DefaultEdge& lhs, const DefaultEdge& rhs) { return lhs.src == rhs.src && lhs.dst == rhs.dst; } @@ -1022,9 +958,9 @@ struct function_traits }; template -static std::tuple get_graph_label_pair( - Direction& direction, label_id_t query_src_label, - label_id_t query_dst_label) { +static std::tuple get_graph_label_pair(Direction& direction, + label_id_t query_src_label, + label_id_t query_dst_label) { label_id_t src_label, dst_label; if (direction == Direction::In) { src_label = query_dst_label; diff --git a/flex/tests/hqps/context_test.cc b/flex/tests/hqps/context_test.cc index 3e4bf4b322c0..c08c8f5fede2 100644 --- a/flex/tests/hqps/context_test.cc +++ b/flex/tests/hqps/context_test.cc @@ -152,7 +152,7 @@ int main() { col1->resize(limit); for (size_t i = 0; i < limit; ++i) { - col1->set_value(i, (int32_t)(i)); + col1->set_value(i, (int32_t) (i)); } { int32_t res = 0; @@ -205,7 +205,7 @@ int main() { col1->resize(limit); col2->resize(limit); for (size_t i = 0; i < limit; ++i) { - col1->set_value(i, (int32_t)(i)); + col1->set_value(i, (int32_t) (i)); col2->set_value(i, (int64_t) i); } { @@ -298,10 +298,10 @@ int main() { col1->resize(limit); col2->resize(limit); for (size_t i = 0; i < limit; i += 2) { - col1->set_value(i, (int32_t)(i)); + col1->set_value(i, (int32_t) (i)); } for (size_t i = 1; i < limit; i += 2) { - col2->set_value(i, (int32_t)(i)); + col2->set_value(i, (int32_t) (i)); } // test two label vertex set prop getter. auto ref_col1 = std::make_shared>(*col1); From c3c9e951e31077749f41cb86ed4c7c629cbd1fcc Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 15 Oct 2024 19:40:30 +0800 Subject: [PATCH 05/17] don't need std_string Committed-by: xiaolei.zl from Dev container --- .../runtime/adhoc/operators/procedure_call.cc | 10 ++----- .../runtime/common/columns/i_context_column.h | 24 --------------- .../runtime/common/columns/value_columns.cc | 1 - .../engines/graph_db/runtime/common/rt_any.cc | 30 ++----------------- flex/engines/graph_db/runtime/common/rt_any.h | 13 -------- 5 files changed, 4 insertions(+), 74 deletions(-) diff --git a/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc index 7bba6af61993..41b79d7be3a3 100644 --- a/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc +++ b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc @@ -53,15 +53,9 @@ std::shared_ptr any_vec_to_column( } return builder.finish(); } else if (first == RTAnyType::kStringValue) { - ValueColumnBuilder builder; + ValueColumnBuilder builder; for (auto& any : any_vec) { - builder.push_back_opt(std::string(any.as_string())); - } - return builder.finish(); - } else if (first == RTAnyType::kStdStringValue) { - ValueColumnBuilder builder; - for (auto& any : any_vec) { - builder.push_back_opt(any.as_std_string()); + builder.push_back_elem(any); } return builder.finish(); } else { diff --git a/flex/engines/graph_db/runtime/common/columns/i_context_column.h b/flex/engines/graph_db/runtime/common/columns/i_context_column.h index cdacb8d5fd24..c35f97f19378 100644 --- a/flex/engines/graph_db/runtime/common/columns/i_context_column.h +++ b/flex/engines/graph_db/runtime/common/columns/i_context_column.h @@ -110,30 +110,6 @@ class SigColumn : public ISigColumn { std::vector sig_list_; }; -template <> -class SigColumn : public ISigColumn { - public: - SigColumn(const std::vector& data) { - std::unordered_map table; - sig_list_.reserve(data.size()); - for (auto& str : data) { - auto iter = table.find(str); - if (iter == table.end()) { - size_t idx = table.size(); - table.emplace(str, idx); - sig_list_.push_back(idx); - } else { - sig_list_.push_back(iter->second); - } - } - } - ~SigColumn() = default; - size_t get_sig(size_t idx) const override { return sig_list_[idx]; } - - private: - std::vector sig_list_; -}; - template <> class SigColumn> : public ISigColumn { public: diff --git a/flex/engines/graph_db/runtime/common/columns/value_columns.cc b/flex/engines/graph_db/runtime/common/columns/value_columns.cc index f136e9f44348..8a1c23ac8dfc 100644 --- a/flex/engines/graph_db/runtime/common/columns/value_columns.cc +++ b/flex/engines/graph_db/runtime/common/columns/value_columns.cc @@ -14,7 +14,6 @@ */ #include "flex/engines/graph_db/runtime/common/columns/value_columns.h" -#include "flex/proto_generated_gie/results.pb.h" namespace gs { diff --git a/flex/engines/graph_db/runtime/common/rt_any.cc b/flex/engines/graph_db/runtime/common/rt_any.cc index d912126b255d..07df11de807f 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.cc +++ b/flex/engines/graph_db/runtime/common/rt_any.cc @@ -35,8 +35,6 @@ const RTAnyType RTAnyType::kBoolValue = RTAnyType(RTAnyType::RTAnyTypeImpl::kBoolValue); const RTAnyType RTAnyType::kStringValue = RTAnyType(RTAnyType::RTAnyTypeImpl::kStringValue); -const RTAnyType RTAnyType::kStdStringValue = - RTAnyType(RTAnyType::RTAnyTypeImpl::kStdStringValue); const RTAnyType RTAnyType::kVertexSetValue = RTAnyType(RTAnyType::RTAnyTypeImpl::kVertexSetValue); const RTAnyType RTAnyType::kStringSetValue = @@ -142,8 +140,6 @@ RTAny::RTAny(const RTAny& rhs) : type_(rhs.type_) { value_.vertex = rhs.value_.vertex; } else if (type_ == RTAnyType::kStringValue) { value_.str_val = rhs.value_.str_val; - } else if (type_ == RTAnyType::kStdStringValue) { - value_.std_str_val = rhs.value_.std_str_val; } else if (type_ == RTAnyType::kNull) { // do nothing } else if (type_ == RTAnyType::kTuple) { @@ -171,8 +167,6 @@ RTAny& RTAny::operator=(const RTAny& rhs) { value_.vertex = rhs.value_.vertex; } else if (type_ == RTAnyType::kStringValue) { value_.str_val = rhs.value_.str_val; - } else if (type_ == RTAnyType::kStdStringValue) { - value_.std_str_val = rhs.value_.std_str_val; } else if (type_ == RTAnyType::kTuple) { value_.t = rhs.value_.t.dup(); } else if (type_ == RTAnyType::kList) { @@ -244,8 +238,8 @@ RTAny RTAny::from_int32(int v) { RTAny RTAny::from_string(const std::string& str) { RTAny ret; - ret.type_ = RTAnyType::kStdStringValue; - ret.value_.std_str_val = str; + ret.type_ = RTAnyType::kStringValue; + ret.value_.str_val = std::string_view(str); return ret; } @@ -368,17 +362,6 @@ std::string_view RTAny::as_string() const { } } -std::string RTAny::as_std_string() const { - if (type_ == RTAnyType::kStdStringValue) { - return *(value_.std_str_val.ptr); - } else if (type_ == RTAnyType::kUnknown) { - return std::string(); - } else { - LOG(FATAL) << "unexpected type" << static_cast(type_.type_enum_); - return std::string(); - } -} - List RTAny::as_list() const { CHECK(type_ == RTAnyType::kList); return value_.list; @@ -462,8 +445,6 @@ bool RTAny::operator<(const RTAny& other) const { } else if (type_ == RTAnyType::kStringValue) { return value_.str_val < other.value_.str_val; - } else if (type_ == RTAnyType::kStdStringValue) { - return *(value_.std_str_val.ptr) < *(other.value_.std_str_val.ptr); } else if (type_ == RTAnyType::kDate32) { return value_.i64_val < other.value_.i64_val; } else if (type_ == RTAnyType::kF64Value) { @@ -490,8 +471,6 @@ bool RTAny::operator==(const RTAny& other) const { return value_.i32_val == other.value_.i32_val; } else if (type_ == RTAnyType::kStringValue) { return value_.str_val == other.value_.str_val; - } else if (type_ == RTAnyType::kStdStringValue) { - return *(value_.std_str_val.ptr) == *(other.value_.std_str_val.ptr); } else if (type_ == RTAnyType::kVertex) { return value_.vertex == other.value_.vertex; } else if (type_ == RTAnyType::kDate32) { @@ -576,9 +555,6 @@ void RTAny::sink_impl(common::Value* value) const { value->set_i64(value_.i64_val); } else if (type_ == RTAnyType::kStringValue) { value->set_str(value_.str_val.data(), value_.str_val.size()); - } else if (type_ == RTAnyType::kStdStringValue) { - value->set_str(value_.std_str_val.ptr->data(), - value_.std_str_val.ptr->size()); } else if (type_ == RTAnyType::kI32Value) { value->set_i32(value_.i32_val); } else if (type_ == RTAnyType::kStringSetValue) { @@ -767,8 +743,6 @@ std::string RTAny::to_string() const { return std::to_string(value_.i64_val); } else if (type_ == RTAnyType::kStringValue) { return std::string(value_.str_val); - } else if (type_ == RTAnyType::kStdStringValue) { - return std::string(*(value_.std_str_val.ptr)); } else if (type_ == RTAnyType::kI32Value) { return std::to_string(value_.i32_val); } else if (type_ == RTAnyType::kVertex) { diff --git a/flex/engines/graph_db/runtime/common/rt_any.h b/flex/engines/graph_db/runtime/common/rt_any.h index 5d831fc57c8d..54b996267bcf 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.h +++ b/flex/engines/graph_db/runtime/common/rt_any.h @@ -230,7 +230,6 @@ union RTAnyValue { const std::vector* vset; const std::set* str_set; std::string_view str_val; - StringPtr std_str_val; Path p; Tuple t; List list; @@ -281,7 +280,6 @@ class RTAny { const std::tuple& as_edge() const; const std::set& as_string_set() const; std::string_view as_string() const; - std::string as_std_string() const; const std::vector& as_vertex_list() const; Path as_path() const; Tuple as_tuple() const; @@ -365,17 +363,6 @@ struct TypedConverter { } }; -template <> -struct TypedConverter { - static RTAnyType type() { return RTAnyType::kStringValue; } - static std::string to_typed(const RTAny& val) { return val.as_std_string(); } - static RTAny from_typed(const std::string& val) { - return RTAny::from_string(val); - } - static const std::string name() { return "string"; } - static std::string typed_from_string(const std::string& str) { return str; } -}; - template <> struct TypedConverter { static RTAnyType type() { return RTAnyType::kU64Value; } From c9bdcbbdb62a447abb8d7983d5dc1abb48cc84a3 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 15 Oct 2024 19:41:58 +0800 Subject: [PATCH 06/17] minor Committed-by: xiaolei.zl from Dev container --- flex/engines/graph_db/runtime/common/rt_any.cc | 1 - flex/engines/graph_db/runtime/common/rt_any.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/flex/engines/graph_db/runtime/common/rt_any.cc b/flex/engines/graph_db/runtime/common/rt_any.cc index 07df11de807f..e3cf4a1d55d8 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.cc +++ b/flex/engines/graph_db/runtime/common/rt_any.cc @@ -245,7 +245,6 @@ RTAny RTAny::from_string(const std::string& str) { RTAny RTAny::from_string(const std::string_view& str) { RTAny ret; - LOG(INFO) << "from_string: " << str; ret.type_ = RTAnyType::kStringValue; ret.value_.str_val = str; return ret; diff --git a/flex/engines/graph_db/runtime/common/rt_any.h b/flex/engines/graph_db/runtime/common/rt_any.h index 54b996267bcf..cc5371e4005f 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.h +++ b/flex/engines/graph_db/runtime/common/rt_any.h @@ -157,7 +157,6 @@ class RTAnyType { kF64Value, kBoolValue, kStringValue, - kStdStringValue, kVertexSetValue, kStringSetValue, kUnknown, @@ -176,7 +175,6 @@ class RTAnyType { static const RTAnyType kF64Value; static const RTAnyType kBoolValue; static const RTAnyType kStringValue; - static const RTAnyType kStdStringValue; static const RTAnyType kVertexSetValue; static const RTAnyType kStringSetValue; static const RTAnyType kUnknown; From 013aa4ee57892ac1c26e4726e5064e6ac3e60388 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 15 Oct 2024 19:51:26 +0800 Subject: [PATCH 07/17] format Committed-by: xiaolei.zl from Dev container --- flex/tests/hqps/context_test.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flex/tests/hqps/context_test.cc b/flex/tests/hqps/context_test.cc index c08c8f5fede2..3e4bf4b322c0 100644 --- a/flex/tests/hqps/context_test.cc +++ b/flex/tests/hqps/context_test.cc @@ -152,7 +152,7 @@ int main() { col1->resize(limit); for (size_t i = 0; i < limit; ++i) { - col1->set_value(i, (int32_t) (i)); + col1->set_value(i, (int32_t)(i)); } { int32_t res = 0; @@ -205,7 +205,7 @@ int main() { col1->resize(limit); col2->resize(limit); for (size_t i = 0; i < limit; ++i) { - col1->set_value(i, (int32_t) (i)); + col1->set_value(i, (int32_t)(i)); col2->set_value(i, (int64_t) i); } { @@ -298,10 +298,10 @@ int main() { col1->resize(limit); col2->resize(limit); for (size_t i = 0; i < limit; i += 2) { - col1->set_value(i, (int32_t) (i)); + col1->set_value(i, (int32_t)(i)); } for (size_t i = 1; i < limit; i += 2) { - col2->set_value(i, (int32_t) (i)); + col2->set_value(i, (int32_t)(i)); } // test two label vertex set prop getter. auto ref_col1 = std::make_shared>(*col1); From 2577a4a05ea5aa512dd8d006634e7b0b9786f7fb Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Wed, 16 Oct 2024 10:45:31 +0800 Subject: [PATCH 08/17] remove duplicated code Committed-by: xiaolei.zl from Dev container --- flex/engines/graph_db/database/graph_db_session.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/flex/engines/graph_db/database/graph_db_session.cc b/flex/engines/graph_db/database/graph_db_session.cc index d3e6db03dcf5..dc2a411c0ef2 100644 --- a/flex/engines/graph_db/database/graph_db_session.cc +++ b/flex/engines/graph_db/database/graph_db_session.cc @@ -225,15 +225,6 @@ AppBase* GraphDBSession::GetApp(const std::string& app_name) { #define likely(x) __builtin_expect(!!(x), 1) -AppBase* GraphDBSession::GetApp(const std::string& app_name) { - auto& app_name_to_path_index = db_.schema().GetPlugins(); - if (app_name_to_path_index.count(app_name) <= 0) { - LOG(ERROR) << "Query name is not registered: " << app_name; - return nullptr; - } - return GetApp(app_name_to_path_index.at(app_name).second); -} - AppBase* GraphDBSession::GetApp(int type) { // create if not exist if (type >= GraphDBSession::MAX_PLUGIN_NUM) { From f9970af4e2c4904f1a1f323664f62d6611242243 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Fri, 18 Oct 2024 14:32:46 +0800 Subject: [PATCH 09/17] reset build_ir_core.sh Committed-by: xiaolei.zl from Dev container --- interactive_engine/compiler/build_ir_core.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/interactive_engine/compiler/build_ir_core.sh b/interactive_engine/compiler/build_ir_core.sh index 3a27f9725c6d..a2d49a4d9446 100755 --- a/interactive_engine/compiler/build_ir_core.sh +++ b/interactive_engine/compiler/build_ir_core.sh @@ -1,12 +1,12 @@ #!/bin/bash -#set -e -#set -x -# -#if $(! command -v cargo &> /dev/null) -#then -# echo "cargo not exit, skip compile" -#else -# cd ../executor/ir/core -# cargo build --release -#fi +set -e +set -x + +if $(! command -v cargo &> /dev/null) +then + echo "cargo not exit, skip compile" +else + cd ../executor/ir/core + cargo build --release +fi From ec09f80252770dbde9d2e9da133f5bc1ff721b96 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Fri, 18 Oct 2024 14:33:31 +0800 Subject: [PATCH 10/17] minor format Committed-by: xiaolei.zl from Dev container --- interactive_engine/compiler/build_ir_core.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interactive_engine/compiler/build_ir_core.sh b/interactive_engine/compiler/build_ir_core.sh index a2d49a4d9446..532e2f0a5f64 100755 --- a/interactive_engine/compiler/build_ir_core.sh +++ b/interactive_engine/compiler/build_ir_core.sh @@ -5,8 +5,8 @@ set -x if $(! command -v cargo &> /dev/null) then - echo "cargo not exit, skip compile" + echo "cargo not exit, skip compile" else - cd ../executor/ir/core - cargo build --release + cd ../executor/ir/core + cargo build --release fi From 75e8299bf143f5f245bb5ad4e0819f0811a51328 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Fri, 18 Oct 2024 17:57:40 +0800 Subject: [PATCH 11/17] fix Committed-by: xiaolei.zl from Dev container --- flex/engines/graph_db/database/graph_db.cc | 5 +- flex/engines/graph_db/database/graph_db.h | 2 +- .../graph_db/database/graph_db_session.cc | 2 +- .../graph_db/database/read_transaction.cc | 7 +- .../graph_db/database/read_transaction.h | 7 +- .../runtime/adhoc/operators/operators.h | 2 +- .../runtime/adhoc/operators/procedure_call.cc | 146 ++++++++++++++---- flex/engines/graph_db/runtime/common/types.cc | 16 ++ flex/engines/graph_db/runtime/common/types.h | 3 + 9 files changed, 147 insertions(+), 43 deletions(-) diff --git a/flex/engines/graph_db/database/graph_db.cc b/flex/engines/graph_db/database/graph_db.cc index ed27fac9b825..1b8fff41a8f6 100644 --- a/flex/engines/graph_db/database/graph_db.cc +++ b/flex/engines/graph_db/database/graph_db.cc @@ -259,9 +259,8 @@ void GraphDB::Close() { std::fill(app_factories_.begin(), app_factories_.end(), nullptr); } -ReadTransaction GraphDB::GetReadTransaction() { - uint32_t ts = version_manager_.acquire_read_timestamp(); - return {graph_, version_manager_, ts}; +ReadTransaction GraphDB::GetReadTransaction(int thread_id) { + return contexts_[thread_id].session.GetReadTransaction(); } InsertTransaction GraphDB::GetInsertTransaction(int thread_id) { diff --git a/flex/engines/graph_db/database/graph_db.h b/flex/engines/graph_db/database/graph_db.h index 502710abd012..d345838f7be3 100644 --- a/flex/engines/graph_db/database/graph_db.h +++ b/flex/engines/graph_db/database/graph_db.h @@ -98,7 +98,7 @@ class GraphDB { * * @return graph_dir The directory of graph data. */ - ReadTransaction GetReadTransaction(); + ReadTransaction GetReadTransaction(int thread_id = 0); /** @brief Create a transaction to insert vertices and edges with a default * allocator. diff --git a/flex/engines/graph_db/database/graph_db_session.cc b/flex/engines/graph_db/database/graph_db_session.cc index dc2a411c0ef2..8173fa65f5f8 100644 --- a/flex/engines/graph_db/database/graph_db_session.cc +++ b/flex/engines/graph_db/database/graph_db_session.cc @@ -29,7 +29,7 @@ namespace gs { ReadTransaction GraphDBSession::GetReadTransaction() const { uint32_t ts = db_.version_manager_.acquire_read_timestamp(); - return ReadTransaction(db_.graph_, db_.version_manager_, ts); + return ReadTransaction(*this, db_.graph_, db_.version_manager_, ts); } InsertTransaction GraphDBSession::GetInsertTransaction() { diff --git a/flex/engines/graph_db/database/read_transaction.cc b/flex/engines/graph_db/database/read_transaction.cc index 723345c6d30b..70e094b022b6 100644 --- a/flex/engines/graph_db/database/read_transaction.cc +++ b/flex/engines/graph_db/database/read_transaction.cc @@ -19,9 +19,10 @@ namespace gs { -ReadTransaction::ReadTransaction(const MutablePropertyFragment& graph, +ReadTransaction::ReadTransaction(const GraphDBSession& session, + const MutablePropertyFragment& graph, VersionManager& vm, timestamp_t timestamp) - : graph_(graph), vm_(vm), timestamp_(timestamp) {} + : session_(session), graph_(graph), vm_(vm), timestamp_(timestamp) {} ReadTransaction::~ReadTransaction() { release(); } timestamp_t ReadTransaction::timestamp() const { return timestamp_; } @@ -135,4 +136,6 @@ void ReadTransaction::release() { } } +const GraphDBSession& ReadTransaction::GetSession() const { return session_; } + } // namespace gs diff --git a/flex/engines/graph_db/database/read_transaction.h b/flex/engines/graph_db/database/read_transaction.h index 5a88b1807f7e..23b93acf3fe3 100644 --- a/flex/engines/graph_db/database/read_transaction.h +++ b/flex/engines/graph_db/database/read_transaction.h @@ -26,6 +26,7 @@ namespace gs { class MutablePropertyFragment; +class GraphDBSession; class VersionManager; template class AdjListView { @@ -276,7 +277,8 @@ class SingleImmutableGraphView { class ReadTransaction { public: - ReadTransaction(const MutablePropertyFragment& graph, VersionManager& vm, + ReadTransaction(const GraphDBSession& session, + const MutablePropertyFragment& graph, VersionManager& vm, timestamp_t timestamp); ~ReadTransaction(); @@ -429,9 +431,12 @@ class ReadTransaction { return SingleImmutableGraphView(*csr); } + const GraphDBSession& GetSession() const; + private: void release(); + const GraphDBSession& session_; const MutablePropertyFragment& graph_; VersionManager& vm_; timestamp_t timestamp_; diff --git a/flex/engines/graph_db/runtime/adhoc/operators/operators.h b/flex/engines/graph_db/runtime/adhoc/operators/operators.h index 9b1a81e51dc5..c3aeb496ef65 100644 --- a/flex/engines/graph_db/runtime/adhoc/operators/operators.h +++ b/flex/engines/graph_db/runtime/adhoc/operators/operators.h @@ -78,7 +78,7 @@ bl::result eval_join(const physical::Join& opr, Context&& ctx, bl::result eval_limit(const algebra::Limit& opr, Context&& ctx); -bl::result eval_procedure_call(std::vector alias, +bl::result eval_procedure_call(const std::vector& alias, const physical::ProcedureCall& opr, const ReadTransaction& txn, Context&& ctx); diff --git a/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc index 41b79d7be3a3..f7d4cc226a83 100644 --- a/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc +++ b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc @@ -46,6 +46,12 @@ std::shared_ptr any_vec_to_column( builder.push_back_opt(any.as_int64()); } return builder.finish(); + } else if (first == RTAnyType::kU64Value) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_uint64()); + } + return builder.finish(); } else if (first == RTAnyType::kF64Value) { ValueColumnBuilder builder; for (auto& any : any_vec) { @@ -58,24 +64,24 @@ std::shared_ptr any_vec_to_column( builder.push_back_elem(any); } return builder.finish(); + } else if (first == RTAnyType::kStringSetValue) { + ValueColumnBuilder> builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_string_set()); + } + return builder.finish(); + } else if (first == RTAnyType::kDate32) { + ValueColumnBuilder builder; + for (auto& any : any_vec) { + builder.push_back_opt(any.as_date32()); + } + return builder.finish(); } else { LOG(FATAL) << "Unsupported RTAny type: " << static_cast(first.type_enum_); } } -RTAny vertex_to_rt_any(const results::Vertex& vertex) { - auto label_id = vertex.label().id(); - auto label_id_vid = decode_unique_vertex_id(vertex.id()); - CHECK(label_id == label_id_vid.first) << "Inconsistent label id."; - return RTAny::from_vertex(label_id, label_id_vid.second); -} - -RTAny edge_to_rt_any(const results::Edge& edge) { - LOG(FATAL) << "Not implemented."; - return RTAny(); -} - RTAny object_to_rt_any(const common::Value& val) { if (val.item_case() == common::Value::kBoolean) { return RTAny::from_bool(val.boolean()); @@ -92,6 +98,73 @@ RTAny object_to_rt_any(const common::Value& val) { } } +Any property_to_any(const results::Property& prop) { + // We just need the value; + const auto& val = prop.value(); + Any res; + if (val.item_case() == common::Value::kBoolean) { + res.set_bool(val.boolean()); + } else if (val.item_case() == common::Value::kI32) { + res.set_i32(val.i32()); + } else if (val.item_case() == common::Value::kI64) { + res.set_i64(val.i64()); + } else if (val.item_case() == common::Value::kF64) { + res.set_double(val.f64()); + } else if (val.item_case() == common::Value::kStr) { + res.set_string_view(std::string_view(val.str())); + } else { + LOG(FATAL) << "Unsupported value type: " << val.item_case(); + } + return res; +} + +RTAny vertex_to_rt_any(const results::Vertex& vertex) { + auto label_id = vertex.label().id(); + auto label_id_vid = decode_unique_vertex_id(vertex.id()); + CHECK(label_id == label_id_vid.first) << "Inconsistent label id."; + return RTAny::from_vertex(label_id, label_id_vid.second); +} + +RTAny edge_to_rt_any(const results::Edge& edge) { + LOG(FATAL) << "Not implemented."; + label_t src_label_id = (label_t) edge.src_label().id(); + label_t dst_label_id = (label_t) edge.dst_label().id(); + auto edge_triplet_tuple = decode_edge_label_id(edge.label().id()); + CHECK((src_label_id == std::get<0>(edge_triplet_tuple)) && + (dst_label_id == std::get<1>(edge_triplet_tuple))) + << "Inconsistent src label id."; + auto src_vertex_id = edge.src_id(); + auto dst_vertex_id = edge.dst_id(); + auto [_, src_vid] = decode_unique_vertex_id(src_vertex_id); + auto [__, dst_vid] = decode_unique_vertex_id(dst_vertex_id); + // properties + auto properties = edge.properties(); + LabelTriplet label_triplet{src_label_id, dst_label_id, + std::get<2>(edge_triplet_tuple)}; + if (properties.size() == 0) { + return RTAny::from_edge( + std::tuple{label_triplet, src_vid, dst_vid, Any(), Direction::kOut}); + } else if (properties.size() == 1) { + LOG(FATAL) << "Not implemented."; + return RTAny::from_edge(std::tuple{label_triplet, src_vid, dst_vid, + property_to_any(properties[0]), + Direction::kOut}); + } else { + std::vector props; + for (auto& prop : properties) { + props.push_back(property_to_any(prop)); + } + Any any; + any.set_record(props); + return RTAny::from_edge( + std::tuple{label_triplet, src_vid, dst_vid, any, Direction::kOut}); + } +} // namespace runtime + +RTAny graph_path_to_rt_any(const results::GraphPath& path) { + LOG(FATAL) << "Not implemented."; +} + RTAny element_to_rt_any(const results::Element& element) { if (element.inner_case() == results::Element::kVertex) { return vertex_to_rt_any(element.vertex()); @@ -99,6 +172,8 @@ RTAny element_to_rt_any(const results::Element& element) { return edge_to_rt_any(element.edge()); } else if (element.inner_case() == results::Element::kObject) { return object_to_rt_any(element.object()); + } else if (element.inner_case() == results::Element::kGraphPath) { + return graph_path_to_rt_any(element.graph_path()); } else { LOG(FATAL) << "Unsupported element type: " << element.inner_case(); } @@ -112,10 +187,6 @@ RTAny collection_to_rt_any(const results::Collection& collection) { return RTAny::from_tuple(std::move(values)); } -RTAny map_to_rt_any(const results::KeyValues& map) { - LOG(FATAL) << "Not implemented."; -} - RTAny column_to_rt_any(const results::Column& column) { auto& entry = column.entry(); if (entry.has_element()) { @@ -123,7 +194,7 @@ RTAny column_to_rt_any(const results::Column& column) { } else if (entry.has_collection()) { return collection_to_rt_any(entry.collection()); } else { - return map_to_rt_any(entry.map()); + LOG(FATAL) << "Unsupported column entry type: " << entry.inner_case(); } } @@ -171,8 +242,8 @@ collective_result_vec_to_column( return std::make_pair(columns, offsets); } -procedure::Query fill_in_query(const procedure::Query& query, - const Context& ctx, size_t idx) { +bl::result fill_in_query(const procedure::Query& query, + const Context& ctx, size_t idx) { procedure::Query real_query; real_query.mutable_query_name()->CopyFrom(query.query_name()); for (auto& param : query.arguments()) { @@ -188,15 +259,21 @@ procedure::Query fill_in_query(const procedure::Query& query, auto val = col->get_elem(idx); auto const_value = argument->mutable_const_(); if (val.type() == gs::runtime::RTAnyType::kVertex) { - LOG(FATAL) << "Not implemented yet"; + RETURN_BAD_REQUEST_ERROR("The input param should not be a vertex"); } else if (val.type() == gs::runtime::RTAnyType::kEdge) { - LOG(FATAL) << "Not implemented yet"; + RETURN_BAD_REQUEST_ERROR("The input param should not be an edge"); } else if (val.type() == gs::runtime::RTAnyType::kI64Value) { const_value->set_i64(val.as_int64()); } else if (val.type() == gs::runtime::RTAnyType::kI32Value) { const_value->set_i32(val.as_int32()); } else if (val.type() == gs::runtime::RTAnyType::kStringValue) { const_value->set_str(std::string(val.as_string())); + } else if (val.type() == gs::runtime::RTAnyType::kF64Value) { + const_value->set_f64(val.as_double()); + } else if (val.type() == gs::runtime::RTAnyType::kBoolValue) { + const_value->set_boolean(val.as_bool()); + } else if (val.type() == gs::runtime::RTAnyType::kDate32) { + const_value->set_i64(val.as_date32()); } else { LOG(ERROR) << "Unsupported type: " << static_cast(val.type().type_enum_); @@ -211,9 +288,9 @@ procedure::Query fill_in_query(const procedure::Query& query, /** * @brief Evaluate the ProcedureCall operator. * The ProcedureCall operator is used to call a stored procedure, which is - * already registered in the system. The return value of the stored procedure is - * a result::CollectiveResults object, we need to convert it to a Column, and - * append to the current context. + * already registered in the system. The return value of the stored procedure + * is a result::CollectiveResults object, we need to convert it to a Column, + * and append to the current context. * * * @param opr The ProcedureCall operator. @@ -224,7 +301,7 @@ procedure::Query fill_in_query(const procedure::Query& query, * * */ -bl::result eval_procedure_call(std::vector aliases, +bl::result eval_procedure_call(const std::vector& aliases, const physical::ProcedureCall& opr, const ReadTransaction& txn, Context&& ctx) { @@ -232,13 +309,14 @@ bl::result eval_procedure_call(std::vector aliases, auto& proc_name = query.query_name(); if (proc_name.item_case() == common::NameOrId::kName) { - // TODO: avoid calling graphDB here. - auto& db = gs::GraphDB::get(); - //------------------------------------------ - // FIXME: sess id is hard coded to 0 - auto& sess = db.GetSession(0); - - AppBase* app = sess.GetApp(proc_name.name()); + const auto& sess = txn.GetSession(); + // cast off const, to get the app pointer. + // Why do we need to cast off const? Because current GetApp method is not + // const. + // TODO(zhanglei): Refactor the GetApp method to be const(maybe create the + // app once initialize, not on need). + GraphDBSession& sess_cast = const_cast(sess); + AppBase* app = const_cast(sess_cast.GetApp(proc_name.name())); if (!app) { RETURN_BAD_REQUEST_ERROR("Stored procedure not found: " + proc_name.name()); @@ -255,7 +333,7 @@ bl::result eval_procedure_call(std::vector aliases, // Call the procedure. // Use real values from the context to replace the placeholders in the // query. - auto real_query = fill_in_query(query, ctx, i); + BOOST_LEAF_AUTO(real_query, fill_in_query(query, ctx, i)); // We need to serialize the protobuf-based arguments to the input format // that a cypher procedure can accept. auto query_str = real_query.SerializeAsString(); @@ -265,7 +343,7 @@ bl::result eval_procedure_call(std::vector aliases, std::vector buffer; Encoder encoder(buffer); Decoder decoder(query_str.data(), query_str.size()); - if (!read_app->run(sess, decoder, encoder)) { + if (!read_app->Query(sess, decoder, encoder)) { RETURN_CALL_PROCEDURE_ERROR("Failed to call procedure: "); } // Decode the result from the encoder. diff --git a/flex/engines/graph_db/runtime/common/types.cc b/flex/engines/graph_db/runtime/common/types.cc index 432be67c5ce0..f217595b8ba4 100644 --- a/flex/engines/graph_db/runtime/common/types.cc +++ b/flex/engines/graph_db/runtime/common/types.cc @@ -33,6 +33,8 @@ uint32_t generate_edge_label_id(label_t src_label_id, label_t dst_label_id, label_t edge_label_id) { uint32_t unique_edge_label_id = src_label_id; static constexpr int num_bits = sizeof(label_t) * 8; + static_assert(num_bits * 3 <= sizeof(uint32_t) * 8, + "label_t is too large to be encoded in 32 bits"); unique_edge_label_id = unique_edge_label_id << num_bits; unique_edge_label_id = unique_edge_label_id | dst_label_id; unique_edge_label_id = unique_edge_label_id << num_bits; @@ -40,6 +42,20 @@ uint32_t generate_edge_label_id(label_t src_label_id, label_t dst_label_id, return unique_edge_label_id; } +std::tuple decode_edge_label_id( + uint32_t edge_label_id) { + static constexpr int num_bits = sizeof(label_t) * 8; + static_assert(num_bits * 3 <= sizeof(uint32_t) * 8, + "label_t is too large to be encoded in 32 bits"); + auto mask = (1 << num_bits) - 1; + label_t edge_label = edge_label_id & mask; + edge_label_id = edge_label_id >> num_bits; + label_t dst_label = edge_label_id & mask; + edge_label_id = edge_label_id >> num_bits; + label_t src_label = edge_label_id & mask; + return std::make_tuple(src_label, dst_label, edge_label); +} + int64_t encode_unique_edge_id(uint32_t label_id, vid_t src, vid_t dst) { // We assume label_id is only used by 24 bits. int64_t unique_edge_id = label_id; diff --git a/flex/engines/graph_db/runtime/common/types.h b/flex/engines/graph_db/runtime/common/types.h index 7f4014ee0949..af5cd4f80c93 100644 --- a/flex/engines/graph_db/runtime/common/types.h +++ b/flex/engines/graph_db/runtime/common/types.h @@ -31,6 +31,9 @@ std::pair decode_unique_vertex_id(uint64_t unique_id); uint32_t generate_edge_label_id(label_t src_label_id, label_t dst_label_id, label_t edge_label_id); int64_t encode_unique_edge_id(uint32_t label_id, vid_t src, vid_t dst); + +std::tuple decode_edge_label_id( + uint32_t edge_label_id); enum class Direction { kOut, kIn, From 6df7e6eeaa5deca5cedb567509648de8fc7a64ca Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Fri, 18 Oct 2024 18:57:08 +0800 Subject: [PATCH 12/17] format Committed-by: xiaolei.zl from Dev container --- .../sdk/python/gs_interactive/tests/test_robustness.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py index 4c02cfaed79f..1dcd59798309 100644 --- a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py +++ b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py @@ -250,11 +250,14 @@ def test_list_jobs(interactive_session, create_vertex_only_modern_graph): resp = interactive_session.list_jobs() assert resp.is_ok() and len(resp.get_value()) > 0 - + + def test_call_proc_in_cypher(interactive_session, neo4j_session, create_modern_graph): print("[Test call procedure in cypher]") import_data_to_full_modern_graph(interactive_session, create_modern_graph) - result = neo4j_session.run('MATCH(p: person) with p.id as oid CALL k_neighbors("person", oid, 1) return label_name, vertex_oid;') + result = neo4j_session.run( + 'MATCH(p: person) with p.id as oid CALL k_neighbors("person", oid, 1) return label_name, vertex_oid;' + ) cnt = 0 for record in result: cnt += 1 From 49479f870cdfa029ff94c3a96bd42cfb4622a522 Mon Sep 17 00:00:00 2001 From: BingqingLyu Date: Mon, 21 Oct 2024 14:19:18 +0800 Subject: [PATCH 13/17] [GIE Runtime] support procedure build in rust --- interactive_engine/executor/ir/common/build.rs | 4 ++++ interactive_engine/executor/ir/common/src/lib.rs | 5 +++++ interactive_engine/executor/ir/runtime/src/assembly.rs | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/interactive_engine/executor/ir/common/build.rs b/interactive_engine/executor/ir/common/build.rs index 6442a98ee65b..96cb3a96dea9 100644 --- a/interactive_engine/executor/ir/common/build.rs +++ b/interactive_engine/executor/ir/common/build.rs @@ -31,6 +31,7 @@ fn codegen_inplace() -> Result<(), Box> { println!("cargo:rerun-if-changed=../proto/results.proto"); println!("cargo:rerun-if-changed=../proto/physical.proto"); println!("cargo:rerun-if-changed=../proto/type.proto"); + println!("cargo:rerun-if-changed=../proto/stored_procedure.proto"); let out_dir = PathBuf::from(GEN_DIR); if out_dir.exists() { let _ = std::fs::remove_dir_all(GEN_DIR); @@ -48,6 +49,7 @@ fn codegen_inplace() -> Result<(), Box> { "../proto/results.proto", "../proto/physical.proto", "../proto/type.proto", + "../proto/stored_procedure.proto", ], &["../proto"], )?; @@ -64,6 +66,7 @@ fn codegen_inplace() -> Result<(), Box> { println!("cargo:rerun-if-changed=../proto/results.proto"); println!("cargo:rerun-if-changed=../proto/physical.proto"); println!("cargo:rerun-if-changed=../proto/type.proto"); + println!("cargo:rerun-if-changed=../proto/stored_procedure.proto"); prost_build::Config::new() .type_attribute(".", "#[derive(Serialize,Deserialize)]") .compile_protos( @@ -75,6 +78,7 @@ fn codegen_inplace() -> Result<(), Box> { "../proto/results.proto", "../proto/physical.proto", "../proto/type.proto", + "../proto/stored_procedure.proto", ], &["../proto"], )?; diff --git a/interactive_engine/executor/ir/common/src/lib.rs b/interactive_engine/executor/ir/common/src/lib.rs index ea5166005db9..7fd8d0710e2c 100644 --- a/interactive_engine/executor/ir/common/src/lib.rs +++ b/interactive_engine/executor/ir/common/src/lib.rs @@ -46,6 +46,8 @@ pub mod generated { pub mod schema; #[path = "physical.rs"] pub mod physical; + #[path = "procedure.rs"] + pub mod procedure; } #[cfg(not(feature = "proto_inplace"))] @@ -65,6 +67,9 @@ pub mod generated { pub mod physical { tonic::include_proto!("physical"); } + pub mod procedure { + tonic::include_proto!("procedure"); + } } pub type KeyId = i32; diff --git a/interactive_engine/executor/ir/runtime/src/assembly.rs b/interactive_engine/executor/ir/runtime/src/assembly.rs index d6ea8040a923..2dd1f2825a15 100644 --- a/interactive_engine/executor/ir/runtime/src/assembly.rs +++ b/interactive_engine/executor/ir/runtime/src/assembly.rs @@ -949,6 +949,10 @@ impl IRJobAssembly { // this would be processed in assemble, and cannot be reached when install. Err(FnGenError::unsupported_error("unreachable sink in install"))? } + OpKind::ProcedureCall(procedure_call) => Err(FnGenError::unsupported_error(&format!( + "ProcedureCall Operator {:?}", + procedure_call + )))?, } prev_op_kind = to_op_kind(op)?; From 0f23f18fbf79b4f4d5d09f19d7dd299d37e5f71b Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Mon, 21 Oct 2024 20:20:21 +0800 Subject: [PATCH 14/17] fix Committed-by: xiaolei.zl from Dev container --- .../graphscope/interactive/client/DriverTest.java | 2 +- flex/storages/rt_mutable_graph/schema.cc | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/flex/interactive/sdk/java/src/test/java/com/alibaba/graphscope/interactive/client/DriverTest.java b/flex/interactive/sdk/java/src/test/java/com/alibaba/graphscope/interactive/client/DriverTest.java index 650728215287..0b9930cd0933 100644 --- a/flex/interactive/sdk/java/src/test/java/com/alibaba/graphscope/interactive/client/DriverTest.java +++ b/flex/interactive/sdk/java/src/test/java/com/alibaba/graphscope/interactive/client/DriverTest.java @@ -619,7 +619,7 @@ public void testCallCypherProcedureProto() { StoredProcedure.Argument.newBuilder() .setParamInd(0) .setParamName("personName") - .setValue(Common.Value.newBuilder().setStr(personNameValue).build()) + .setConst(Common.Value.newBuilder().setStr(personNameValue).build()) .build()); StoredProcedure.Query query = builder.build(); { diff --git a/flex/storages/rt_mutable_graph/schema.cc b/flex/storages/rt_mutable_graph/schema.cc index f63d60fc23a7..005590f89704 100644 --- a/flex/storages/rt_mutable_graph/schema.cc +++ b/flex/storages/rt_mutable_graph/schema.cc @@ -1335,19 +1335,6 @@ bool Schema::EmplacePlugins( Schema::BUILTIN_TVSP_PLUGIN_NAME, std::make_pair("", Schema::BUILTIN_TVSP_PLUGIN_ID)); - // Emplace the built-in plugins - plugin_name_to_path_and_id_.emplace( - Schema::BUILTIN_COUNT_VERTICES_PLUGIN_NAME, - std::make_pair("", Schema::BUILTIN_COUNT_VERTICES_PLUGIN_ID)); - plugin_name_to_path_and_id_.emplace( - Schema::BUILTIN_PAGERANK_PLUGIN_NAME, - std::make_pair("", Schema::BUILTIN_PAGERANK_PLUGIN_ID)); - plugin_name_to_path_and_id_.emplace( - Schema::BUILTIN_K_DEGREE_NEIGHBORS_PLUGIN_NAME, - std::make_pair("", Schema::BUILTIN_K_DEGREE_NEIGHBORS_PLUGIN_ID)); - plugin_name_to_path_and_id_.emplace( - Schema::BUILTIN_TVSP_PLUGIN_NAME, - std::make_pair("", Schema::BUILTIN_TVSP_PLUGIN_ID)); LOG(INFO) << "Load " << plugin_name_to_path_and_id_.size() << " plugins"; return true; } From 185512697b997e83dbb50f9baa390d1fca277123 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 22 Oct 2024 12:03:45 +0800 Subject: [PATCH 15/17] fix ci Committed-by: xiaolei.zl from Dev container --- .github/workflows/interactive.yml | 2 +- .../gs_interactive/tests/test_robustness.py | 2 +- flex/tests/hqps/hqps_robust_test.sh | 36 ++++++++++++++++--- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.github/workflows/interactive.yml b/.github/workflows/interactive.yml index fc10b28cf220..1039ce0cd073 100644 --- a/.github/workflows/interactive.yml +++ b/.github/workflows/interactive.yml @@ -175,7 +175,7 @@ jobs: INTERACTIVE_WORKSPACE: /tmp/interactive_workspace run: | cd ${GITHUB_WORKSPACE}/flex/tests/hqps - bash hqps_robust_test.sh ${INTERACTIVE_WORKSPACE} ./interactive_config_test.yaml + bash hqps_robust_test.sh ${INTERACTIVE_WORKSPACE} ./interactive_config_test.yaml ./interactive_config_test_cbo.yaml - name: Sample Query test env: diff --git a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py index 1dcd59798309..9f40404891aa 100644 --- a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py +++ b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py @@ -251,7 +251,7 @@ def test_list_jobs(interactive_session, create_vertex_only_modern_graph): resp = interactive_session.list_jobs() assert resp.is_ok() and len(resp.get_value()) > 0 - +@pytest.mark.skipif(os.environ.get("RUN_ON_PROTO", None) != "ON", reason="Only works on proto") def test_call_proc_in_cypher(interactive_session, neo4j_session, create_modern_graph): print("[Test call procedure in cypher]") import_data_to_full_modern_graph(interactive_session, create_modern_graph) diff --git a/flex/tests/hqps/hqps_robust_test.sh b/flex/tests/hqps/hqps_robust_test.sh index b93e3a65f94d..8090d8be8164 100644 --- a/flex/tests/hqps/hqps_robust_test.sh +++ b/flex/tests/hqps/hqps_robust_test.sh @@ -20,14 +20,15 @@ ADMIN_PORT=7777 QUERY_PORT=10000 CYPHER_PORT=7687 -if [ ! $# -eq 2 ]; then - echo "only receives: $# args, need 2" - echo "Usage: $0 " +if [ ! $# -eq 3 ]; then + echo "only receives: $# args, need 3" + echo "Usage: $0 " exit 1 fi INTERACTIVE_WORKSPACE=$1 ENGINE_CONFIG_PATH=$2 +CBO_ENGINE_CONFIG_PATH=$3 if [ ! -d ${INTERACTIVE_WORKSPACE} ]; then echo "INTERACTIVE_WORKSPACE: ${INTERACTIVE_WORKSPACE} not exists" @@ -38,6 +39,11 @@ if [ ! -f ${ENGINE_CONFIG_PATH} ]; then exit 1 fi +if [ ! -f ${CBO_ENGINE_CONFIG_PATH} ]; then + echo "CBO_ENGINE_CONFIG_PATH: ${CBO_ENGINE_CONFIG_PATH} not exists" + exit 1 +fi + RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color @@ -63,13 +69,19 @@ trap kill_service EXIT # start engine service start_engine_service(){ + # expect one argument + if [ ! $# -eq 1 ]; then + err "start_engine_service need one argument" + exit 1 + fi + local config_path=$1 #check SERVER_BIN exists if [ ! -f ${SERVER_BIN} ]; then err "SERVER_BIN not found" exit 1 fi - cmd="${SERVER_BIN} -c ${ENGINE_CONFIG_PATH} --enable-admin-service true " + cmd="${SERVER_BIN} -c ${config_path} --enable-admin-service true " cmd="${cmd} -w ${INTERACTIVE_WORKSPACE} --start-compiler true &" echo "Start engine service with command: ${cmd}" @@ -91,13 +103,27 @@ run_robust_test(){ popd } +run_additional_robust_test(){ + pushd ${FLEX_HOME}/interactive/sdk/python/gs_interactive + export RUN_ON_PROTO=ON + cmd="python3 -m pytest -s tests/test_robustness.py -k test_call_proc_in_cypher" + echo "Run additional robust test with command: ${cmd}" + eval ${cmd} || (err "Run additional robust test failed"; exit 1) + info "Run additional robust test success" + popd +} + kill_service -start_engine_service +start_engine_service $ENGINE_CONFIG_PATH export INTERACTIVE_ADMIN_ENDPOINT=http://localhost:${ADMIN_PORT} export INTERACTIVE_STORED_PROC_ENDPOINT=http://localhost:${QUERY_PORT} export INTERACTIVE_CYPHER_ENDPOINT=neo4j://localhost:${CYPHER_PORT} export INTERACTIVE_GREMLIN_ENDPOINT=ws://localhost:${GREMLIN_PORT}/gremlin run_robust_test +kill_service +sleep 5 +start_engine_service $CBO_ENGINE_CONFIG_PATH +run_additional_robust_test kill_service \ No newline at end of file From a27839c5d2630b095567aea1a5697e7b53577ded Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 22 Oct 2024 13:28:12 +0800 Subject: [PATCH 16/17] format Committed-by: xiaolei.zl from Dev container --- .../sdk/python/gs_interactive/tests/test_robustness.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py index 9f40404891aa..eba1763b8975 100644 --- a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py +++ b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py @@ -251,7 +251,10 @@ def test_list_jobs(interactive_session, create_vertex_only_modern_graph): resp = interactive_session.list_jobs() assert resp.is_ok() and len(resp.get_value()) > 0 -@pytest.mark.skipif(os.environ.get("RUN_ON_PROTO", None) != "ON", reason="Only works on proto") + +@pytest.mark.skipif( + os.environ.get("RUN_ON_PROTO", None) != "ON", reason="Only works on proto" +) def test_call_proc_in_cypher(interactive_session, neo4j_session, create_modern_graph): print("[Test call procedure in cypher]") import_data_to_full_modern_graph(interactive_session, create_modern_graph) From 15406355b82dffda2c699a5bde361d51f94c8fe3 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl" Date: Tue, 22 Oct 2024 15:40:53 +0800 Subject: [PATCH 17/17] minor Committed-by: xiaolei.zl from Dev container --- flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc index f7d4cc226a83..09b1fb17b0ee 100644 --- a/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc +++ b/flex/engines/graph_db/runtime/adhoc/operators/procedure_call.cc @@ -223,7 +223,6 @@ collective_result_vec_to_column( record_cnt += collective_results_vec[i].results_size(); offsets.push_back(record_cnt); } - LOG(INFO) << "record_cnt: " << record_cnt; std::vector> any_vec(expect_col_num); for (size_t i = 0; i < collective_results_vec.size(); ++i) { for (int32_t j = 0; j < collective_results_vec[i].results_size(); ++j) { @@ -370,7 +369,6 @@ bl::result eval_procedure_call(const std::vector& aliases, << aliases.size(); RETURN_CALL_PROCEDURE_ERROR("Column size mismatch"); } - LOG(INFO) << "Procedure call returns " << columns.size() << " columns"; if (columns.size() >= 1) { ctx.set_with_reshuffle(aliases[0], columns[0], offsets); }