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"])
Thank you for your reply!
As I shared in the previous post, the following python code is sending the parameter for CI_name:
with open ('CI.csv','r') as first_file:
csv_f = csv.DictReader(first_file)
for row in csv_f:
counter(row["n.Name"])
and then the following code is processing it:
def counter(CI_name):
driver = GraphDatabase.driver(uri, auth=("neo4j", "BPI14"))
with driver.session() as session:
session.run(
"""
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}})
"""
)
Thank you for pointing out the parameter name issue! However, even though I changed it, I am still getting the same error. The query is working well in the browser.
I just want to clarify that I already added the following line in the log:
apoc.export.file.enabled=true
Thank you so much! That solved my problem!
I changed the code as following:
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)