cleishm / libcypher-parser

Cypher Parser Library
Apache License 2.0
147 stars 39 forks source link

APOC support #35

Closed kernowal closed 2 years ago

kernowal commented 4 years ago

Hi @cleishm,

It seems that some APOC procedures are not supported. The following example query throws an error due to the parenthese after apoc.convert.toBoolean.

Query:

    MATCH (:NodeType)-[rel:relationship]->(:NodeType2)
    UNWIND rel.list_data as data
    WITH data, split(data, " ")[-1] as flag
    WHERE apoc.convert.toBoolean(flag)
    RETURN data

Note here: rel.list_data is of the format ["some_value flag", "some_value flag",...] where the flag string is being converted into a boolean via the APOC procedure.

This gives the output:

 @0    5..188  statement                  body=@1
 @1    5..188  > query                    clauses=[@2, @12, @17, @35]
 @2    5..60   > > MATCH                  pattern=@3
 @3   11..55   > > > pattern              paths=[@4]
 @4   11..55   > > > > pattern path       (@5)-[@7]-(@10)
 @5   11..22   > > > > > node pattern     (:@6)
 @6   12..21   > > > > > > label          :`NodeType`
 @7   22..43   > > > > > rel pattern      -[@8:@9]->
 @8   24..27   > > > > > > identifier     `rel`
 @9   27..40   > > > > > > rel type       :`relationship`
@10   43..55   > > > > > node pattern     (:@11)
@11   44..54   > > > > > > label          :`NodeType2`
@12   60..93   > > UNWIND                 expression=@13, alias=@16
@13   67..81   > > > property             @14.@15
@14   67..70   > > > > identifier         `rel`
@15   71..80   > > > > prop name          `list_data`
@16   84..88   > > > identifier           `data`
@17   93..165  > > WITH                   projections=[@18, @20], WHERE=@29
@18   98..102  > > > projection           expression=@19
@19   98..102  > > > > identifier         `data`
@20  104..137  > > > projection           expression=@21, alias=@28
@21  104..125  > > > > subscript          @22[@26]
@22  104..120  > > > > > apply            @23(@24, @25)
@23  104..109  > > > > > > function name  `split`
@24  110..114  > > > > > > identifier     `data`
@25  116..119  > > > > > > string         " "
@26  121..123  > > > > > unary operator   - @27
@27  122..123  > > > > > > integer        1
@28  128..132  > > > > identifier         `flag`
@29  143..165  > > > property             @30.@33
@30  143..155  > > > > property           @31.@32
@31  143..147  > > > > > identifier       `apoc`
@32  148..155  > > > > > prop name        `convert`
@33  156..165  > > > > prop name          `toBoolean`
@34  165..175  > > error                  >>(flag)\n   <<
@35  176..188  > > RETURN                 projections=[@36]
@36  183..188  > > > projection           expression=@37
@37  183..187  > > > > identifier         `data`

This is a valid implementation of the apoc procedure which performs as expected. Is there any current support for APOC procedures or are there plans to include this in a future release?

Thanks in advance!

UPDATE

This seems a similar issue to https://github.com/cleishm/libcypher-parser/issues/19 which has been closed. What was the outcome of this?

In a similar fashion, putting backticks around apoc.convert.toBoolean to escape the projection removes the error, but this then does not work in neo

cleishm commented 4 years ago

I can't reproduce this with the version build from the main branch. Can you try with that and confirm?

cleishm commented 2 years ago

Resolved in the main branch.