【问题标题】:How to pass a parameter to apoc.export.csv.query in python?如何在 python 中将参数传递给 apoc.export.csv.query?
【发布时间】:2020-04-09 09:57:31
【问题描述】:

我正在尝试将数据从 CSV 文件发送到 python 中的 apoc 查询。 我的查询如下所示:

"""

            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

你能帮我解决这个问题吗?

谢谢!

【问题讨论】:

    标签: python neo4j neo4j-apoc


    【解决方案1】:

    我通过如下更改查询解决了这个问题:

     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

    【讨论】:

      猜你喜欢
      • 2017-12-29
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      相关资源
      最近更新 更多