I am trying to send data from a CSV file to apoc query in python. My query looks like follows:
"""
CALL apoc.export.csv.query("MATCH(n:Entity{EntityType:'Configuration_Item', Name:$CI_name}) --(ev:Event)--(c:Common)
optional match (c)--(ev_c:Event)--(en:Entity)
where en.EntityType='Change' or en.EntityType='Interaction'
with en.EntityType as ent,ev_c.Activity as act, en.IDraw as ID, ev.Start as date
order by ev.Start where not ent='null'
return collect(act), ID, ent", "results.csv",{stream:true, params:{CI_Name:$CI_name}})
"""
and the Python code which sends the data is as follows:
with open ('CI.csv','r') as first_file:
csv_f = csv.DictReader(first_file)
for row in csv_f:
counter(row["n.Name"])
However, I am getting the following error
raise CypherError.hydrate(*metadata) neobolt.exceptions.ClientError: Expected parameter(s): CI_name
Could you help me with fixing this?
Thanks!
I solved the problem by changing the query as follows:
query="""
CALL apoc.export.csv.query("MATCH(n:Entity{EntityType:'Configuration_Item'}) --(ev:Event)--(c:Common)
where n.Name='%s'
optional match (c)--(ev_c:Event)--(en:Entity)
where en.EntityType='Change' or en.EntityType='Interaction'
with en.EntityType as ent,ev_c.Activity as act, en.IDraw as ID, ev.Start as date
order by ev.Start where not ent='null'
return collect(act), ID, ent", "/results_test.csv",{stream:true})
"""
query = query % (CI_name)
graph.run(query)
source: https://pythonpedia.com/en/tutorial/5841/neo4j-and-cypher-using-py2neo