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

Cypher Merge or other nGQL to property-wise conditionally insert #2628

Open
wey-gu opened this issue Jul 19, 2021 · 1 comment
Open

Cypher Merge or other nGQL to property-wise conditionally insert #2628

wey-gu opened this issue Jul 19, 2021 · 1 comment
Labels
type/feature req Type: feature request

Comments

@wey-gu
Copy link
Contributor

wey-gu commented Jul 19, 2021

Is your feature request related to a problem? Please describe.
Similar use case when using MERGE in Cypher.

If we would like to query in one shoot(instead of two queries) to create a user tag vertex only when its email property was not associated with any existing user vertices.

Describe the solution you'd like
Some expression to enable conditionally insert? The easy way/ugly may be to:

  • a) add parsing rule on variable support in INSERT VERTEX?
  • b) add pipe support in INSERT VERTEX?
(root@nebula) [basketballplayer]> $var = LOOKUP ON user WHERE user.email == "Rudy.Gay@domain.tld" YIELD user.email as email | \
                               ->        GROUP BY $-.email YIELD $-.email as email, count(*) AS number | \
                               ->        YIELD CASE $-.number == 0 WHEN true THEN "user200" ELSE "userdummy" END AS user_vid;
+-------------+
| user_vid    |
+-------------+
| "userdummy" |
+-------------+
Got 1 rows (time spent 4169/44468 us)

a)

$var = LOOKUP ON user WHERE user.email == "Rudy.Gay@domain.tld" YIELD user.email as email | \
       GROUP BY $-.email YIELD $-.email as email, count(*) AS number | \
       YIELD CASE $-.number == 0 WHEN true THEN "user200" ELSE "userdummy" END AS user_vid;
insert vertex user(email) values $var.user_vid:("Rudy.Gay@domain.tld")

(root@nebula) [basketballplayer]> $var = LOOKUP ON user WHERE user.email == "Rudy.Gay@domain.tld" YIELD user.email as email | \
                               ->        GROUP BY $-.email YIELD $-.email as email, count(*) AS number | \
                               ->        YIELD CASE $-.number == 0 WHEN true THEN "user200" ELSE "userdummy" END AS user_vid; \
                               -> insert vertex user(email) values $var.user_vid:("Rudy.Gay@domain.tld")
[ERROR (-1004)]: SyntaxError: syntax error near `$var'

Mon, 19 Jul 2021 17:37:29 CST

b)

(root@nebula) [basketballplayer]> LOOKUP ON user WHERE user.email == "Rudy.Gay@domain.tld" YIELD user.email as email | \
                               ->        GROUP BY $-.email YIELD $-.email as email, count(*) AS number | \
                               ->        YIELD CASE $-.number == 0 WHEN true THEN "user200" ELSE "userdummy" END AS user_vid |\
                               -> insert vertex user(email) values $-.user_vid:("Rudy.Gay@domain.tld")
[ERROR (-1004)]: SyntaxError: syntax error near `insert'

Mon, 19 Jul 2021 17:43:05 CST

Describe alternatives you've considered
Cypher MERGE support? or other smart expressions to enable the condition based on the property of an insert.

Additional context

https://discuss.nebula-graph.com.cn/t/topic/3457

https://nebulagraph.slack.com/archives/CJNFUM7AR/p1626558554041700

@Shylock-Hg
Copy link
Contributor

There will be consistency issue, if rmw operation isn't atomic.

@CPWstatic CPWstatic transferred this issue from vesoft-inc/nebula-graph Aug 27, 2021
@CPWstatic CPWstatic added the type/feature req Type: feature request label Aug 28, 2021
yixinglu pushed a commit to yixinglu/nebula that referenced this issue Sep 14, 2023
* Update LM interface

* Set LM url for test

* Remove unused method

* Add missing errors

* Update log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature req Type: feature request
Projects
None yet
Development

No branches or pull requests

3 participants