A new brain tease for the apoc lovers

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

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

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.

1 Like

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

2 Likes