AT

Can GraphBinary be used to save a graph to file?

TTanvir10/12/2023
Can GraphBinary be used to save graph in a file. Any example is welcome.
Solution:
I think you would have to use GraphSON the way @danielcraig23 described. Or if using Java, Gryo. We simply never created GraphBinaryGraphWriter implementations because GraphBinary was built for network serialization. I suppose it could be used that way, but no one has ever really made a request to do that.
Jump to solution
Ddanielcraig2310/16/2023
I use something like this to save a subgraph to file:
Graph modernGraph = TinkerFactory.createModern();

GraphTraversalSource g = AnonymousTraversalSource.traversal().withEmbedded(modernGraph);

final Graph graph = (Graph) g.V()
.hasLabel("person")
.bothE()
.subgraph("subGraph")
.cap("subGraph")
.next();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);
gts.io("personGraph.json").write().iterate();
Graph modernGraph = TinkerFactory.createModern();

GraphTraversalSource g = AnonymousTraversalSource.traversal().withEmbedded(modernGraph);

final Graph graph = (Graph) g.V()
.hasLabel("person")
.bothE()
.subgraph("subGraph")
.cap("subGraph")
.next();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);
gts.io("personGraph.json").write().iterate();
Ddanielcraig2310/16/2023
The resulting json is quite large but it looks something like this
No description
Ddanielcraig2310/16/2023
If you truly want to save your whole graph, you can do a query like the following:
final Graph graph = (Graph) g.E()
.subgraph("subGraph")
.cap("subGraph")
.next();
final Graph graph = (Graph) g.E()
.subgraph("subGraph")
.cap("subGraph")
.next();
instead of the g.V().hasLabel("person").bothE() query For creating a tinkerGraph from the file, I do the following:

GraphTraversalSource g;

private static Graph buildGraph() {
BaseConfiguration configuration = new BaseConfiguration();
configuration.setProperty("gremlin.tinkerGraph.vertexIdManager", "ANY");

return TinkerGraph.open(configuration);
}

@Before
public void init() {
Graph graph = buildGraph();
g = AnonymousTraversalSource.traversal().withEmbedded(graph);
g.io("src/test/resources/testGraph2.json").read().iterate();
}

@Test
public void given_when_then_example_test() {
Long vertexCount = g.V().count().next();
Assert.assertEquals(5, vertexCount)
}

GraphTraversalSource g;

private static Graph buildGraph() {
BaseConfiguration configuration = new BaseConfiguration();
configuration.setProperty("gremlin.tinkerGraph.vertexIdManager", "ANY");

return TinkerGraph.open(configuration);
}

@Before
public void init() {
Graph graph = buildGraph();
g = AnonymousTraversalSource.traversal().withEmbedded(graph);
g.io("src/test/resources/testGraph2.json").read().iterate();
}

@Test
public void given_when_then_example_test() {
Long vertexCount = g.V().count().next();
Assert.assertEquals(5, vertexCount)
}
This is how I write Junit test cases with graph snapshots as test resources The vertexIdManager config is needed to allow Tinkergraph to mimic the rules that Neptune has for vertex ID's but maybe that part's not interesting to you
Solution
Sspmallette10/16/2023
I think you would have to use GraphSON the way @danielcraig23 described. Or if using Java, Gryo. We simply never created GraphBinaryGraphWriter implementations because GraphBinary was built for network serialization. I suppose it could be used that way, but no one has ever really made a request to do that.
TTanvir11/10/2023
Thanks for the answer. Meanwhile tried using Janusgraph and saving graph locally using barkley db.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
How to get cardinality of property?I have a multi property and I want to find out its cardinality. How can I do that? valueMap/elementMinverted regex searchHey, In my vertices I store escaped regexp statements as labels (e.g: 'wh.' which in theory should Debug message spam from tinkerpop server 3.7Right now, when connecting to my local tinkerpop server, I am getting incredible amounts of debug loShould by() Modulator Work For More Types?This works. `gremlin> g.V().out().out().path().by("name") ==>[marko,josh,ripple] ==>[marko,josh,lop]InProcess GraphDB with Gremlin Support? (C# or NodeJS)Hello, is there any in process GraphDB out there in the world? Best would be c# or NodeJS and not JaEasiest Way to Get List Cardinality Properties As a List?What is the easiest way to retrieve the vertex properties that have list cardinality back as a list filter lambda in remote consolehi all, i’m trying to do filter on remote console to neptune server but keep getting MalformedQueryEwithin() and case insensitiveI need to check if a property of a node is in a list of values. How can I do that in a case insensitproject("p").by(__.values("a", "b") Only Outputs Single Property, Bug or Expected?I am curious why this does not behave in the way I expected. Not a problem - solution question. I Use of by()Can somebody explain the usecase of by() function in gremlin in very simple language.@GremlinDSL support in the GremlinLangScriptEngineHi, I recently sent a pull-request into the github ArcadeDB repository to add support binding custoRepeatStep does not appear to respect barriersI was digging into some traversal performance and had something similar to the following: ``` g.V(<Trying to find a Vertex using a variable injected earlier in the traversalI am trying to add a series of vertices and edges to an existing graph. The newly created Vertex wiDoes Gremlin support API for CRUD operations?Currently using g.V() for read and g.addV() for write.Individual Vertex per property or Vertex with grouped propertiesI'm building an identity graph that also stores User profile data - things like email address, phoneFilter out empty resultsgremlin> g.V().hasLabel('metadata').valueMap() ==>{} ==>{} ==>{oncall_roster=[oncall_schedule]} HowQuestion on running queries in windows env.I get an error `RuntimeError: Event loop is closed`, but after troubleshooting I notice that my scriPropertiesStep.hashcode() not always uniqueAs background... We're working with Gremlin (groovy) to write queries against an in memory graph modConditionally update one vertex property when another property matches a certain provided valuehttps://stackoverflow.com/questions/76971695/update-vertex-properties-when-property-a-matches-properTrying to run a local version for a test, what is the correct serializer?Windows machine, local host. I can't find the Running this, https://github.com/bricaud/gremlin-serv