LOOKUP 语法

LOOKUP 语句指定过滤条件对数据进行查询。LOOKUP 语句之后通常跟着 WHERE 子句。WHERE 子句用于向条件中添加过滤性的谓词,从而对数据进行过滤。

注意: 在使用 LOOKUP 语句之前,请确保已创建索引。查看索引文档了解有关索引的更多信息。

  1. LOOKUP ON {<vertex_tag> | <edge_type>} WHERE <expression> [ AND | UNION expression ...]) ] [YIELD <return_list>]
  2. <return_list>
  3. <col_name> [AS <col_alias>] [, <col_name> [AS <col_alias>] ...]
  • LOOKUP 语句用于寻找点或边的集合。
  • WHERE 指定被筛选的逻辑条件。同样支持逻辑关键词 AND、UNION、NOT,详情参见 WHERE 的用法。 注意: WHERE 子句在 LOOKUP 中暂不支持如下操作:
    • $-$^
    • 在关系表达式中,暂不支持操作符两边都是field-name 的表达式,如 (tagName.column1 > tagName.column2)
    • 暂不支持运算表达式和 function 表达式中嵌套 AliasProp 表达式。
  • YIELD 指定返回结果。如未指定,则在 LOOKUP 标签时返回点 ID,在 LOOKUP 边类型时返回边的起点 ID、终点 ID 和 ranking 值。

点查询

如下示例返回名称为 Tony Parker,标签为 player 的顶点。

  1. nebula> CREATE TAG INDEX index_player ON player(name, age);
  2. nebula> LOOKUP ON player WHERE player.name == "Tony Parker";
  3. ============
  4. | VertexID |
  5. ============
  6. | 101 |
  7. ------------
  8. nebula> LOOKUP ON player WHERE player.name == "Tony Parker" \
  9. YIELD player.name, player.age;
  10. =======================================
  11. | VertexID | player.name | player.age |
  12. =======================================
  13. | 101 | Tony Parker | 36 |
  14. ---------------------------------------
  15. nebula> LOOKUP ON player WHERE player.name== "Kobe Bryant" YIELD player.name AS name | \
  16. GO FROM $-.VertexID OVER serve YIELD $-.name, serve.start_year, serve.end_year, $$.team.name;
  17. ==================================================================
  18. | $-.name | serve.start_year | serve.end_year | $$.team.name |
  19. ==================================================================
  20. | Kobe Bryant | 1996 | 2016 | Lakers |
  21. ------------------------------------------------------------------

边查询

如下示例返回 degree 为 90,边类型为 follow 的边。

  1. nebula> CREATE EDGE INDEX index_follow ON follow(degree);
  2. nebula> LOOKUP ON follow WHERE follow.degree == 90;
  3. =============================
  4. | SrcVID | DstVID | Ranking |
  5. =============================
  6. | 100 | 106 | 0 |
  7. -----------------------------
  8. nebula> LOOKUP ON follow WHERE follow.degree == 90 YIELD follow.degree;
  9. =============================================
  10. | SrcVID | DstVID | Ranking | follow.degree |
  11. =============================================
  12. | 100 | 106 | 0 | 90 |
  13. ---------------------------------------------
  14. nebula> LOOKUP ON follow WHERE follow.degree == 60 YIELD follow.degree AS Degree | \
  15. GO FROM $-.DstVID OVER serve YIELD $-.DstVID, serve.start_year, serve.end_year, $$.team.name;
  16. ================================================================
  17. | $-.DstVID | serve.start_year | serve.end_year | $$.team.name |
  18. ================================================================
  19. | 105 | 2010 | 2018 | Spurs |
  20. ----------------------------------------------------------------
  21. | 105 | 2009 | 2010 | Cavaliers |
  22. ----------------------------------------------------------------
  23. | 105 | 2018 | 2019 | Raptors |
  24. ----------------------------------------------------------------