cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

A new brain tease for the apoc lovers

paolodipietro58
Graph Voyager

Preformatted textRun-in community edition an Mac M1

Well, I have the following query fragment (maybe @glilienfield can remember some pieces!)

......

CALL apoc.do.case([

    subbrand IS NOT NULL AND brand IS NULL,
         '
              MERGE (card)-[:CARD_HAS_NO_BRAND]->(error)    
              return error as res',

    subbrand IS NULL AND brand IS NOT NULL,
         '
              MERGE (card)-[:CARD_HAS_NO_SUB_BRAND]->(error)    
              return error as res',

    subbrand IS NULL AND brand IS NULL,
         '
              MERGE (card)-[:CARD_HAS_NO_BRAND]->(error)    
              MERGE (card)-[:CARD_HAS_NO_SUB_BRAND]->(error)    
              return errors AS res'
          ],
     'MERGE (subBrand:SubBrand { name: subbrand })
         MERGE (a_brand:Brand { name: brand })
         MERGE (card)-[has_sub_brand:CARD_HAS_SUB_BRAND]->(subBrand)
               SET has_sub_brand.debit = CASE toLower(row.type) WHEN "debit" THEN TRUE else FALSE END
         MERGE (subBrand)-[:SUB_BRAND_BELONGS_TO_BRAND]->(a_brand)
         RETURN subBrand', 

    {brand: brand, card: card, subbrand: subbrand, error: error, row: row}
    ) yield value as subBrand

It returns the following error:

Procedure call provides too many arguments: got 4 expected no more than 3.

Procedure apoc.do.case has signature: apoc.do.case(conditionals :: LIST? OF ANY?, elseQuery  =  '' :: STRING?, params  =  Map{} :: MAP?) :: value :: MAP?
meaning that it expects at least 1 argument of type LIST? OF ANY?
Description: apoc.do.case([condition, query, condition, query, ...], elseQuery:'', params:{}) yield value - given a list of conditional / writing query pairs, executes the query associated with the first conditional evaluating to true (or the else query if none are true) with the given parameters (line 27, column 1 (offset: 1289))
"CALL apoc.do.case(country IS NOT NULL AND a_country IS NOT NULL,"
 ^

it is my first time with apoc.do.case and I spent half a day to find where that damn fourth parameter is hiding. I wasn't able to find it. For me, I have 3 couple (condition/query) into the first param between [ ], then I have the else clause and finally the parameters: just 3 elements.

But it stubbornly says there are four. I didn't find the fourth.

the cypher manual is here: https://neo4j.com/labs/apoc/4.4/overview/apoc.do/apoc.do.case/

Who is so cute to indicate the error?

Thank you in advance

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

Do you have the wrong snippet? It is complaining about the the apoc.do.case that has the following condition, which is not shown in your snippet:

"CALL apoc.do.case(country IS NOT NULL AND a_country IS NOT NULL,"

Your use in the snippet does seem to have just three parameters.

View solution in original post

3 REPLIES 3

bennu_neo
Neo4j
Neo4j

Hi @paolodipietro58 ,

What you shared runs fine on my instance tho. Neo4j 4.4.3

MATCH (card)
with card limit 1
MATCH (error)
with error,card limit 1
with error, card,   "sub" as subbrand, "br" as brand, {} as row
CALL apoc.do.case([

    subbrand IS NOT NULL AND brand IS NULL,
         '
              MERGE (card)-[:CARD_HAS_NO_BRAND]->(error)    
              return error as res',

    subbrand IS NULL AND brand IS NOT NULL,
         '
              MERGE (card)-[:CARD_HAS_NO_SUB_BRAND]->(error)    
              return error as res',

    subbrand IS NULL AND brand IS NULL,
         '
              MERGE (card)-[:CARD_HAS_NO_BRAND]->(error)    
              MERGE (card)-[:CARD_HAS_NO_SUB_BRAND]->(error)    
              return errors AS res'
          ],
     'MERGE (subBrand:SubBrand { name: subbrand })
         MERGE (a_brand:Brand { name: brand })
         MERGE (card)-[has_sub_brand:CARD_HAS_SUB_BRAND]->(subBrand)
               SET has_sub_brand.debit = CASE toLower(row.type) WHEN "debit" THEN TRUE else FALSE END
         MERGE (subBrand)-[:SUB_BRAND_BELONGS_TO_BRAND]->(a_brand)
         RETURN subBrand', 

    {brand: brand, card: card, subbrand: subbrand, error: error, row: row}
    ) yield value as subBrand
return *

Bennu

Oh, y’all wanted a twist, ey?

glilienfield
Ninja
Ninja

Do you have the wrong snippet? It is complaining about the the apoc.do.case that has the following condition, which is not shown in your snippet:

"CALL apoc.do.case(country IS NOT NULL AND a_country IS NOT NULL,"

Your use in the snippet does seem to have just three parameters.

can I say stupid?
when you look for the speck in the eye and don't see the beam!

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit - November 16 - 17, 2022.


Free NODES Training Series


October 19th -

Intro to Neo4j


October 20th -

Healthcare Analytics Using Neo4j


October 25th -

Handling Neo4j data with Apache Hop


October 26th -

Blazing Fast Graphs: Hands-on with Apache Arrow and Neo4j


November 2nd -

Graph EDA Using the Neo4j GDS Client