【发布时间】:2014-10-14 11:53:33
【问题描述】:
我一直在尝试使用 Cypher 加载一组 CSV 文件来构建 VMware 运行状态的视图。我能够执行以下查询:
LOAD CSV WITH HEADERS FROM 'file:///Users/rmorgan/Downloads/All_vm_hierrachy.csv' as csvline
with csvline
where csvline.type = 'VirtualMachine'
MERGE (host:HostSystem { name: csvline.hostid, description: csvline.hosttype })
MERGE (pool:ResourcePool { name: csvline.resourcePool})
MERGE (parent:Folder { name: csvline.parentid, description: csvline.parenttype })
MERGE (vm:VirtualMachine { name: csvline.moid, description: csvline.name })
CREATE (host)-[:HAS_VM]->(vm)
CREATE (vm)-[:HAS_PARENT]->(parent)
CREATE (vm)-[:HAS_RESOURCEPOOL]->(pool);
这会加载有关主机的详细信息,我找到匹配的主机对象,然后使用 SET 添加更多属性。
LOAD CSV WITH HEADERS FROM 'file:///Users/rmorgan/Downloads/All_vm_hierrachy.csv' as csvline
with csvline
where csvline.type = 'HostSystem' and csvline.parenttype = 'ClusterComputeResource'
match (h:HostSystem {name:csvline.moid})
set h.fullName = csvline.name
merge (p:ClusterComputeResource {name: csvline.parentid, type: csvline.parenttype})
CREATE (p)-[:HAS_CHILD]->(h);
两个查询都加载同一个文件,但实例化不同的对象。有没有办法将它们结合起来?我想在里面放一个 CASE 声明:
LOAD CSV WITH HEADERS FROM 'file:///Users/rmorgan/Downloads/All_vm_hierrachy.csv' as csvline
with csvline
CASE csvline.type = 'HostSystem'
// create some objects and add attributes
CASE csvline.type = 'VirtualMachine'
// create some objects and add other attributes
END
// create some common objects / attributes irrespective of the path above
我还想嵌套这些以产生更复杂的执行路径
LOAD CSV WITH HEADERS FROM 'file:///Users/rmorgan/Downloads/All_vm_hierrachy.csv' as csvline
with csvline
CASE csvline.type = 'HostSystem'
// create host object
CASE csvline.parenttype = 'ClusterComputeResource'
// create ClusterComputeResource object, link to host
CASE csvline.parenttype = 'ComputeResource'
// create ComputeResource object, link to host
CASE csvline.type = 'VirtualMachine'
// create some objects and add other attributes
END
// create some common objects / attributes irrespective of the path above
这在 Cypher 中可行吗?这些命令似乎存在,但我无法让它们一起工作。
【问题讨论】:
标签: cypher