Spanner Graph 算法架构要求和功能兼容性

架构要求

Spanner Graph 算法可在具有满足以下要求的架构的图上运行:

以下是不受支持的架构的示例:

-- Unsupported: Both `Person` and `Account` can only be referred to via label `Entity`.
CREATE PROPERTY GRAPH FinGraph
  NODE TABLES (
    Person KEY (id)
      LABEL Entity PROPERTIES (...),
    Account KEY (id)
      LABEL Entity PROPERTIES (...)
  );

以下是受支持的架构示例:

-- Supported: Even though label `Entity` refers to both `Person` and `Account`,
-- label `Customer` uniquely identifies `Person`, label `Account` uniquely identifies `Account`.
CREATE PROPERTY GRAPH FinGraph
  NODE TABLES (
    Person KEY (id)
      LABEL Customer PROPERTIES (...)
      LABEL Entity PROPERTIES (...),
    Account KEY (id)
      LABEL Account PROPERTIES (...)
      LABEL Entity PROPERTIES (...)
  );

功能兼容性

本部分概述了算法查询与常规图表功能的兼容性。

支持的 MATCH 子句

算法查询结构中使用 MATCH 子句来定义算法的输入图时,您必须考虑以下事项:

  1. 每个 MATCH 只能包含一个带有命名变量的元素模式(节点或边)。
  2. 如果边模式包含端节点的显式模式,请勿在节点模式中使用节点标签或变量。
  3. 如果 WHERE 子句不引用其他位置定义的变量,则可以在元素模式中使用该子句。
  4. MATCH 子句中的标签表达式必须唯一标识一个元素表。

以下示例演示了受支持的 MATCH 子句:

-- Supported: Assuming only 1 element table has `Account` label:
MATCH (a:Account)

MATCH (a:Account WHERE a.id > 400)

MATCH (a:Account WHERE a.id IN [101, 102, 105])

MATCH -[e:Transfers WHERE e.amount < 500]->

以下示例展示了不受支持的 MATCH 子句:

-- Unsupported: End nodes for edge patterns cannot have labels or named variables.
MATCH (a:Account)-[]->

-- Unsupported: Each MATCH can only name one variable.
MATCH (a:Account)-[e:Transfers]->

-- Unsupported: If there are multiple node element tables in the graph, each MATCH
-- must uniquely identify one element table.
MATCH (a)

-- Unsupported: The `Entity` label maps to both `Account` and `Person` node element tables.
MATCH (a:Account | Entity)

使用 RETURN 子句

算法查询结构中的 RETURN 子句用于定义算法查询返回的数据。您可以在 RETURN 子句中引用算法输出签名中的列,但需遵守以下限制:

  • 如果算法输出 Node,您可以返回该节点的任何属性。您还可以返回节点的 ELEMENT_DEFINITION_NAME
  • 如果算法输出 Path,您可以返回 PATH_LENGTH(path).
  • 您可以返回算法中的任何标量输出。
  • 您可以返回任何字面常量。

以下示例演示了受支持的 RETURN 子句:

-- Supported.
CALL PageRank(...) YIELD node, score
RETURN ELEMENT_DEFINITION_NAME(node) AS node_type, node.id, score

-- Supported: You can return constants.
CALL PageRank(...) YIELD node, score
RETURN node.id, score, "pagerank-run1" AS algo_run_id

-- Supported.
CALL ShortestPath(...) YIELD source_node, target_node, path, cost
RETURN source_node.id AS source_id, target_node.id AS target_id,
  PATH_LENGTH(path) AS length, cost

以下示例展示了不受支持的 RETURN 子句:

-- Unsupported: You cannot return the graph element `node` directly.
RETURN node, score

-- Unsupported: You can only return properties of `node`. Applying a function to a node property
-- is not supported.
RETURN node.id + 1, score

-- Unsupported: You can only return the scalar `score` directly from the algorithm output. Applying
-- a function to scalar output is not supported.
RETURN node.id, score + 1

-- Unsupported: General function calls are not allowed.
RETURN JSON_OBJECT(node.id, score) as json_obj

不支持参数

算法查询不支持查询参数

支持基于视图创建的图表

视图上创建图时,只有在用于定义算法输入的节点和边(包括边的端节点)不是基于视图的情况下,才支持算法查询。

后续步骤