Search in sources :

Example 1 with StringDeserialization

use of org.neo4j.internal.batchimport.input.csv.StringDeserialization in project neo4j by neo4j.

the class CsvOutput method consume.

private void consume(String name, InputIterator entities, Header header, Deserializer deserializer) throws IOException {
    try (PrintStream out = file(name + "header.csv")) {
        serialize(out, header);
    }
    try {
        int threads = Runtime.getRuntime().availableProcessors();
        ExecutorService executor = Executors.newFixedThreadPool(threads);
        for (int i = 0; i < threads; i++) {
            int id = i;
            executor.submit((Callable<Void>) () -> {
                StringDeserialization deserialization = new StringDeserialization(config);
                try (PrintStream out = file(name + "-" + id + ".csv");
                    InputChunk chunk = entities.newChunk()) {
                    InputEntity entity = new InputEntity();
                    while (entities.next(chunk)) {
                        while (chunk.next(entity)) {
                            out.println(deserializer.apply(entity, deserialization, header));
                        }
                    }
                }
                return null;
            });
        }
        executor.shutdown();
        executor.awaitTermination(10, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException(e);
    }
}
Also used : PrintStream(java.io.PrintStream) StringDeserialization(org.neo4j.internal.batchimport.input.csv.StringDeserialization) ExecutorService(java.util.concurrent.ExecutorService) InputEntity(org.neo4j.internal.batchimport.input.InputEntity) InputChunk(org.neo4j.internal.batchimport.input.InputChunk) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ExecutorService (java.util.concurrent.ExecutorService)1 InputChunk (org.neo4j.internal.batchimport.input.InputChunk)1 InputEntity (org.neo4j.internal.batchimport.input.InputEntity)1 StringDeserialization (org.neo4j.internal.batchimport.input.csv.StringDeserialization)1