我有一个文件,包含大约100万个密码查询。我逐行读取文件,然后使用bolt接口执行它们。有更快的方法吗? 一个查询如下所示:
OPTIONAL MATCH (n:Location{SureName:'9143146669213334465'})
WITH n, n IS NULL as notLoaded
RETURN CASE WHEN notLoaded THEN 'Location: ' + 9143146669213334465 + ' was NOT loaded'
WHEN n.SubType IS NULL THEN 'Rack' + ' is missing'
WHEN n.SubType = 'Rack' THEN 'Attribute: ' + 'Rack' + ' was loaded successfully'
ELSE 'Different value for attribute was loaded: ' + n.SubType +'/'+'Rack'
END AS result
UNION
OPTIONAL MATCH (n:Location{SureName:'9143146669213334465'})
WITH n, n IS NULL as notLoaded
RETURN CASE WHEN notLoaded THEN 'Location: ' + 9143146669213334465 + ' was NOT loaded'
WHEN n.Category IS NULL THEN 'INFRASTRUCTURE' + ' is missing'
WHEN n.Category = 'INFRASTRUCTURE' THEN 'Attribute: ' + 'INFRASTRUCTURE' + ' was loaded successfully'
ELSE 'Different value for attribute was loaded: ' + n.Category +'/'+'Rack'
END AS result
UNION
OPTIONAL MATCH (n:Location{SureName:'9143146669213334465'})
WITH n, n IS NULL as notLoaded
RETURN CASE WHEN notLoaded THEN 'Location: ' + 9143146669213334465 + ' was NOT loaded'
WHEN n.DisplayName IS NULL THEN 'NAME/O2OR_HUIB_04 / O2OR_HUIN_04 - IP DSLAM Type 5 - Model B' + ' is missing'
WHEN n.DisplayName = 'NAME/O2OR_HUIB_04 / O2OR_HUIN_04 - IP DSLAM Type 5 - Model B' THEN 'Attribute: ' + 'NAME/O2OR_HUIB_04 / O2OR_HUIN_04 - IP DSLAM Type 5 - Model B' + ' was loaded successfully'
ELSE 'Different value for attribute was loaded: ' + n.DisplayName +'/'+'Rack'
END AS result
UNION
OPTIONAL MATCH (n:Location{SureName:'9143146669213334465'})
WITH n, n IS NULL as notLoaded
RETURN CASE WHEN notLoaded THEN 'Location: ' + 9143146669213334465 + ' was NOT loaded'
WHEN n.Latitude IS NULL THEN '' + ' is missing'
WHEN n.Latitude = '' THEN 'Attribute: ' + '' + ' was loaded successfully'
ELSE 'Different value for attribute was loaded: ' + n.Latitude +'/'+'Rack'
END AS result
UNION
OPTIONAL MATCH (n:Location{SureName:'9143146669213334465'})
WITH n, n IS NULL as notLoaded
RETURN CASE WHEN notLoaded THEN 'Location: ' + 9143146669213334465 + ' was NOT loaded'
WHEN n.Longitude IS NULL THEN '' + ' is missing'
WHEN n.Longitude = '' THEN 'Attribute: ' + '' + ' was loaded successfully'
ELSE 'Different value for attribute was loaded: ' + n.Longitude +'/'+'Rack'
END AS result
UNION
OPTIONAL MATCH (n:Location{SureName:'9143146669213334465'})
WITH n, n IS NULL as notLoaded
RETURN CASE WHEN notLoaded THEN 'Location: ' + 9143146669213334465 + ' was NOT loaded'
WHEN n.UUID IS NULL THEN '' + ' is missing'
WHEN n.UUID = '' THEN 'Attribute: ' + '' + ' was loaded successfully'
ELSE 'Different value for attribute was loaded: ' + n.UUID +'/'+'Rack'
END AS result
谢谢。
答案 0 :(得分:0)
您可以将它们拆分为批量,然后使用多个线程并行执行批量。
类似:
package com.r39.ws.cns.services.graphSync.neo4j;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.Session;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Example {
public void runQueries(Driver driver) {
int numThreads = 10;
int bulkSize = 1000;
ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
try {
List<String> queries = readNextBulkFromFile(bulkSize);
while (queries.size() > 0) {
Worker worker = new Worker(driver, queries);
executorService.submit(worker);
queries = readNextBulkFromFile(bulkSize);
}
} finally {
executorService.shutdown();
}
}
private List<String> readNextBulkFromFile(int bulkSize) {
// TODO read next bulk of queries
return new ArrayList<>();
}
private static class Worker implements Runnable {
private Driver driver;
private List<String> queries;
public Worker(Driver driver, List<String> queries) {
this.driver = driver;
this.queries = queries;
}
@Override
public void run() {
try (Session session = driver.session()) {
for (String query : queries) {
session.run(query);
}
}
}
}
}