private long appendNodes( PrintWriter out ) { long nodes = 0; for ( Node node : graph.getNodes() ) { appendNode( out, node ); nodes++; } return nodes; }
private long appendRelationships( PrintWriter out ) { long relationships = 0; for ( Node node : graph.getNodes() ) { for ( Relationship rel : node.getRelationships( Direction.OUTGOING ) ) { appendRelationship( out, rel ); relationships++; } } return relationships; }
public static Map<String,Class> collectPropTypesForNodes(SubGraph graph) { Map<String,Class> propTypes = new LinkedHashMap<>(); for (Node node : graph.getNodes()) { updateKeyTypes(propTypes, node); } return propTypes; } public static Map<String,Class> collectPropTypesForRelationships(SubGraph graph) {
private void exportNodes(PrintWriter out, Reporter reporter, int batchSize) { if (graph.getNodes().iterator().hasNext()) { begin(out); appendNodes(out, batchSize, reporter); commit(out); out.flush(); } }
private long appendNodes(PrintWriter out, int batchSize, Reporter reporter) { long count = 0; for (Node node : graph.getNodes()) { if (count > 0 && count % batchSize == 0) restart(out); count++; appendNode(out, node, reporter); } return count; }
@Override public ProgressInfo dump(SubGraph graph, Writer writer, Reporter reporter, ExportConfig config) throws Exception { Consumer<JsonGenerator> consumer = (jsonGenerator) -> { try { writeNodes(graph.getNodes(), reporter, jsonGenerator, config); writeRels(graph.getRelationships(), reporter, jsonGenerator, config); } catch (IOException e) { throw new RuntimeException(e); } }; return dump(writer, reporter, consumer); }
private void writeKey(XMLStreamWriter writer, SubGraph ops, ExportConfig config) throws Exception { Map<String, Class> keyTypes = new HashMap<>(); for (Node node : ops.getNodes()) { if (node.getLabels().iterator().hasNext()) { keyTypes.put("label", String.class); } updateKeyTypes(keyTypes, node); } boolean useTypes = config.useTypes(); ExportFormat format = config.getFormat(); if (format == ExportFormat.GEPHI) { keyTypes.put("TYPE", String.class); } writeKey(writer, keyTypes, "node", useTypes); keyTypes.clear(); for (Relationship rel : ops.getRelationships()) { keyTypes.put("label", String.class); updateKeyTypes(keyTypes, rel); } if (format == ExportFormat.GEPHI) { keyTypes.put("TYPE", String.class); } writeKey(writer, keyTypes, "edge", useTypes); }
private void writeNodes(SubGraph graph, CSVWriter out, Reporter reporter, Map<String, Class> nodePropTypes, int cols, int batchSize, String delimiter) { String[] row=new String[cols]; int nodes = 0; for (Node node : graph.getNodes()) { row[0]=String.valueOf(node.getId()); row[1]=getLabelsString(node); collectProps(nodePropTypes.keySet(), node, reporter, row, 2, delimiter); out.writeNext(row, applyQuotesToAll); nodes++; if (batchSize==-1 || nodes % batchSize == 0) { reporter.update(nodes, 0, 0); nodes = 0; } } if (nodes>0) { reporter.update(nodes, 0, 0); } }
public void write(SubGraph graph, Writer writer, Reporter reporter, ExportConfig config) throws Exception { XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(writer); writeHeader(xmlWriter); writeKey(xmlWriter, graph, config); writeGraph(xmlWriter); for (Node node : graph.getNodes()) { int props = writeNode(xmlWriter, node, config); reporter.update(1, 0, props); } for (Relationship rel : graph.getRelationships()) { int props = writeRelationship(xmlWriter, rel, config); reporter.update(0, 1, props); } writeFooter(xmlWriter); }
@Procedure @Description("apoc.export.graphml.query(query,file,config) - exports nodes and relationships from the cypher statement as graphml to the provided file") public Stream<ProgressInfo> query(@Name("query") String query, @Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception { ExportConfig c = new ExportConfig(config); Result result = db.execute(query); SubGraph graph = CypherResultSubGraph.from(result, db, c.getRelsInBetween()); String source = String.format("statement: nodes(%d), rels(%d)", Iterables.count(graph.getNodes()), Iterables.count(graph.getRelationships())); return exportGraphML(fileName, source, graph, c); }
@Override protected Iterable<Node> nodes() { return subGraph.getNodes(); }
@Procedure @Description("apoc.export.cypher.query(query,file,config) - exports nodes and relationships from the cypher statement incl. indexes as cypher statements to the provided file") public Stream<DataProgressInfo> query(@Name("query") String query, @Name(value = "file",defaultValue = "") String fileName, @Name(value = "config",defaultValue = "{}") Map<String, Object> config) throws IOException { if (Util.isNullOrEmpty(fileName)) fileName=null; ExportConfig c = new ExportConfig(config); Result result = db.execute(query); SubGraph graph = CypherResultSubGraph.from(result, db, c.getRelsInBetween()); String source = String.format("statement: nodes(%d), rels(%d)", Iterables.count(graph.getNodes()), Iterables.count(graph.getRelationships())); return exportCypher(fileName, source, graph, c, false); }
public static Map<String,Class> collectPropTypesForNodes(SubGraph graph) { Map<String,Class> propTypes = new LinkedHashMap<>(); for (Node node : graph.getNodes()) { updateKeyTypes(propTypes, node); } return propTypes; } public static Map<String,Class> collectPropTypesForRelationships(SubGraph graph) {
private long appendNodes( PrintWriter out ) { long nodes = 0; for ( Node node : graph.getNodes() ) { appendNode( out, node ); nodes++; } return nodes; }
private void appendNodes(Writer writer, Reporter reporter) throws IOException { for (Node node : gdb.getNodes()) { writer.write("("); writer.write(Long.toString(node.getId())); reporter.update(1, 0, formatProperties(writer, node)); writer.write(")\n"); } }
private long appendNodes(PrintWriter out, int batchSize, ProgressReporter reporter) { long count = 0; for (Node node : graph.getNodes()) { if (count > 0 && count % batchSize == 0) restart(out); count++; appendNode(out, node, reporter); } return count; }
private long appendRelationships( PrintWriter out ) { long relationships = 0; for ( Node node : graph.getNodes() ) { for ( Relationship rel : node.getRelationships( Direction.OUTGOING ) ) { appendRelationship( out, rel ); relationships++; } } return relationships; }
private void writeKeyTypes(Writer writer, SubGraph graph) throws IOException { Map<String,Class> keyTypes = new HashMap<>(); for (Node node : graph.getNodes()) { updateKeyTypes(keyTypes, node); } writeKeyTypes(writer, keyTypes, "node"); keyTypes.clear(); for (Relationship rel : graph.getRelationships()) { updateKeyTypes(keyTypes, rel); } writeKeyTypes(writer, keyTypes, "edge"); }
private void writeKeyTypes(XMLStreamWriter writer, SubGraph ops) throws IOException, XMLStreamException { Map<String, Class> keyTypes = new HashMap<>(); for (Node node : ops.getNodes()) { updateKeyTypes(keyTypes, node); } writeKeyTypes(writer, keyTypes, "node"); keyTypes.clear(); for (Relationship rel : ops.getRelationships()) { updateKeyTypes(keyTypes, rel); } writeKeyTypes(writer, keyTypes, "edge"); }
public void write(SubGraph graph, Writer writer, Reporter reporter, Config config) throws IOException { writeHeader(writer); if (config.useTypes()) writeKeyTypes(writer, graph); for (Node node : graph.getNodes()) { int props=writeNode(writer,node); reporter.update(1,0,props); } for (Relationship rel : graph.getRelationships()) { int props=writeRelationship(writer, rel); reporter.update(0,1,props); } writeFooter(writer); } private void writeKeyTypes(Writer writer, SubGraph graph) throws IOException {