我有一个包含10行的小样本数据集,我从csv文件导入,其中包含名为TEvent的节点
LOAD CSV WITH HEADERS FROM "file:///path/to/file.csv" AS rec
CREATE (te: TEvent {l: rec.L, c: rec.C, t: rec.T, x: rec.X, us: rec.US, v: rec.V, d: rec.D, u: rec.U, h: rec.H, lc: rec.L+"_"+rec.C, lch: rec.L+"_"+rec.C+"_"+rec.H})
示例文件内容为
L,C,T,H,V,D,U,X,US
158,26823,2,2,.03,4.33,1.06,3,1
854,26843,2,2,.13,14.04,3.21,5,1.79
130,26861,2,2,.05,3.39,2.52,3,2.48
818,26863,2,2,.13,2.15,1.42,5,1.27
835,26880,2,2,.01,3.74,1.94,4,2.35
873,26902,2,2,20.27,24.65,8.69,12,4.74
187,26903,2,2,.15,.79,.5,4,.56
167,26941,2,2,0,0,0,0,0
147,26942,2,2,.36,.12,.27,2,.22
130,26982,2,2,.17,7.49,7.06,3,6.48
我使用以下Cypher语句创建了时间轴索引
WITH range(2014, 2020) AS years, range(1,12) as months, range(0,23) as hours
FOREACH(year IN years |
MERGE (y:Year {year: year})
FOREACH(month IN months |
CREATE (m:Month {month: month})
MERGE (y)-[:HAS_MONTH]->(m)
FOREACH(day IN (CASE
WHEN month IN [1,3,5,7,8,10,12] THEN range(1,31)
WHEN month = 2 THEN
CASE
WHEN year % 4 <> 0 THEN range(1,28)
WHEN year % 100 <> 0 THEN range(1,29)
WHEN year % 400 <> 0 THEN range(1,29)
ELSE range(1,28)
END
ELSE range(1,30)
END) |
CREATE (d:Day {day: day})
MERGE (m)-[:HAS_DAY]->(d)
FOREACH(hour IN hours |
CREATE (h:Hour {hour: hour})
MERGE (d)-[:HAS_HOUR]->(h)))))
现在,我尝试使用
将创建的TEvent节点中的属性H与时间线中的小时相关联MATCH (te: TEvent)
MATCH (y: Year {year: 2016})-[]->(m: Month {month: 7})-[]->(d: Day {day: 4})- []->(h:Hour {hour: te.h})
MERGE (h)<-[:AT]-(te)
RETURN h;
一致地返回(没有变化,没有记录)。
然后,我使用
创建了3个节点 CREATE (:A {h: 2}), (:A {h:3}), (:A{h:6})
现在,如果我尝试仅更改标签的相同尝试
MATCH (te: A)
MATCH (y: Year {year: 2016})-[]->(m: Month {month: 7})-[]->(d: Day {day: 4})-[]->(h:Hour) WHERE h.hour = te.h
MERGE (h)<-[:AT]-(te)
RETURN h;
返回预期结果
h
"{""month"":7,""hour"":2,""year"":2016,""day"":4}"
"{""month"":7,""hour"":3,""year"":2016,""day"":4}"
"{""month"":7,""hour"":6,""year"":2016,""day"":4}"
我无法理解为什么第一个失败以及如何纠正它。
感谢任何帮助。 TIA。
干杯, 维文
答案 0 :(得分:0)
默认情况下,CSV的单元格都是字符串。
您需要对数字数据使用toInt(row.h)
,并在图表中使用数字。