从 Alpha Cypher 聚合迁移到新的 Cypher 投影

谁应该阅读本指南

本指南面向使用 Alpha Cypher 聚合 gds.alpha.graph.project 的用户。Cypher 投影现在使用 gds.graph.project 聚合函数完成。我们假设大多数提到的操作和概念无需过多解释即可理解。因此,我们在示例和比较中有意简明扼要。有关更多详细信息,请参阅 Cypher 投影文档

API 更改

新的 Cypher 投影取代了 Alpha Cypher 聚合。与 Alpha Cypher 聚合类似,新的 Cypher 投影是一个聚合函数,作为 Cypher 查询的一部分调用。

API 已进行以下更改

  • 新的 Cypher 投影使用 gds.graph.project 而不是 gds.alpha.graph.project 调用。

  • 新的 Cypher 投影定义了一个单独的映射参数,用于定义投影相关信息,例如标签或属性。

    • 仍然存在一个单独的映射参数来定义图配置。

  • 关系配置映射的 properties 键已重命名为 relationshipProperties

  • 其他验证以减少 API 的误用

    • 验证每个 sourceNode* 条目都有一个对应的 targetNode* 条目,反之亦然。

    • 如果上述任何要点未遵循,则提供帮助以迁移到此新 API。

表 1. Alpha 聚合/新投影之间的结构变化
旧版 新版
$query
RETURN gds.alpha.graph.project(
  $graphName,
  sourceNode,
  targetNode,
  $nodeConfig,
  $relationshipConfig,
  $configuration
)
$relationshipQuery
RETURN gds.graph.project(
  $graphName,
  sourceNode,
  targetNode,
  $dataConfig,
  $configuration
)

示例

以下示例不包含调用聚合函数之前的完整 Cypher 查询,也不包含任何 YIELD 或返回字段。这两个方面没有变化。

表 2. 并排比较
Alpha 新版

: 无任何配置的投影

...
RETURN gds.alpha.graph.project('g', source, target)
...
RETURN gds.graph.project('g', source, target)

: 多图投影

...
RETURN gds.alpha.graph.project(
  'g',
  source,
  target,
  {
    sourceNodeLabels: labels(source),
    targetNodeLabels: labels(target),
  }, {
    relationshipType: type(r)
  }
)
...
RETURN gds.graph.project(
  'g',
  source,
  target,
  {
    sourceNodeLabels: labels(source),
    targetNodeLabels: labels(target),
    relationshipType: type(rel)
  }
)

: 带有属性的图投影

...
RETURN gds.alpha.graph.project(
  'g',
  source,
  target,
  {
    sourceNodeLabels: labels(source),
    targetNodeLabels: labels(target),
    sourceNodeProperties: source { .age },
    targetNodeProperties: target { .age },
  }, {
    relationshipType: type(rel),
    properties: rel { .numberOfPages }
  }
)
...
RETURN gds.graph.project(
  'g',
  source,
  target,
  {
    sourceNodeLabels: labels(source),
    targetNodeLabels: labels(target),
    sourceNodeProperties: source { .age },
    targetNodeProperties: target { .age },
    relationshipType: type(rel),
    relationshipProperties: rel { .numberOfPages }
  }
)

: 带有一侧属性的图投影

...
RETURN gds.alpha.graph.project(
  'g',
  source,
  target,
  {
    sourceNodeLabels: labels(source),
    sourceNodeProperties: source { .age },
  }
)
...
RETURN gds.graph.project(
  'g',
  source,
  target,
  {
    sourceNodeLabels: labels(source),
    targetNodeLabels: NULL,
    sourceNodeProperties: source { .age },
    targetNodeProperties: NULL,
  }
)