This is an automated email from the ASF dual-hosted git repository. okram pushed a commit to branch tp4 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/tp4 by this push: new d026ee8 staged emit() and until() wrt repeat(). Trying to figure out the best way to represent the ordering for Pipes and Beam... d026ee8 is described below commit d026ee8c40fd1e0d9d219018522474feb4786ce6 Author: Marko A. Rodriguez <okramma...@gmail.com> AuthorDate: Sat Mar 16 16:07:05 2019 -0600 staged emit() and until() wrt repeat(). Trying to figure out the best way to represent the ordering for Pipes and Beam... --- .../org/apache/tinkerpop/language/Traversal.java | 22 +++++++++++++++++++-- .../tinkerpop/machine/bytecode/BytecodeUtil.java | 2 +- .../tinkerpop/machine/bytecode/Compilation.java | 11 +++++++++++ .../tinkerpop/machine/bytecode/Instruction.java | 6 ++++++ .../machine/function/branch/RepeatBranch.java | 23 ++++++++++++++++------ .../apache/tinkerpop/machine/beam/RepeatFn.java | 2 +- 6 files changed, 56 insertions(+), 10 deletions(-) diff --git a/java/core/src/main/java/org/apache/tinkerpop/language/Traversal.java b/java/core/src/main/java/org/apache/tinkerpop/language/Traversal.java index 357c73d..01740c3 100644 --- a/java/core/src/main/java/org/apache/tinkerpop/language/Traversal.java +++ b/java/core/src/main/java/org/apache/tinkerpop/language/Traversal.java @@ -21,6 +21,7 @@ package org.apache.tinkerpop.language; import org.apache.tinkerpop.machine.bytecode.Bytecode; import org.apache.tinkerpop.machine.bytecode.BytecodeUtil; import org.apache.tinkerpop.machine.bytecode.Compilation; +import org.apache.tinkerpop.machine.bytecode.Instruction; import org.apache.tinkerpop.machine.bytecode.Symbols; import org.apache.tinkerpop.machine.coefficient.Coefficient; import org.apache.tinkerpop.machine.coefficient.LongCoefficient; @@ -89,6 +90,15 @@ public class Traversal<C, S, E> implements Iterator<E> { return (Traversal) this; } + public Traversal<C, S, E> emit(final Traversal<C, E, ?> emitTraversal) { + final Instruction<C> lastInstruction = this.bytecode.lastInstruction(); + if (lastInstruction.op().equals(Symbols.REPEAT)) + lastInstruction.addArgs('e', emitTraversal.bytecode); + else + this.bytecode.addInstruction(this.currentCoefficient, Symbols.REPEAT, 'e', emitTraversal.bytecode); + return this; + } + public Traversal<C, S, E> filter(final Traversal<C, E, ?> filterTraversal) { this.bytecode.addInstruction(this.currentCoefficient, Symbols.FILTER, filterTraversal.bytecode); return this; @@ -165,7 +175,11 @@ public class Traversal<C, S, E> implements Iterator<E> { } public Traversal<C, S, E> repeat(final Traversal<C, E, E> repeatTraversal) { - this.bytecode.addInstruction(this.currentCoefficient, Symbols.REPEAT, repeatTraversal.bytecode); + final Instruction<C> lastInstruction = this.bytecode.lastInstruction(); + if (lastInstruction.op().equals(Symbols.REPEAT)) + lastInstruction.addArgs('r', repeatTraversal.bytecode); + else + this.bytecode.addInstruction(this.currentCoefficient, Symbols.REPEAT, 'r', repeatTraversal.bytecode); return this; } @@ -192,7 +206,11 @@ public class Traversal<C, S, E> implements Iterator<E> { } public Traversal<C, S, E> until(final Traversal<C, E, ?> untilTraversal) { - this.bytecode.lastInstruction().addArg(untilTraversal.bytecode); + final Instruction<C> lastInstruction = this.bytecode.lastInstruction(); + if (lastInstruction.op().equals(Symbols.REPEAT)) + lastInstruction.addArgs('u', untilTraversal.bytecode); + else + this.bytecode.addInstruction(this.currentCoefficient, Symbols.REPEAT, 'u', untilTraversal.bytecode); return this; } diff --git a/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/BytecodeUtil.java b/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/BytecodeUtil.java index f4ad337..f62cd4a 100644 --- a/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/BytecodeUtil.java +++ b/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/BytecodeUtil.java @@ -175,7 +175,7 @@ public final class BytecodeUtil { case Symbols.PATH: return new PathMap<>(coefficient, labels, Compilation.compile(instruction.args())); case Symbols.REPEAT: - return new RepeatBranch(coefficient, labels, Compilation.compile(instruction.args())); + return new RepeatBranch<>(coefficient, labels, Compilation.repeatCompile(instruction.args())); case Symbols.SUM: return new SumReduce<>(coefficient, labels); case Symbols.UNFOLD: diff --git a/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Compilation.java b/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Compilation.java index e1fa5ef..98c86a4 100644 --- a/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Compilation.java +++ b/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Compilation.java @@ -138,4 +138,15 @@ public final class Compilation<C, S, E> implements Serializable { } return compilations; } + + public static List<Object> repeatCompile(final Object... args) { + final List<Object> objects = new ArrayList<>(); + for (final Object arg : args) { + if (arg instanceof Bytecode) + objects.add(new Compilation<>((Bytecode) arg)); + else + objects.add(arg); + } + return objects; + } } diff --git a/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java b/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java index 76c7eed..b5fb297 100644 --- a/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java +++ b/java/core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java @@ -66,6 +66,12 @@ public final class Instruction<C> { this.args[this.args.length - 1] = arg; } + public void addArgs(final Object... args) { + for (final Object arg : args) { + this.addArg(arg); + } + } + @Override public String toString() { return StringFactory.makeInstructionString(this); diff --git a/java/core/src/main/java/org/apache/tinkerpop/machine/function/branch/RepeatBranch.java b/java/core/src/main/java/org/apache/tinkerpop/machine/function/branch/RepeatBranch.java index 011494b..ff0026a 100644 --- a/java/core/src/main/java/org/apache/tinkerpop/machine/function/branch/RepeatBranch.java +++ b/java/core/src/main/java/org/apache/tinkerpop/machine/function/branch/RepeatBranch.java @@ -21,10 +21,11 @@ package org.apache.tinkerpop.machine.function.branch; import org.apache.tinkerpop.machine.bytecode.Compilation; import org.apache.tinkerpop.machine.coefficient.Coefficient; import org.apache.tinkerpop.machine.function.AbstractFunction; -import org.apache.tinkerpop.machine.function.branch.selector.Selector; import org.apache.tinkerpop.machine.function.BranchFunction; +import org.apache.tinkerpop.machine.function.branch.selector.Selector; import org.apache.tinkerpop.util.StringFactory; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -34,18 +35,24 @@ import java.util.Set; */ public class RepeatBranch<C, S> extends AbstractFunction<C> implements BranchFunction<C, S, S, Boolean> { + private final Map<Character, Compilation<C, S, S>> compilations; private final Compilation<C, S, S> repeat; - private final Compilation<C, S, ?> until; + private final Compilation<C, S, S> until; - public RepeatBranch(final Coefficient<C> coefficient, final Set<String> labels, final List<Compilation<C, S, ?>> repeatCompilations) { + public RepeatBranch(final Coefficient<C> coefficient, final Set<String> labels, final List<Object> arguments) { super(coefficient, labels); - this.repeat = (Compilation<C, S, S>) repeatCompilations.get(0); - this.until = repeatCompilations.get(1); + this.compilations = new LinkedHashMap<>(); + for (int i = 0; i < arguments.size(); i = i + 2) { + this.compilations.put((Character) arguments.get(i), (Compilation<C, S, S>) arguments.get(i + 1)); + } + + this.repeat = this.compilations.get('r'); + this.until = this.compilations.get('u'); } @Override public String toString() { - return StringFactory.makeFunctionString(this, this.repeat, this.until); + return StringFactory.makeFunctionString(this, this.compilations); } public Compilation<C, S, S> getRepeat() { @@ -56,6 +63,10 @@ public class RepeatBranch<C, S> extends AbstractFunction<C> implements BranchFun return this.until; } + public Map<Character, Compilation<C, S, S>> getCompilations() { + return this.compilations; + } + @Override public Selector<C, S, Boolean> getBranchSelector() { return null; diff --git a/java/machine/beam/src/main/java/org/apache/tinkerpop/machine/beam/RepeatFn.java b/java/machine/beam/src/main/java/org/apache/tinkerpop/machine/beam/RepeatFn.java index 33a1040..17d02eb 100644 --- a/java/machine/beam/src/main/java/org/apache/tinkerpop/machine/beam/RepeatFn.java +++ b/java/machine/beam/src/main/java/org/apache/tinkerpop/machine/beam/RepeatFn.java @@ -50,6 +50,6 @@ public class RepeatFn<C, S> extends AbstractFn<C, S, S> { else if (!this.deadEnd) out.get(this.repeatLoop).output(traverser.clone()); else - throw new IllegalStateException("There are not enough repetition to account for this traveral"); + throw new IllegalStateException("There are not enough repetitions to account for this traversal"); } }