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

predicate should accept a list of booleans #2472

Closed
kindlychung opened this issue Apr 14, 2021 · 10 comments
Closed

predicate should accept a list of booleans #2472

kindlychung opened this issue Apr 14, 2021 · 10 comments
Assignees

Comments

@kindlychung
Copy link

The current syntax is:

<predicate>(<variable> IN <list> WHERE <condition>)

Which can lead to bizzar statements like:

return any(n in [true] where n)
match (p:player) return p.age > 35 as senior | return collect($-.senior) as seniorList  | return any(n in $-.seniorList where n)

I'd very much prefer:

return any([true])
match (p:player) return p.age > 35 as senior | return collect($-.senior) as seniorList  | return any($-.seniorList)
@kindlychung
Copy link
Author

Considering we already have list comprehension, the following should be intuitively correct:

return any([n in range(1, 5) | n > 3])

At the moment this is illegal.

@jievince
Copy link
Contributor

The current syntax is:

<predicate>(<variable> IN <list> WHERE <condition>)

Which can lead to bizzar statements like:

return any(n in [true] where n)
match (p:player) return p.age > 35 as senior | return collect($-.senior) as seniorList  | return any(n in $-.seniorList where n)

I'd very much prefer:

return any([true])
match (p:player) return p.age > 35 as senior | return collect($-.senior) as seniorList  | return any($-.seniorList)

Hi kindlychung,
When the list is all bool types,you think the where pattern of predicate is unnecessary. Do I get what you mean?
But the list is not strong-typed, so the list main contain other types of data,
eg. return any(n in [true, 3, "jack"]), if there is no where, what's boolean value of 3 or "jack"?

@jievince
Copy link
Contributor

In list comprehension, [n in list where filter | mapping], the pattern filter is used to filter some items of the list, and the pattern mapping is used to mapping each item in the list to other value.

Considering we already have list comprehension, the following should be intuitively correct:

return any([n in range(1, 5) | n > 3])

At the moment this is illegal.
The predicate should not support mapping function, because it is contradictory with its original design intent

@kindlychung
Copy link
Author

But the list is not strong-typed, so the list main contain other types of data

I see. Is it too late to introduce a new list type with homogeneous types at this stage?

@kindlychung
Copy link
Author

kindlychung commented Apr 15, 2021

Actually I think it can still work. Basically we can just treat any non-booleans as false. For example return any( [true, 1, 2, 3]) can just evaluate to true, while return any([2, 1, 3]) and return any([1, false, 99]) can both evaluate to false.

@jievince
Copy link
Contributor

Basically we can just treat any non-booleans as false.
This is an unreasonable assumption. BTW, a predicate without specifying a filter is equivalent to this form `any(n in [true, 1,2] where toBoolean(n) == true). So toBoolean(1) returns true, toBoolean(0) returns false, and many data types like list, vertex can't be converted to a bool value.

@jievince
Copy link
Contributor

jievince commented Apr 15, 2021

But the list is not strong-typed, so the list main contain other types of data

I see. Is it too late to introduce a new list type with homogeneous types at this stage?

Writing a type of list<int> in SQL is too ugly

@kindlychung
Copy link
Author

kindlychung commented Apr 16, 2021

This is an unreasonable assumption. BTW, a predicate without specifying a filter is equivalent to this form `any(n in [true, 1,2] where toBoolean(n) == true). So toBoolean(1) returns true, toBoolean(0) returns false, and many data types like list, vertex can't be converted to a bool value.

Could you please give an example of "a predicate without a filter"? I tried this:

(root@nebula) [(none)]> return any(n in [1])
[ERROR (-7)]: SyntaxError: syntax error near `)'

An implicit where toBoolean(x) filter is nice. And if any(n in [1] where toBoolean(x) == true) can be simplified to any(n in [1] ), why not just any([1])?

@kindlychung
Copy link
Author

Hm, it seems converting a number to boolean is not allowed in 2.0:

(root@nebula) [nba]> with 1 as x return toBoolean(1)
[ERROR (-12)]: SemanticError: `toBoolean(1)' is not a valid expression : Parameter's type error

@CPWstatic
Copy link
Contributor

Thanks for introducing some convenience syntax for us, but we are now trying to be compatible with the openCypher firstly. Your proposed syntax about the any predicate seems only a syntax sugar but nothing new. And the toBoolean part is also compatible concerned that the toBoolean function supports only string to bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants