org.apache.tinkerpop.gremlin.process.traversal.IO Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.IO.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestIo.java From sqlg with MIT License | 6 votes |
@Test public void g_io_writeXkryoX() throws IOException { loadModern(); final String fileToWrite = TestHelper.generateTempFile(WriteTest.class, "tinkerpop-modern-v3d0", ".kryo").getAbsolutePath().replace('\\', '/'); final File f = new File(fileToWrite); assertThat(f.length() == 0, is(true)); final Traversal<Object,Object> traversal = this.sqlgGraph.traversal() .io(fileToWrite) .with(IO.writer, IO.gryo) .with(IO.registry, SqlgIoRegistryV3.instance()) .write(); printTraversalForm(traversal); traversal.iterate(); assertThat(f.length() > 0, is(true)); }
Example #2
Source File: HadoopIoStep.java From tinkerpop with Apache License 2.0 | 6 votes |
private void configureForRead(final Graph graph) { final String inputFormatClassNameOrKeyword = parameters.get(IO.reader, this::detectReader).get(0); String inputFormatClassName; if (inputFormatClassNameOrKeyword.equals(IO.graphson)) inputFormatClassName = GraphSONInputFormat.class.getName(); else if (inputFormatClassNameOrKeyword.equals(IO.gryo)) inputFormatClassName = GryoInputFormat.class.getName(); else if (inputFormatClassNameOrKeyword.equals(IO.graphml)) throw new IllegalStateException("GraphML is not a supported file format for OLAP"); else inputFormatClassName = inputFormatClassNameOrKeyword; graph.configuration().setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, inputFormatClassName); graph.configuration().setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, file); addParametersToConfiguration(graph); }
Example #3
Source File: HadoopIoStep.java From tinkerpop with Apache License 2.0 | 6 votes |
private void configureForWrite(final Graph graph) { final String outputFormatClassNameOrKeyword = parameters.get(IO.writer, this::detectWriter).get(0); String outputFormatClassName; if (outputFormatClassNameOrKeyword.equals(IO.graphson)) outputFormatClassName = GraphSONOutputFormat.class.getName(); else if (outputFormatClassNameOrKeyword.equals(IO.gryo)) outputFormatClassName = GryoOutputFormat.class.getName(); else if (outputFormatClassNameOrKeyword.equals(IO.graphml)) throw new IllegalStateException("GraphML is not a supported file format for OLAP"); else outputFormatClassName = outputFormatClassNameOrKeyword; graph.configuration().setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, outputFormatClassName); graph.configuration().setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, file); addParametersToConfiguration(graph); }
Example #4
Source File: HadoopIoStep.java From tinkerpop with Apache License 2.0 | 6 votes |
/** * Overwrites all configurations from values passed using {@link GraphTraversal#with(String, Object)}. */ private void addParametersToConfiguration(final Graph graph) { parameters.getRaw(IO.writer, IO.writer, IO.registry).entrySet().forEach(kv -> { if (kv.getValue().size() == 1) graph.configuration().setProperty(kv.getKey().toString(), kv.getValue().get(0)); else { // reset the default configuration with the first option then add to that for List options for (int ix = 0; ix < kv.getValue().size(); ix++) { if (ix == 0) graph.configuration().setProperty(kv.getKey().toString(), kv.getValue().get(ix)); else graph.configuration().addProperty(kv.getKey().toString(), kv.getValue().get(ix)); } } }); }
Example #5
Source File: TestIo.java From sqlg with MIT License | 6 votes |
@Test public void g_io_writeXjsonX() throws IOException { loadModern(); final String fileToWrite = TestHelper.generateTempFile(WriteTest.class,"tinkerpop-modern-v3d0", ".json").getAbsolutePath().replace('\\', '/'); final File f = new File(fileToWrite); assertThat(f.length() == 0, is(true)); final Traversal<Object,Object> traversal = this.sqlgGraph.traversal() .io(fileToWrite) .with(IO.writer, IO.graphson) .with(IO.registry, SqlgIoRegistryV3.instance()) .write(); printTraversalForm(traversal); traversal.iterate(); assertThat(f.length() > 0, is(true)); }
Example #6
Source File: TestIo.java From sqlg with MIT License | 6 votes |
@Test public void g_io_write_withXwriter_graphsonX() throws IOException { loadModern(); final String fileToWrite = TestHelper.generateTempFile(WriteTest.class, "tinkerpop-modern-v3d0", ".json").getAbsolutePath().replace('\\', '/'); final File f = new File(fileToWrite); assertThat(f.length() == 0, is(true)); final Traversal<Object, Object> traversal = this.sqlgGraph.traversal().io(fileToWrite) .with(IO.writer, IO.graphson) .with(IO.registry, SqlgIoRegistryV3.instance()) .write(); printTraversalForm(traversal); traversal.iterate(); assertThat(f.length() > 0, is(true)); }
Example #7
Source File: TinkerGraphIoStepTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldWriteReadWithCustomIoRegistryGraphSON() throws Exception { final UUID uuid = UUID.randomUUID(); g.addV("person").property("name","stephen").property("custom", new CustomId("a", uuid)).iterate(); final File file = TestHelper.generateTempFile(TinkerGraphIoStepTest.class, "shouldWriteReadWithCustomIoRegistryGraphSON", ".json"); g.io(file.getAbsolutePath()).with(IO.registry, CustomId.CustomIdIoRegistry.class.getName()).write().iterate(); final Graph emptyGraph = TinkerGraph.open(); final GraphTraversalSource emptyG = emptyGraph.traversal(); try { emptyG.io(file.getAbsolutePath()).read().iterate(); fail("Can't read without a registry"); } catch (Exception ignored) { // do nothing } emptyG.io(file.getAbsolutePath()).with(IO.registry, CustomId.CustomIdIoRegistry.instance()).read().iterate(); assertEquals(1, emptyG.V().has("custom", new CustomId("a", uuid)).count().next().intValue()); }
Example #8
Source File: TinkerGraphIoStepTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldWriteReadWithCustomIoRegistryGryo() throws Exception { final UUID uuid = UUID.randomUUID(); g.addV("person").property("name","stephen").property("custom", new CustomId("a", uuid)).iterate(); final File file = TestHelper.generateTempFile(TinkerGraphIoStepTest.class, "shouldWriteReadWithCustomIoRegistryGryo", ".kryo"); g.io(file.getAbsolutePath()).with(IO.registry, CustomId.CustomIdIoRegistry.class.getName()).write().iterate(); final Graph emptyGraph = TinkerGraph.open(); final GraphTraversalSource emptyG = emptyGraph.traversal(); try { emptyG.io(file.getAbsolutePath()).read().iterate(); fail("Can't read without a registry"); } catch (Exception ignored) { // do nothing } emptyG.io(file.getAbsolutePath()).with(IO.registry, CustomId.CustomIdIoRegistry.instance()).read().iterate(); assertEquals(1, emptyG.V().has("custom", new CustomId("a", uuid)).count().next().intValue()); }
Example #9
Source File: HugeGraphWriteTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Override public Traversal<Object,Object> get_g_io_writeXkryoX( final String fileToWrite) throws IOException { return g.io(fileToWrite) .with(IO.registry, HugeGraphIoRegistry.instance()) .write(); }
Example #10
Source File: TestIo.java From sqlg with MIT License | 5 votes |
@Test public void g_io_write_withXwrite_gryoX() throws IOException { loadModern(); final String fileToWrite = TestHelper.generateTempFile(WriteTest.class, "tinkerpop-modern-v3d0", ".kryo").getAbsolutePath().replace('\\', '/'); final File f = new File(fileToWrite); assertThat(f.length() == 0, is(true)); final Traversal<Object, Object> traversal = this.sqlgGraph.traversal().io(fileToWrite) .with(IO.writer, IO.gryo) .with(IO.registry, SqlgIoRegistryV3.instance()) .write(); printTraversalForm(traversal); traversal.iterate(); assertThat(f.length() > 0, is(true)); }
Example #11
Source File: IoStep.java From tinkerpop with Apache License 2.0 | 5 votes |
protected List<IoRegistry> detectRegistries() { final List<Object> k = parameters.get(IO.registry, null); return k.stream().map(cn -> { try { if (cn instanceof IoRegistry) return (IoRegistry) cn; else { final Class<?> clazz = Class.forName(cn.toString()); return (IoRegistry) clazz.getMethod("instance").invoke(null); } } catch (Exception ex) { throw new IllegalStateException(ex); } }).collect(Collectors.toList()); }
Example #12
Source File: IoStep.java From tinkerpop with Apache License 2.0 | 5 votes |
protected String detectFileType() { if (file.endsWith(".kryo")) return IO.gryo; else if (file.endsWith(".json")) return IO.graphson; else if (file.endsWith(".xml")) return IO.graphml; else throw new IllegalStateException("Could not detect the file format - specify the writer explicitly or rename file with a standard extension"); }
Example #13
Source File: HugeGraphWriteTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Override public Traversal<Object, Object> get_g_io_write_withXwriter_gryoX( String fileToWrite) throws IOException { return g.io(fileToWrite) .with(IO.writer, IO.gryo) .with(IO.registry, HugeGraphIoRegistry.instance()) .write(); }
Example #14
Source File: ReadTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Traversal<Object,Object> get_g_io_read_withXreader_gryoX(final String fileToRead) throws IOException { return g.io(fileToRead).with(IO.reader, IO.gryo).read(); }
Example #15
Source File: ReadTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Traversal<Object,Object> get_g_io_read_withXreader_graphsonX(final String fileToRead) throws IOException { return g.io(fileToRead).with(IO.reader, IO.graphson).read(); }
Example #16
Source File: ReadTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Traversal<Object,Object> get_g_io_read_withXreader_graphmlX(final String fileToRead) throws IOException { return g.io(fileToRead).with(IO.reader, IO.graphml).read(); }
Example #17
Source File: WriteTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Traversal<Object,Object> get_g_io_write_withXwriter_graphmlX(final String fileToWrite) throws IOException { return g.io(fileToWrite).with(IO.writer, IO.graphml).write(); }
Example #18
Source File: WriteTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Traversal<Object,Object> get_g_io_write_withXwriter_graphsonX(final String fileToWrite) throws IOException { return g.io(fileToWrite).with(IO.writer, IO.graphson).write(); }
Example #19
Source File: WriteTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public Traversal<Object,Object> get_g_io_write_withXwriter_gryoX(final String fileToWrite) throws IOException { return g.io(fileToWrite).with(IO.writer, IO.gryo).write(); }