Как передать параметр в apo c .export.csv.query в python? - PullRequest
0 голосов
/ 09 апреля 2020

Я пытаюсь отправить данные из файла CSV в запрос apo c в python. Мой запрос выглядит следующим образом:

"""

            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}})
           """

и код Python, который отправляет данные, выглядит следующим образом:

with open ('CI.csv','r') as first_file:
csv_f = csv.DictReader(first_file)
for row in csv_f:
    counter(row["n.Name"])

Однако я получаю следующую ошибку

повысить CypherError.hydrate (* метаданные) neobolt.exceptions.ClientError: Ожидаемые параметры: CI_name

Не могли бы вы помочь мне исправить это?

Спасибо!

1 Ответ

0 голосов
/ 11 апреля 2020

Я решил проблему, изменив запрос следующим образом:

 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)             

источник: https://pythonpedia.com/en/tutorial/5841/neo4j-and-cypher-using-py2neo

...