You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/11/10 16:52:00 UTC
[1/2] tinkerpop git commit: gremlin-pipes is now its own top-level
project. NOTE -- this is NOT permanent. talking with @spmallette on figuring
how to make this a tutorial. Need it into a project first. As things advance
we can move the project elsewhere
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1543 feb3403c4 -> 8c7eebf36
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/Parser.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/Parser.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/Parser.java
deleted file mode 100644
index b844471..0000000
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/Parser.java
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.tinkergraph.g2;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.P;
-import org.apache.tinkerpop.gremlin.util.CoreImports;
-import org.javatuples.Pair;
-import org.javatuples.Triplet;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class Parser {
-
- private static final char NO_CHAR = '\u0489';
- private static final char SPACE = ' ';
- private static Set<Character> PIPES = new HashSet<>(Arrays.asList('-', '/', '|', '\\'));
- private static Set<Character> ENDS = new HashSet<>(Arrays.asList(SPACE, NO_CHAR));
-
- private static final List<Triplet<Pattern, String, Boolean>> OPERATOR_PATTERNS = new ArrayList<Triplet<Pattern, String, Boolean>>() {{
- add(Triplet.with(Pattern.compile("(?<=^~)[^~]*(?=~>>)"), "outE", false));
- add(Triplet.with(Pattern.compile("(?<=<<~)[^~]*(?=~)"), "inE", false));
- add(Triplet.with(Pattern.compile("(?<=<<~)[^~]*(?=~>>)"), "bothE", false));
- add(Triplet.with(Pattern.compile("(?<=^~)[^~]*(?=~>)"), "out", false));
- add(Triplet.with(Pattern.compile("(?<=^<~)[^~]*(?=~>)"), "both", false));
- add(Triplet.with(Pattern.compile("(?<=^<~)[^~]*(?=~)"), "in", false));
- add(Triplet.with(Pattern.compile("(?<=^<<)$"), "inV", false));
- add(Triplet.with(Pattern.compile("(?<=^>>)$"), "outV", false));
- add(Triplet.with(Pattern.compile("(?<=^<<>>)$"), "bothV", false));
- // add(Triplet.with(Pattern.compile("(?<=%)$"), "map", true));
- add(Triplet.with(Pattern.compile("(?<=^#)$"), "filter", true));
- add(Triplet.with(Pattern.compile("(?<=^~)(.*)"), "values", false));
- add(Triplet.with(Pattern.compile("(?<=^@)(.*)"), "as", false));
- add(Triplet.with(Pattern.compile("(?<=^#)([\\*].*)"), "where", false));
- add(Triplet.with(Pattern.compile("(?<=^\\*)(.*)"), "select", false));
- add(Triplet.with(Pattern.compile("(?<=^#!)(.*)"), "hasNot", false));
- add(Triplet.with(Pattern.compile("(?<=^#)(.*)"), "has", false));
- add(Triplet.with(Pattern.compile("(?<=^!)$"), "not", true));
- add(Triplet.with(Pattern.compile("(?<=^}\\$)$"), "count", false));
- add(Triplet.with(Pattern.compile("(?<=^}\\+)$"), "sum", false));
- add(Triplet.with(Pattern.compile("(?<=^}%\\$)(.*)"), "groupCount", false));
- add(Triplet.with(Pattern.compile("(?<=^}%)(.*)"), "group", false));
- add(Triplet.with(Pattern.compile("(?<=^})([0-9]*)(?=\\{)"), "barrier", false));
- add(Triplet.with(Pattern.compile("(?<=^})([a-z|A-Z]*)(?=\\{)"), "aggregate", false));
- add(Triplet.with(Pattern.compile("(?<=^i)$"), "identity", false));
- add(Triplet.with(Pattern.compile("(?<=^M)$"), "match", true));
- add(Triplet.with(Pattern.compile("(?<=^U)$"), "union", true));
- add(Triplet.with(Pattern.compile("(?<=^x)(.*)"), "times", false));
- add(Triplet.with(Pattern.compile("(?<=\\{)"), "flatMap", true));
- }};
-
- private static final Pattern PREDICATE_PATTERN = Pattern.compile("([^!<>=]+)(([<>][=]?)|([!=]=))([^!<>=]+)");
- private static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]");
-
- private static final Map<String, Enum> TOKEN_MAP = new HashMap<>();
-
- static {
- CoreImports.getEnumImports().forEach(token -> {
- TOKEN_MAP.put("`" + token.name(), token);
- });
- }
-
- // accessible objects
-
- private String traversalSource;
- private Bytecode rootTraversal;
-
- // source matrix
-
- private char[][] source;
- private int cRow;
- private int cColumn;
- private int numRows;
- private int numCols;
- private Pair<Integer, Integer> repeat = null;
-
- public Parser(final String source) {
- this.buildCharacterSource(source);
- }
-
- public Parser(final File file) {
- try {
- final BufferedReader reader = new BufferedReader(new FileReader(file));
- final StringBuilder builder = new StringBuilder();
- String line;
- while ((line = reader.readLine()) != null) {
- builder.append(line).append("\n");
- }
- this.buildCharacterSource(builder.toString());
- } catch (final Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- private void buildCharacterSource(final String source) {
- final String[] lines = source.split("\n");
- for (String line : lines) {
- line = line.replaceAll("\\s+$", "");
- if (line.length() > this.numCols)
- this.numCols = line.length();
- }
- this.numRows = lines.length;
- this.source = new char[this.numRows][this.numCols];
- int row = 0;
- for (String line : lines) {
- line = line.replaceAll("\\s+$", "");
- final char[] chars = line.toCharArray();
- for (int column = 0; column < this.numCols; column++) {
- this.source[row][column] = column > chars.length - 1 ? SPACE : chars[column];
- }
- row++;
- }
- this.traversalSource = this.advanceToSource();
- this.rootTraversal = this.advanceThroughBytecode();
- }
-
- public Bytecode getBytecode() {
- return this.rootTraversal;
- }
-
- public String getSourceCode() {
- final StringBuilder builder = new StringBuilder();
- for (final char[] row : this.source) {
- builder.append(new String(row)).append("\n");
- }
- return builder.toString();
- }
-
- public String getTraversalSource() {
- return this.traversalSource;
- }
-
- //////////////
-
- private String advanceToSource() {
- for (int column = 0; column < this.numCols; column++) {
- for (int row = 0; row < this.numRows; row++) {
- if (SPACE != this.source[row][column]) {
- this.cRow = row;
- this.cColumn = column;
- return this.advanceThroughNextInstruction();
- }
- }
- }
- throw new IllegalStateException("The source does not have a traversal source defined");
- }
-
- private Bytecode advanceThroughBytecode() {
- final Bytecode bytecode = new Bytecode();
- while (processNextInstruction(bytecode)) {
-
- }
- //System.out.println(bytecode);
- return bytecode;
- }
-
- private static Bytecode processBytecode(final String traversal) {
- return new Parser(traversal).getBytecode();
- }
-
- private boolean processNextInstruction(final Bytecode bytecode) {
- String instruction = this.advanceThroughNextInstruction();
- if (null == instruction) {
- if (null != this.repeat) {
- final Pair<Integer, Integer> temp = this.repeat;
- this.repeat = null;
- bytecode.addStep("repeat", this.getChildBytecode().toArray());
- int rTemp = this.cRow;
- int cTemp = this.cColumn;
- this.setCursor(temp.getValue0() + 1, temp.getValue1() + 1);
- final Bytecode untilTraversal = this.getChildBytecode().get(0);
- for (final Bytecode.Instruction inst : untilTraversal.getStepInstructions()) {
- bytecode.addStep(inst.getOperator(), inst.getArguments());
- }
- this.setCursor(rTemp, cTemp);
- return true;
- } else {
- return false;
- }
- }
- ///
- instruction = instruction.trim();
- //System.out.println(instruction + "!!");
- for (final Triplet<Pattern, String, Boolean> entry : OPERATOR_PATTERNS) {
- final Pattern pattern = entry.getValue0();
- final String operand = entry.getValue1();
- final Boolean children = entry.getValue2();
- final Matcher matcher = pattern.matcher(instruction);
- if (matcher.find()) {
- final String arguments = matcher.group();
- if (!arguments.isEmpty()) {
- Object[] args;
- if (operand.equals("has")) {
- final Matcher m = PREDICATE_PATTERN.matcher(instruction.substring(1));
- args = m.find() ?
- new Object[]{m.group(1), this.mapToPredicate(m.group(2), m.group(5))} :
- this.processArguments(arguments);
- } else if (operand.equals("where")) {
- final Matcher m = PREDICATE_PATTERN.matcher(instruction.substring(1));
- args = m.find() ?
- new Object[]{m.group(1).substring(1), this.mapToPredicate(m.group(2), m.group(5).substring(1))} :
- this.processArguments(arguments);
- } else
- args = this.processArguments(arguments);
- bytecode.addStep(operand, args);
- } else if (children) {
- this.moveCursor(0, 1);
- bytecode.addStep(operand, this.getChildBytecode().toArray());
- } else
- bytecode.addStep(operand);
- return true;
- }
- }
- ////////
- if (instruction.equals("[")) {
- for (final Bytecode b : this.getChildBytecode()) {
- if (b.getInstructions().iterator().hasNext())
- bytecode.addStep("by", b);
- else
- bytecode.addStep("by");
- }
- } else if (instruction.contains("(")) {
- bytecode.addStep(instruction.substring(0, instruction.indexOf('(')),
- this.processArguments(instruction.substring(instruction.indexOf('(') + 1, instruction.length() - 1)));
- } else
- bytecode.addStep(instruction);
-
- return true;
- }
-
- private List<Bytecode> getChildBytecode() {
- return this.getChildBytecode(true, 0, this.cRow, this.cColumn, new ArrayList<>());
- }
-
- private List<Bytecode> getChildBytecode(final boolean branch, final int previousRowOffset, final int cRow, final int cColumn, final List<Bytecode> children) {
- this.setCursor(cRow, cColumn);
- int endRow = -1;
- int endColumn = -1;
- if (branch) {
- int openNest = 1;
- while (true) {
- if ('[' == this.currentCharacter()) {
- openNest++;
- } else if (']' == this.currentCharacter()) {
- openNest--;
- if (0 == openNest) {
- endRow = this.cRow;
- endColumn = this.cColumn + 1;
- break;
- }
- } else if (NO_CHAR == this.currentCharacter()) {
- endRow = this.cRow;
- endColumn = this.cColumn + 1;
- break;
- }
- this.moveCursor(0, 1);
- }
- }
- this.setCursor(cRow, cColumn);
- if ('|' == this.peekCharacter(-1, 0) && previousRowOffset <= 0)
- this.getChildBytecode(false, -1, cRow - 1, cColumn, children);
- //
- this.setCursor(cRow, cColumn);
- if ('/' == this.peekCharacter(-1, 0))
- this.getChildBytecode(false, -1, cRow - 1, cColumn + 1, children);
- else if ('/' == this.peekCharacter(-1, 1))
- this.getChildBytecode(false, -1, cRow - 1, cColumn + 1, children);
- //
- this.setCursor(cRow, cColumn);
- if ('-' == this.currentCharacter() || '-' == this.peekCharacter(0, 1)) {
- this.moveCursor(0, 1);
- children.add(this.advanceThroughBytecode());
- }
- //
- this.setCursor(cRow, cColumn);
- if ('\\' == this.peekCharacter(1, 0))
- this.getChildBytecode(false, 1, cRow + 1, cColumn + 1, children);
- else if ('\\' == this.peekCharacter(1, 1))
- this.getChildBytecode(false, 1, cRow + 1, cColumn + 1, children);
- //
- this.setCursor(cRow, cColumn);
- if ('|' == this.peekCharacter(1, 0) && previousRowOffset >= 0)
- this.getChildBytecode(false, 1, cRow + 1, cColumn, children);
- //
- if (branch)
- this.setCursor(endRow, endColumn);
- return children;
- }
-
- private boolean advanceToNextInstruction() {
- while (true) {
- final char current = this.currentCharacter();
- if ('[' == current && '^' == this.peekCharacter(1, 0)) {
- this.repeat = Pair.with(this.cRow, this.cColumn);
- this.moveCursor(0, 1);
- return true;
- }
- if (PIPES.contains(current)) {
- if ('-' == current)
- this.moveCursor(0, 1);
- else if ('/' == current) {
- if ('/' == this.peekCharacter(-1, 1))
- this.moveCursor(-1, 1);
- else if ('-' == this.peekCharacter(0, 1))
- this.moveCursor(0, 1);
- else
- return false;
- } else if ('\\' == current) {
- if ('\\' == this.peekCharacter(1, 1))
- this.moveCursor(1, 1);
- else if ('-' == this.peekCharacter(0, 1))
- this.moveCursor(0, 1);
- else
- return false;
- } else
- return false;
- } else if (ENDS.contains(current)) {
- if ('/' == this.peekCharacter(-1, 0))
- this.moveCursor(-1, 0);
- else if ('\\' == this.peekCharacter(1, 0))
- this.moveCursor(1, 0);
- else
- return false;
- } else
- return true;
- }
- }
-
- private String advanceThroughNextInstruction() {
- if (!this.advanceToNextInstruction())
- return null;
- String instruction = "";
- char current;
- while (NO_CHAR != (current = this.currentCharacter())) {
- if ('-' == current || ('[' == current && !instruction.isEmpty()))
- break;
- if ('[' == current && instruction.isEmpty()) {
- this.moveCursor(0, 1);
- return "[";
- } else if (']' == current) {
- this.moveCursor(0, 1);
- break;
- } else {
- instruction = instruction + current;
- this.moveCursor(0, 1);
- }
- }
- return instruction.trim().isEmpty() ? null : instruction;
-
- }
-
- //////////
-
- private char currentCharacter() {
- return this.cRow >= 0 && this.cRow < this.numRows && this.cColumn >= 0 && this.cColumn < this.numCols ?
- this.source[this.cRow][this.cColumn] :
- NO_CHAR;
- }
-
- private char peekCharacter(final int rOffset, final int cOffset) {
- final int tempRow = this.cRow;
- final int tempColumn = this.cColumn;
- this.moveCursor(rOffset, cOffset);
- final char peek = this.currentCharacter();
- this.setCursor(tempRow, tempColumn);
- return peek;
- }
-
- private void moveCursor(final int rOffset, final int cOffset) {
- this.setCursor(this.cRow + rOffset, this.cColumn + cOffset);
- }
-
- private void setCursor(final int cRow, final int cColumn) {
- this.cRow = cRow;
- this.cColumn = cColumn;
- }
-
- private <V> P<V> mapToPredicate(final String predicate, final V value) {
- if (predicate.equals("=="))
- return P.eq(value);
- else if (predicate.equals(">="))
- return P.gte(value);
- else if (predicate.equals("<="))
- return P.lte(value);
- else if (predicate.equals(">"))
- return P.gt(value);
- else if (predicate.equals("<"))
- return P.lt(value);
- else if (predicate.equals("!="))
- return P.neq(value);
- else
- throw new IllegalStateException("Can not parse predicate: " + predicate + ":" + value);
-
- }
-
- private Object[] processArguments(final String arguments) {
- final String[] args = arguments.split(",");
- final Object[] objects = new Object[args.length];
- for (int i = 0; i < args.length; i++) {
- final String arg = args[i];
- if (arg.equals("true") || arg.equals("false"))
- objects[i] = Boolean.valueOf(arg);
- else if (NUMBER_PATTERN.matcher(arg).find()) {
- if (arg.contains(".") && arg.endsWith("f"))
- objects[i] = Float.valueOf(arg);
- else if (arg.contains("."))
- objects[i] = Double.valueOf(arg);
- else if (arg.endsWith("l"))
- objects[i] = Long.valueOf(arg);
- else
- objects[i] = Integer.valueOf(arg);
- } else if (arg.startsWith("'") && arg.endsWith("'"))
- objects[i] = arg.substring(1, arg.length() - 1);
- else if (arg.startsWith("`"))
- objects[i] = TOKEN_MAP.get(arg);
- else
- objects[i] = arg;
- }
- return objects;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/PipesTranslator.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/PipesTranslator.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/PipesTranslator.java
deleted file mode 100644
index 2faa605..0000000
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/PipesTranslator.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.tinkergraph.g2;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.Compare;
-import org.apache.tinkerpop.gremlin.process.traversal.P;
-import org.apache.tinkerpop.gremlin.process.traversal.Translator;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.BiPredicate;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class PipesTranslator implements Translator.ScriptTranslator {
-
- private static final String EMPTY_STRING = new String();
-
- private final String traversalSource;
- private final List<String> sourceCode = PipesTranslator.generateSourceCode();
-
- private static Map<Enum, String> ENUM_MAP = new HashMap<Enum, String>() {{
- put(Compare.eq, "==");
- put(Compare.gt, ">");
- put(Compare.gte, ">=");
- put(Compare.lt, "<");
- put(Compare.lte, "<=");
- put(Compare.neq, "!=");
- }};
-
- private PipesTranslator(final String traversalSource) {
- this.traversalSource = traversalSource;
- }
-
- public static PipesTranslator of(final String traversalSource) {
- return new PipesTranslator(traversalSource);
- }
-
- @Override
- public String getTraversalSource() {
- return this.traversalSource;
- }
-
- @Override
- public String getTargetLanguage() {
- return new GremlinPipesScriptEngineFactory().getLanguageName();
- }
-
- @Override
- public String translate(final Bytecode bytecode) {
-
- int cRow = 10;
- int cCol = 0;
- this.insertStatement(cRow, cCol, this.traversalSource);
- cCol = cCol + this.traversalSource.length();
- for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) {
- final String[] statements = processInstruction(instruction.getOperator(), instruction.getArguments()).split("\n");
- int tempCol = cCol;
- int tempRow = cRow;
- for (int i = 0; i < statements.length; i++) {
- if (0 == i)
- tempCol = tempCol + statements[i].length() + 1;
- this.insertStatement(cRow + i, cCol, i == 0 ? "-" + statements[i] : statements[i]);
- }
- cRow = tempRow;
- cCol = tempCol;
- }
- StringBuilder builder = new StringBuilder();
- for (final String line : this.sourceCode) {
- builder.append(line).append("\n");
- }
- return builder.toString().trim();
- }
-
- private static String processInstruction(final String operator, final Object[] arguments) {
- switch (operator) {
- case "out":
- return "~" + commaSeparateOrNoneArguments(arguments) + "~>";
- case "in":
- return "<~" + commaSeparateOrNoneArguments(arguments) + "~";
- case "both":
- return "<~" + commaSeparateOrNoneArguments(arguments) + "~>";
- case "outE":
- return "~" + commaSeparateOrNoneArguments(arguments) + "~>>";
- case "inE":
- return "<<~" + commaSeparateOrNoneArguments(arguments) + "~";
- case "bothE":
- return "<<~" + commaSeparateOrNoneArguments(arguments) + "~>>";
- case "outV":
- return ">>";
- case "inV":
- return "<<";
- case "bothV":
- return "<<>>";
- case "count":
- return "}$";
- case "sum":
- return "}+";
- case "barrier":
- return "}" + commaSeparateOrNoneArguments(arguments) + "{";
- case "values":
- return "~" + commaSeparateOrNoneArguments(arguments);
- case "select":
- return "*" + commaSeparateOrNoneArguments(arguments);
- case "as":
- return "@" + commaSeparateOrNoneArguments(arguments);
- case "has":
- return "#" + commaSeparateOrNoneArguments(arguments).replaceAll(",", "");
- case "where": {
- if (arguments[0] instanceof String) {
- return "#*" + arguments[0] + ENUM_MAP.get(((P) arguments[1]).getBiPredicate()) + "*" + ((P)arguments[1]).getOriginalValue();
- } else if (arguments[0] instanceof P) {
- return "#" + ENUM_MAP.get(((P) arguments[0]).getBiPredicate()) + "*" + ((P)arguments[0]).getOriginalValue();
- }
- }
-
- case "match": {
- String statement = "M[ ]\n";
- for (final Object bytecode : arguments) {
- statement = statement + " |" + PipesTranslator.of("-").translate((Bytecode) bytecode) + "\n";
- }
- return statement;
- }
- default:
- return 0 == arguments.length ? operator : operator + "(" + commaSeparateOrNoneArguments(arguments) + ")";
- }
- }
-
- private static String commaSeparateOrNoneArguments(final Object[] arguments) {
- if (0 == arguments.length)
- return EMPTY_STRING;
- else {
- final StringBuilder builder = new StringBuilder();
- for (final Object argument : arguments) {
- builder.append(stringifyArgument(argument)).append(',');
- }
- builder.deleteCharAt(builder.length() - 1);
- return builder.toString();
- }
- }
-
- private static String stringifyArgument(final Object argument) {
- if (argument instanceof Enum)
- return "`" + ((Enum) argument).name();
- else if (argument instanceof Number) {
- if (argument instanceof Integer)
- return argument.toString();
- else if (argument instanceof Long)
- return argument + "l";
- else if (argument instanceof Float)
- return argument + "f";
- else if (argument instanceof Double)
- return argument + "d";
- else
- throw new IllegalArgumentException("Unknown number: " + argument);
- } else if (argument instanceof P) {
- final BiPredicate predicate = ((P) argument).getBiPredicate();
- if (predicate instanceof Compare)
- return ENUM_MAP.get(predicate) + stringifyArgument(((P) argument).getValue());
- else
- return argument.toString();
- } else if (argument instanceof Bytecode.Binding)
- return stringifyArgument(((Bytecode.Binding) argument).value());
- else
- return argument.toString();
- }
-
- private static List<String> generateSourceCode() {
- final List<String> sourceCode = new ArrayList<>(25);
- for (int rows = 0; rows < 25; rows++) {
- StringBuilder s = new StringBuilder();
- for (int columns = 0; columns < 100; columns++) {
- s.append(' ');
- }
- sourceCode.add(s.toString());
- }
- return sourceCode;
- }
-
- private void insertStatement(final int row, final int column, final String statement) {
- final String rLine = this.sourceCode.get(row);
- final String newRLine = rLine.substring(0, column) + statement + rLine.substring(column + statement.length());
- this.sourceCode.remove(row);
- this.sourceCode.add(row, newRLine);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProcessStandardTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProcessStandardTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProcessStandardTest.java
deleted file mode 100644
index 0242a0c..0000000
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProcessStandardTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.tinkergraph.g2.jsr223;
-
-import org.apache.tinkerpop.gremlin.GraphProviderClass;
-import org.apache.tinkerpop.gremlin.process.ProcessStandardSuite;
-import org.apache.tinkerpop.gremlin.tinkergraph.process.jsr223.TinkerGraphJavaTranslatorProvider;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-import org.junit.runner.RunWith;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-@RunWith(ProcessStandardSuite.class)
-@GraphProviderClass(provider = TinkerGraphPipesTranslatorProvider.class, graph = TinkerGraph.class)
-public class TinkerGraphPipesTranslatorProcessStandardTest {
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProvider.java
deleted file mode 100644
index 32c66dc..0000000
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/jsr223/TinkerGraphPipesTranslatorProvider.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.tinkergraph.g2.jsr223;
-
-import org.apache.tinkerpop.gremlin.LoadGraphWith;
-import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionComputerTest;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProgramTest;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategyProcessTest;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.tinkergraph.TinkerGraphProvider;
-import org.apache.tinkerpop.gremlin.tinkergraph.g2.PipesTranslator;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class TinkerGraphPipesTranslatorProvider extends TinkerGraphProvider {
-
- private static Set<String> SKIP_TESTS = new HashSet<>(Arrays.asList(
- "testProfileStrategyCallback",
- "testProfileStrategyCallbackSideEffect",
- TraversalInterruptionTest.class.getCanonicalName(),
- TraversalInterruptionComputerTest.class.getCanonicalName(),
- "shouldNeverPropagateANoBulkTraverser",
- "shouldNeverPropagateANullValuedTraverser",
- ElementIdStrategyProcessTest.class.getCanonicalName(),
- EventStrategyProcessTest.class.getCanonicalName(),
- ProgramTest.Traversals.class.getCanonicalName()));
-
-
- @Override
- public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName,
- final LoadGraphWith.GraphData loadGraphWith) {
-
- final Map<String, Object> config = super.getBaseConfiguration(graphName, test, testMethodName, loadGraphWith);
- config.put("skipTest", SKIP_TESTS.contains(testMethodName) || SKIP_TESTS.contains(test.getCanonicalName()));
- return config;
- }
-
- @Override
- public GraphTraversalSource traversal(final Graph graph) {
- if ((Boolean) graph.configuration().getProperty("skipTest"))
- return graph.traversal();
- //throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance());
- else {
- final GraphTraversalSource g = graph.traversal();
- return g.withStrategies(new TranslationStrategy(g, PipesTranslator.of("g")));
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory b/tinkergraph-gremlin/src/test/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory
deleted file mode 100644
index caec4a9..0000000
--- a/tinkergraph-gremlin/src/test/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.tinkerpop.gremlin.tinkergraph.g2.GremlinPipesScriptEngineFactory
\ No newline at end of file
[2/2] tinkerpop git commit: gremlin-pipes is now its own top-level
project. NOTE -- this is NOT permanent. talking with @spmallette on figuring
how to make this a tutorial. Need it into a project first. As things advance
we can move the project elsewhere
Posted by ok...@apache.org.
gremlin-pipes is now its own top-level project. NOTE -- this is NOT permanent. talking with @spmallette on figuring how to make this a tutorial. Need it into a project first. As things advance we can move the project elsewhere.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8c7eebf3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8c7eebf3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8c7eebf3
Branch: refs/heads/TINKERPOP-1543
Commit: 8c7eebf36fff7b5ecea7c833bd06b092a2fe84fa
Parents: feb3403
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Nov 10 09:51:30 2016 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Nov 10 09:51:30 2016 -0700
----------------------------------------------------------------------
gremlin-pipes/pom.xml | 88 ++++
.../apache/tinkerpop/gremlin/pipes/Parser.java | 453 +++++++++++++++++++
.../gremlin/pipes/PipesTranslator.java | 210 +++++++++
.../pipes/jsr223/GremlinPipesScriptEngine.java | 82 ++++
.../jsr223/GremlinPipesScriptEngineFactory.java | 122 +++++
...op.gremlin.jsr223.GremlinScriptEngineFactory | 1 +
.../gremlin/pipes/GremlinPipesToyTest.java | 70 +++
...GraphPipesTranslatorProcessStandardTest.java | 33 ++
.../TinkerGraphPipesTranslatorProvider.java | 239 ++++++++++
pom.xml | 1 +
.../g2/GremlinPipesScriptEngine.java | 80 ----
.../g2/GremlinPipesScriptEngineFactory.java | 122 -----
.../tinkergraph/g2/GremlinPipesToyTest.java | 70 ---
.../gremlin/tinkergraph/g2/Parser.java | 453 -------------------
.../gremlin/tinkergraph/g2/PipesTranslator.java | 209 ---------
...GraphPipesTranslatorProcessStandardTest.java | 34 --
.../TinkerGraphPipesTranslatorProvider.java | 76 ----
...op.gremlin.jsr223.GremlinScriptEngineFactory | 1 -
18 files changed, 1299 insertions(+), 1045 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-pipes/pom.xml b/gremlin-pipes/pom.xml
new file mode 100644
index 0000000..83d3e8d
--- /dev/null
+++ b/gremlin-pipes/pom.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tinkerpop</groupId>
+ <artifactId>tinkerpop</artifactId>
+ <version>3.2.4-SNAPSHOT</version>
+ </parent>
+ <artifactId>gremlin-pipes</artifactId>
+ <name>Apache TinkerPop :: Gremlin Pipes</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tinkerpop</groupId>
+ <artifactId>gremlin-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- TESTING -->
+ <dependency>
+ <groupId>org.apache.tinkerpop</groupId>
+ <artifactId>tinkergraph-gremlin</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tinkerpop</groupId>
+ <artifactId>gremlin-test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <properties>
+ <!-- provides a way to convert maven.test.skip value to skipTests for use in skipping python tests -->
+ <maven.test.skip>false</maven.test.skip>
+ <skipTests>${maven.test.skip}</skipTests>
+ </properties>
+ <build>
+ <directory>${basedir}/target</directory>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <resources>
+ <resource>
+ <directory>src/main/resources
+ </directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>${basedir}/src/test/resources
+ </directory>
+ </testResource>
+ </testResources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <python.home>${project.build.outputDirectory}</python.home>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/Parser.java
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/Parser.java b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/Parser.java
new file mode 100644
index 0000000..fc5c016
--- /dev/null
+++ b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/Parser.java
@@ -0,0 +1,453 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.pipes;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.util.CoreImports;
+import org.javatuples.Pair;
+import org.javatuples.Triplet;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class Parser {
+
+ private static final char NO_CHAR = '\u0489';
+ private static final char SPACE = ' ';
+ private static Set<Character> PIPES = new HashSet<>(Arrays.asList('-', '/', '|', '\\'));
+ private static Set<Character> ENDS = new HashSet<>(Arrays.asList(SPACE, NO_CHAR));
+
+ private static final List<Triplet<Pattern, String, Boolean>> OPERATOR_PATTERNS = new ArrayList<Triplet<Pattern, String, Boolean>>() {{
+ add(Triplet.with(Pattern.compile("(?<=^~)[^~]*(?=~>>)"), "outE", false));
+ add(Triplet.with(Pattern.compile("(?<=<<~)[^~]*(?=~)"), "inE", false));
+ add(Triplet.with(Pattern.compile("(?<=<<~)[^~]*(?=~>>)"), "bothE", false));
+ add(Triplet.with(Pattern.compile("(?<=^~)[^~]*(?=~>)"), "out", false));
+ add(Triplet.with(Pattern.compile("(?<=^<~)[^~]*(?=~>)"), "both", false));
+ add(Triplet.with(Pattern.compile("(?<=^<~)[^~]*(?=~)"), "in", false));
+ add(Triplet.with(Pattern.compile("(?<=^<<)$"), "inV", false));
+ add(Triplet.with(Pattern.compile("(?<=^>>)$"), "outV", false));
+ add(Triplet.with(Pattern.compile("(?<=^<<>>)$"), "bothV", false));
+ // add(Triplet.with(Pattern.compile("(?<=%)$"), "map", true));
+ add(Triplet.with(Pattern.compile("(?<=^#)$"), "filter", true));
+ add(Triplet.with(Pattern.compile("(?<=^~)(.*)"), "values", false));
+ add(Triplet.with(Pattern.compile("(?<=^@)(.*)"), "as", false));
+ add(Triplet.with(Pattern.compile("(?<=^#)([\\*].*)"), "where", false));
+ add(Triplet.with(Pattern.compile("(?<=^\\*)(.*)"), "select", false));
+ add(Triplet.with(Pattern.compile("(?<=^#!)(.*)"), "hasNot", false));
+ add(Triplet.with(Pattern.compile("(?<=^#)(.*)"), "has", false));
+ add(Triplet.with(Pattern.compile("(?<=^!)$"), "not", true));
+ add(Triplet.with(Pattern.compile("(?<=^}\\$)$"), "count", false));
+ add(Triplet.with(Pattern.compile("(?<=^}\\+)$"), "sum", false));
+ add(Triplet.with(Pattern.compile("(?<=^}%\\$)(.*)"), "groupCount", false));
+ add(Triplet.with(Pattern.compile("(?<=^}%)(.*)"), "group", false));
+ add(Triplet.with(Pattern.compile("(?<=^})([0-9]*)(?=\\{)"), "barrier", false));
+ add(Triplet.with(Pattern.compile("(?<=^})([a-z|A-Z]*)(?=\\{)"), "aggregate", false));
+ add(Triplet.with(Pattern.compile("(?<=^i)$"), "identity", false));
+ add(Triplet.with(Pattern.compile("(?<=^M)$"), "match", true));
+ add(Triplet.with(Pattern.compile("(?<=^U)$"), "union", true));
+ add(Triplet.with(Pattern.compile("(?<=^x)(.*)"), "times", false));
+ add(Triplet.with(Pattern.compile("(?<=\\{)"), "flatMap", true));
+ }};
+
+ private static final Pattern PREDICATE_PATTERN = Pattern.compile("([^!<>=]+)(([<>][=]?)|([!=]=))([^!<>=]+)");
+ private static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]");
+
+ private static final Map<String, Enum> TOKEN_MAP = new HashMap<>();
+
+ static {
+ CoreImports.getEnumImports().forEach(token -> {
+ TOKEN_MAP.put("`" + token.name(), token);
+ });
+ }
+
+ // accessible objects
+
+ private String traversalSource;
+ private Bytecode rootTraversal;
+
+ // source matrix
+
+ private char[][] source;
+ private int cRow;
+ private int cColumn;
+ private int numRows;
+ private int numCols;
+ private Pair<Integer, Integer> repeat = null;
+
+ public Parser(final String source) {
+ this.buildCharacterSource(source);
+ }
+
+ public Parser(final File file) {
+ try {
+ final BufferedReader reader = new BufferedReader(new FileReader(file));
+ final StringBuilder builder = new StringBuilder();
+ String line;
+ while ((line = reader.readLine()) != null) {
+ builder.append(line).append("\n");
+ }
+ this.buildCharacterSource(builder.toString());
+ } catch (final Exception e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
+ private void buildCharacterSource(final String source) {
+ final String[] lines = source.split("\n");
+ for (String line : lines) {
+ line = line.replaceAll("\\s+$", "");
+ if (line.length() > this.numCols)
+ this.numCols = line.length();
+ }
+ this.numRows = lines.length;
+ this.source = new char[this.numRows][this.numCols];
+ int row = 0;
+ for (String line : lines) {
+ line = line.replaceAll("\\s+$", "");
+ final char[] chars = line.toCharArray();
+ for (int column = 0; column < this.numCols; column++) {
+ this.source[row][column] = column > chars.length - 1 ? SPACE : chars[column];
+ }
+ row++;
+ }
+ this.traversalSource = this.advanceToSource();
+ this.rootTraversal = this.advanceThroughBytecode();
+ }
+
+ public Bytecode getBytecode() {
+ return this.rootTraversal;
+ }
+
+ public String getSourceCode() {
+ final StringBuilder builder = new StringBuilder();
+ for (final char[] row : this.source) {
+ builder.append(new String(row)).append("\n");
+ }
+ return builder.toString();
+ }
+
+ public String getTraversalSource() {
+ return this.traversalSource;
+ }
+
+ //////////////
+
+ private String advanceToSource() {
+ for (int column = 0; column < this.numCols; column++) {
+ for (int row = 0; row < this.numRows; row++) {
+ if (SPACE != this.source[row][column]) {
+ this.cRow = row;
+ this.cColumn = column;
+ return this.advanceThroughNextInstruction();
+ }
+ }
+ }
+ throw new IllegalStateException("The source does not have a traversal source defined");
+ }
+
+ private Bytecode advanceThroughBytecode() {
+ final Bytecode bytecode = new Bytecode();
+ while (processNextInstruction(bytecode)) {
+
+ }
+ //System.out.println(bytecode);
+ return bytecode;
+ }
+
+ private static Bytecode processBytecode(final String traversal) {
+ return new Parser(traversal).getBytecode();
+ }
+
+ private boolean processNextInstruction(final Bytecode bytecode) {
+ String instruction = this.advanceThroughNextInstruction();
+ if (null == instruction) {
+ if (null != this.repeat) {
+ final Pair<Integer, Integer> temp = this.repeat;
+ this.repeat = null;
+ bytecode.addStep("repeat", this.getChildBytecode().toArray());
+ int rTemp = this.cRow;
+ int cTemp = this.cColumn;
+ this.setCursor(temp.getValue0() + 1, temp.getValue1() + 1);
+ final Bytecode untilTraversal = this.getChildBytecode().get(0);
+ for (final Bytecode.Instruction inst : untilTraversal.getStepInstructions()) {
+ bytecode.addStep(inst.getOperator(), inst.getArguments());
+ }
+ this.setCursor(rTemp, cTemp);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ ///
+ instruction = instruction.trim();
+ //System.out.println(instruction + "!!");
+ for (final Triplet<Pattern, String, Boolean> entry : OPERATOR_PATTERNS) {
+ final Pattern pattern = entry.getValue0();
+ final String operand = entry.getValue1();
+ final Boolean children = entry.getValue2();
+ final Matcher matcher = pattern.matcher(instruction);
+ if (matcher.find()) {
+ final String arguments = matcher.group();
+ if (!arguments.isEmpty()) {
+ Object[] args;
+ if (operand.equals("has")) {
+ final Matcher m = PREDICATE_PATTERN.matcher(instruction.substring(1));
+ args = m.find() ?
+ new Object[]{m.group(1), this.mapToPredicate(m.group(2), m.group(5))} :
+ this.processArguments(arguments);
+ } else if (operand.equals("where")) {
+ final Matcher m = PREDICATE_PATTERN.matcher(instruction.substring(1));
+ args = m.find() ?
+ new Object[]{m.group(1).substring(1), this.mapToPredicate(m.group(2), m.group(5).substring(1))} :
+ this.processArguments(arguments);
+ } else
+ args = this.processArguments(arguments);
+ bytecode.addStep(operand, args);
+ } else if (children) {
+ this.moveCursor(0, 1);
+ bytecode.addStep(operand, this.getChildBytecode().toArray());
+ } else
+ bytecode.addStep(operand);
+ return true;
+ }
+ }
+ ////////
+ if (instruction.equals("[")) {
+ for (final Bytecode b : this.getChildBytecode()) {
+ if (b.getInstructions().iterator().hasNext())
+ bytecode.addStep("by", b);
+ else
+ bytecode.addStep("by");
+ }
+ } else if (instruction.contains("(")) {
+ bytecode.addStep(instruction.substring(0, instruction.indexOf('(')),
+ this.processArguments(instruction.substring(instruction.indexOf('(') + 1, instruction.length() - 1)));
+ } else
+ bytecode.addStep(instruction);
+
+ return true;
+ }
+
+ private List<Bytecode> getChildBytecode() {
+ return this.getChildBytecode(true, 0, this.cRow, this.cColumn, new ArrayList<>());
+ }
+
+ private List<Bytecode> getChildBytecode(final boolean branch, final int previousRowOffset, final int cRow, final int cColumn, final List<Bytecode> children) {
+ this.setCursor(cRow, cColumn);
+ int endRow = -1;
+ int endColumn = -1;
+ if (branch) {
+ int openNest = 1;
+ while (true) {
+ if ('[' == this.currentCharacter()) {
+ openNest++;
+ } else if (']' == this.currentCharacter()) {
+ openNest--;
+ if (0 == openNest) {
+ endRow = this.cRow;
+ endColumn = this.cColumn + 1;
+ break;
+ }
+ } else if (NO_CHAR == this.currentCharacter()) {
+ endRow = this.cRow;
+ endColumn = this.cColumn + 1;
+ break;
+ }
+ this.moveCursor(0, 1);
+ }
+ }
+ this.setCursor(cRow, cColumn);
+ if ('|' == this.peekCharacter(-1, 0) && previousRowOffset <= 0)
+ this.getChildBytecode(false, -1, cRow - 1, cColumn, children);
+ //
+ this.setCursor(cRow, cColumn);
+ if ('/' == this.peekCharacter(-1, 0))
+ this.getChildBytecode(false, -1, cRow - 1, cColumn + 1, children);
+ else if ('/' == this.peekCharacter(-1, 1))
+ this.getChildBytecode(false, -1, cRow - 1, cColumn + 1, children);
+ //
+ this.setCursor(cRow, cColumn);
+ if ('-' == this.currentCharacter() || '-' == this.peekCharacter(0, 1)) {
+ this.moveCursor(0, 1);
+ children.add(this.advanceThroughBytecode());
+ }
+ //
+ this.setCursor(cRow, cColumn);
+ if ('\\' == this.peekCharacter(1, 0))
+ this.getChildBytecode(false, 1, cRow + 1, cColumn + 1, children);
+ else if ('\\' == this.peekCharacter(1, 1))
+ this.getChildBytecode(false, 1, cRow + 1, cColumn + 1, children);
+ //
+ this.setCursor(cRow, cColumn);
+ if ('|' == this.peekCharacter(1, 0) && previousRowOffset >= 0)
+ this.getChildBytecode(false, 1, cRow + 1, cColumn, children);
+ //
+ if (branch)
+ this.setCursor(endRow, endColumn);
+ return children;
+ }
+
+ private boolean advanceToNextInstruction() {
+ while (true) {
+ final char current = this.currentCharacter();
+ if ('[' == current && '^' == this.peekCharacter(1, 0)) {
+ this.repeat = Pair.with(this.cRow, this.cColumn);
+ this.moveCursor(0, 1);
+ return true;
+ }
+ if (PIPES.contains(current)) {
+ if ('-' == current)
+ this.moveCursor(0, 1);
+ else if ('/' == current) {
+ if ('/' == this.peekCharacter(-1, 1))
+ this.moveCursor(-1, 1);
+ else if ('-' == this.peekCharacter(0, 1))
+ this.moveCursor(0, 1);
+ else
+ return false;
+ } else if ('\\' == current) {
+ if ('\\' == this.peekCharacter(1, 1))
+ this.moveCursor(1, 1);
+ else if ('-' == this.peekCharacter(0, 1))
+ this.moveCursor(0, 1);
+ else
+ return false;
+ } else
+ return false;
+ } else if (ENDS.contains(current)) {
+ if ('/' == this.peekCharacter(-1, 0))
+ this.moveCursor(-1, 0);
+ else if ('\\' == this.peekCharacter(1, 0))
+ this.moveCursor(1, 0);
+ else
+ return false;
+ } else
+ return true;
+ }
+ }
+
+ private String advanceThroughNextInstruction() {
+ if (!this.advanceToNextInstruction())
+ return null;
+ String instruction = "";
+ char current;
+ while (NO_CHAR != (current = this.currentCharacter())) {
+ if ('-' == current || ('[' == current && !instruction.isEmpty()))
+ break;
+ if ('[' == current && instruction.isEmpty()) {
+ this.moveCursor(0, 1);
+ return "[";
+ } else if (']' == current) {
+ this.moveCursor(0, 1);
+ break;
+ } else {
+ instruction = instruction + current;
+ this.moveCursor(0, 1);
+ }
+ }
+ return instruction.trim().isEmpty() ? null : instruction;
+
+ }
+
+ //////////
+
+ private char currentCharacter() {
+ return this.cRow >= 0 && this.cRow < this.numRows && this.cColumn >= 0 && this.cColumn < this.numCols ?
+ this.source[this.cRow][this.cColumn] :
+ NO_CHAR;
+ }
+
+ private char peekCharacter(final int rOffset, final int cOffset) {
+ final int tempRow = this.cRow;
+ final int tempColumn = this.cColumn;
+ this.moveCursor(rOffset, cOffset);
+ final char peek = this.currentCharacter();
+ this.setCursor(tempRow, tempColumn);
+ return peek;
+ }
+
+ private void moveCursor(final int rOffset, final int cOffset) {
+ this.setCursor(this.cRow + rOffset, this.cColumn + cOffset);
+ }
+
+ private void setCursor(final int cRow, final int cColumn) {
+ this.cRow = cRow;
+ this.cColumn = cColumn;
+ }
+
+ private <V> P<V> mapToPredicate(final String predicate, final V value) {
+ if (predicate.equals("=="))
+ return P.eq(value);
+ else if (predicate.equals(">="))
+ return P.gte(value);
+ else if (predicate.equals("<="))
+ return P.lte(value);
+ else if (predicate.equals(">"))
+ return P.gt(value);
+ else if (predicate.equals("<"))
+ return P.lt(value);
+ else if (predicate.equals("!="))
+ return P.neq(value);
+ else
+ throw new IllegalStateException("Can not parse predicate: " + predicate + ":" + value);
+
+ }
+
+ private Object[] processArguments(final String arguments) {
+ final String[] args = arguments.split(",");
+ final Object[] objects = new Object[args.length];
+ for (int i = 0; i < args.length; i++) {
+ final String arg = args[i];
+ if (arg.equals("true") || arg.equals("false"))
+ objects[i] = Boolean.valueOf(arg);
+ else if (NUMBER_PATTERN.matcher(arg).find()) {
+ if (arg.contains(".") && arg.endsWith("f"))
+ objects[i] = Float.valueOf(arg);
+ else if (arg.contains("."))
+ objects[i] = Double.valueOf(arg);
+ else if (arg.endsWith("l"))
+ objects[i] = Long.valueOf(arg);
+ else
+ objects[i] = Integer.valueOf(arg);
+ } else if (arg.startsWith("'") && arg.endsWith("'"))
+ objects[i] = arg.substring(1, arg.length() - 1);
+ else if (arg.startsWith("`"))
+ objects[i] = TOKEN_MAP.get(arg);
+ else
+ objects[i] = arg;
+ }
+ return objects;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/PipesTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/PipesTranslator.java b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/PipesTranslator.java
new file mode 100644
index 0000000..9cfbb41
--- /dev/null
+++ b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/PipesTranslator.java
@@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.pipes;
+
+import org.apache.tinkerpop.gremlin.pipes.jsr223.GremlinPipesScriptEngineFactory;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Compare;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Translator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiPredicate;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class PipesTranslator implements Translator.ScriptTranslator {
+
+ private static final String EMPTY_STRING = new String();
+
+ private final String traversalSource;
+ private final List<String> sourceCode = PipesTranslator.generateSourceCode();
+
+ private static Map<Enum, String> ENUM_MAP = new HashMap<Enum, String>() {{
+ put(Compare.eq, "==");
+ put(Compare.gt, ">");
+ put(Compare.gte, ">=");
+ put(Compare.lt, "<");
+ put(Compare.lte, "<=");
+ put(Compare.neq, "!=");
+ }};
+
+ private PipesTranslator(final String traversalSource) {
+ this.traversalSource = traversalSource;
+ }
+
+ public static PipesTranslator of(final String traversalSource) {
+ return new PipesTranslator(traversalSource);
+ }
+
+ @Override
+ public String getTraversalSource() {
+ return this.traversalSource;
+ }
+
+ @Override
+ public String getTargetLanguage() {
+ return new GremlinPipesScriptEngineFactory().getLanguageName();
+ }
+
+ @Override
+ public String translate(final Bytecode bytecode) {
+
+ int cRow = 10;
+ int cCol = 0;
+ this.insertStatement(cRow, cCol, this.traversalSource);
+ cCol = cCol + this.traversalSource.length();
+ for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) {
+ final String[] statements = processInstruction(instruction.getOperator(), instruction.getArguments()).split("\n");
+ int tempCol = cCol;
+ int tempRow = cRow;
+ for (int i = 0; i < statements.length; i++) {
+ if (0 == i)
+ tempCol = tempCol + statements[i].length() + 1;
+ this.insertStatement(cRow + i, cCol, i == 0 ? "-" + statements[i] : statements[i]);
+ }
+ cRow = tempRow;
+ cCol = tempCol;
+ }
+ StringBuilder builder = new StringBuilder();
+ for (final String line : this.sourceCode) {
+ builder.append(line).append("\n");
+ }
+ return builder.toString().trim();
+ }
+
+ private static String processInstruction(final String operator, final Object[] arguments) {
+ switch (operator) {
+ case "out":
+ return "~" + commaSeparateOrNoneArguments(arguments) + "~>";
+ case "in":
+ return "<~" + commaSeparateOrNoneArguments(arguments) + "~";
+ case "both":
+ return "<~" + commaSeparateOrNoneArguments(arguments) + "~>";
+ case "outE":
+ return "~" + commaSeparateOrNoneArguments(arguments) + "~>>";
+ case "inE":
+ return "<<~" + commaSeparateOrNoneArguments(arguments) + "~";
+ case "bothE":
+ return "<<~" + commaSeparateOrNoneArguments(arguments) + "~>>";
+ case "outV":
+ return ">>";
+ case "inV":
+ return "<<";
+ case "bothV":
+ return "<<>>";
+ case "count":
+ return "}$";
+ case "sum":
+ return "}+";
+ case "barrier":
+ return "}" + commaSeparateOrNoneArguments(arguments) + "{";
+ case "values":
+ return "~" + commaSeparateOrNoneArguments(arguments);
+ case "select":
+ return "*" + commaSeparateOrNoneArguments(arguments);
+ case "as":
+ return "@" + commaSeparateOrNoneArguments(arguments);
+ case "has":
+ return "#" + commaSeparateOrNoneArguments(arguments).replaceAll(",", "");
+ case "where": {
+ if (arguments[0] instanceof String) {
+ return "#*" + arguments[0] + ENUM_MAP.get(((P) arguments[1]).getBiPredicate()) + "*" + ((P) arguments[1]).getOriginalValue();
+ } else if (arguments[0] instanceof P) {
+ return "#" + ENUM_MAP.get(((P) arguments[0]).getBiPredicate()) + "*" + ((P) arguments[0]).getOriginalValue();
+ }
+ }
+
+ case "match": {
+ String statement = "M[ ]\n";
+ for (final Object bytecode : arguments) {
+ statement = statement + " |" + PipesTranslator.of("-").translate((Bytecode) bytecode) + "\n";
+ }
+ return statement;
+ }
+ default:
+ return 0 == arguments.length ? operator : operator + "(" + commaSeparateOrNoneArguments(arguments) + ")";
+ }
+ }
+
+ private static String commaSeparateOrNoneArguments(final Object[] arguments) {
+ if (0 == arguments.length)
+ return EMPTY_STRING;
+ else {
+ final StringBuilder builder = new StringBuilder();
+ for (final Object argument : arguments) {
+ builder.append(stringifyArgument(argument)).append(',');
+ }
+ builder.deleteCharAt(builder.length() - 1);
+ return builder.toString();
+ }
+ }
+
+ private static String stringifyArgument(final Object argument) {
+ if (argument instanceof Enum)
+ return "`" + ((Enum) argument).name();
+ else if (argument instanceof Number) {
+ if (argument instanceof Integer)
+ return argument.toString();
+ else if (argument instanceof Long)
+ return argument + "l";
+ else if (argument instanceof Float)
+ return argument + "f";
+ else if (argument instanceof Double)
+ return argument + "d";
+ else
+ throw new IllegalArgumentException("Unknown number: " + argument);
+ } else if (argument instanceof P) {
+ final BiPredicate predicate = ((P) argument).getBiPredicate();
+ if (predicate instanceof Compare)
+ return ENUM_MAP.get(predicate) + stringifyArgument(((P) argument).getValue());
+ else
+ return argument.toString();
+ } else if (argument instanceof Bytecode.Binding)
+ return stringifyArgument(((Bytecode.Binding) argument).value());
+ else
+ return argument.toString();
+ }
+
+ private static List<String> generateSourceCode() {
+ final List<String> sourceCode = new ArrayList<>(25);
+ for (int rows = 0; rows < 25; rows++) {
+ StringBuilder s = new StringBuilder();
+ for (int columns = 0; columns < 100; columns++) {
+ s.append(' ');
+ }
+ sourceCode.add(s.toString());
+ }
+ return sourceCode;
+ }
+
+ private void insertStatement(final int row, final int column, final String statement) {
+ final String rLine = this.sourceCode.get(row);
+ final String newRLine = rLine.substring(0, column) + statement + rLine.substring(column + statement.length());
+ this.sourceCode.remove(row);
+ this.sourceCode.add(row, newRLine);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngine.java b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngine.java
new file mode 100644
index 0000000..3ce118e
--- /dev/null
+++ b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngine.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.pipes.jsr223;
+
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory;
+import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
+import org.apache.tinkerpop.gremlin.pipes.Parser;
+import org.apache.tinkerpop.gremlin.pipes.PipesTranslator;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
+
+import javax.script.AbstractScriptEngine;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class GremlinPipesScriptEngine extends AbstractScriptEngine implements GremlinScriptEngine {
+
+ @Override
+ public Object eval(final String script, final ScriptContext context) throws ScriptException {
+ final Parser parser = new Parser(script);
+ final TraversalSource source = (TraversalSource) context.getBindings(ScriptContext.ENGINE_SCOPE).get(parser.getTraversalSource());
+ System.out.println(script);
+ return JavaTranslator.of(source).translate(parser.getBytecode());
+ }
+
+ @Override
+ public Object eval(final Reader reader, final ScriptContext context) throws ScriptException {
+ try {
+ final BufferedReader buffer = new BufferedReader(reader);
+ final StringBuilder builder = new StringBuilder();
+ String line;
+ while (null != (line = buffer.readLine())) {
+ builder.append(line).append("\n");
+ }
+ return this.eval(builder.toString(), context);
+ } catch (final IOException e) {
+ throw new ScriptException(e);
+ }
+ }
+
+ @Override
+ public Bindings createBindings() {
+ return new SimpleBindings();
+ }
+
+ @Override
+ public GremlinScriptEngineFactory getFactory() {
+ return new GremlinPipesScriptEngineFactory();
+ }
+
+ @Override
+ public Traversal.Admin eval(final Bytecode bytecode, final Bindings bindings) throws ScriptException {
+ return (Traversal.Admin) this.eval(PipesTranslator.of("g").translate(bytecode), bindings);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngineFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngineFactory.java b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngineFactory.java
new file mode 100644
index 0000000..7d998b7
--- /dev/null
+++ b/gremlin-pipes/src/main/java/org/apache/tinkerpop/gremlin/pipes/jsr223/GremlinPipesScriptEngineFactory.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.pipes.jsr223;
+
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineManager;
+import org.apache.tinkerpop.gremlin.util.Gremlin;
+
+import javax.script.ScriptEngine;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class GremlinPipesScriptEngineFactory implements GremlinScriptEngineFactory {
+
+ private static final String ENGINE_NAME = "gremlin-pipes";
+ private static final String LANGUAGE_NAME = "gremlin-pipes";
+ private static final String PLAIN = "plain";
+ private static final List<String> EXTENSIONS = Collections.singletonList("txt");
+
+ @Override
+ public void setCustomizerManager(final GremlinScriptEngineManager manager) {
+
+ }
+
+ @Override
+ public String getEngineName() {
+ return ENGINE_NAME;
+ }
+
+ @Override
+ public String getEngineVersion() {
+ return Gremlin.version();
+ }
+
+ @Override
+ public List<String> getExtensions() {
+ return EXTENSIONS;
+ }
+
+ @Override
+ public String getLanguageName() {
+ return LANGUAGE_NAME;
+ }
+
+ @Override
+ public String getLanguageVersion() {
+ return Gremlin.version();
+ }
+
+ @Override
+ public String getMethodCallSyntax(final String obj, final String m, final String... args) {
+ return null;
+ }
+
+ @Override
+ public List<String> getMimeTypes() {
+ return Collections.singletonList(PLAIN);
+ }
+
+ @Override
+ public List<String> getNames() {
+ return Collections.singletonList(LANGUAGE_NAME);
+ }
+
+ @Override
+ public String getOutputStatement(final String toDisplay) {
+ return toDisplay;
+ }
+
+ @Override
+ public Object getParameter(final String key) {
+ if (key.equals(ScriptEngine.ENGINE)) {
+ return this.getEngineName();
+ } else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
+ return this.getEngineVersion();
+ } else if (key.equals(ScriptEngine.NAME)) {
+ return ENGINE_NAME;
+ } else if (key.equals(ScriptEngine.LANGUAGE)) {
+ return this.getLanguageName();
+ } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
+ return this.getLanguageVersion();
+ } else
+ return null;
+ }
+
+ @Override
+ public String getProgram(final String... statements) {
+ String program = "";
+
+ for (String statement : statements) {
+ program = program + statement + "\n";
+ }
+
+ return program;
+ }
+
+ @Override
+ public GremlinScriptEngine getScriptEngine() {
+ return new GremlinPipesScriptEngine();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory b/gremlin-pipes/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory
new file mode 100644
index 0000000..bae0421
--- /dev/null
+++ b/gremlin-pipes/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory
@@ -0,0 +1 @@
+org.apache.tinkerpop.gremlin.pipes.jsr223.GremlinPipesScriptEngineFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/GremlinPipesToyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/GremlinPipesToyTest.java b/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/GremlinPipesToyTest.java
new file mode 100644
index 0000000..e57b4ad
--- /dev/null
+++ b/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/GremlinPipesToyTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.pipes;
+
+import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.junit.Test;
+
+import java.io.File;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class GremlinPipesToyTest {
+
+ @Test
+ public void aTest() {
+ assert T.id instanceof Enum;
+ }
+
+ @Test
+ public void shouldParse() {
+ final GraphTraversalSource g = TinkerFactory.createModern().traversal();
+ for (int i = 2; i < 8; i++) {
+ final Parser parser = new Parser(new File("/Users/marko/Desktop/g" + i + ".txt"));
+ System.out.println("\n///////////////////////////////////////////////////");
+ System.out.println("///////////////////////////////////////////////////");
+ System.out.println("///////////////////////////////////////////////////\n");
+ System.out.println("// 2g source\n");
+ System.out.println(parser.getSourceCode());
+ System.out.println("\n// Gremlin bytecode");
+ System.out.println(parser.getBytecode());
+ System.out.println("\n// Gremlin machine code");
+ final Traversal.Admin<?, ?> traversal = JavaTranslator.of(g).translate(parser.getBytecode());
+ System.out.println(traversal);
+ System.out.println("\n// Optimized machine code");
+ traversal.applyStrategies();
+ System.out.println(traversal);
+ System.out.println("\n// Result");
+ System.out.println(traversal.toList());
+ }
+ }
+
+ @Test
+ public void shouldTranslate() {
+ final GraphTraversalSource g = TinkerFactory.createModern().traversal();
+ String translation = PipesTranslator.of("g").translate(g.V().out().in("created","knows").values("name").count().asAdmin().getBytecode());
+ System.out.println(translation);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProcessStandardTest.java
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProcessStandardTest.java b/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProcessStandardTest.java
new file mode 100644
index 0000000..299fa15
--- /dev/null
+++ b/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProcessStandardTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.pipes;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.process.ProcessStandardSuite;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(ProcessStandardSuite.class)
+@GraphProviderClass(provider = TinkerGraphPipesTranslatorProvider.class, graph = TinkerGraph.class)
+public class TinkerGraphPipesTranslatorProcessStandardTest {
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProvider.java b/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProvider.java
new file mode 100644
index 0000000..048710e
--- /dev/null
+++ b/gremlin-pipes/src/test/java/org/apache/tinkerpop/gremlin/pipes/TinkerGraphPipesTranslatorProvider.java
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.pipes;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.AbstractGraphProvider;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionComputerTest;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProgramTest;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategyProcessTest;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.GraphTest;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.io.IoEdgeTest;
+import org.apache.tinkerpop.gremlin.structure.io.IoVertexTest;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedGraphTest;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphTest;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerEdge;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerElement;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphVariables;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerProperty;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertexProperty;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class TinkerGraphPipesTranslatorProvider extends AbstractGraphProvider {
+
+ private static final Set<Class> IMPLEMENTATION = new HashSet<Class>() {{
+ add(TinkerEdge.class);
+ add(TinkerElement.class);
+ add(TinkerGraph.class);
+ add(TinkerGraphVariables.class);
+ add(TinkerProperty.class);
+ add(TinkerVertex.class);
+ add(TinkerVertexProperty.class);
+ }};
+
+ @Override
+ public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName,
+ final LoadGraphWith.GraphData loadGraphWith) {
+ final TinkerGraph.DefaultIdManager idManager = selectIdMakerFromGraphData(loadGraphWith);
+ final String idMaker = (idManager.equals(TinkerGraph.DefaultIdManager.ANY) ? selectIdMakerFromTest(test, testMethodName) : idManager).name();
+ return new HashMap<String, Object>() {{
+ put(Graph.GRAPH, TinkerGraph.class.getName());
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, idMaker);
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, idMaker);
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, idMaker);
+ if (requiresListCardinalityAsDefault(loadGraphWith, test, testMethodName))
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name());
+ if (requiresPersistence(test, testMethodName)) {
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
+ final File tempDir = TestHelper.makeTestDataPath(test, "temp");
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION,
+ tempDir.getAbsolutePath() + File.separator + testMethodName + ".kryo");
+ }
+ put("skipTest", SKIP_TESTS.contains(testMethodName) || SKIP_TESTS.contains(test.getCanonicalName()));
+ }};
+
+ }
+
+ @Override
+ public void clear(final Graph graph, final Configuration configuration) throws Exception {
+ if (graph != null)
+ graph.close();
+
+ // in the even the graph is persisted we need to clean up
+ final String graphLocation = configuration.getString(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, null);
+ if (graphLocation != null) {
+ final File f = new File(graphLocation);
+ f.delete();
+ }
+ }
+
+ @Override
+ public Set<Class> getImplementations() {
+ return IMPLEMENTATION;
+ }
+
+ /**
+ * Determines if a test requires TinkerGraph persistence to be configured with graph location and format.
+ */
+ protected static boolean requiresPersistence(final Class<?> test, final String testMethodName) {
+ return test == GraphTest.class && testMethodName.equals("shouldPersistDataOnClose");
+ }
+
+ /**
+ * Determines if a test requires a different cardinality as the default or not.
+ */
+ protected static boolean requiresListCardinalityAsDefault(final LoadGraphWith.GraphData loadGraphWith,
+ final Class<?> test, final String testMethodName) {
+ return loadGraphWith == LoadGraphWith.GraphData.CREW
+ || (test == StarGraphTest.class && testMethodName.equals("shouldAttachWithCreateMethod"))
+ || (test == DetachedGraphTest.class && testMethodName.equals("testAttachableCreateMethod"));
+ }
+
+ /**
+ * Some tests require special configuration for TinkerGraph to properly configure the id manager.
+ */
+ protected TinkerGraph.DefaultIdManager selectIdMakerFromTest(final Class<?> test, final String testMethodName) {
+ if (test.equals(GraphTest.class)) {
+ final Set<String> testsThatNeedLongIdManager = new HashSet<String>() {{
+ add("shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentations");
+ add("shouldIterateVerticesWithNumericIdSupportUsingIntegerRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingIntegerRepresentations");
+ add("shouldIterateVerticesWithNumericIdSupportUsingFloatRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingFloatRepresentations");
+ add("shouldIterateVerticesWithNumericIdSupportUsingStringRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingStringRepresentations");
+ add("shouldIterateEdgesWithNumericIdSupportUsingDoubleRepresentation");
+ add("shouldIterateEdgesWithNumericIdSupportUsingDoubleRepresentations");
+ add("shouldIterateEdgesWithNumericIdSupportUsingIntegerRepresentation");
+ add("shouldIterateEdgesWithNumericIdSupportUsingIntegerRepresentations");
+ add("shouldIterateEdgesWithNumericIdSupportUsingFloatRepresentation");
+ add("shouldIterateEdgesWithNumericIdSupportUsingFloatRepresentations");
+ add("shouldIterateEdgesWithNumericIdSupportUsingStringRepresentation");
+ add("shouldIterateEdgesWithNumericIdSupportUsingStringRepresentations");
+ }};
+
+ final Set<String> testsThatNeedUuidIdManager = new HashSet<String>() {{
+ add("shouldIterateVerticesWithUuidIdSupportUsingStringRepresentation");
+ add("shouldIterateVerticesWithUuidIdSupportUsingStringRepresentations");
+ add("shouldIterateEdgesWithUuidIdSupportUsingStringRepresentation");
+ add("shouldIterateEdgesWithUuidIdSupportUsingStringRepresentations");
+ }};
+
+ if (testsThatNeedLongIdManager.contains(testMethodName))
+ return TinkerGraph.DefaultIdManager.LONG;
+ else if (testsThatNeedUuidIdManager.contains(testMethodName))
+ return TinkerGraph.DefaultIdManager.UUID;
+ } else if (test.equals(IoEdgeTest.class)) {
+ final Set<String> testsThatNeedLongIdManager = new HashSet<String>() {{
+ add("shouldReadWriteEdge[graphson-v1]");
+ add("shouldReadWriteDetachedEdgeAsReference[graphson-v1]");
+ add("shouldReadWriteDetachedEdge[graphson-v1]");
+ add("shouldReadWriteEdge[graphson-v2]");
+ add("shouldReadWriteDetachedEdgeAsReference[graphson-v2]");
+ add("shouldReadWriteDetachedEdge[graphson-v2]");
+ }};
+
+ if (testsThatNeedLongIdManager.contains(testMethodName))
+ return TinkerGraph.DefaultIdManager.LONG;
+ } else if (test.equals(IoVertexTest.class)) {
+ final Set<String> testsThatNeedLongIdManager = new HashSet<String>() {{
+ add("shouldReadWriteVertexWithBOTHEdges[graphson-v1]");
+ add("shouldReadWriteVertexWithINEdges[graphson-v1]");
+ add("shouldReadWriteVertexWithOUTEdges[graphson-v1]");
+ add("shouldReadWriteVertexNoEdges[graphson-v1]");
+ add("shouldReadWriteDetachedVertexNoEdges[graphson-v1]");
+ add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson-v1]");
+ add("shouldReadWriteVertexMultiPropsNoEdges[graphson-v1]");
+ add("shouldReadWriteVertexWithBOTHEdges[graphson-v2]");
+ add("shouldReadWriteVertexWithINEdges[graphson-v2]");
+ add("shouldReadWriteVertexWithOUTEdges[graphson-v2]");
+ add("shouldReadWriteVertexNoEdges[graphson-v2]");
+ add("shouldReadWriteDetachedVertexNoEdges[graphson-v2]");
+ add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson-v2]");
+ add("shouldReadWriteVertexMultiPropsNoEdges[graphson-v2]");
+ }};
+
+ if (testsThatNeedLongIdManager.contains(testMethodName))
+ return TinkerGraph.DefaultIdManager.LONG;
+ }
+
+ return TinkerGraph.DefaultIdManager.ANY;
+ }
+
+ /**
+ * Test that load with specific graph data can be configured with a specific id manager as the data type to
+ * be used in the test for that graph is known.
+ */
+ protected TinkerGraph.DefaultIdManager selectIdMakerFromGraphData(final LoadGraphWith.GraphData loadGraphWith) {
+ if (null == loadGraphWith) return TinkerGraph.DefaultIdManager.ANY;
+ if (loadGraphWith.equals(LoadGraphWith.GraphData.CLASSIC))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.MODERN))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.CREW))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.GRATEFUL))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else
+ throw new IllegalStateException(String.format("Need to define a new %s for %s", TinkerGraph.IdManager.class.getName(), loadGraphWith.name()));
+ }
+
+ private static Set<String> SKIP_TESTS = new HashSet<>(Arrays.asList(
+ "testProfileStrategyCallback",
+ "testProfileStrategyCallbackSideEffect",
+ TraversalInterruptionTest.class.getCanonicalName(),
+ TraversalInterruptionComputerTest.class.getCanonicalName(),
+ "shouldNeverPropagateANoBulkTraverser",
+ "shouldNeverPropagateANullValuedTraverser",
+ ElementIdStrategyProcessTest.class.getCanonicalName(),
+ EventStrategyProcessTest.class.getCanonicalName(),
+ ProgramTest.Traversals.class.getCanonicalName()));
+
+ @Override
+ public GraphTraversalSource traversal(final Graph graph) {
+ if ((Boolean) graph.configuration().getProperty("skipTest"))
+ return graph.traversal();
+ //throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance());
+ else {
+ final GraphTraversalSource g = graph.traversal();
+ return g.withStrategies(new TranslationStrategy(g, PipesTranslator.of("g")));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e58bf07..e06c0d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -118,6 +118,7 @@ limitations under the License.
<module>gremlin-groovy-test</module>
<module>tinkergraph-gremlin</module>
<module>gremlin-python</module>
+ <module>gremlin-pipes</module>
<module>hadoop-gremlin</module>
<module>spark-gremlin</module>
<module>giraph-gremlin</module>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngine.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngine.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngine.java
deleted file mode 100644
index 7f7182b..0000000
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngine.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.tinkergraph.g2;
-
-import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
-import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory;
-import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
-
-import javax.script.AbstractScriptEngine;
-import javax.script.Bindings;
-import javax.script.ScriptContext;
-import javax.script.ScriptException;
-import javax.script.SimpleBindings;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Reader;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class GremlinPipesScriptEngine extends AbstractScriptEngine implements GremlinScriptEngine {
-
- @Override
- public Object eval(final String script, final ScriptContext context) throws ScriptException {
- final Parser parser = new Parser(script);
- final TraversalSource source = (TraversalSource) context.getBindings(ScriptContext.ENGINE_SCOPE).get(parser.getTraversalSource());
- System.out.println(script);
- return JavaTranslator.of(source).translate(parser.getBytecode());
- }
-
- @Override
- public Object eval(final Reader reader, final ScriptContext context) throws ScriptException {
- try {
- final BufferedReader buffer = new BufferedReader(reader);
- final StringBuilder builder = new StringBuilder();
- String line;
- while (null != (line = buffer.readLine())) {
- builder.append(line).append("\n");
- }
- return this.eval(builder.toString(), context);
- } catch (final IOException e) {
- throw new ScriptException(e);
- }
- }
-
- @Override
- public Bindings createBindings() {
- return new SimpleBindings();
- }
-
- @Override
- public GremlinScriptEngineFactory getFactory() {
- return new GremlinPipesScriptEngineFactory();
- }
-
- @Override
- public Traversal.Admin eval(final Bytecode bytecode, final Bindings bindings) throws ScriptException {
- return (Traversal.Admin) this.eval(PipesTranslator.of("g").translate(bytecode), bindings);
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngineFactory.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngineFactory.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngineFactory.java
deleted file mode 100644
index 10d3af1..0000000
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesScriptEngineFactory.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.tinkergraph.g2;
-
-import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
-import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory;
-import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineManager;
-import org.apache.tinkerpop.gremlin.util.Gremlin;
-
-import javax.script.ScriptEngine;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class GremlinPipesScriptEngineFactory implements GremlinScriptEngineFactory {
-
- private static final String ENGINE_NAME = "gremlin-pipes";
- private static final String LANGUAGE_NAME = "gremlin-pipes";
- private static final String PLAIN = "plain";
- private static final List<String> EXTENSIONS = Collections.singletonList("txt");
-
- @Override
- public void setCustomizerManager(final GremlinScriptEngineManager manager) {
-
- }
-
- @Override
- public String getEngineName() {
- return ENGINE_NAME;
- }
-
- @Override
- public String getEngineVersion() {
- return Gremlin.version();
- }
-
- @Override
- public List<String> getExtensions() {
- return EXTENSIONS;
- }
-
- @Override
- public String getLanguageName() {
- return LANGUAGE_NAME;
- }
-
- @Override
- public String getLanguageVersion() {
- return Gremlin.version();
- }
-
- @Override
- public String getMethodCallSyntax(final String obj, final String m, final String... args) {
- return null;
- }
-
- @Override
- public List<String> getMimeTypes() {
- return Collections.singletonList(PLAIN);
- }
-
- @Override
- public List<String> getNames() {
- return Collections.singletonList(LANGUAGE_NAME);
- }
-
- @Override
- public String getOutputStatement(final String toDisplay) {
- return toDisplay;
- }
-
- @Override
- public Object getParameter(final String key) {
- if (key.equals(ScriptEngine.ENGINE)) {
- return this.getEngineName();
- } else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
- return this.getEngineVersion();
- } else if (key.equals(ScriptEngine.NAME)) {
- return ENGINE_NAME;
- } else if (key.equals(ScriptEngine.LANGUAGE)) {
- return this.getLanguageName();
- } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
- return this.getLanguageVersion();
- } else
- return null;
- }
-
- @Override
- public String getProgram(final String... statements) {
- String program = "";
-
- for (String statement : statements) {
- program = program + statement + "\n";
- }
-
- return program;
- }
-
- @Override
- public GremlinScriptEngine getScriptEngine() {
- return new GremlinPipesScriptEngine();
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8c7eebf3/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesToyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesToyTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesToyTest.java
deleted file mode 100644
index 2389120..0000000
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/g2/GremlinPipesToyTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.tinkergraph.g2;
-
-import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
-import org.junit.Test;
-
-import java.io.File;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class GremlinPipesToyTest {
-
- @Test
- public void aTest() {
- assert T.id instanceof Enum;
- }
-
- @Test
- public void shouldParse() {
- final GraphTraversalSource g = TinkerFactory.createModern().traversal();
- for (int i = 2; i < 8; i++) {
- final Parser parser = new Parser(new File("/Users/marko/Desktop/g" + i + ".txt"));
- System.out.println("\n///////////////////////////////////////////////////");
- System.out.println("///////////////////////////////////////////////////");
- System.out.println("///////////////////////////////////////////////////\n");
- System.out.println("// 2g source\n");
- System.out.println(parser.getSourceCode());
- System.out.println("\n// Gremlin bytecode");
- System.out.println(parser.getBytecode());
- System.out.println("\n// Gremlin machine code");
- final Traversal.Admin<?, ?> traversal = JavaTranslator.of(g).translate(parser.getBytecode());
- System.out.println(traversal);
- System.out.println("\n// Optimized machine code");
- traversal.applyStrategies();
- System.out.println(traversal);
- System.out.println("\n// Result");
- System.out.println(traversal.toList());
- }
- }
-
- @Test
- public void shouldTranslate() {
- final GraphTraversalSource g = TinkerFactory.createModern().traversal();
- String translation = PipesTranslator.of("g").translate(g.V().out().in("created","knows").values("name").count().asAdmin().getBytecode());
- System.out.println(translation);
- }
-}