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

variable WITH not AS treated as NULL, is this expected? #3635

Open
wey-gu opened this issue Jan 5, 2022 · 0 comments
Open

variable WITH not AS treated as NULL, is this expected? #3635

wey-gu opened this issue Jan 5, 2022 · 0 comments
Labels
type/question Type: question about the product

Comments

@wey-gu
Copy link
Contributor

wey-gu commented Jan 5, 2022

The only diff between 1. and 2. is that in 2. there is one extra alias: , upstream_len AS upstream_len before the RETURN clause.

Thus, when upstream_len was not claimed, WITH CASE WHEN upstream_len IS NULL will be TRUE forever instead of error alias not declared.

I was aware of this behavior (differentiate from n4j on requiring explicitly specifying alias in latest WITH before RETURN), but this seems to be confusing as it treated upstream_len as NULL instead of raising an error to warn the user to declare it.

1

MATCH (source:`Table`)
        WHERE id(source) == "hive://gold.test_schema/test_table1"
        OPTIONAL MATCH `path`=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:`Table`)
        WITH upstream_entity, upstream_len, `path`
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge)
        WITH CASE WHEN upstream_badge IS NULL THEN collect(NULL)
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.Badge.category})
        END AS upstream_badges, upstream_entity, upstream_len, `path`
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`)
        WITH upstream_entity, upstream_len, upstream_badges,
        sum(upstream_read.read_count) AS upstream_read_count, `path`
        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(`path`)[-2])})
        END AS upstream_entities RETURN upstream_entities

+-------------------+
| upstream_entities |
+-------------------+
| []                |
+-------------------+

2

MATCH (source:`Table`)
        WHERE id(source) == "hive://gold.test_schema/test_table1"
        OPTIONAL MATCH `path`=(source)-[upstream_len:HAS_UPSTREAM*..3]->(upstream_entity:`Table`)
        WITH upstream_entity, upstream_len, `path`
        OPTIONAL MATCH (upstream_entity)-[:HAS_BADGE]->(upstream_badge:Badge)
        WITH CASE WHEN upstream_badge IS NULL THEN collect(NULL)
        ELSE collect(distinct {key:id(upstream_badge),category:upstream_badge.Badge.category})
        END AS upstream_badges, upstream_entity, upstream_len, `path`
        OPTIONAL MATCH (upstream_entity:`Table`)-[upstream_read:READ_BY]->(:`User`)
        WITH upstream_entity, upstream_len, upstream_badges,
        sum(upstream_read.read_count) AS upstream_read_count, `path`
        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(`path`)[-2])})
        END AS upstream_entities, upstream_len AS upstream_len RETURN upstream_entities

+-----------------------------------------------------------------------------------------------------------------------------------------------------+
| downstream_entities                                                                                                                                 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+
| [{badges: [], key: "hive://gold.test_schema/test's_table4", level: 2, parent: "dynamo://gold.test_schema/test_table2", 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}]     |
| [{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's_table4", level: 2, parent: "hive://gold.test_schema/test_view1", 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}] |
+-----------------------------------------------------------------------------------------------------------------------------------------------------+

diff:
diff_1_2

@wey-gu wey-gu added the type/question Type: question about the product label Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question Type: question about the product
Projects
None yet
Development

No branches or pull requests

1 participant