You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/06/03 20:40:21 UTC

[tinkerpop] branch master updated (66fc4e2 -> a8a004a)

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

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


    from 66fc4e2  Merge branch 'tp34'
     new c52d264  TINKERPOP-1935 Improved error message when GraphML used with multi-properties CTR
     new 720e816  Merge branch 'tp33' into tp34
     new a8a004a  Merge branch 'tp34'

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGELOG.asciidoc                                     |  1 +
 .../gremlin/structure/io/graphml/GraphMLWriter.java    | 18 ++++++++++++++++--
 .../apache/tinkerpop/gremlin/structure/io/IoTest.java  | 14 ++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)


[tinkerpop] 01/03: TINKERPOP-1935 Improved error message when GraphML used with multi-properties CTR

Posted by sp...@apache.org.
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 c52d2649d64cc88786be55cf761fdd303bdca2d6
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Mon Jun 3 16:11:31 2019 -0400

    TINKERPOP-1935 Improved error message when GraphML used with multi-properties CTR
---
 CHANGELOG.asciidoc                                      |  1 +
 .../gremlin/structure/io/graphml/GraphMLWriter.java     | 17 +++++++++++++++--
 .../apache/tinkerpop/gremlin/structure/io/IoTest.java   | 14 ++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 9cc28dc..232312d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -24,6 +24,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 === TinkerPop 3.3.8 (Release Date: NOT OFFICIALLY RELEASED YET)
 
 * Bump to Groovy 2.4.17.
+* Improved error messaging when an attempt is made to serialize multi-properties to GraphML.
 
 [[release-3-3-7]]
 === TinkerPop 3.3.7 (Release Date: May 28, 2019)
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
index e2a0952..21fe416 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
@@ -310,9 +310,11 @@ public final class GraphMLWriter implements GraphWriter {
             for (String key : keys) {
                 writer.writeStartElement(GraphMLTokens.DATA);
                 writer.writeAttribute(GraphMLTokens.KEY, key);
+                final VertexProperty<Object> currentValue = getCheckedVertexProperty(vertex, key);
+
                 // technically there can't be a null here as gremlin structure forbids that occurrence even if Graph
                 // implementations support it, but out to empty string just in case.
-                writer.writeCharacters(vertex.property(key).orElse("").toString());
+                writer.writeCharacters(currentValue.orElse("").toString());
                 writer.writeEndElement();
             }
             writer.writeEndElement();
@@ -388,7 +390,9 @@ public final class GraphMLWriter implements GraphWriter {
             final Vertex vertex = vertices.next();
             for (String key : vertex.keys()) {
                 if (!vertexKeyTypes.containsKey(key)) {
-                    vertexKeyTypes.put(key, GraphMLWriter.getStringType(vertex.property(key).value()));
+                    final VertexProperty<Object> currentValue = getCheckedVertexProperty(vertex, key);
+
+                    vertexKeyTypes.put(key, GraphMLWriter.getStringType(currentValue.value()));
                 }
             }
         }
@@ -396,6 +400,15 @@ public final class GraphMLWriter implements GraphWriter {
         return vertexKeyTypes;
     }
 
+    private static VertexProperty<Object> getCheckedVertexProperty(Vertex vertex, String key) {
+        final Iterator<VertexProperty<Object>> properties = vertex.properties(key);
+        final VertexProperty<Object> currentValue = properties.next();
+
+        if (properties.hasNext())
+            throw new IllegalStateException("Multiple properties exists for the provided key: [%s] and multi-properties are not directly supported by GraphML format");
+        return currentValue;
+    }
+
     private static Map<String, String> determineEdgeTypes(final Graph graph) {
         final Map<String, String> edgeKeyTypes = new HashMap<>();
         final Iterator<Edge> edges = graph.edges();
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
index 0221555..050be08 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
@@ -92,8 +92,10 @@ import static org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexProper
 import static org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures.FEATURE_STRING_VALUES;
 import static org.apache.tinkerpop.gremlin.structure.io.IoCore.graphson;
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.StringContains.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeThat;
@@ -245,6 +247,18 @@ public class IoTest {
             }
         }
 
+        @Test
+        @LoadGraphWith(LoadGraphWith.GraphData.CREW)
+        public void shouldNotWriteGraphMLFromGraphWithMultiProperties() throws Exception {
+            try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
+                final GraphMLWriter w = GraphMLWriter.build().create();
+                w.writeGraph(bos, graph);
+                fail("Should not be able to write multi-properties to GraphML");
+            } catch (IllegalStateException iae) {
+                assertThat(iae.getMessage(), containsString("multi-properties are not directly supported by GraphML format"));
+            }
+        }
+
         /**
          * Note: this is only a very lightweight test of writer/reader encoding. It is known that there are characters
          * which, when written by GraphMLWriter, cause parse errors for GraphMLReader. However, this happens uncommonly


[tinkerpop] 02/03: Merge branch 'tp33' into tp34

Posted by sp...@apache.org.
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 720e8166400c33570c26fda5536c12b242e2602f
Merge: efe140f c52d264
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Mon Jun 3 16:40:02 2019 -0400

    Merge branch 'tp33' into tp34

 CHANGELOG.asciidoc                                     |  1 +
 .../gremlin/structure/io/graphml/GraphMLWriter.java    | 18 ++++++++++++++++--
 .../apache/tinkerpop/gremlin/structure/io/IoTest.java  | 14 ++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --cc gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
index cc66d37,21fe416..59812f0
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
@@@ -329,14 -309,12 +329,17 @@@ public final class GraphMLWriter implem
  
              for (String key : keys) {
                  writer.writeStartElement(GraphMLTokens.DATA);
 -                writer.writeAttribute(GraphMLTokens.KEY, key);
 +                if (intersection != null && intersection.contains(key)) {
 +                    writer.writeAttribute(GraphMLTokens.KEY, key.concat(GraphMLTokens.VERTEX_SUFFIX));
 +                } else {
 +                    writer.writeAttribute(GraphMLTokens.KEY, key);
 +                }
++
+                 final VertexProperty<Object> currentValue = getCheckedVertexProperty(vertex, key);
+ 
                  // technically there can't be a null here as gremlin structure forbids that occurrence even if Graph
                  // implementations support it, but out to empty string just in case.
-                 writer.writeCharacters(vertex.property(key).orElse("").toString());
+                 writer.writeCharacters(currentValue.orElse("").toString());
                  writer.writeEndElement();
              }
              writer.writeEndElement();


[tinkerpop] 03/03: Merge branch 'tp34'

Posted by sp...@apache.org.
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 a8a004a8441c4819120ce490a6403f57e862bedc
Merge: 66fc4e2 720e816
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Mon Jun 3 16:40:09 2019 -0400

    Merge branch 'tp34'

 CHANGELOG.asciidoc                                     |  1 +
 .../gremlin/structure/io/graphml/GraphMLWriter.java    | 18 ++++++++++++++++--
 .../apache/tinkerpop/gremlin/structure/io/IoTest.java  | 14 ++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)