Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-24-2020 08:46 AM
Is there a way to use multiple where clauses as seen below? Currently it will run and process the first group of MERGE clauses after the first WITH but the second and third MERGE groups after the other WITH Clauses do not run. I assume it is because the first WITH clauses has a following WHERE NOT Clause that filters out what the second and thirt WITH Clauses are requesting?
Anyone know of a way to run this all in one still in one statement? I am running this through Kettle, and for my purpose it must be in a single statement.
LOAD CSV WITH HEADERS FROM 'file:///detail.csv' AS row
MERGE (gpath:GranPath {circPathInstID:row.CircPathInstID})
ON CREATE SET
gpath.circPathHumID = row.CircPathHumID,
gpath.revision = row.CircPathRevNbr,
gpath.status = row.Status,
gpath.category = row.Type,
gpath.productService = row.ProductService,
gpath.bandwidth = row.Bandwidth,
gpath.bps = row.BpsUsed
ON MATCH SET
gpath.circPathHumID = row.CircPathHumID,
gpath.revision = row.CircPathRevNbr,
gpath.status = row.Status,
gpath.category = row.Type,
gpath.productService = row.ProductService,
gpath.bandwidth = row.Bandwidth,
gpath.bps = row.BpsUsed
WITH row, gpath
WHERE NOT gpath.category IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS','ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT']
MERGE (upath:UnmNonEthPath {name:row.CircPathHumID, status:row.CurrentPending})
MERGE (upath)-[:DATA_SOURCE {source:"GRANITE"}]->(gpath)
WITH row, gpath
WHERE gpath.category IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS']
MERGE (usvc:UnmService {name:row.CircPathHumID, status:row.CurrentPending})
MERGE (usvc)-[:DATA_SOURCE {source:"GRANITE"}]->(gpath)
WITH row, gpath
WHERE gpath.category IN ['ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT']
MERGE (uxp:UnmTransport {name:row.CircPathHumID, status:row.CurrentPending})
MERGE (uxp)-[:DATA_SOURCE {source:"GRANITE"}]->(gpath)
07-24-2020 10:44 AM
You can use FOREACH:
WITH row, gpath
FOREACH(ignoreMe IN CASE WHEN NOT row.Type IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS','ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] THEN [1] ELSE [] END |
MERGE (upath:UnmNonEthPath {name:row.CircPathHumID, status:row.CurrentPending})
MERGE (upath)-[:DATA_SOURCE {source:"GRANITE"}]->(gpath)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS'] THEN [1] ELSE [] END |
MERGE (usvc:UnmService {name:row.CircPathHumID, status:row.CurrentPending})
MERGE (usvc)-[:DATA_SOURCE {source:"GRANITE"}]->(gpath)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] THEN [1] ELSE [] END |
MERGE (uxp:UnmTransport {name:row.CircPathHumID, status:row.CurrentPending})
MERGE (uxp)-[:DATA_SOURCE {source:"GRANITE"}]->(gpath)
)
;
07-24-2020 12:09 PM
ameyasoft, that worked great! I hope you can help once more. I tried to use that for another similar one but slightly more complex that involves further MATCH clauses and Neo does not like the use of MATCH inside FOREACH it appears.. do you have any suggestions for this?
UNWIND $rows AS row
MATCH (port:GranPort {portInstID:row.PortInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(uport:UnmPort)-[:PORT_LOGICAL_INTERFACE]-(lif:UnmLogicalInterface {status:row.PathCurPend})
MATCH (path:GranPath {circPathInstID:row.CircPathInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(upath)
WITH row, lif
FOREACH(ignoreMe IN CASE WHEN NOT row.Type IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS','ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] THEN [1] ELSE [] END |
MERGE (lif)-[:LOGICAL_INTERFACE_ASSIGNED {source:"GRANITE"}]->(upath)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS'] THEN [1] ELSE [] END |
MERGE (sif:UnmSubInterface {name:lif.name + ".0", status:row.PathCurPend})
MERGE (lif)-[:LOGICAL_IF_SUB_IF {source:"GRANITE"}]->(sif)
MERGE (upath)-[:SERVICE_SUB_IF {source:"GRANITE"}]->(sif)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] and row.CHAN_INST_ID IS NOT NULL THEN [1] ELSE [] END |
MATCH (gchan:GranChan {chanInstID:row.ChanInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(uchan:UnmChan)
MATCH (cpath:GranPath {circPathInstID:row.MemberPathInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(ucpath)
MERGE (lif)-[:LOGICAL_INTERFACE_ASSIGNED {source:"GRANITE"}]->(upath)
MERGE (sif:UnmSubInterface {name:lif.name + "." + row.ChanName, status:row.ChanCurPend})
MERGE (lif)-[:LOGICAL_IF_SUB_IF {source:"GRANITE"}]->(sif)
MERGE (uchan)-[:CHAN_SUB_IF {source:"GRANITE"}]->(sif)
MERGE (ucpath)-[:SERVICE_SUB_IF {source:"GRANITE"}]->(sif)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] AND row.CHAN_INST_ID IS NULL THEN [1] ELSE [] END |
MATCH (port:GranPort {portInstID:row.PortInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(uport)-[PORT_LOGICAL_INTERFACE]-(lif:UnmLogicalInterface {status:row.PathCurPend})
MATCH (path:GranPath {circPathInstID:row.CircPathInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(upath)
MERGE (lif)-[:LOGICAL_INTERFACE_ASSIGNED {source:"GRANITE"}]->(upath)
)
07-24-2020 01:09 PM
Try this:
WITH row
MATCH (port:GranPort {portInstID:row.PortInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(uport:UnmPort)-[:PORT_LOGICAL_INTERFACE]-(lif:UnmLogicalInterface {status:row.PathCurPend})
MATCH (path:GranPath {circPathInstID:row.CircPathInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(upath)
MATCH (gchan:GranChan {chanInstID:row.ChanInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(uchan:UnmChan)
MATCH (cpath:GranPath {circPathInstID:row.MemberPathInstID})-[:DATA_SOURCE {source:"GRANITE"}]-(ucpath)
FOREACH(ignoreMe IN CASE WHEN NOT row.Type IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS','ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] THEN [1] ELSE [] END |
MERGE (lif)-[:LOGICAL_INTERFACE_ASSIGNED {source:"GRANITE"}]->(upath)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET','PRI TRUNKS','CUSTOMER SIP TRUNKS'] THEN [1] ELSE [] END |
MERGE (sif:UnmSubInterface {name:lif.name + ".0", status:row.PathCurPend})
MERGE (lif)-[:LOGICAL_IF_SUB_IF {source:"GRANITE"}]->(sif)
MERGE (upath)-[:SERVICE_SUB_IF {source:"GRANITE"}]->(sif)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] and row.CHAN_INST_ID IS NOT NULL THEN [1] ELSE [] END |
MERGE (lif)-[:LOGICAL_INTERFACE_ASSIGNED {source:"GRANITE"}]->(upath)
MERGE (sif:UnmSubInterface {name:lif.name + "." + row.ChanName, status:row.ChanCurPend})
MERGE (lif)-[:LOGICAL_IF_SUB_IF {source:"GRANITE"}]->(sif)
MERGE (uchan)-[:CHAN_SUB_IF {source:"GRANITE"}]->(sif)
MERGE (ucpath)-[:SERVICE_SUB_IF {source:"GRANITE"}]->(sif)
)
FOREACH(ignoreMe IN CASE WHEN row.Type IN ['ETHERNET TRANSPORT', 'EPON ETHERNET TRANSPORT'] AND row.CHAN_INST_ID IS NULL THEN [1] ELSE [] END |
MERGE (lif)-[:LOGICAL_INTERFACE_ASSIGNED {source:"GRANITE"}]->(upath)
)
All the sessions of the conference are now available online