Repository: alibaba/GraphScope (language: python)

Issue:
[BUG] Metadata missing for PathExpand
```cypher
MATCH (p: PERSON{id: $personId}) -[k:KNOWS*1..4]-(f: PERSON {firstName: $firstName})
WHERE p <> f
with f AS f, length(k) as len
with f AS f, min(len) as distance
ORDER  BY distance ASC, f.lastName ASC, f.id ASC
LIMIT 20
```

For this query, the `PathExpand` operator is supposed to carry metadata info, mainly the edge types triplet.


Discussion / hints:

Fix patch:
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 eeca97c8838b..31314ffcb4a6 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
@@ -20,11 +20,6 @@
 import com.alibaba.graphscope.common.config.PegasusConfig;
 import com.alibaba.graphscope.common.ir.meta.schema.CommonOptTable;
 import com.alibaba.graphscope.common.ir.rel.*;
-import com.alibaba.graphscope.common.ir.rel.GraphLogicalAggregate;
-import com.alibaba.graphscope.common.ir.rel.GraphLogicalDedupBy;
-import com.alibaba.graphscope.common.ir.rel.GraphLogicalProject;
-import com.alibaba.graphscope.common.ir.rel.GraphLogicalSort;
-import com.alibaba.graphscope.common.ir.rel.GraphShuttle;
 import com.alibaba.graphscope.common.ir.rel.graph.*;
 import com.alibaba.graphscope.common.ir.rel.graph.match.GraphLogicalMultiMatch;
 import com.alibaba.graphscope.common.ir.rel.graph.match.GraphLogicalSingleMatch;
@@ -52,6 +47,7 @@
 import org.apache.calcite.rel.logical.LogicalFilter;
 import org.apache.calcite.rel.logical.LogicalJoin;
 import org.apache.calcite.rel.logical.LogicalUnion;
+import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeField;
 import org.apache.calcite.rex.*;
 import org.apache.calcite.sql.SqlKind;
@@ -220,6 +216,7 @@ public RelNode visit(GraphLogicalPathExpand pxd) {
         GraphAlgebraPhysical.PathExpand.ExpandBase.Builder expandBaseBuilder =
                 GraphAlgebraPhysical.PathExpand.ExpandBase.newBuilder();
         RelNode fused = pxd.getFused();
+        RelDataType rowType;
         if (fused != null) {
             // the case that expand base is fused
             if (fused instanceof GraphPhysicalGetV) {
@@ -231,6 +228,7 @@ public RelNode visit(GraphLogicalPathExpand pxd) {
                     GraphPhysicalExpand fusedExpand = (GraphPhysicalExpand) fusedGetV.getInput();
                     GraphAlgebraPhysical.EdgeExpand.Builder expand = buildEdgeExpand(fusedExpand);
                     expandBaseBuilder.setEdgeExpand(expand);
+                    rowType = fusedExpand.getRowType();
                 } else {
                     throw new UnsupportedOperationException(
                             "unsupported fused plan in path expand base: "
@@ -241,6 +239,7 @@ public RelNode visit(GraphLogicalPathExpand pxd) {
                 GraphPhysicalExpand fusedExpand = (GraphPhysicalExpand) fused;
                 GraphAlgebraPhysical.EdgeExpand.Builder expand = buildEdgeExpand(fusedExpand);
                 expandBaseBuilder.setEdgeExpand(expand);
+                rowType = fusedExpand.getFusedExpand().getRowType();
             } else {
                 throw new UnsupportedOperationException(
                         "unsupported fused plan in path expand base");
@@ -252,6 +251,7 @@ public RelNode visit(GraphLogicalPathExpand pxd) {
             GraphAlgebraPhysical.GetV.Builder getV = buildGetV((GraphLogicalGetV) pxd.getGetV());
             expandBaseBuilder.setEdgeExpand(expand);
             expandBaseBuilder.setGetV(getV);
+            rowType = pxd.getExpand().getRowType();
         }
         pathExpandBuilder.setBase(expandBaseBuilder);
         pathExpandBuilder.setPathOpt(Utils.protoPathOpt(pxd.getPathOpt()));
@@ -266,6 +266,7 @@ public RelNode visit(GraphLogicalPathExpand pxd) {
         }
         oprBuilder.setOpr(
                 GraphAlgebraPhysical.PhysicalOpr.Operator.newBuilder().setPath(pathExpandBuilder));
+        oprBuilder.addAllMetaData(Utils.physicalProtoRowType(rowType, isColumnId));
         if (isPartitioned) {
             addRepartitionToAnother(pxd.getStartAlias().getAliasId());
         }
@@ -281,8 +282,11 @@ public RelNode visit(GraphPhysicalExpand physicalExpand) {
         GraphAlgebraPhysical.EdgeExpand.Builder edgeExpand = buildEdgeExpand(physicalExpand);
         oprBuilder.setOpr(
                 GraphAlgebraPhysical.PhysicalOpr.Operator.newBuilder().setEdge(edgeExpand));
+        // Currently we use the row type of ExpandE as the output row type of the fused
+        // ExpandV, as desired by the engine implementation.
         oprBuilder.addAllMetaData(
-                Utils.physicalProtoRowType(physicalExpand.getRowType(), isColumnId));
+                Utils.physicalProtoRowType(
+                        physicalExpand.getFusedExpand().getRowType(), isColumnId));
         if (isPartitioned) {
             addRepartitionToAnother(physicalExpand.getStartAlias().getAliasId());
         }


Test patch:
diff --git a/interactive_engine/compiler/src/test/resources/proto/edge_expand_degree_test.json b/interactive_engine/compiler/src/test/resources/proto/edge_expand_degree_test.json
index 13624a1f0839..3d26da0d02ca 100644
--- a/interactive_engine/compiler/src/test/resources/proto/edge_expand_degree_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/edge_expand_degree_test.json
@@ -51,7 +51,21 @@
     },
     "metaData": [{
       "type": {
-        "dataType": "INT64"
+        "graphType": {
+          "elementOpt": "EDGE",
+          "graphDataType": [{
+            "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
+            },
+            "props": [{
+              "propId": {
+                "name": "weight"
+              },
+              "type": "DOUBLE"
+            }]
+          }]
+        }
       },
       "alias": -1
     }]
diff --git a/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_filter_test.json b/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_filter_test.json
index b46ab5eedfea..9ecbf3cfe5ec 100644
--- a/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_filter_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_filter_test.json
@@ -51,24 +51,17 @@
     "metaData": [{
       "type": {
         "graphType": {
+          "elementOpt": "EDGE",
           "graphDataType": [{
             "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
             },
             "props": [{
               "propId": {
-                "name": "id"
-              },
-              "type": "INT64"
-            }, {
-              "propId": {
-                "name": "name"
+                "name": "weight"
               },
-              "type": "STRING"
-            }, {
-              "propId": {
-                "name": "age"
-              },
-              "type": "INT32"
+              "type": "DOUBLE"
             }]
           }]
         }
diff --git a/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_test.json b/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_test.json
index f848b668e9e2..bbe42e4abf29 100644
--- a/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_test.json
@@ -52,28 +52,22 @@
     "metaData": [{
       "type": {
         "graphType": {
+          "elementOpt": "EDGE",
           "graphDataType": [{
             "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
             },
             "props": [{
               "propId": {
-                "name": "id"
-              },
-              "type": "INT64"
-            }, {
-              "propId": {
-                "name": "name"
+                "name": "weight"
               },
-              "type": "STRING"
-            }, {
-              "propId": {
-                "name": "age"
-              },
-              "type": "INT32"
+              "type": "DOUBLE"
             }]
           }]
         }
-      }
+      },
+      "alias": -1
     }]
   }, {
     "opr": {
diff --git a/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_with_filters_test.json b/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_with_filters_test.json
index 441a7f5b7428..2df0b7aa68ea 100644
--- a/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_with_filters_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/edge_expand_vertex_with_filters_test.json
@@ -80,24 +80,17 @@
     "metaData": [{
       "type": {
         "graphType": {
+          "elementOpt": "EDGE",
           "graphDataType": [{
             "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
             },
             "props": [{
               "propId": {
-                "name": "id"
-              },
-              "type": "INT64"
-            }, {
-              "propId": {
-                "name": "name"
+                "name": "weight"
               },
-              "type": "STRING"
-            }, {
-              "propId": {
-                "name": "age"
-              },
-              "type": "INT32"
+              "type": "DOUBLE"
             }]
           }]
         }
diff --git a/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_degree_test.json b/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_degree_test.json
index 651127d1ed42..dd438fb4be1a 100644
--- a/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_degree_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_degree_test.json
@@ -58,7 +58,21 @@
     },
     "metaData": [{
       "type": {
-        "dataType": "INT64"
+        "graphType": {
+          "elementOpt": "EDGE",
+          "graphDataType": [{
+            "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
+            },
+            "props": [{
+              "propId": {
+                "name": "weight"
+              },
+              "type": "DOUBLE"
+            }]
+          }]
+        }
       },
       "alias": -1
     }]
diff --git a/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_filter_test.json b/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_filter_test.json
index 2fdee59e51c8..421c740fc602 100644
--- a/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_filter_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_filter_test.json
@@ -58,24 +58,17 @@
     "metaData": [{
       "type": {
         "graphType": {
+          "elementOpt": "EDGE",
           "graphDataType": [{
             "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
             },
             "props": [{
               "propId": {
-                "name": "id"
-              },
-              "type": "INT64"
-            }, {
-              "propId": {
-                "name": "name"
+                "name": "weight"
               },
-              "type": "STRING"
-            }, {
-              "propId": {
-                "name": "age"
-              },
-              "type": "INT32"
+              "type": "DOUBLE"
             }]
           }]
         }
diff --git a/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_test.json b/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_test.json
index fa03b93fb621..054044601b5b 100644
--- a/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/partitioned_edge_expand_vertex_test.json
@@ -59,28 +59,22 @@
     "metaData": [{
       "type": {
         "graphType": {
+          "elementOpt": "EDGE",
           "graphDataType": [{
             "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
             },
             "props": [{
               "propId": {
-                "name": "id"
-              },
-              "type": "INT64"
-            }, {
-              "propId": {
-                "name": "name"
+                "name": "weight"
               },
-              "type": "STRING"
-            }, {
-              "propId": {
-                "name": "age"
-              },
-              "type": "INT32"
+              "type": "DOUBLE"
             }]
           }]
         }
-      }
+      },
+      "alias": -1
     }]
   }, {
     "opr": {
diff --git a/interactive_engine/compiler/src/test/resources/proto/path_expand_test.json b/interactive_engine/compiler/src/test/resources/proto/path_expand_test.json
index 339d34540f53..304c237dfe7c 100644
--- a/interactive_engine/compiler/src/test/resources/proto/path_expand_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/path_expand_test.json
@@ -70,7 +70,27 @@
         "pathOpt": "SIMPLE",
         "resultOpt": "ALL_V"
       }
-    }
+    },
+    "metaData": [{
+      "type": {
+        "graphType": {
+          "elementOpt": "EDGE",
+          "graphDataType": [{
+            "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
+            },
+            "props": [{
+              "propId": {
+                "name": "weight"
+              },
+              "type": "DOUBLE"
+            }]
+          }]
+        }
+      },
+      "alias": -1
+    }]
   }, {
     "opr": {
       "sink": {
diff --git a/interactive_engine/compiler/src/test/resources/proto/path_fused_expand_test.json b/interactive_engine/compiler/src/test/resources/proto/path_fused_expand_test.json
index 3805b180f88d..2f5ed2d97ff4 100644
--- a/interactive_engine/compiler/src/test/resources/proto/path_fused_expand_test.json
+++ b/interactive_engine/compiler/src/test/resources/proto/path_fused_expand_test.json
@@ -57,7 +57,27 @@
         "pathOpt": "SIMPLE",
         "resultOpt": "ALL_V"
       }
-    }
+    },
+    "metaData": [{
+      "type": {
+        "graphType": {
+          "elementOpt": "EDGE",
+          "graphDataType": [{
+            "label": {
+              "srcLabel": 0,
+              "dstLabel": 0
+            },
+            "props": [{
+              "propId": {
+                "name": "weight"
+              },
+              "type": "DOUBLE"
+            }]
+          }]
+        }
+      },
+      "alias": -1
+    }]
   }, {
     "opr": {
       "sink": {