Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-08-2020 08:52 AM
Hello,
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,
Pinar.
Solved! Go to Solution.
04-10-2020 11:46 AM
I guess the problem is how to pass parameter CI_name from function parameter to the cypher query. Could you please try referring the below link
04-09-2020 06:21 AM
Hi @pinartyilmaz,
Welcome to the community!!
How are you passing parameter value for parameter variable CI_name in your code?
04-09-2020 09:16 AM
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}})
"""
)
04-10-2020 12:12 AM
04-10-2020 07:33 AM
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
04-10-2020 10:34 AM
Insert a forward slash before the file name:
return collect(act), ID, ent", "/results.csv"
04-10-2020 11:15 AM
Hi, thank you for your comment! I tried but it did not solve my problem, I am still getting the same error.
04-10-2020 11:46 AM
I guess the problem is how to pass parameter CI_name from function parameter to the cypher query. Could you please try referring the below link
04-11-2020 03:08 AM
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)
All the sessions of the conference are now available online