tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [2/3] tinkerpop git commit: Merge remote-tracking branch 'origin/TINKERPOP-1278' into TINKERPOP-1278
Date Tue, 23 Aug 2016 18:12:28 GMT
Merge remote-tracking branch 'origin/TINKERPOP-1278' into TINKERPOP-1278

Conflicts:
	gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/41bb1f73
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/41bb1f73
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/41bb1f73

Branch: refs/heads/TINKERPOP-1278
Commit: 41bb1f73bf08704bb10ad50f7e26e6ef830be80c
Parents: f7b9b1a 1cdf2d9
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Tue Aug 23 14:01:19 2016 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Tue Aug 23 14:01:19 2016 -0400

----------------------------------------------------------------------
 .../structure/io/graphson/GraphSONModule.java   |  59 +++--
 .../structure/io/graphson/GraphSONTokens.java   |  12 +-
 .../GraphSONTraversalSerializersV2d0.java       | 245 +++++++------------
 .../process/traversal/step/filter/IsTest.java   |   4 +-
 .../io/graphson/GraphSONTranslator.java         |   6 +-
 5 files changed, 143 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41bb1f73/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index e332834,0265cd2..b7678fc
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@@ -60,9 -60,9 +62,10 @@@ import java.time.Year
  import java.time.YearMonth;
  import java.time.ZoneOffset;
  import java.time.ZonedDateTime;
 +import java.util.Collections;
  import java.util.LinkedHashMap;
  import java.util.Map;
+ import java.util.stream.Stream;
  
  /**
   * The set of serializers that handle the core graph interfaces.  These serializers support
normalization which
@@@ -85,43 -85,57 +88,58 @@@ abstract class GraphSONModule extends T
       */
      static final class GraphSONModuleV2d0 extends GraphSONModule {
  
 -        private static final LinkedHashMap<Class, String> TYPE_DEFINITIONS = new LinkedHashMap<Class,
String>() {{
 -            // Those don't have deserializers because handled by Jackson,
 -            // but we still want to rename them in GraphSON
 -            put(ByteBuffer.class, "bytebuffer");
 -            put(Short.class, "int16");
 -            put(Integer.class, "int32");
 -            put(Long.class, "int64");
 -            put(Double.class, "double");
 -            put(Float.class, "float");
 +        private static final Map<Class, String> TYPE_DEFINITIONS = Collections.unmodifiableMap(
 +                new LinkedHashMap<Class, String>() {{
 +                    // Those don't have deserializers because handled by Jackson,
 +                    // but we still want to rename them in GraphSON
 +                    put(ByteBuffer.class, "bytebuffer");
 +                    put(Short.class, "int16");
 +                    put(Integer.class, "int32");
 +                    put(Long.class, "int64");
 +                    put(Double.class, "double");
 +                    put(Float.class, "float");
  
 -            // Time serializers/deserializers
 -            put(Duration.class, "duration");
 -            put(Instant.class, "instant");
 -            put(LocalDate.class, "localdate");
 -            put(LocalDateTime.class, "localdatetime");
 -            put(LocalTime.class, "localtime");
 -            put(MonthDay.class, "monthday");
 -            put(OffsetDateTime.class, "offsetdatetime");
 -            put(OffsetTime.class, "offsettime");
 -            put(Period.class, "period");
 -            put(Year.class, "year");
 -            put(YearMonth.class, "yearmonth");
 -            put(ZonedDateTime.class, "zoneddatetime");
 -            put(ZoneOffset.class, "zoneoffset");
 +                    // Time serializers/deserializers
 +                    put(Duration.class, "duration");
 +                    put(Instant.class, "instant");
 +                    put(LocalDate.class, "localdate");
 +                    put(LocalDateTime.class, "localdatetime");
 +                    put(LocalTime.class, "localtime");
 +                    put(MonthDay.class, "monthday");
 +                    put(OffsetDateTime.class, "offsetdatetime");
 +                    put(OffsetTime.class, "offsettime");
 +                    put(Period.class, "period");
 +                    put(Year.class, "year");
 +                    put(YearMonth.class, "yearmonth");
 +                    put(ZonedDateTime.class, "zoneddatetime");
 +                    put(ZoneOffset.class, "zoneoffset");
  
 -            // Tinkerpop Graph objects
 -            put(Vertex.class, "vertex");
 -            put(Edge.class, "edge");
 -            put(Property.class, "property");
 -            put(Path.class, "path");
 -            put(VertexProperty.class, "vertexproperty");
 -            put(Metrics.class, "metrics");
 -            put(TraversalMetrics.class, "traversalmetrics");
 -            put(Traverser.class, "traverser");
 -            put(Tree.class, "tree");
 -            put(Bytecode.class, "bytecode");
 -            put(Bytecode.Binding.class, "binding");
 -            put(AndP.class, "P");
 -            put(OrP.class, "P");
 -            put(P.class, "P");
 -            Stream.of(
 -                    VertexProperty.Cardinality.values(),
 -                    Column.values(),
 -                    Direction.values(),
 -                    //Operator.values(),
 -                    Order.values(),
 -                    Pop.values(),
 -                    SackFunctions.Barrier.values(),
 -                    Scope.values(),
 -                    T.values()).flatMap(Stream::of).forEach(e -> put(e.getClass(), e.getDeclaringClass().getSimpleName()));
 -        }};
 +                    // Tinkerpop Graph objects
 +                    put(Vertex.class, "vertex");
 +                    put(Edge.class, "edge");
 +                    put(Property.class, "property");
 +                    put(Path.class, "path");
 +                    put(VertexProperty.class, "vertexproperty");
 +                    put(Metrics.class, "metrics");
 +                    put(TraversalMetrics.class, "traversalmetrics");
 +                    put(Traverser.class, "traverser");
 +                    put(Tree.class, "tree");
++                    put(Bytecode.class, "bytecode");
++                    put(Bytecode.Binding.class, "binding");
++                    put(AndP.class, "P");
++                    put(OrP.class, "P");
++                    put(P.class, "P");
++                    Stream.of(
++                            VertexProperty.Cardinality.values(),
++                            Column.values(),
++                            Direction.values(),
++                            //Operator.values(),
++                            Order.values(),
++                            Pop.values(),
++                            SackFunctions.Barrier.values(),
++                            Scope.values(),
++                            T.values()).flatMap(Stream::of).forEach(e -> put(e.getClass(),
e.getDeclaringClass().getSimpleName()));
 +                }});
  
          /**
           * Constructs a new object.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41bb1f73/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
index 080f64d,89f4662..a9c1731
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
@@@ -220,67 -220,19 +220,19 @@@ final class GraphSONTraversalSerializer
              super(Bytecode.class);
          }
  
-         private static void processInstruction(final JsonNode instruction, final ObjectCodec
oc, final Bytecode bytecode, final boolean source) throws IOException {
-             final String operator = instruction.get(0).textValue();
-             final List<Object> arguments = new ArrayList<>();
-             for (int j = 1; j < instruction.size(); j++) {
-                 final JsonNode argument = instruction.get(j);
-                 if (argument.getNodeType().equals(JsonNodeType.OBJECT)) {
-                     if (argument.has(GraphSONTokens.VALUETYPE)) {
-                         final String type = argument.get(GraphSONTokens.VALUETYPE).textValue();
-                         if (type.equals("Bytecode"))
-                             arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class));
-                         else if (type.equals("Binding"))
-                             arguments.add(oc.readValue(argument.traverse(oc), Bytecode.Binding.class));
-                         else if (type.equals("P"))
-                             arguments.add(oc.readValue(argument.traverse(oc), P.class));
-                         else if (type.equals("Lambda"))
-                             arguments.add(oc.readValue(argument.traverse(oc), Lambda.class));
-                         else
-                             arguments.add(oc.readValue(argument.traverse(oc), Enum.class));
-                     } else {
-                         arguments.add(oc.readValue(argument.traverse(oc), Object.class));
// TODO: vertices/edges/etc. don't get processed correctly
-                     }
-                 } else if (argument.getNodeType().equals(JsonNodeType.NUMBER)) {
-                     arguments.add(argument.asInt()); // TODO
-                 } else if (argument.getNodeType().equals(JsonNodeType.STRING)) {
-                     arguments.add(argument.textValue());
-                 } else if (argument.getNodeType().equals(JsonNodeType.BOOLEAN)) {
-                     arguments.add(argument.booleanValue());
-                 } else if (argument.getNodeType().equals(JsonNodeType.ARRAY)) {
-                     final List<Object> list = new ArrayList<>();
-                     for (int k = 0; k < argument.size(); k++) {
-                         list.add(oc.readValue(argument.get(k).traverse(oc), Object.class));
-                         //list.add(argument.get(k).textValue());
-                     }
-                     arguments.add(list);
-                 } else {
-                     throw new IOException("Unknown argument: " + argument);
-                 }
-             }
-             if (source)
-                 bytecode.addSource(operator, arguments.toArray());
-             else
-                 bytecode.addStep(operator, arguments.toArray());
-         }
- 
          @Override
-         public Bytecode deserialize(final JsonParser jsonParser, final DeserializationContext
deserializationContext) throws IOException, JsonProcessingException {
 -        Bytecode createObject(final Map<String, Object> data) {
++        public Bytecode createObject(final Map<String, Object> data) {
              final Bytecode bytecode = new Bytecode();
-             final ObjectCodec oc = jsonParser.getCodec();
-             final JsonNode node = oc.readTree(jsonParser);
-             assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Bytecode");
-             if (node.has("source")) {
-                 final JsonNode source = node.get("source");
-                 for (int i = 0; i < source.size(); i++) {
-                     processInstruction(source.get(i), oc, bytecode, true);
+             if (data.containsKey(GraphSONTokens.SOURCE)) {
+                 final List<List<Object>> instructions = (List) data.get(GraphSONTokens.SOURCE);
+                 for (final List<Object> instruction : instructions) {
+                     bytecode.addSource((String) instruction.get(0), Arrays.copyOfRange(instruction.toArray(),
1, instruction.size()));
                  }
              }
-             if (node.has("step")) {
-                 final JsonNode step = node.get("step");
-                 for (int i = 0; i < step.size(); i++) {
-                     processInstruction(step.get(i), oc, bytecode, false);
- 
+             if (data.containsKey(GraphSONTokens.STEP)) {
+                 final List<List<Object>> instructions = (List) data.get(GraphSONTokens.STEP);
+                 for (final List<Object> instruction : instructions) {
+                     bytecode.addStep((String) instruction.get(0), Arrays.copyOfRange(instruction.toArray(),
1, instruction.size()));
                  }
              }
              return bytecode;
@@@ -330,24 -267,16 +267,16 @@@
          }
  
          @Override
-         public P deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
- 
-             final ObjectCodec oc = jsonParser.getCodec();
-             final JsonNode node = oc.readTree(jsonParser);
-             assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("P");
-             final JsonNode predicate = node.get("predicate");
-             if (predicate.textValue().equals("and") || predicate.textValue().equals("or"))
{
-                 final List<P<?>> arguments = new ArrayList<>();
-                 for (int i = 0; i < node.get(GraphSONTokens.VALUE).size(); i++) {
-                     arguments.add(oc.readValue(node.get(GraphSONTokens.VALUE).get(i).traverse(oc),
P.class));
-                 }
-                 return predicate.textValue().equals("and") ? new AndP(arguments) : new OrP(arguments);
 -        P createObject(final Map<String, Object> data) {
++        public P createObject(final Map<String, Object> data) {
+             final String predicate = (String) data.get(GraphSONTokens.PREDICATE);
+             final Object value = data.get(GraphSONTokens.VALUE);
+             if (predicate.equals(GraphSONTokens.AND) || predicate.equals(GraphSONTokens.OR))
{
+                 return predicate.equals(GraphSONTokens.AND) ? new AndP((List<P>) value)
: new OrP((List<P>) value);
              } else {
                  try {
-                     final Object argument = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc),
Object.class);
-                     return (P) P.class.getMethod(predicate.textValue(), argument instanceof
Collection ? Collection.class : Object.class).invoke(null, argument); // TODO: number stuff,
eh?
+                     return (P) P.class.getMethod(predicate, value instanceof Collection
? Collection.class : Object.class).invoke(null, value); // TODO: number stuff, eh?
                  } catch (final Exception e) {
-                     throw new IOException(e.getMessage(), e);
+                     throw new IllegalStateException(e.getMessage(), e);
                  }
              }
          }
@@@ -360,22 -289,19 +289,19 @@@
          }
  
          @Override
-         public Lambda deserialize(final JsonParser jsonParser, final DeserializationContext
deserializationContext) throws IOException, JsonProcessingException {
- 
-             final ObjectCodec oc = jsonParser.getCodec();
-             final JsonNode node = oc.readTree(jsonParser);
-             assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Lambda");
-             final String lambdaScript = node.get(GraphSONTokens.VALUE).textValue();
-             final String lambdaLanguage = node.get("language").textValue();
-             final int lambdaArguments = node.get("arguments").intValue();
-             if (-1 == lambdaArguments || lambdaArguments > 2)
-                 return new Lambda.UnknownArgLambda(lambdaScript, lambdaLanguage, lambdaArguments);
-             else if (0 == lambdaArguments)
-                 return new Lambda.ZeroArgLambda<>(lambdaScript, lambdaLanguage);
-             else if (1 == lambdaArguments)
-                 return new Lambda.OneArgLambda<>(lambdaScript, lambdaLanguage);
 -        Lambda createObject(final Map<String, Object> data) {
++        public Lambda createObject(final Map<String, Object> data) {
+             final String script = (String) data.get(GraphSONTokens.SCRIPT);
+             final String language = (String) data.get(GraphSONTokens.LANGUAGE);
+             final int arguments = ((Number) data.getOrDefault(GraphSONTokens.ARGUMENTS,
-1)).intValue();
+             //
+             if (-1 == arguments || arguments > 2)
+                 return new Lambda.UnknownArgLambda(script, language, arguments);
+             else if (0 == arguments)
+                 return new Lambda.ZeroArgLambda<>(script, language);
+             else if (1 == arguments)
+                 return new Lambda.OneArgLambda<>(script, language);
              else
-                 return new Lambda.TwoArgLambda<>(lambdaScript, lambdaLanguage);
+                 return new Lambda.TwoArgLambda<>(script, language);
          }
      }
  
@@@ -386,13 -312,8 +312,8 @@@
          }
  
          @Override
-         public Bytecode.Binding deserialize(final JsonParser jsonParser, final DeserializationContext
deserializationContext) throws IOException, JsonProcessingException {
-             final ObjectCodec oc = jsonParser.getCodec();
-             final JsonNode node = oc.readTree(jsonParser);
-             assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Binding");
-             final String variable = node.get("variable").textValue();
-             final Object value = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc),
Object.class);
-             return new Bytecode.Binding<>(variable, value);
 -        Bytecode.Binding createObject(final Map<String, Object> data) {
++        public Bytecode.Binding createObject(final Map<String, Object> data) {
+             return new Bytecode.Binding<>((String) data.get(GraphSONTokens.KEY), data.get(GraphSONTokens.VALUE));
          }
      }
  


Mime
View raw message