question

sean.fennell_168661 avatar image
sean.fennell_168661 asked JoshPerryman commented

Truncate Graph using Java

Is there a way to truncate a graph using Java?

javatruncate
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

sean.fennell_168661 avatar image
sean.fennell_168661 answered JoshPerryman commented

Got this from Jonathan:

https://docs.datastax.com/en/developer/java-driver-dse/1.8/manual/graph/querying/graph_options/


You can run system queries by building a SimpleGraphStatement with the query as a string:


GraphStatement s = new SimpleGraphStatement("system.graph('demo').ifExists().truncate()")
        .setSystemQuery();
dseSession.executeGraph(s);
3 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

JoshPerryman avatar image JoshPerryman commented ·

Ah ha! So they have an unpublished truncate method. I'm going to have to try that out.

I wonder what else is hidden on `system.graph()`.

Thanks for sharing.

0 Likes 0 ·
sean.fennell_168661 avatar image sean.fennell_168661 JoshPerryman commented ·

truncate is a feature of the labs preview version. You won't find it in 6.7 or earlier.

0 Likes 0 ·
JoshPerryman avatar image JoshPerryman sean.fennell_168661 commented ·

Very good to know.

0 Likes 0 ·
sean.fennell_168661 avatar image
sean.fennell_168661 answered sean.fennell_168661 commented

It looks like I can get this effect doing g.V().drop(). Does truncate do more?

1 comment Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

sean.fennell_168661 avatar image sean.fennell_168661 commented ·

it turns out using g.V().drop() with a large enough graph cannot complete. the max-mutations may be exceeded. Using .with("max-mutations", N) can only go as high as the largest integer which may not be large enough to adequately drop all the vertices in a large graph.

0 Likes 0 ·
JoshPerryman avatar image
JoshPerryman answered

Sean, that's what I do. I've got it coded a few different ways.

In my integration tests class, I first make sure that allow_scan is enabled and then run g.V().drop().iterate().


I have a data loader code that uses DSE Analytics with the Java API (and let me tell you, coding Spark with Java is a pain, but I'm in a Java-only shop and Scala wouldn't fly here.). It too uses g.V().drop().iterate(), but it seems to take a long time even with graphs that are just a few GB of data.


I suspect that there's some bookkeeping that DSE Graph is wanting to do in the background which prevent it from just doing a TRUNCATE TABLE operation on each table.

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.