Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the multi query parts of openCypher. #3519

Conversation

CPWstatic
Copy link
Contributor

@CPWstatic CPWstatic commented Dec 21, 2021

What type of PR is this?

  • bug
  • feature
  • enhancement

What does this PR do?

Which issue(s)/PR(s) this PR relates to?

Special notes for your reviewer, ex. impact of this fix, etc:

Additional context/ Design document:

Checklist:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the corresponding label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

A little incompatible: The returned column names are the same sequence with the declared columns, while it is random in former release.

      MATCH (v:player)-[:like]->(v2)
      WHERE v.name == "Tony Parker" and v2.age == 42
      WITH *, v.age + 100 AS age
      RETURN *, v2.name

Now this query returns:

      | v    | v2   | age | v2.name      |

New features:

      MATCH (m)-[]-(n), (n)-[]-(l) WHERE id(m)=="Tim Duncan"
      RETURN m.name AS n1, n.name AS n2, l.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
      MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
      MATCH (n)-[]-(l)
      RETURN m.name AS n1, n.name AS n2, l.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
      MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
      OPTIONAL MATCH (n)<-[:serve]-(l)
      RETURN m.name AS n1, n.name AS n2, l AS n3 ORDER BY n1, n2, n3 LIMIT 10

We have more test cases in pr #3537

@CPWstatic CPWstatic added the wip Solution: work in progress label Dec 21, 2021
@CPWstatic CPWstatic force-pushed the impl_match_multi_path_according_to_the_paper branch from 9f7da29 to e5c2101 Compare December 23, 2021 05:41
@CPWstatic CPWstatic added ready for review ready-for-testing PR: ready for the CI test and removed wip Solution: work in progress labels Dec 23, 2021
@Sophie-Xie Sophie-Xie added doc affected PR: improvements or additions to documentation incompatible PR: incompatible with the recently released version labels Dec 23, 2021
@wey-gu
Copy link
Contributor

wey-gu commented Dec 24, 2021

It worked like a charm!!!

Thanks!!!

 MATCH (db:Database)-[:CLUSTER]->(clstr:Cluster)-[:SCHEMA]->(schema:Schema) \
                       ->         -[:TABLE]->(tbl:Table)-[:COLUMN]->(col:Column) \
                       ->         WHERE id(tbl) == "hive://gold.test_schema/test_table1" \
                       ->         OPTIONAL MATCH (tbl)-[:DESCRIPTION]->(tbl_dscrpt:Description) \
                       ->         OPTIONAL MATCH (col:Column)-[:DESCRIPTION]->(col_dscrpt:Description) \
                       ->         OPTIONAL MATCH (col:Column)-[:STAT]->(stat:Stat) \
                       ->         OPTIONAL MATCH (col:Column)-[:HAS_BADGE]->(badge:Badge) \
                       ->         RETURN db, clstr, schema, tbl, tbl_dscrpt, col, col_dscrpt, col.sort_order as sort_order, collect(distinct stat) as col_stats, \
                       ->         collect(distinct badge) as col_badges \
                       ->         ORDER BY sort_order;
+-------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| db                                                                                                                | clstr                                                                                                        | schema                                                                                                                         | tbl                                                                                                                                                       | tbl_dscrpt                                                                                                                                                             | col                                                                                                                                                                         | col_dscrpt                                                                                                                                                                    | sort_order | col_stats                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | col_badges                                                                                                                                                                                                                                                                                                          |
+-------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ("database://hive" :Database{name: "hive", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold" :Cluster{name: "gold", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema" :Schema{name: "test_schema", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266433}) | ("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266404}) | ("hive://gold.test_schema/test_table1/_description" :Description{description: "1st test table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema/test_table1/col1" :Column{col_type: "string", name: "col1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388, sort_order: 1}) | ("hive://gold.test_schema/test_table1/col1/_description" :Description{description: "col1 description", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | 1          | [("hive://gold.test_schema/test_table1/col1/verified/" :Stat{end_epoch: "1562300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1432300762", stat_type: "verified", stat_val: "230430"}), ("hive://gold.test_schema/test_table1/col1/distinct values/" :Stat{end_epoch: "1562300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1432300762", stat_type: "distinct values", stat_val: "8"}), ("hive://gold.test_schema/test_table1/col1/max/" :Stat{end_epoch: "1562300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1432300762", stat_type: "max", stat_val: "zebra"}), ("hive://gold.test_schema/test_table1/col1/num nulls/" :Stat{end_epoch: "1562300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1432300762", stat_type: "num nulls", stat_val: "500320"}), ("hive://gold.test_schema/test_table1/col1/min/" :Stat{end_epoch: "1562300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1432300762", stat_type: "min", stat_val: "aardvark"})] | [("pk" :Badge{category: "column", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388})]                                                                                                                                                                                                           |
| ("database://hive" :Database{name: "hive", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold" :Cluster{name: "gold", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema" :Schema{name: "test_schema", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266433}) | ("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266404}) | ("hive://gold.test_schema/test_table1/_description" :Description{description: "1st test table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema/test_table1/col2" :Column{col_type: "string", name: "col2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388, sort_order: 2}) | ("hive://gold.test_schema/test_table1/col2/_description" :Description{description: "col2 description", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | 2          | []                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | [("pii" :Tag{published: "unique_tag", publisher_last_updated_epoch_ms: 1640266424, tag_type: "default"} :Badge{category: "column", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388})]                                                                                                          |
| ("database://hive" :Database{name: "hive", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold" :Cluster{name: "gold", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema" :Schema{name: "test_schema", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266433}) | ("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266404}) | ("hive://gold.test_schema/test_table1/_description" :Description{description: "1st test table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema/test_table1/col3" :Column{col_type: "string", name: "col3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388, sort_order: 3}) | ("hive://gold.test_schema/test_table1/col3/_description" :Description{description: "col3 description", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | 3          | []                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | [("fk" :Badge{category: "column", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}), ("pii" :Tag{published: "unique_tag", publisher_last_updated_epoch_ms: 1640266424, tag_type: "default"} :Badge{category: "column", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388})] |
| ("database://hive" :Database{name: "hive", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold" :Cluster{name: "gold", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema" :Schema{name: "test_schema", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266433}) | ("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266404}) | ("hive://gold.test_schema/test_table1/_description" :Description{description: "1st test table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema/test_table1/col4" :Column{col_type: "string", name: "col4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388, sort_order: 4}) | ("hive://gold.test_schema/test_table1/col4/_description" :Description{description: "col4 description", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | 4          | []                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | []                                                                                                                                                                                                                                                                                                                  |
| ("database://hive" :Database{name: "hive", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold" :Cluster{name: "gold", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema" :Schema{name: "test_schema", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266433}) | ("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266404}) | ("hive://gold.test_schema/test_table1/_description" :Description{description: "1st test table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | ("hive://gold.test_schema/test_table1/col5" :Column{col_type: "float", name: "col5", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388, sort_order: 5})  | ("hive://gold.test_schema/test_table1/col5/_description" :Description{description: "col5 description", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266388}) | 5          | [("hive://gold.test_schema/test_table1/col5/max/" :Stat{end_epoch: "1572300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1534300762", stat_type: "max", stat_val: "500.0"}), ("hive://gold.test_schema/test_table1/col5/average/" :Stat{end_epoch: "1572300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1532300762", stat_type: "average", stat_val: "5.0"}), ("hive://gold.test_schema/test_table1/col5/min/" :Stat{end_epoch: "1572300762", published: "unique_tag", publisher_last_updated_epoch_ms: 1640266389, start_epoch: "1534300762", stat_type: "min", stat_val: "-500.0"})]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | []                                                                                                                                                                                                                                                                                                                  |
+-------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Got 5 rows (time spent 11982/61432 us)

Thu, 23 Dec 2021 21:35:10 CST

Background:
Given a graph with space named "nba"

Scenario: Multi Path Patterns
Copy link
Contributor

@czpmango czpmango Dec 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test cases:

MATCH (m:player{name:"Tim Duncan"})-[:like]-(n)--()
WITH  m
MATCH (m)--(n)
RETURN count(*) AS scount
MATCH (m:player{name:"Tim Duncan"})-[:like]-(n)--()
WITH  m,n
MATCH (m)--(n)
RETURN count(*) AS scount

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks.

@CPWstatic CPWstatic force-pushed the impl_match_multi_path_according_to_the_paper branch from 9f8aa44 to ebec681 Compare December 25, 2021 06:51
@wey-gu
Copy link
Contributor

wey-gu commented Dec 25, 2021

updated: this was based on commit 1 days before and I noticed there is an Fix union commit after this WIP build, maybe that just fixed this one(or?), if so, plz ignore this, I will build from your head later.

This result seems to differ from the same query/data in n4j, not sure it's wrong behavior or what I had done wrongly.

# it looks good till now
MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        return downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath 

+--------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| downstream_entity                                                                                                                                            | upstream_entity | downstream_len                                                                                                                                                                                                                                                                                                                                                                                                                                 | upstream_len | upath    | dpath                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})       | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                            | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>                                                                                                                                                                                                                                                                                                         |
| ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})  | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                         | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})>                                                                                                                                                                                                                                                                                                    |
| ("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})     | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test_table3" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]   | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>     |
| ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]] | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})> |
| ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "hive://gold.test_schema/test_view1"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]       | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>      |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Got 5 rows (time spent 6771/140510 us)

# Then OPTIONAL MATCH resulted in empty, from the above result we know that upstream is empty while downstream should have results:

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        RETURN upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath 

+-----------------+-------------------+--------------+----------------+-------+-------+
| upstream_entity | downstream_entity | upstream_len | downstream_len | upath | dpath |
+-----------------+-------------------+--------------+----------------+-------+-------+
+-----------------+-------------------+--------------+----------------+-------+-------+

# This query is verifying downstream expanding shouldn't be empty:

MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
    WHERE id(downstream_entity) IN ["dynamo://gold.test_schema/test_table2"] \
    RETURN downstream_entity,downstream_badge

+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| downstream_entity                                                                                                                                           | downstream_badge                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}) | ("npi" :Badge{category: "table_status", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})  |
| ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}) | ("json" :Badge{category: "table_status", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
Got 2 rows (time spent 3420/42999 us)

ref:
full(longer query) from n4j

@wey-gu
Copy link
Contributor

wey-gu commented Dec 25, 2021

  • graphD crashed when WHERE id(v) IN ["foo"] , don't have time to see if it's caused by this branch or existing, To be checked later
(root@nebula) [amundsen]> """
                       -> MATCH (db:Database)-[:CLUSTER]->(clstr:Cluster)-[:SCHEMA]->(schema:Schema)-[:TABLE]->(tbl:Table)
                       ->         WHERE id(tbl) == 'hive://gold.test_schema/test_table1'
                       ->         WITH db.name as database_name, clstr.name as cluster_name, schema.name as schema_name, tbl
                       ->         OPTIONAL MATCH (tbl)-[:DESCRIPTION]->(dscrpt:Description)
                       ->         RETURN database_name, cluster_name, schema_name, tbl.name as table_name,
                       ->         dscrpt.description as table_description;
                       -> """
+---------------+--------------+---------------+---------------+-------------------+
| database_name | cluster_name | schema_name   | table_name    | table_description |
+---------------+--------------+---------------+---------------+-------------------+
| "hive"        | "gold"       | "test_schema" | "test_table1" | "1st test table"  |
+---------------+--------------+---------------+---------------+-------------------+
Got 1 rows (time spent 11845/90694 us)

Sat, 25 Dec 2021 19:57:34 CST

(root@nebula) [amundsen]> """
                       -> MATCH (db:Database)-[:CLUSTER]->(clstr:Cluster)-[:SCHEMA]->(schema:Schema)-[:TABLE]->(tbl:Table)
                       ->         WHERE id(tbl) IN ['hive://gold.test_schema/test_table1']
                       ->         WITH db.name as database_name, clstr.name as cluster_name, schema.name as schema_name, tbl
                       ->         OPTIONAL MATCH (tbl:Table)-[:DESCRIPTION]->(dscrpt:Description)
                       ->         RETURN database_name, cluster_name, schema_name, tbl.name as table_name,
                       ->         dscrpt.description as table_description;
                       -> """
2021/12/25 19:56:39 [ERROR] Failed to reconnect, failed to open transport, error: dial tcp 192.168.8.128:9669: connect: connection refused
2021/12/25 19:56:39 Loop error, failed to open transport, error: dial tcp 192.168.8.128:9669: connect: connection refused

Bye root!
Sat, 25 Dec 2021 19:56:39 CST

panic: Loop error, failed to open transport, error: dial tcp 192.168.8.128:9669: connect: connection refused

goroutine 1 [running]:
log.Panicf({0x10500d752, 0xe}, {0x14000291e28, 0x1, 0x1})
	/opt/homebrew/Cellar/go/1.17.5/libexec/src/log/log.go:361 +0xa8
main.main()
	/Users/weyl/dev/nebula-console/main.go:473 +0xcb4
	

@CPWstatic CPWstatic force-pushed the impl_match_multi_path_according_to_the_paper branch from 204247c to 43febea Compare December 26, 2021 01:30
size_t startIndex = 0;
bool startFromEdge = false;

NG_RETURN_IF_ERROR(findStarts(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move the logic of StartVidFinder or IndexSelection to the optimizer in the future?
These logic makes the plannner complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok if you have a full solution, talk is always cheap.

@CPWstatic CPWstatic force-pushed the impl_match_multi_path_according_to_the_paper branch from 65d3f4c to 0cd750d Compare December 27, 2021 08:23
@CPWstatic
Copy link
Contributor Author

  • graphD crashed when WHERE id(v) IN ["foo"] , don't have time to see if it's caused by this branch or existing, To be checked later
(root@nebula) [amundsen]> """
                       -> MATCH (db:Database)-[:CLUSTER]->(clstr:Cluster)-[:SCHEMA]->(schema:Schema)-[:TABLE]->(tbl:Table)
                       ->         WHERE id(tbl) == 'hive://gold.test_schema/test_table1'
                       ->         WITH db.name as database_name, clstr.name as cluster_name, schema.name as schema_name, tbl
                       ->         OPTIONAL MATCH (tbl)-[:DESCRIPTION]->(dscrpt:Description)
                       ->         RETURN database_name, cluster_name, schema_name, tbl.name as table_name,
                       ->         dscrpt.description as table_description;
                       -> """
+---------------+--------------+---------------+---------------+-------------------+
| database_name | cluster_name | schema_name   | table_name    | table_description |
+---------------+--------------+---------------+---------------+-------------------+
| "hive"        | "gold"       | "test_schema" | "test_table1" | "1st test table"  |
+---------------+--------------+---------------+---------------+-------------------+
Got 1 rows (time spent 11845/90694 us)

Sat, 25 Dec 2021 19:57:34 CST

(root@nebula) [amundsen]> """
                       -> MATCH (db:Database)-[:CLUSTER]->(clstr:Cluster)-[:SCHEMA]->(schema:Schema)-[:TABLE]->(tbl:Table)
                       ->         WHERE id(tbl) IN ['hive://gold.test_schema/test_table1']
                       ->         WITH db.name as database_name, clstr.name as cluster_name, schema.name as schema_name, tbl
                       ->         OPTIONAL MATCH (tbl:Table)-[:DESCRIPTION]->(dscrpt:Description)
                       ->         RETURN database_name, cluster_name, schema_name, tbl.name as table_name,
                       ->         dscrpt.description as table_description;
                       -> """
2021/12/25 19:56:39 [ERROR] Failed to reconnect, failed to open transport, error: dial tcp 192.168.8.128:9669: connect: connection refused
2021/12/25 19:56:39 Loop error, failed to open transport, error: dial tcp 192.168.8.128:9669: connect: connection refused

Bye root!
Sat, 25 Dec 2021 19:56:39 CST

panic: Loop error, failed to open transport, error: dial tcp 192.168.8.128:9669: connect: connection refused

goroutine 1 [running]:
log.Panicf({0x10500d752, 0xe}, {0x14000291e28, 0x1, 0x1})
	/opt/homebrew/Cellar/go/1.17.5/libexec/src/log/log.go:361 +0xa8
main.main()
	/Users/weyl/dev/nebula-console/main.go:473 +0xcb4
	

I didn't reproduce this one.

@wey-gu
Copy link
Contributor

wey-gu commented Dec 27, 2021

I didn't reproduce this one.

Thanks, my attempts of reproducing failed, too, it should be a false report, sorry for that.

Copy link
Contributor

@yixinglu yixinglu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! 🥇
Maybe we could consider to test the openCypher test cases in new PR.

std::unordered_set<std::string> nodeAliasesSeen;
// TODO: Maybe it is better to rebuild the graph and find all connected components.
auto& pathInfos = matchClauseCtx->paths;
for (auto iter = pathInfos.begin(); iter < pathInfos.end(); ++iter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iter != pathInfos.end()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emmm, seems not that much necessary, the std::vector::iterator supports both < and !=.

std::unordered_set<std::string> nodeAliasesSeen;
// TODO: Maybe it is better to rebuild the graph and find all connected components.
auto& pathInfos = matchClauseCtx->paths;
for (auto iter = pathInfos.begin(); iter < pathInfos.end(); ++iter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iter != pathInfos.end()

MATCH (a)-[]-(b)
RETURN a.name AS n1, b.name AS n2 ORDER BY n1, n2 LIMIT 10
"""
Then a ExecutionError should be raised at runtime: Scan vertices must specify limit number.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error message will be updated in #3549

@CPWstatic CPWstatic force-pushed the impl_match_multi_path_according_to_the_paper branch from 0cd750d to ca04bab Compare December 27, 2021 10:58
@CPWstatic
Copy link
Contributor Author

updated: this was based on commit 1 days before and I noticed there is an Fix union commit after this WIP build, maybe that just fixed this one(or?), if so, plz ignore this, I will build from your head later.

This result seems to differ from the same query/data in n4j, not sure it's wrong behavior or what I had done wrongly.

# it looks good till now
MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        return downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath 

+--------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| downstream_entity                                                                                                                                            | upstream_entity | downstream_len                                                                                                                                                                                                                                                                                                                                                                                                                                 | upstream_len | upath    | dpath                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})       | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                            | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>                                                                                                                                                                                                                                                                                                         |
| ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})  | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                         | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})>                                                                                                                                                                                                                                                                                                    |
| ("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})     | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test_table3" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]   | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>     |
| ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]] | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})> |
| ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__        | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "hive://gold.test_schema/test_view1"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]       | __NULL__     | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>      |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Got 5 rows (time spent 6771/140510 us)

# Then OPTIONAL MATCH resulted in empty, from the above result we know that upstream is empty while downstream should have results:

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        RETURN upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath 

+-----------------+-------------------+--------------+----------------+-------+-------+
| upstream_entity | downstream_entity | upstream_len | downstream_len | upath | dpath |
+-----------------+-------------------+--------------+----------------+-------+-------+
+-----------------+-------------------+--------------+----------------+-------+-------+

# This query is verifying downstream expanding shouldn't be empty:

MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
    WHERE id(downstream_entity) IN ["dynamo://gold.test_schema/test_table2"] \
    RETURN downstream_entity,downstream_badge

+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| downstream_entity                                                                                                                                           | downstream_badge                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}) | ("npi" :Badge{category: "table_status", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})  |
| ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}) | ("json" :Badge{category: "table_status", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
Got 2 rows (time spent 3420/42999 us)

ref: full(longer query) from n4j

Fixed in the latest commit, please try it.

@wey-gu
Copy link
Contributor

wey-gu commented Dec 27, 2021

continue of #3519 (comment)

Now with the latest build, that step was fixed, while when I move on to the further extra optional match/ WITH lines, something is wrong here.

The result remains OK till this:(below results are correct)

# n4j
MATCH (source:Table {key: "hive://gold.test_schema/test_table1"})
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table)
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table)
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge)
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge)
        WITH CASE WHEN downstream_badge IS NULL THEN []
        ELSE collect(distinct {key:downstream_badge.key,category:downstream_badge.category})
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN []
        ELSE collect(distinct {key:upstream_badge.key,category:upstream_badge.category})
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath
        OPTIONAL MATCH (downstream_entity:Table)-[downstream_read:READ_BY]->(:User)
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath,
        downstream_badges, upstream_badges, sum(downstream_read.read_count) as downstream_read_count
        OPTIONAL MATCH (upstream_entity:Table)-[upstream_read:READ_BY]->(:User)
        RETURN upstream_entity, downstream_entity, upstream_len, downstream_len,
        downstream_badges, upstream_badges, downstream_read_count,
        sum(upstream_read.read_count) as upstream_read_count, upath, dpath
╒═════════════════╤══════════════════════════════════════════════════════════════════════╤══════════════╤══════════════════════════════════════════════════════════════════════╤══════════════════════════════════════════════════════════════════════╤═════════════════╤═══════════════════════╤═════════════════════╤═══════╤══════════════════════════════════════════════════════════════════════╕
│"upstream_entity""downstream_entity""upstream_len""downstream_len""downstream_badges""upstream_badges""downstream_read_count""upstream_read_count""upath""dpath"                                                               │
╞═════════════════╪══════════════════════════════════════════════════════════════════════╪══════════════╪══════════════════════════════════════════════════════════════════════╪══════════════════════════════════════════════════════════════════════╪═════════════════╪═══════════════════════╪═════════════════════╪═══════╪══════════════════════════════════════════════════════════════════════╡
│null             │{"name":"test_view1","publisher_last_updated_epoch_ms":1640401809838,"│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │00null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │published_tag":"unique_tag","key":"hive://gold.test_schema/test_view1"│              │eage_unique_tag"}]                                                    │                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │,"is_view":true}                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_view1","publisher_│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │last_updated_epoch_ms":1640401809838,"published_tag":"unique_tag","key│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │":"hive://gold.test_schema/test_view1","is_view":true}]               │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test's_table4","publisher_last_updated_epoch_ms":164040180983null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │0                      │0                    │null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │8,"published_tag":"unique_tag","key":"hive://gold.test_schema/test's_t│              │eage_unique_tag"},{"publisher_last_updated_epoch_ms":1640401809910,"pu│                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │able4","is_view":true}                                                │              │blished_tag":"lineage_unique_tag"}]                                   │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_view1","publisher_│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │last_updated_epoch_ms":1640401809838,"published_tag":"unique_tag","key│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │":"hive://gold.test_schema/test_view1","is_view":true},{"name":"test_v│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │iew1","publisher_last_updated_epoch_ms":1640401809838,"published_tag":│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"unique_tag","key":"hive://gold.test_schema/test_view1","is_view":true│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │},{"publisher_last_updated_epoch_ms":1640401809910,"published_tag":"li│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │neage_unique_tag"},{"name":"test's_table4","publisher_last_updated_epo│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │ch_ms":1640401809838,"published_tag":"unique_tag","key":"hive://gold.t│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │est_schema/test's_table4","is_view":true}]                            │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test_table2","publisher_last_updated_epoch_ms":1640401810033,│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[{"category":"table_status","key":"npi"},{"category":"table_status","k│[]               │520                    │0                    │null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │"published_tag":"unique_tag","key":"dynamo://gold.test_schema/test_tab│              │eage_unique_tag"}]                                                    │ey":"json"}]                                                          │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │le2","is_view":false}                                                 │              │                                                                      │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_table2","publisher│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_last_updated_epoch_ms":1640401810033,"published_tag":"unique_tag","ke│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │y":"dynamo://gold.test_schema/test_table2","is_view":false}]          │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test_table3","publisher_last_updated_epoch_ms":1640401809838,│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │0                      │0                    │null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │"published_tag":"unique_tag","key":"hive://gold.test_schema/test_table│              │eage_unique_tag"},{"publisher_last_updated_epoch_ms":1640401809910,"pu│                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │3","is_view":true}                                                    │              │blished_tag":"lineage_unique_tag"}]                                   │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_table2","publisher│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_last_updated_epoch_ms":1640401810033,"published_tag":"unique_tag","ke│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │y":"dynamo://gold.test_schema/test_table2","is_view":false},{"name":"t│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │est_table2","publisher_last_updated_epoch_ms":1640401810033,"published│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_tag":"unique_tag","key":"dynamo://gold.test_schema/test_table2","is_v│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │iew":false},{"publisher_last_updated_epoch_ms":1640401809910,"publishe│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │d_tag":"lineage_unique_tag"},{"name":"test_table3","publisher_last_upd│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │ated_epoch_ms":1640401809838,"published_tag":"unique_tag","key":"hive:│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │//gold.test_schema/test_table3","is_view":true}]                      │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test's_table4","publisher_last_updated_epoch_ms":164040180983│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │00null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │8,"published_tag":"unique_tag","key":"hive://gold.test_schema/test's_t│              │eage_unique_tag"},{"publisher_last_updated_epoch_ms":1640401809910,"pu│                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │able4","is_view":true}                                                │              │blished_tag":"lineage_unique_tag"}]                                   │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_table2","publisher│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_last_updated_epoch_ms":1640401810033,"published_tag":"unique_tag","ke│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │y":"dynamo://gold.test_schema/test_table2","is_view":false},{"name":"t│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │est_table2","publisher_last_updated_epoch_ms":1640401810033,"published│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_tag":"unique_tag","key":"dynamo://gold.test_schema/test_table2","is_v│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │iew":false},{"publisher_last_updated_epoch_ms":1640401809910,"publishe│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │d_tag":"lineage_unique_tag"},{"name":"test's_table4","publisher_last_u│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │pdated_epoch_ms":1640401809838,"published_tag":"unique_tag","key":"hiv│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │e://gold.test_schema/test's_table4","is_view":true}]                  │
└─────────────────┴──────────────────────────────────────────────────────────────────────┴──────────────┴──────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────┴─────────────────┴───────────────────────┴─────────────────────┴───────┴──────────────────────────────────────────────────────────────────────┘
#nebula
MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        RETURN upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath 

+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+-----------------+-----------------------+---------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| upstream_entity | downstream_entity                                                                                                                                            | upstream_len | downstream_len                                                                                                                                                                                                                                                                                                                                                                                                                                 | downstream_badges | upstream_badges | downstream_read_count | upstream_read_count | upath    | dpath                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+-----------------+-----------------------+---------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| __NULL__        | ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]] | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})> |
| __NULL__        | ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})  | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                         | []                | []              | 520                   | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})>                                                                                                                                                                                                                                                                                                    |
| __NULL__        | ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "hive://gold.test_schema/test_view1"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]       | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>      |
| __NULL__        | ("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})       | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                            | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>                                                                                                                                                                                                                                                                                                         |
| __NULL__        | ("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})     | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test_table3" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]   | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>     |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+-----------------+-----------------------+---------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

The issue comes in further(incorrect):

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath \
        WITH CASE WHEN upstream_len IS NULL THEN collect(NULL) \
        ELSE COLLECT(distinct{level:SIZE(upstream_len), source:split(id(upstream_entity),'://')[0], \
        key:id(upstream_entity), badges:upstream_badges, usage:upstream_read_count, parent:id(nodes(upath)[-2])}) \
        END AS upstream_entities, CASE WHEN downstream_len IS NULL THEN collect(NULL) \
        ELSE COLLECT(distinct{level:SIZE(downstream_len), source:split(id(downstream_entity),'://')[0], \
        key:id(downstream_entity), badges:downstream_badges, usage:downstream_read_count, parent:id(nodes(dpath)[-2])}) \
        END AS downstream_entities RETURN downstream_entities, upstream_entities
        
+---------------------+-------------------+
| downstream_entities | upstream_entities |
+---------------------+-------------------+
| []                  | []                |
+---------------------+-------------------+

Where it turned out downstream_len IS NULL was not properly checked as inside the CASE WHEN, thus the result was [].

Please check queries a. and b. on this and check on the cluster I shared to you.

CASE WHEN downstream_len IS NULL THEN collect(NULL) \
        ELSE COLLECT(distinct{level:SIZE(downstream_len), source:split(id(downstream_entity),'://')[0], \
        key:id(downstream_entity), badges:downstream_badges, usage:downstream_read_count, parent:id(nodes(dpath)[-2])}) \
        END AS downstream_entities RETURN downstream_entities, upstream_entities

a.

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath \
        RETURN (downstream_len IS NULL) AS a_downstream_len_IS_NULL

+--------------------------+
| a_downstream_len_IS_NULL |
+--------------------------+
| false                    |
| false                    |
| false                    |
| false                    |
| false                    |
+--------------------------+

b.

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath \
        RETURN (downstream_len IS NULL) AS a_downstream_len_IS_NULL, COLLECT(distinct{level:SIZE(downstream_len), source:split(id(downstream_entity),'://')[0], \
        key:id(downstream_entity), badges:downstream_badges, usage:downstream_read_count, parent:id(nodes(dpath)[-2])}) \
        AS b_downstream_entities 
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| a_downstream_len_IS_NULL | b_downstream_entities                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| false                    | [{badges: [], key: "hive://gold.test_schema/test's_table4", level: 2, parent: "dynamo://gold.test_schema/test_table2", source: "hive", usage: 0}, {badges: [], key: "dynamo://gold.test_schema/test_table2", level: 1, parent: "hive://gold.test_schema/test_table1", source: "dynamo", usage: 520}, {badges: [], key: "hive://gold.test_schema/test's_table4", level: 2, parent: "hive://gold.test_schema/test_view1", source: "hive", usage: 0}, {badges: [], key: "hive://gold.test_schema/test_view1", level: 1, parent: "hive://gold.test_schema/test_table1", source: "hive", usage: 0}, {badges: [], key: "hive://gold.test_schema/test_table3", level: 2, parent: "dynamo://gold.test_schema/test_table2", source: "hive", usage: 0}] |
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

ref of n4j

MATCH (source:Table {key: "hive://gold.test_schema/test_table1"})
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table)
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table)
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge)
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge)
        WITH CASE WHEN downstream_badge IS NULL THEN []
        ELSE collect(distinct {key:downstream_badge.key,category:downstream_badge.category})
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN []
        ELSE collect(distinct {key:upstream_badge.key,category:upstream_badge.category})
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath
        OPTIONAL MATCH (downstream_entity:Table)-[downstream_read:READ_BY]->(:User)
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath,
        downstream_badges, upstream_badges, sum(downstream_read.read_count) as downstream_read_count
        OPTIONAL MATCH (upstream_entity:Table)-[upstream_read:READ_BY]->(:User)
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len,
        downstream_badges, upstream_badges, downstream_read_count,
        sum(upstream_read.read_count) as upstream_read_count, upath, dpath
        WITH CASE WHEN upstream_len IS NULL THEN []
        ELSE COLLECT(distinct{level:SIZE(upstream_len), source:split(upstream_entity.key,'://')[0],
        key:upstream_entity.key, badges:upstream_badges, usage:upstream_read_count, parent:nodes(upath)[-2].key})
        END AS upstream_entities, CASE WHEN downstream_len IS NULL THEN []
        ELSE COLLECT(distinct{level:SIZE(downstream_len), source:split(downstream_entity.key,'://')[0],
        key:downstream_entity.key, badges:downstream_badges, usage:downstream_read_count, parent:nodes(dpath)[-2].key})
        END AS downstream_entities RETURN downstream_entities, upstream_entities

╒══════════════════════════════════════════════════════════════════════╤═══════════════════╕
│"downstream_entities"                                                 │"upstream_entities"│
╞══════════════════════════════════════════════════════════════════════╪═══════════════════╡
│[{"badges":[],"parent":"hive://gold.test_schema/test_table1","level":1│[]                 │
│,"usage":0,"source":"hive","key":"hive://gold.test_schema/test_view1"}│                   │
│,{"badges":[],"parent":"hive://gold.test_schema/test_view1","level":2,│                   │
│"usage":0,"source":"hive","key":"hive://gold.test_schema/test's_table4│                   │
│"},{"badges":[{"category":"table_status","key":"npi"},{"category":"tab│                   │
│le_status","key":"json"}],"parent":"hive://gold.test_schema/test_table│                   │
│1","level":1,"usage":520,"source":"dynamo","key":"dynamo://gold.test_s│                   │
│chema/test_table2"},{"badges":[],"parent":"dynamo://gold.test_schema/t│                   │
│est_table2","level":2,"usage":0,"source":"hive","key":"hive://gold.tes│                   │
│t_schema/test_table3"},{"badges":[],"parent":"dynamo://gold.test_schem│                   │
│a/test_table2","level":2,"usage":0,"source":"hive","key":"hive://gold.│                   │
│test_schema/test's_table4"}]                                          │                   │
└──────────────────────────────────────────────────────────────────────┴───────────────────┘

@CPWstatic
Copy link
Contributor Author

continue of #3519 (comment)

Now with the latest build, that step was fixed, while when I move on to the further extra optional match/ WITH lines, something is wrong here.

The result remains OK till this:(below results are correct)

# n4j
MATCH (source:Table {key: "hive://gold.test_schema/test_table1"})
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table)
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table)
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge)
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge)
        WITH CASE WHEN downstream_badge IS NULL THEN []
        ELSE collect(distinct {key:downstream_badge.key,category:downstream_badge.category})
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN []
        ELSE collect(distinct {key:upstream_badge.key,category:upstream_badge.category})
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath
        OPTIONAL MATCH (downstream_entity:Table)-[downstream_read:READ_BY]->(:User)
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath,
        downstream_badges, upstream_badges, sum(downstream_read.read_count) as downstream_read_count
        OPTIONAL MATCH (upstream_entity:Table)-[upstream_read:READ_BY]->(:User)
        RETURN upstream_entity, downstream_entity, upstream_len, downstream_len,
        downstream_badges, upstream_badges, downstream_read_count,
        sum(upstream_read.read_count) as upstream_read_count, upath, dpath
╒═════════════════╤══════════════════════════════════════════════════════════════════════╤══════════════╤══════════════════════════════════════════════════════════════════════╤══════════════════════════════════════════════════════════════════════╤═════════════════╤═══════════════════════╤═════════════════════╤═══════╤══════════════════════════════════════════════════════════════════════╕
│"upstream_entity""downstream_entity""upstream_len""downstream_len""downstream_badges""upstream_badges""downstream_read_count""upstream_read_count""upath""dpath"                                                               │
╞═════════════════╪══════════════════════════════════════════════════════════════════════╪══════════════╪══════════════════════════════════════════════════════════════════════╪══════════════════════════════════════════════════════════════════════╪═════════════════╪═══════════════════════╪═════════════════════╪═══════╪══════════════════════════════════════════════════════════════════════╡
│null             │{"name":"test_view1","publisher_last_updated_epoch_ms":1640401809838,"│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │00null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │published_tag":"unique_tag","key":"hive://gold.test_schema/test_view1"│              │eage_unique_tag"}]                                                    │                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │,"is_view":true}                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_view1","publisher_│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │last_updated_epoch_ms":1640401809838,"published_tag":"unique_tag","key│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │":"hive://gold.test_schema/test_view1","is_view":true}]               │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test's_table4","publisher_last_updated_epoch_ms":164040180983null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │0                      │0                    │null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │8,"published_tag":"unique_tag","key":"hive://gold.test_schema/test's_t│              │eage_unique_tag"},{"publisher_last_updated_epoch_ms":1640401809910,"pu│                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │able4","is_view":true}                                                │              │blished_tag":"lineage_unique_tag"}]                                   │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_view1","publisher_│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │last_updated_epoch_ms":1640401809838,"published_tag":"unique_tag","key│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │":"hive://gold.test_schema/test_view1","is_view":true},{"name":"test_v│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │iew1","publisher_last_updated_epoch_ms":1640401809838,"published_tag":│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"unique_tag","key":"hive://gold.test_schema/test_view1","is_view":true│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │},{"publisher_last_updated_epoch_ms":1640401809910,"published_tag":"li│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │neage_unique_tag"},{"name":"test's_table4","publisher_last_updated_epo│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │ch_ms":1640401809838,"published_tag":"unique_tag","key":"hive://gold.t│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │est_schema/test's_table4","is_view":true}]                            │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test_table2","publisher_last_updated_epoch_ms":1640401810033,│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[{"category":"table_status","key":"npi"},{"category":"table_status","k│[]               │520                    │0                    │null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │"published_tag":"unique_tag","key":"dynamo://gold.test_schema/test_tab│              │eage_unique_tag"}]                                                    │ey":"json"}]                                                          │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │le2","is_view":false}                                                 │              │                                                                      │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_table2","publisher│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_last_updated_epoch_ms":1640401810033,"published_tag":"unique_tag","ke│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │y":"dynamo://gold.test_schema/test_table2","is_view":false}]          │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test_table3","publisher_last_updated_epoch_ms":1640401809838,│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │0                      │0                    │null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │"published_tag":"unique_tag","key":"hive://gold.test_schema/test_table│              │eage_unique_tag"},{"publisher_last_updated_epoch_ms":1640401809910,"pu│                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │3","is_view":true}                                                    │              │blished_tag":"lineage_unique_tag"}]                                   │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_table2","publisher│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_last_updated_epoch_ms":1640401810033,"published_tag":"unique_tag","ke│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │y":"dynamo://gold.test_schema/test_table2","is_view":false},{"name":"t│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │est_table2","publisher_last_updated_epoch_ms":1640401810033,"published│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_tag":"unique_tag","key":"dynamo://gold.test_schema/test_table2","is_v│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │iew":false},{"publisher_last_updated_epoch_ms":1640401809910,"publishe│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │d_tag":"lineage_unique_tag"},{"name":"test_table3","publisher_last_upd│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │ated_epoch_ms":1640401809838,"published_tag":"unique_tag","key":"hive:│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │//gold.test_schema/test_table3","is_view":true}]                      │
├─────────────────┼──────────────────────────────────────────────────────────────────────┼──────────────┼──────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────────┼─────────────────────┼───────┼──────────────────────────────────────────────────────────────────────┤
│null             │{"name":"test's_table4","publisher_last_updated_epoch_ms":164040180983│null          │[{"publisher_last_updated_epoch_ms":1640401809909,"published_tag":"lin│[]                                                                    │[]               │00null   │[{"name":"test_table1","publisher_last_updated_epoch_ms":1640401810033│
│                 │8,"published_tag":"unique_tag","key":"hive://gold.test_schema/test's_t│              │eage_unique_tag"},{"publisher_last_updated_epoch_ms":1640401809910,"pu│                                                                      │                 │                       │                     │       │,"published_tag":"unique_tag","key":"hive://gold.test_schema/test_tabl│
│                 │able4","is_view":true}                                                │              │blished_tag":"lineage_unique_tag"}]                                   │                                                                      │                 │                       │                     │       │e1","is_view":false},{"publisher_last_updated_epoch_ms":1640401809909,│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │"published_tag":"lineage_unique_tag"},{"name":"test_table2","publisher│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_last_updated_epoch_ms":1640401810033,"published_tag":"unique_tag","ke│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │y":"dynamo://gold.test_schema/test_table2","is_view":false},{"name":"t│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │est_table2","publisher_last_updated_epoch_ms":1640401810033,"published│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │_tag":"unique_tag","key":"dynamo://gold.test_schema/test_table2","is_v│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │iew":false},{"publisher_last_updated_epoch_ms":1640401809910,"publishe│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │d_tag":"lineage_unique_tag"},{"name":"test's_table4","publisher_last_u│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │pdated_epoch_ms":1640401809838,"published_tag":"unique_tag","key":"hiv│
│                 │                                                                      │              │                                                                      │                                                                      │                 │                       │                     │       │e://gold.test_schema/test's_table4","is_view":true}]                  │
└─────────────────┴──────────────────────────────────────────────────────────────────────┴──────────────┴──────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────┴─────────────────┴───────────────────────┴─────────────────────┴───────┴──────────────────────────────────────────────────────────────────────┘
#nebula
MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        RETURN upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath 

+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+-----------------+-----------------------+---------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| upstream_entity | downstream_entity                                                                                                                                            | upstream_len | downstream_len                                                                                                                                                                                                                                                                                                                                                                                                                                 | downstream_badges | upstream_badges | downstream_read_count | upstream_read_count | upath    | dpath                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+-----------------+-----------------------+---------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| __NULL__        | ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]] | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})> |
| __NULL__        | ("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})  | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                         | []                | []              | 520                   | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})>                                                                                                                                                                                                                                                                                                    |
| __NULL__        | ("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813}) | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "hive://gold.test_schema/test_view1"->"hive://gold.test_schema/test's_table4" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]       | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test's_table4" :Table{is_view: true, name: "test's_table4", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>      |
| __NULL__        | ("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})       | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"hive://gold.test_schema/test_view1" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]                                                                                                                                                                                                                            | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_view1" :Table{is_view: true, name: "test_view1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>                                                                                                                                                                                                                                                                                                         |
| __NULL__        | ("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})     | __NULL__     | [[:HAS_DOWNSTREAM "hive://gold.test_schema/test_table1"->"dynamo://gold.test_schema/test_table2" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}], [:HAS_DOWNSTREAM "dynamo://gold.test_schema/test_table2"->"hive://gold.test_schema/test_table3" @0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]]   | []                | []              | 0                     | 0                   | __NULL__ | <("hive://gold.test_schema/test_table1" :Table{is_view: false, name: "test_table1", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("dynamo://gold.test_schema/test_table2" :Table{is_view: false, name: "test_table2", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814})-[:HAS_DOWNSTREAM@0 {END_LABEL: "Table", START_LABEL: "Table", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405814}]->("hive://gold.test_schema/test_table3" :Table{is_view: true, name: "test_table3", published: "unique_tag", publisher_last_updated_epoch_ms: 1640405813})>     |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+-----------------+-----------------------+---------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

The issue comes in further(incorrect):

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath \
        WITH CASE WHEN upstream_len IS NULL THEN collect(NULL) \
        ELSE COLLECT(distinct{level:SIZE(upstream_len), source:split(id(upstream_entity),'://')[0], \
        key:id(upstream_entity), badges:upstream_badges, usage:upstream_read_count, parent:id(nodes(upath)[-2])}) \
        END AS upstream_entities, CASE WHEN downstream_len IS NULL THEN collect(NULL) \
        ELSE COLLECT(distinct{level:SIZE(downstream_len), source:split(id(downstream_entity),'://')[0], \
        key:id(downstream_entity), badges:downstream_badges, usage:downstream_read_count, parent:id(nodes(dpath)[-2])}) \
        END AS downstream_entities RETURN downstream_entities, upstream_entities
        
+---------------------+-------------------+
| downstream_entities | upstream_entities |
+---------------------+-------------------+
| []                  | []                |
+---------------------+-------------------+

Where it turned out downstream_len IS NULL was not properly checked as inside the CASE WHEN, thus the result was [].

Please check queries a. and b. on this and check on the cluster I shared to you.

CASE WHEN downstream_len IS NULL THEN collect(NULL) \
        ELSE COLLECT(distinct{level:SIZE(downstream_len), source:split(id(downstream_entity),'://')[0], \
        key:id(downstream_entity), badges:downstream_badges, usage:downstream_read_count, parent:id(nodes(dpath)[-2])}) \
        END AS downstream_entities RETURN downstream_entities, upstream_entities

a.

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath \
        RETURN (downstream_len IS NULL) AS a_downstream_len_IS_NULL

+--------------------------+
| a_downstream_len_IS_NULL |
+--------------------------+
| false                    |
| false                    |
| false                    |
| false                    |
| false                    |
+--------------------------+

b.

MATCH (source:Table) \
    WHERE id(source) == "hive://gold.test_schema/test_table1" \
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table) \
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table) \
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath \
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge) \
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge) \
        WITH CASE WHEN downstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(downstream_badge),category:downstream_badge.category}) \
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN collect(NULL) \
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.category}) \
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath \
        OPTIONAL MATCH (downstream_entity:`Table`)-[downstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath, \
        downstream_badges, upstream_badges, sum(downstream_read.read_count) AS downstream_read_count \
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`) \
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, \
        downstream_badges, upstream_badges, downstream_read_count, \
        sum(upstream_read.read_count) AS upstream_read_count, upath, dpath \
        RETURN (downstream_len IS NULL) AS a_downstream_len_IS_NULL, COLLECT(distinct{level:SIZE(downstream_len), source:split(id(downstream_entity),'://')[0], \
        key:id(downstream_entity), badges:downstream_badges, usage:downstream_read_count, parent:id(nodes(dpath)[-2])}) \
        AS b_downstream_entities 
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| a_downstream_len_IS_NULL | b_downstream_entities                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| false                    | [{badges: [], key: "hive://gold.test_schema/test's_table4", level: 2, parent: "dynamo://gold.test_schema/test_table2", source: "hive", usage: 0}, {badges: [], key: "dynamo://gold.test_schema/test_table2", level: 1, parent: "hive://gold.test_schema/test_table1", source: "dynamo", usage: 520}, {badges: [], key: "hive://gold.test_schema/test's_table4", level: 2, parent: "hive://gold.test_schema/test_view1", source: "hive", usage: 0}, {badges: [], key: "hive://gold.test_schema/test_view1", level: 1, parent: "hive://gold.test_schema/test_table1", source: "hive", usage: 0}, {badges: [], key: "hive://gold.test_schema/test_table3", level: 2, parent: "dynamo://gold.test_schema/test_table2", source: "hive", usage: 0}] |
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

ref of n4j

MATCH (source:Table {key: "hive://gold.test_schema/test_table1"})
        OPTIONAL MATCH dpath=(source)-[downstream_len:HAS_DOWNSTREAM*..3]->(downstream_entity:Table)
        OPTIONAL MATCH upath=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:Table)
        WITH downstream_entity, upstream_entity, downstream_len, upstream_len, upath, dpath
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge)
        OPTIONAL MATCH (downstream_entity)-[:HAS_BADGE]->(downstream_badge:Badge)
        WITH CASE WHEN downstream_badge IS NULL THEN []
        ELSE collect(distinct {key:downstream_badge.key,category:downstream_badge.category})
        END AS downstream_badges, CASE WHEN upstream_badge IS NULL THEN []
        ELSE collect(distinct {key:upstream_badge.key,category:upstream_badge.category})
        END AS upstream_badges, upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath
        OPTIONAL MATCH (downstream_entity:Table)-[downstream_read:READ_BY]->(:User)
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len, upath, dpath,
        downstream_badges, upstream_badges, sum(downstream_read.read_count) as downstream_read_count
        OPTIONAL MATCH (upstream_entity:Table)-[upstream_read:READ_BY]->(:User)
        WITH upstream_entity, downstream_entity, upstream_len, downstream_len,
        downstream_badges, upstream_badges, downstream_read_count,
        sum(upstream_read.read_count) as upstream_read_count, upath, dpath
        WITH CASE WHEN upstream_len IS NULL THEN []
        ELSE COLLECT(distinct{level:SIZE(upstream_len), source:split(upstream_entity.key,'://')[0],
        key:upstream_entity.key, badges:upstream_badges, usage:upstream_read_count, parent:nodes(upath)[-2].key})
        END AS upstream_entities, CASE WHEN downstream_len IS NULL THEN []
        ELSE COLLECT(distinct{level:SIZE(downstream_len), source:split(downstream_entity.key,'://')[0],
        key:downstream_entity.key, badges:downstream_badges, usage:downstream_read_count, parent:nodes(dpath)[-2].key})
        END AS downstream_entities RETURN downstream_entities, upstream_entities

╒══════════════════════════════════════════════════════════════════════╤═══════════════════╕
│"downstream_entities"                                                 │"upstream_entities"│
╞══════════════════════════════════════════════════════════════════════╪═══════════════════╡
│[{"badges":[],"parent":"hive://gold.test_schema/test_table1","level":1│[]                 │
│,"usage":0,"source":"hive","key":"hive://gold.test_schema/test_view1"}│                   │
│,{"badges":[],"parent":"hive://gold.test_schema/test_view1","level":2,│                   │
│"usage":0,"source":"hive","key":"hive://gold.test_schema/test's_table4│                   │
│"},{"badges":[{"category":"table_status","key":"npi"},{"category":"tab│                   │
│le_status","key":"json"}],"parent":"hive://gold.test_schema/test_table│                   │
│1","level":1,"usage":520,"source":"dynamo","key":"dynamo://gold.test_s│                   │
│chema/test_table2"},{"badges":[],"parent":"dynamo://gold.test_schema/t│                   │
│est_table2","level":2,"usage":0,"source":"hive","key":"hive://gold.tes│                   │
│t_schema/test_table3"},{"badges":[],"parent":"dynamo://gold.test_schem│                   │
│a/test_table2","level":2,"usage":0,"source":"hive","key":"hive://gold.│                   │
│test_schema/test's_table4"}]                                          │                   │
└──────────────────────────────────────────────────────────────────────┴───────────────────┘
CASE WHEN downstream_len IS NULL THEN collect(NULL) \
        ELSE COLLECT(distinct{level:SIZE(downstream_len), source:split(id(downstream_entity),'://')[0], \
        key:id(downstream_entity), badges:downstream_badges, usage:downstream_read_count, parent:id(nodes(dpath)[-2])}) \
        END AS downstream_entities RETURN downstream_entities, upstream_entities

This seem like expression issue, will debug later.

@CPWstatic CPWstatic force-pushed the impl_match_multi_path_according_to_the_paper branch from ca04bab to 4898aa5 Compare December 28, 2021 03:03
yixinglu
yixinglu previously approved these changes Dec 28, 2021
@jievince
Copy link
Contributor

See this case:

match (v:player)-[e]-(v:team) return v, e

The result seems different with neo4j.

if (notVisited) {
queue.push(dep);
std::vector<folly::Future<Status>>& futures = futureMap[exe->id()];
if (exe->node()->kind() == PlanNode::Kind::kArgument) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need special handling?

@CPWstatic
Copy link
Contributor Author

match (v:player)-[e]-(v:team) return v, e

Emmm, i see, seems we do not ever support this case. I'll forbid this one first, until we have plannode like expand into or another good way to implement this case.

@CPWstatic
Copy link
Contributor Author

See this case:

match (v:player)-[e]-(v:team) return v, e

The result seems different with neo4j.

A second thought, we might not need to implement it, as it is equal to:

match (v:player)-[e]-(v2:team) where v==v2 return v, e

Copy link
Contributor

@jievince jievince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc affected PR: improvements or additions to documentation incompatible PR: incompatible with the recently released version ready for review ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants