This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 3357af53801fdb9e5f10d54bcccfa24126c46e1e
Author: Stephen Mallette <[email protected]>
AuthorDate: Fri Oct 20 09:22:52 2023 -0400

    Allowed io() to recognize .graphml file extension CTR
---
 CHANGELOG.asciidoc                                 |  1 +
 docs/src/reference/the-traversal.asciidoc          | 28 +++++++++++++++-------
 .../process/traversal/step/sideEffect/IoStep.java  |  2 +-
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6e53144486..d451e6e03d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ This release also includes changes from <<release-3-5-8, 
3.5.8>>.
 
 * Fixed a javadoc comment in `GraphTraversal.not()` method.
 * Allowed `gremlin-driver` to be used over HTTP for experimental purposes.
+* Allowed `io()` to automatically detect ".graphml" as a file extension.
 * Deprecated the `HandshakeInterceptor` in favor of a more generic 
`RequestInterceptor`.
 * Fixed a bug in `StarGraph` where `EdgeFilter` did not remove associated Edge 
Properties.
 * Added translator to the Go GLV.
diff --git a/docs/src/reference/the-traversal.asciidoc 
b/docs/src/reference/the-traversal.asciidoc
index dd1e72c9f8..762f8f47f2 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -1801,6 +1801,10 @@ The version of the formats (e.g. GraphSON 2.0 or 3.0) 
utilized by `io()` is dete
 of TinkerPop. It is also possible for graph providers to override these 
defaults, so consult the documentation of the
 underlying graph database in use for any details on that.
 
+NOTE: The `io()` step will try to automatically detect the appropriate 
`GraphReader` or `GraphWriter` to use based on
+the file extension. If the file has a different extension than the ones 
expected, use `with()` as shown above to set the
+`reader` or `writer` explicitly.
+
 For more advanced configuration of `GraphReader` and `GraphWriter` operations 
(e.g. normalized output for GraphSON,
 disabling class registrations for Gryo, etc.) then construct the appropriate 
`GraphReader` and `GraphWriter` using
 the `build()` method on their implementations and use it directly. It can be 
passed directly to the `IO.reader` or
@@ -1823,16 +1827,18 @@ WARNING: GraphML is a "lossy" format in that it only 
supports primitive values f
 support for `Graph` variables.  It will use `toString` to serialize property 
values outside of those primitives.
 
 WARNING: GraphML as a specification allows for `<edge>` and `<node>` elements 
to appear in any order.  Most software
-that writes GraphML (including as TinkerPop's `GraphMLWriter`) write `<node>` 
elements before `<edge>` elements.  However it
-is important to note that `GraphMLReader` will read this data in order and 
order can matter.  This is because TinkerPop
-does not allow the vertex label to be changed after the vertex has been 
created.  Therefore, if an `<edge>` element
-comes before the `<node>`, the label on the vertex will be ignored.  It is 
thus better to order `<node>` elements in the
-GraphML to appear before all `<edge>` elements if vertex labels are important 
to the graph.
+that writes GraphML (including as TinkerPop's `GraphMLWriter`) write `<node>` 
elements before `<edge>` elements.
+However it is important to note that `GraphMLReader` will read this data in 
order and order can matter.  This is because
+TinkerPop does not allow the vertex label to be changed after the vertex has 
been created.  Therefore, if an `<edge>`
+element comes before the `<node>`, the label on the vertex will be ignored.  
It is thus better to order `<node>`
+elements in the GraphML to appear before all `<edge>` elements if vertex 
labels are important to the graph.
 
 [source,java]
 ----
-g.io("graph.xml").read().iterate()
-g.io("graph.xml").write().iterate()
+// expects a file extension of .xml or .graphml to determine that
+// a GraphML reader/writer should be used.
+g.io("graph.xml").read().iterate();
+g.io("graph.xml").write().iterate();
 ----
 
 NOTE: If using GraphML generated from TinkerPop 2.x, read more about its 
incompatibilities in the
@@ -1852,8 +1858,10 @@ but it is generally best used in two cases:
 
 [source,java]
 ----
-g.io("graph.json").read().iterate()
-g.io("graph.json").write().iterate()
+// expects a file extension of .json to interpret that
+// a GraphSON reader/writer should be used
+g.io("graph.json").read().iterate();
+g.io("graph.json").write().iterate();
 ----
 
 NOTE: Additional documentation for GraphSON can be found in the 
link:https://tinkerpop.apache.org/docs/x.y.z/dev/io/#graphson[IO Reference].
@@ -1877,6 +1885,8 @@ other.  Failure to do so, may result in errors.
 
 [source,java]
 ----
+// expects a file extension of .kryo to interpret that
+// a GraphSON reader/writer should be used
 g.io("graph.kryo").read().iterate()
 g.io("graph.kryo").write().iterate()
 ----
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/IoStep.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/IoStep.java
index dc5f0403c5..3adff7f0b8 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/IoStep.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/IoStep.java
@@ -210,7 +210,7 @@ public class IoStep<S> extends AbstractStep<S,S> implements 
ReadWriting {
             return IO.gryo;
         else if (file.endsWith(".json"))
             return IO.graphson;
-        else if (file.endsWith(".xml"))
+        else if (file.endsWith(".xml") || file.endsWith(".graphml"))
             return IO.graphml;
         else
             throw new IllegalStateException("Could not detect the file format 
- specify the writer explicitly or rename file with a standard extension");

Reply via email to