use of apoc.export.util.ProgressReporter in project neo4j-apoc-procedures by neo4j-contrib.
the class ExportCSV method exportCsv.
private Stream<ProgressInfo> exportCsv(@Name("file") String fileName, String source, Object data, Map<String, Object> config) throws Exception {
checkWriteAllowed();
ExportConfig c = new ExportConfig(config);
ProgressReporter reporter = new ProgressReporter(null, null, new ProgressInfo(fileName, source, "csv"));
PrintWriter printWriter = getPrintWriter(fileName, null);
CsvFormat exporter = new CsvFormat(db);
if (data instanceof SubGraph)
exporter.dump(((SubGraph) data), printWriter, reporter, c);
if (data instanceof Result)
exporter.dump(((Result) data), printWriter, reporter, c);
return reporter.stream();
}
use of apoc.export.util.ProgressReporter in project neo4j-apoc-procedures by neo4j-contrib.
the class ExportCypher method exportCypher.
private Stream<DataProgressInfo> exportCypher(@Name("file") String fileName, String source, SubGraph graph, ExportConfig c, boolean onlySchema) throws IOException {
if (fileName != null)
checkWriteAllowed();
ProgressInfo progressInfo = new ProgressInfo(fileName, source, "cypher");
progressInfo.batchSize = c.getBatchSize();
ProgressReporter reporter = new ProgressReporter(null, null, progressInfo);
boolean separatedFiles = !onlySchema && c.separateFiles();
FileManagerFactory.ExportCypherFileManager cypherFileManager = FileManagerFactory.createFileManager(fileName, separatedFiles, c.streamStatements());
if (c.streamStatements()) {
Future<Boolean> future = null;
try {
final ArrayBlockingQueue<DataProgressInfo> queue = new ArrayBlockingQueue<>(100);
ProgressReporter reporterWithConsumer = reporter.withConsumer((pi) -> queue.offer(pi == ProgressInfo.EMPTY ? DataProgressInfo.EMPTY : new DataProgressInfo(pi).enrich(cypherFileManager)));
future = Util.inTxFuture(Pools.DEFAULT, db, () -> {
doExport(graph, c, onlySchema, reporterWithConsumer, cypherFileManager);
return true;
});
QueueBasedSpliterator<DataProgressInfo> spliterator = new QueueBasedSpliterator<>(queue, DataProgressInfo.EMPTY, terminationGuard);
return StreamSupport.stream(spliterator, false);
} finally {
Util.waitForFutures(Collections.singletonList(future));
}
} else {
doExport(graph, c, onlySchema, reporter, cypherFileManager);
return reporter.stream().map(DataProgressInfo::new).map((dpi) -> dpi.enrich(cypherFileManager));
}
}
use of apoc.export.util.ProgressReporter in project neo4j-apoc-procedures by neo4j-contrib.
the class ExportGraphML method file.
@Procedure(name = "apoc.import.graphml", mode = Mode.WRITE)
@Description("apoc.import.graphml(file,config) - imports graphml file")
public Stream<ProgressInfo> file(@Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception {
ProgressInfo result = Util.inThread(() -> {
ExportConfig exportConfig = new ExportConfig(config);
ProgressReporter reporter = new ProgressReporter(null, null, new ProgressInfo(fileName, "file", "graphml"));
XmlGraphMLReader graphMLReader = new XmlGraphMLReader(db).reporter(reporter).batchSize(exportConfig.getBatchSize()).relType(exportConfig.defaultRelationshipType()).nodeLabels(exportConfig.readLabels());
if (exportConfig.storeNodeIds())
graphMLReader.storeNodeIds();
graphMLReader.parseXML(FileUtils.readerFor(fileName));
return reporter.getTotal();
});
return Stream.of(result);
}
use of apoc.export.util.ProgressReporter in project neo4j-apoc-procedures by neo4j-contrib.
the class ExportGraphML method exportGraphML.
private Stream<ProgressInfo> exportGraphML(@Name("file") String fileName, String source, SubGraph graph, ExportConfig config) throws Exception, XMLStreamException {
FileUtils.checkReadAllowed(fileName);
ProgressReporter reporter = new ProgressReporter(null, null, new ProgressInfo(fileName, source, "graphml"));
PrintWriter printWriter = getPrintWriter(fileName, null);
XmlGraphMLWriter exporter = new XmlGraphMLWriter();
exporter.write(graph, printWriter, reporter, config);
printWriter.flush();
printWriter.close();
return reporter.stream();
}
Aggregations