Search in sources :

Example 1 with ProgressReporter

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();
}
Also used : ExportConfig(apoc.export.util.ExportConfig) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter) SubGraph(org.neo4j.cypher.export.SubGraph) NodesAndRelsSubGraph(apoc.export.util.NodesAndRelsSubGraph) DatabaseSubGraph(org.neo4j.cypher.export.DatabaseSubGraph) PrintWriter(java.io.PrintWriter) FileUtils.getPrintWriter(apoc.util.FileUtils.getPrintWriter) Result(org.neo4j.graphdb.Result)

Example 2 with ProgressReporter

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));
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) QueueBasedSpliterator(apoc.util.QueueBasedSpliterator) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter)

Example 3 with ProgressReporter

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);
}
Also used : ExportConfig(apoc.export.util.ExportConfig) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter)

Example 4 with ProgressReporter

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();
}
Also used : ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter) PrintWriter(java.io.PrintWriter) FileUtils.getPrintWriter(apoc.util.FileUtils.getPrintWriter)

Aggregations

ProgressReporter (apoc.export.util.ProgressReporter)4 ProgressInfo (apoc.result.ProgressInfo)4 ExportConfig (apoc.export.util.ExportConfig)2 FileUtils.getPrintWriter (apoc.util.FileUtils.getPrintWriter)2 PrintWriter (java.io.PrintWriter)2 NodesAndRelsSubGraph (apoc.export.util.NodesAndRelsSubGraph)1 QueueBasedSpliterator (apoc.util.QueueBasedSpliterator)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 DatabaseSubGraph (org.neo4j.cypher.export.DatabaseSubGraph)1 SubGraph (org.neo4j.cypher.export.SubGraph)1 Result (org.neo4j.graphdb.Result)1