It seems no matter how I'm carving this up I get errors typically 'Query cannot conclude with CALL'
I'm not sure exactly what in this cypher would be properly segmented into returning items and action on each iteration, as it is a bit hybrid. The contents are about 100,000 rows, and it hangs when trying to import, so I'm trying to see how I can batch it. Do I somehow need to break this up into a smaller cypher to work within periodic.iterate, or can I somehow batch this entire procedure?
here's the cypher:
MATCH (cdl:Crmdataload {name:'CommitCRM'})
OPTIONAL MATCH (lc:Charge)
WITH max(lc.createdon) as lastnewcharge,timestamp() AS howsoonisnow
WITH apoc.date.format(coalesce(lastnewcharge,0),'ms','yyyy-MM-dd HH:mm:ss.sss','CST') AS lastnewcharge,howsoonisnow
CALL apoc.load.driver('com.extendedsystems.jdbc.advantage.ADSDriver')
call apoc.load.jdbc('jdbc:extendedsystems:advantage://commitcrm:6262;catalog=//commitcrm/CommitCRM/Db','SELECT RECID,SLIPDATE,WORKERID,CARDID,TICKETID,ITEMID,DESCRIPTION
,HOURSAMOUNT,QUANTITY,PRICE,TOTAL,CREATEDATE,UPDATEDATE,UPDATEUSER,CREATEUSER,USER1,CONTACTID,BCRECID,BCCODE,FROMTIME,TOTIME from slips WHERE CREATEDATE > \''+lastnewcharge+'\'') YIELD row
MERGE (c:Charge {recid:row.RECID})
SET c.date=row.SLIPDATE,c.description=row.DESCRIPTION,c.hours=row.HOURSAMOUNT,c.quantity=row.QUANTITY,c.price=row.PRICE,c.createdon=row.CREATEDATE,c.updatedon=row.UPDATEDATE,c.fromtime=row.FROMTIME,c.totime=row.TOTIME
WITH row,c,howsoonisnow
OPTIONAL MATCH (e:Crmemployee {acctrecid:row.WORKERID})
//OPTIONAL MATCH (a:Company {acctrecid:row.CARDID})
OPTIONAL MATCH (t:Ticket {recid:row.TICKETID})
OPTIONAL MATCH (i:Crmitem {recid:row.ITEMID})
OPTIONAL MATCH (uu:Crmemployee {acctrecid:row.UPDATEUSER})
OPTIONAL MATCH (cu:Crmemployee {acctrecid:row.CREATEUSER})
OPTIONAL MATCH (ct:Contact {acctrecid:row.CONTACTID})
OPTIONAL MATCH (bc:Contract {recid:row.BCRECID})
FOREACH (ignoreMe in CASE WHEN not(exists(e.acctrecid)) THEN [1] ELSE [] END | MERGE (c)-[:ENTRY_FOR]->(e))
//FOREACH (ignoreMe in CASE WHEN not(exists(e.acctrecid)) THEN [1] ELSE [] END | MERGE (c)-[:ENTRY_FOR_ACCOUNT]->(a))
FOREACH (ignoreMe in CASE WHEN not(exists(t.recid)) THEN [1] ELSE [] END | MERGE (c)-[:PART_OF_TICKET]->(t))
FOREACH (ignoreMe in CASE WHEN not(exists(i.recid)) THEN [1] ELSE [] END | MERGE (c)-[:INCLUDES_ITEM]->(i))
FOREACH (ignoreMe in CASE WHEN not(exists(uu.acctrecid)) THEN [1] ELSE [] END | MERGE (c)-[:LAST_UPDATED_BY]->(uu))
FOREACH (ignoreMe in CASE WHEN not(exists(cu.acctrecid)) THEN [1] ELSE [] END | MERGE (c)-[:CREATED_BY]->(cu))
FOREACH (ignoreMe in CASE WHEN not(exists(ct.recid)) THEN [1] ELSE [] END | MERGE (c)-[:CLIENT_CONTACT]->(ct))
FOREACH (ignoreMe in CASE WHEN not(exists(bc.recid)) THEN [1] ELSE [] END | MERGE (c)-[:UNDER_CONTRACT]->(bc))
WITH howsoonisnow,c
MATCH (cdl:Crmdataload {name:'CommitCRM'})
// SET the timestamp for when this :Charge update procedure last ran
SET cdl.lastnewcharge=howsoonisnow
RETURN count(*)