You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mrql.apache.org by fe...@apache.org on 2014/03/13 15:24:27 UTC
[02/26] MRQL-32: Refactoring directory structure for Eclipse
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/gen/SymbolTable.java
----------------------------------------------------------------------
diff --git a/src/main/java/gen/SymbolTable.java b/src/main/java/gen/SymbolTable.java
deleted file mode 100644
index 52ea868..0000000
--- a/src/main/java/gen/SymbolTable.java
+++ /dev/null
@@ -1,193 +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.mrql.gen;
-
-import java.io.*;
-import java.util.Iterator;
-
-
-/* A symbol in the symbol table */
-class SymbolCell {
- String name;
- Tree binding;
- SymbolCell next;
- SymbolCell ( String n, Tree v, SymbolCell r ) { name=n; binding=v; next=r; }
-}
-
-
-final class SymbolTableIterator implements Iterator<String> {
- SymbolTable table;
- SymbolTable original_table;
-
- SymbolTableIterator ( SymbolTable t ) {
- table = new SymbolTable();
- original_table = t;
- for ( int i = 0; i < t.symbol_table_size; i++ )
- table.symbol_table[i] = t.symbol_table[i];
- for ( int i = 0; i < t.scope_stack.length; i++ )
- table.scope_stack[i] = t.scope_stack[i];
- table.scope_stack_top = t.scope_stack_top;
- }
-
- public boolean hasNext () {
- if (table.scope_stack_top <= 0)
- return false;
- int n = table.scope_stack[table.scope_stack_top-1];
- if (n < 0 || !table.symbol_table[n].binding.equals(original_table.lookup(table.symbol_table[n].name))) {
- table.scope_stack_top--;
- return hasNext();
- };
- return true;
- }
-
- public String next () {
- int n = table.scope_stack[--table.scope_stack_top];
- String var = table.symbol_table[n].name;
- table.symbol_table[n] = table.symbol_table[n].next;
- return var;
- }
-
- public void remove () {}
-}
-
-
-public class SymbolTable implements Iterable<String> {
- final static int symbol_table_size = 997;
- final static int initial_scope_stack_length = 1000;
-
- SymbolCell[] symbol_table;
- int[] scope_stack;
- int scope_stack_top = 0;
-
- public SymbolTable () {
- symbol_table = new SymbolCell[symbol_table_size];
- scope_stack = new int[initial_scope_stack_length];
- scope_stack_top = 0;
- for (int i = 0; i < symbol_table_size; i++)
- symbol_table[i] = null;
- }
-
- public Iterator<String> iterator () {
- return new SymbolTableIterator(this);
- }
-
- /* a hashing function for strings */
- int hash ( String s ) {
- return Math.abs(s.hashCode()) % symbol_table_size;
- }
-
- /* insert a new item in the symbol table */
- public void insert ( String key, Tree binding ) {
- int loc = hash(key);
- symbol_table[loc] = new SymbolCell(key,binding,symbol_table[loc]);
- if (scope_stack_top >= scope_stack.length) {
- int[] v = new int[scope_stack.length*2];
- for ( int i = 0; i < scope_stack.length; i++ )
- v[i] = scope_stack[i];
- scope_stack = v;
- };
- scope_stack[scope_stack_top++] = loc;
- }
-
- /* replace an item with a given name in the symbol table */
- public void replace ( String key, Tree binding ) {
- int loc = hash(key);
- for (SymbolCell s = symbol_table[loc]; s != null; s=s.next)
- if (s.name.equals(key))
- s.binding = binding;
- }
-
- /* remove an item with a given name from the symbol table */
- public boolean remove ( String key ) {
- int loc = hash(key);
- SymbolCell prev = symbol_table[loc];
- if (prev == null)
- return false;
- if (prev.name.equals(key)) {
- symbol_table[loc] = prev.next;
- return true;
- };
- for (SymbolCell s = prev.next; s != null; s=s.next, prev=prev.next)
- if (s.name.equals(key)) {
- prev.next = s.next;
- return true;
- };
- return false;
- }
-
- /* lookup for an item in the symbol table */
- public Tree lookup ( String key ) {
- int loc = hash(key);
- for (SymbolCell s = symbol_table[loc]; s != null; s=s.next)
- if (s.name.equals(key))
- return s.binding;
- return null; // if not found
- }
-
- /* return true if key is local */
- public boolean is_local ( String key ) {
- int loc = hash(key);
- int i = 0;
- for ( SymbolCell s = symbol_table[loc]; s != null; s = s.next, i++ )
- if (s.name.equals(key)) {
- int k = 0;
- for ( int j = scope_stack_top-1; j >= 0 && scope_stack[j] >= 0; j--)
- if (scope_stack[j] == loc)
- if (k++ == i)
- return true;
- return false;
- };
- return false; // if not found
- }
-
- /* start a new environment */
- public void begin_scope () {
- if (scope_stack_top >= scope_stack.length) {
- int[] v = new int[scope_stack.length*2];
- for ( int i = 0; i < scope_stack.length; i++ )
- v[i] = scope_stack[i];
- scope_stack = v;
- };
- scope_stack[scope_stack_top++] = -1;
- }
-
- /* pop the last environment */
- public void end_scope () {
- int i = scope_stack_top-1;
- for (; scope_stack[i]>=0 && i>0; i--) {
- int loc = scope_stack[i];
- symbol_table[loc] = symbol_table[loc].next;
- };
- scope_stack_top = i;
- }
-
- /* display the content of the symbol table */
- public void display () {
- SymbolCell[] s = new SymbolCell[symbol_table_size];
- for (int i = 0; i<symbol_table_size; i++)
- s[i] = symbol_table[i];
- for (int i = scope_stack_top-1; i>=0; i--)
- if (scope_stack[i] == -1)
- System.out.println("----------------");
- else {
- SymbolCell c = s[scope_stack[i]];
- s[scope_stack[i]] = c.next;
- System.out.println(c.name + ": " + c.binding);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/gen/Tree.java
----------------------------------------------------------------------
diff --git a/src/main/java/gen/Tree.java b/src/main/java/gen/Tree.java
deleted file mode 100644
index 7ddc582..0000000
--- a/src/main/java/gen/Tree.java
+++ /dev/null
@@ -1,93 +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.mrql.gen;
-
-import java_cup.runtime.*;
-import java.io.*;
-import java.util.HashMap;
-
-
-abstract public class Tree implements Serializable {
-
- /* the current line number in the parsed file */
- public static int line_number = 0;
-
- /* the current char position in the parsed file */
- public static int position_number = 0;
-
- /* true when Trees are parsed rather than processed */
- public static boolean parsed = false;
-
- /* the line number of the Tree in the parsed file */
- public int line;
-
- /* the char position of the Tree in the parsed file */
- public int position;
-
- Tree () { line = line_number; position = position_number; }
-
- /* deep equality */
- public abstract boolean equals ( Tree e );
-
- final public boolean is_node () { return (this instanceof Node); }
- final public boolean is_variable () { return (this instanceof VariableLeaf); }
- final public boolean is_long () { return (this instanceof LongLeaf); }
- final public boolean is_string () { return (this instanceof StringLeaf); }
- final public boolean is_double () { return (this instanceof DoubleLeaf); }
-
- final public String variableValue () { return (this instanceof VariableLeaf) ? ((VariableLeaf)this).value() : ""; }
- final public long longValue () { return (this instanceof LongLeaf) ? ((LongLeaf)this).value() : (long)0; }
- final public String stringValue () { return (this instanceof StringLeaf) ? ((StringLeaf)this).value() : ""; }
- final public double doubleValue () { return (this instanceof DoubleLeaf) ? ((DoubleLeaf)this).value() : (double)0.0; }
-
- /* size used for pretty() */
- protected abstract int size ();
-
- /* print the Tree into a string */
- public abstract String toString ();
-
- /* pretty-print the Tree padded with position space characters */
- public abstract String pretty ( int position );
-
- private static Tree fix_tree ( Tree e ) {
- if (e instanceof Node) {
- Trees cs = Trees.nil;
- for ( Tree a: ((Node) e).children().tail() )
- cs = cs.append(fix_tree(a));
- return new Node(((VariableLeaf)(((Node) e).children().head())).value(),cs);
- } else return e;
- }
-
- /* the inverse of toString() */
- final public static synchronized Tree parse ( String s ) throws Exception {
- GenParser.scanner = new GenLex(new StringReader("#<"+s+">"));
- GenParser.out = new PrintStream(new ByteArrayOutputStream());
- new GenParser(GenParser.scanner).parse();
- return fix_tree(GenParser.parse_tree);
- }
-
- private static HashMap<String,String> names = new HashMap<String,String>(1000);
-
- public static String add ( String s ) {
- String ns = names.get(s);
- if (ns == null) {
- names.put(s,s);
- return s;
- } else return ns;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/gen/Trees.java
----------------------------------------------------------------------
diff --git a/src/main/java/gen/Trees.java b/src/main/java/gen/Trees.java
deleted file mode 100644
index 86f65ca..0000000
--- a/src/main/java/gen/Trees.java
+++ /dev/null
@@ -1,194 +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.mrql.gen;
-
-import java.util.Iterator;
-import java.io.*;
-
-
-final class TreeIterator implements Iterator<Tree> {
- Trees trees;
-
- TreeIterator ( Trees trees ) { this.trees = trees; }
-
- public boolean hasNext () { return trees.tail != null; }
-
- public Tree next () {
- Tree res = trees.head;
- trees = trees.tail;
- return res;
- }
-
- public void remove () { trees = trees.tail; }
-}
-
-
-final public class Trees implements Iterable<Tree>, Serializable {
- private final static int screen_size = 100;
- public Tree head;
- public Trees tail;
-
- public Trees ( Tree head, Trees tail ) {
- if (tail == null)
- throw new Error("Gen: an empty list of nodes must be nil, not null");
- this.head = head;
- this.tail = tail;
- }
-
- public Trees () {
- head = null;
- tail = null;
- }
-
- public final static Trees nil = new Trees();
-
- public Trees ( Tree head ) {
- this.head = head;
- tail = nil;
- }
-
- public Tree head () {
- if (tail == null)
- throw new Error("Gen: tried to retrieve the head of an empty list of nodes");
- return head;
- }
-
- public Trees tail () {
- if (tail == null)
- throw new Error("Gen: tried to retrieve the tail of an empty list of nodes");
- return tail;
- }
-
- public boolean is_empty () {
- return (tail == null);
- }
-
- /* number of nodes */
- public int length () {
- int n = 0;
- for (Trees r = this; !r.is_empty(); r = r.tail)
- n += 1;
- return n;
- }
-
- /* put an Tree e at the beginning of the nodes */
- public Trees cons ( Tree e ) {
- return new Trees(e,this);
- }
-
- /* put an Tree e at the end of the nodes */
- public Trees append ( Tree e ) {
- if (is_empty())
- return new Trees(e);
- else {
- Trees temp = new Trees(e,new Trees(e));
- Trees res = temp;
- for (Trees r = this; !r.is_empty(); r = r.tail) {
- temp.tail = temp.tail.cons(r.head);
- temp = temp.tail;
- };
- return res.tail;
- }
- }
-
- /* append two lists of nodes */
- public Trees append ( Trees s ) {
- if (is_empty())
- return s;
- else if (s.is_empty())
- return this;
- else {
- Trees temp = s.cons(s.head);
- Trees res = temp;
- for (Trees r = this; !r.is_empty(); r = r.tail)
- { temp.tail = temp.tail.cons(r.head);
- temp = temp.tail;
- }
- return res.tail;
- }
- }
-
- /* reverse the order of nodes */
- public Trees reverse () {
- Trees res = nil;
- for (Trees r = this; !r.is_empty(); r = r.tail)
- res = res.cons(r.head);
- return res;
- }
-
- /* is e one of the nodes? */
- public boolean member ( Tree e ) {
- for (Trees r = this; !r.is_empty(); r = r.tail)
- if (r.head.equals(e))
- return true;
- return false;
- }
-
- /* return the nth node */
- public Tree nth ( int n ) {
- Trees r = this;
- for (int i = 0; !r.is_empty() && i < n; r = r.tail(), i++)
- ;
- if (r.is_empty())
- throw new Error("Gen: tried to retrieve a nonexistent nth element from a list of nodes");
- else return r.head;
- }
-
- /* deep equality */
- public boolean equals ( Trees s ) {
- Trees n = this;
- Trees m = s;
- for(; n.tail != null && m.tail != null; n = n.tail, m = m.tail )
- if (!n.head.equals(m.head))
- return false;
- return (m.tail == null) && (n.tail == null);
- }
-
- protected int size () {
- int n = 1;
- for (Trees r = this; !r.is_empty(); r = r.tail)
- n += r.head.size()+1;
- return n;
- }
-
- public Iterator<Tree> iterator () { return new TreeIterator(this); }
-
- /* print the nodes */
- public String toString () {
- if (is_empty())
- return "()";
- String s = "(" + head;
- for (Trees r = tail; !r.is_empty(); r = r.tail)
- s = s + "," + r.head;
- return s + ")";
- }
-
- /* pretty-print the nodes */
- public String pretty ( int position ) {
- if (is_empty() || (position+size() <= screen_size))
- return toString();
- String s = "(" + head.pretty(position+1);
- for (Trees r=tail; !r.is_empty(); r=r.tail) {
- s = s + ",\n";
- for (int i=0; i<position+1; i++)
- s = s + " ";
- s = s + r.head.pretty(position+1);
- };
- return s + ")";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/gen/VariableLeaf.java
----------------------------------------------------------------------
diff --git a/src/main/java/gen/VariableLeaf.java b/src/main/java/gen/VariableLeaf.java
deleted file mode 100644
index c4c0ed9..0000000
--- a/src/main/java/gen/VariableLeaf.java
+++ /dev/null
@@ -1,52 +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.mrql.gen;
-
-import java.io.*;
-
-
-final public class VariableLeaf extends Tree {
- public String value;
-
- public VariableLeaf ( String s ) {
- super();
- value = Tree.add(s);
- }
-
- final public String value () { return value; }
-
- public boolean equals ( Tree e ) {
- return (e instanceof VariableLeaf)
- && value == ((VariableLeaf) e).value;
- }
-
- protected int size () { return value.length(); }
-
- public String toString () { return value; }
-
- public String pretty ( int position ) { return value; }
-
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- value = Tree.add(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/gen/gen.cup
----------------------------------------------------------------------
diff --git a/src/main/java/gen/gen.cup b/src/main/java/gen/gen.cup
deleted file mode 100644
index 91432ba..0000000
--- a/src/main/java/gen/gen.cup
+++ /dev/null
@@ -1,179 +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.mrql.gen;
-
-import java_cup.runtime.*;
-import java.util.Stack;
-
-parser code {:
-
- static int[] tokens = {
- GenSym.error, GenSym.CHAR, GenSym.ID, GenSym.CSTRING, GenSym.LONG, GenSym.DOUBLE,
- GenSym.META, GenSym.MATCH, GenSym.CASE, GenSym.IS, GenSym.COLON, GenSym.COMMA,
- GenSym.GT, GenSym.LP, GenSym.RP, GenSym.LB, GenSym.RB, GenSym.LSB, GenSym.RSB,
- GenSym.BQ, GenSym.BQP, GenSym.DOTSP, GenSym.ANY, GenSym.OPER, GenSym.FAIL
- };
-
- static String[] token_names = {
- "error", "character", "identifier", "string", "integer", "float",
- "#<", "match", "case", "is", ":", ",", ">", "(", ")", "[", "]", "{", "}",
- "`", "`(", "...(", "_", "operator", "fail"
- };
-
- public static String print ( Symbol s ) {
- for (int i=0; i<tokens.length; i++)
- if (tokens[i]==s.sym)
- { String res = token_names[i] + " ";
- if (s.value==null)
- return res;
- else if (s.value instanceof Long)
- return res + ((Long) s.value).longValue();
- else if (s.value instanceof Double)
- return res + ((Double) s.value).doubleValue();
- else if (s.value instanceof String)
- return res + (String) s.value;
- }
- return "?";
- }
-
- public static java.io.PrintStream out;
-
- public static GenLex scanner;
-
- public static Tree parse_tree;
-
- public static int newlines = 0;
-
- public static int lcase = 0;
-
- public static Stack<String> labels = new Stack<String>();
-
- public void syntax_error ( Symbol token ) {
- throw new Error("*** Syntax Error: " + print(token) + " (line: " + scanner.line_pos()
- + ", position: " + scanner.char_pos() + ")");
- }
-
-:};
-
-/* Terminals (tokens returned by the scanner). */
-terminal META, METAL, MATCH, CASE, FAIL, IS, DOTS, COLON, COMMA, GT, LP, RP, LB, RB, LSB, RSB, BQ, BQP, DOTSP, ANY;
-
-terminal String CHAR;
-terminal String ID;
-terminal Long LONG;
-terminal Double DOUBLE;
-terminal String CSTRING;
-terminal String OPER;
-
-non terminal Tree exp, name, variable, rest;
-non terminal Trees expl;
-non terminal String case, cases, schar, jcode, scode;
-non terminal pcode, prog;
-
-precedence left OPER;
-precedence nonassoc META;
-precedence nonassoc MATCH;
-precedence nonassoc CASE;
-precedence nonassoc CSTRING;
-precedence nonassoc CHAR;
-
-start with prog;
-
-prog ::= pcode
- ;
-pcode ::= scode:s {: parser.out.print(s); :}
- | pcode scode:s {: parser.out.print(s); :}
- ;
-jcode ::= scode:s {: RESULT = s; :}
- | jcode:c scode:s {: RESULT = c+s; :}
- ;
-scode ::= schar:s {: RESULT = s; :}
- | LSB RSB {: RESULT = "{}"; :}
- | LSB jcode:c RSB {: RESULT = "{"+c+"}"; :}
- | METAL RB {: RESULT = "Trees.nil"; :}
- | META exp:e GT {: GenParser.parse_tree = e;
- RESULT = Meta.reify(e);
- for (int i=0; i < parser.newlines; i++)
- RESULT += "\n";
- parser.newlines = 0; :}
- | METAL expl:r RB {: RESULT = Meta.reify(new Node("Node",
- new Trees(new VariableLeaf("F"),r)));
- RESULT = RESULT.substring(13,RESULT.length()-1);
- for (int i=0; i < parser.newlines; i++)
- RESULT += "\n";
- parser.newlines = 0; :}
- | MATCH {: Meta.level++;
- GenLex.context.new_context();
- GenLex.context.in_match_body();
- :}
- jcode:c LSB cases:el RSB {: RESULT = "{ boolean FOUND_" + Meta.level + " = false; Tree E_"
- + Meta.level + " = " + c + "; " + el + " }";
- GenLex.context.close_context(GenParser.scanner);
- for (int i=0; i < parser.newlines; i++)
- RESULT += "\n";
- parser.newlines = 0;
- Meta.level--; :}
- | FAIL {: RESULT = "{ FOUND_" + Meta.level + "=false; break " + GenParser.labels.peek() + "; }"; :}
- ;
-schar ::= CHAR:c {: RESULT = c; :}
- | CSTRING:s {: RESULT = Crypt.encrypt(s); :}
- ;
-cases ::= jcode:j case:c {: RESULT = j+c; :}
- | cases:cl case:c {: RESULT = cl + " if (!FOUND_" + Meta.level + ") " + c; :}
- ;
-case ::= CASE {: GenParser.labels.push("LCASE_"+GenParser.lcase++); :}
- exp:e COLON jcode:j {: Condition m = Meta.pattern(e,"E_" + Meta.level);
- RESULT = "{ " + GenParser.labels.pop() + ": ";
- RESULT += (m.pred.equals("true")) ? "" : "if (" + m.pred + ") ";
- for (int i=0; i < parser.newlines; i++)
- RESULT += "\n";
- parser.newlines = 0;
- RESULT += "{ " + m.stmt + " FOUND_" + Meta.level
- + "=true; " + j + " }";
- for (int i = 0; i <= m.unmatched_brackets; i++)
- RESULT += "}";
- RESULT += ";"; :}
- ;
-name ::= ID:s {: RESULT = new VariableLeaf(s); :}
- ;
-variable ::= name:s {: RESULT = s; :}
- | BQ name:s {: RESULT = new Node("Escape",new Trees(s)); :}
- | BQP jcode:c RP {: RESULT = new Node("Code",new Trees(new StringLeaf(c))); :}
- | ANY {: RESULT = new VariableLeaf("_any_"); :}
- ;
-exp ::= LONG:n {: RESULT = new LongLeaf(n.longValue()); :}
- | DOUBLE:n {: RESULT = new DoubleLeaf(n.doubleValue()); :}
- | CSTRING:s {: RESULT = new StringLeaf(s); :}
- | variable:e {: RESULT = e; :}
- | variable:e LP RP {: RESULT = new Node("Node",new Trees(e)); :}
- | variable:e LP expl:el RP {: RESULT = new Node("Node",new Trees(e,el)); :}
- | BQ name:s LB exp:e RB {: RESULT = new Node("Higher",new Trees(s,new Trees(e))); :}
- | name:s IS exp:e {: RESULT = new Node("IS",new Trees(s,new Trees(e))); :}
- | LP exp:e RP {: RESULT = e; :}
- | exp:e1 OPER:o exp:e2 {: RESULT = new Node("Node",new Trees(new VariableLeaf(o),
- new Trees(e1,new Trees(e2)))); :}
- ;
-expl ::= exp:e {: RESULT = new Trees(e); :}
- | rest:e {: RESULT = new Trees(e); :}
- | expl:el COMMA rest:e {: RESULT = el.append(e); :}
- | expl:el COMMA exp:e {: RESULT = el.append(e); :}
- ;
-rest ::= DOTS name:n {: RESULT = new Node("Dots",new Trees(n)); :}
- | DOTSP jcode:c RP {: RESULT = new Node("Dots",new Trees(new StringLeaf(c))); :}
- | DOTS {: RESULT = new Node("Dots"); :}
- ;
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/gen/gen.lex
----------------------------------------------------------------------
diff --git a/src/main/java/gen/gen.lex b/src/main/java/gen/gen.lex
deleted file mode 100644
index 06b073d..0000000
--- a/src/main/java/gen/gen.lex
+++ /dev/null
@@ -1,210 +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.mrql.gen;
-
-import java_cup.runtime.Symbol;
-
-final class Context {
- public int[] parentheses;
- public boolean[] match_begin;
- public int current;
- public Context () {
- current = 0;
- parentheses = new int[1000];
- match_begin = new boolean[1000];
- parentheses[0] = 0;
- match_begin[0] = false;
- }
- public boolean no_parentheses () {
- return parentheses[current] == 0;
- }
- public void new_context () {
- parentheses[++current] = 0;
- match_begin[current] = false;
- }
- public void close_context ( GenLex lex ) {
- if (parentheses[current--] > 0)
- lex.error("Unbalanced Parentheses in Gen construction/pattern");
- if (current < 0)
- lex.error("Wrong match statement");
- }
- public void open_parenthesis () {
- parentheses[current]++;
- }
- public boolean close_parenthesis () {
- return (--parentheses[current] == 0) && current > 0 && !match_begin[current];
- }
- public void in_match_body () {
- match_begin[current] = true;
- }
- public boolean match_body () { return match_begin[current]; }
-}
-%%
-%state gen
-%class GenLex
-%public
-%line
-%char
-%cup
-
-%eofval{
- return new java_cup.runtime.Symbol(GenSym.EOF);
-%eofval}
-
-%{
- public void error ( String msg ) {
- throw new Error("*** Lexical Error: " + msg + " (line: " + line_pos() + ", position: " + char_pos() + ")");
- }
-
- public static Context context = new Context();
-
- static int prev_char_pos = -1;
-
- public int line_pos () { return yyline+1; }
-
- public int char_pos () { return yychar-prev_char_pos; }
-
- public Symbol symbol ( int s ) {
- Tree.line_number = line_pos();
- Tree.position_number = char_pos();
- //System.out.println(context.parentheses[context.current]+" "+context.match_begin[context.current]+" "+GenParser.print(new Symbol(s)));
- return new Symbol(s);
- }
-
- public Symbol symbol ( int s, Object o ) {
- Tree.line_number = line_pos();
- Tree.position_number = char_pos();
- //System.out.println(context.parentheses[context.current]+" "+context.match_begin[context.current]+" "+GenParser.print(new Symbol(s,o)));
- return new Symbol(s,o);
- }
-%}
-
-DIGIT = [0-9]
-ID = [a-zA-Z_][a-zA-Z0-9_]*
-OPER = [!@#$%\^\&*-+=|\\~]+
-NEWLINE = [\n\r]
-DIGITS = {DIGIT}+
-INT = ({DIGIT}|[1-9]{DIGITS}|-{DIGIT}|-[1-9]{DIGITS})
-FRAC = [.]{DIGITS}
-EXP = [eE][+-]?{DIGITS}
-DOUBLE = ({INT}{FRAC}|{INT}{EXP}|{INT}{FRAC}{EXP})
-
-%%
-<gen> {INT} { return symbol(GenSym.LONG,new Long(yytext())); }
-<gen> {DOUBLE} { return symbol(GenSym.DOUBLE,new Double(yytext())); }
-<gen> ":" { yybegin(YYINITIAL);
- context.close_context(this);
- return symbol(GenSym.COLON); }
-<gen> "_" { return symbol(GenSym.ANY); }
-<gen> "," { return symbol(GenSym.COMMA); }
-<gen> "`(" { context.new_context();
- context.open_parenthesis();
- yybegin(YYINITIAL);
- return symbol(GenSym.BQP);
- }
-<gen> "...(" { context.new_context();
- context.open_parenthesis();
- yybegin(YYINITIAL);
- return symbol(GenSym.DOTSP);
- }
-<gen> "`" { return symbol(GenSym.BQ); }
-<gen> "..." { return symbol(GenSym.DOTS); }
-<gen> "(" { context.open_parenthesis();
- return symbol(GenSym.LP);
- }
-<gen> ")" { context.close_parenthesis();
- return symbol(GenSym.RP);
- }
-<gen> "[" { context.open_parenthesis();
- return symbol(GenSym.LB);
- }
-<gen> "]" { context.close_parenthesis();
- if (context.no_parentheses())
- { yybegin(YYINITIAL);
- context.close_context(this);
- };
- return symbol(GenSym.RB);
- }
-<gen> ">" { yybegin(YYINITIAL);
- context.close_parenthesis();
- context.close_context(this);
- return symbol(GenSym.GT);
- }
-<gen> "is" { return symbol(GenSym.IS); }
-<gen> {ID} { return symbol(GenSym.ID,yytext()); }
-<gen> {OPER} { return symbol(GenSym.OPER,yytext()); }
-<gen> \/\*[^*/]*\*\/ { for (char c: yytext().toCharArray())
- if (c=='\n' || c=='\r')
- GenParser.newlines++;
- prev_char_pos = yychar; }
-<gen> "//"[^\n\r]* { prev_char_pos = 0; }
-<gen> [ \t\f] {}
-<gen> {NEWLINE} { GenParser.newlines++; prev_char_pos = yychar; }
-<gen> . { error("Illegal character in Gen construction/pattern: "+yytext()); }
-<YYINITIAL> "match" { return symbol(GenSym.MATCH); }
-<YYINITIAL> "case" { if (!context.match_body())
- return symbol(GenSym.CHAR,yytext());
- context.new_context();
- yybegin(gen);
- return symbol(GenSym.CASE);
- }
-<YYINITIAL> "fail" { return symbol(GenSym.FAIL); }
-<YYINITIAL> "`" { error("Backquote outside a Gen construction/pattern"); }
-<YYINITIAL> "#<" { context.new_context();
- context.open_parenthesis();
- yybegin(gen);
- return symbol(GenSym.META);
- }
-<YYINITIAL> "#[" { context.new_context();
- context.open_parenthesis();
- yybegin(gen);
- return symbol(GenSym.METAL);
- }
-<YYINITIAL> "{" { context.open_parenthesis();
- if (context.match_body())
- return symbol(GenSym.LSB);
- else return symbol(GenSym.CHAR,yytext());
- }
-<YYINITIAL> "("|"[" { context.open_parenthesis();
- return symbol(GenSym.CHAR,yytext());
- }
-<YYINITIAL> "}" { context.close_parenthesis();
- if (context.match_body())
- return symbol(GenSym.RSB);
- else return symbol(GenSym.CHAR,yytext());
- }
-<YYINITIAL> ")" { if (context.close_parenthesis())
- { context.close_context(this);
- yybegin(gen);
- return symbol(GenSym.RP);
- } else return symbol(GenSym.CHAR,yytext());
- }
-<YYINITIAL> "]" { if (context.close_parenthesis())
- { context.close_context(this);
- yybegin(gen);
- return symbol(GenSym.RB);
- } else return symbol(GenSym.CHAR,yytext());
- }
-\"[^\"]*\" { return symbol(GenSym.CSTRING,yytext().substring(1,yytext().length()-1)); }
-<YYINITIAL> {ID} { return symbol(GenSym.CHAR,yytext()); }
-<YYINITIAL> {OPER} { return symbol(GenSym.CHAR,yytext()); }
-<YYINITIAL> \/\*[^*/]*\*\/ { prev_char_pos = yychar; return symbol(GenSym.CHAR,yytext()); }
-<YYINITIAL> "//"[^\n\r]* { prev_char_pos = 0; return symbol(GenSym.CHAR,yytext()); }
-<YYINITIAL> [ \t\f] { return symbol(GenSym.CHAR,yytext()); }
-<YYINITIAL> {NEWLINE} { prev_char_pos = yychar; return symbol(GenSym.CHAR,yytext()); }
-<YYINITIAL> . { return symbol(GenSym.CHAR,yytext()); }
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/multipleinputs/DelegatingInputFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/multipleinputs/DelegatingInputFormat.java b/src/main/java/multipleinputs/DelegatingInputFormat.java
new file mode 100644
index 0000000..0d9b8f9
--- /dev/null
+++ b/src/main/java/multipleinputs/DelegatingInputFormat.java
@@ -0,0 +1,127 @@
+/**
+ * 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.hadoop.mapreduce.lib.input;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapreduce.InputFormat;
+import org.apache.hadoop.mapreduce.InputSplit;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.hadoop.mapreduce.TaskAttemptContext;
+import org.apache.hadoop.util.ReflectionUtils;
+
+/**
+ * An {@link InputFormat} that delegates behavior of paths to multiple other
+ * InputFormats.
+ *
+ * @see MultipleInputs#addInputPath(Job, Path, Class, Class)
+ */
+public class DelegatingInputFormat<K, V> extends InputFormat<K, V> {
+
+ @SuppressWarnings("unchecked")
+ public List<InputSplit> getSplits(JobContext job)
+ throws IOException, InterruptedException {
+ Configuration conf = job.getConfiguration();
+ Job jobCopy =new Job(conf);
+ List<InputSplit> splits = new ArrayList<InputSplit>();
+ Map<Path, InputFormat> formatMap =
+ MultipleInputs.getInputFormatMap(job);
+ Map<Path, Class<? extends Mapper>> mapperMap = MultipleInputs
+ .getMapperTypeMap(job);
+ Map<Class<? extends InputFormat>, List<Path>> formatPaths
+ = new HashMap<Class<? extends InputFormat>, List<Path>>();
+
+ // First, build a map of InputFormats to Paths
+ for (Entry<Path, InputFormat> entry : formatMap.entrySet()) {
+ if (!formatPaths.containsKey(entry.getValue().getClass())) {
+ formatPaths.put(entry.getValue().getClass(), new LinkedList<Path>());
+ }
+
+ formatPaths.get(entry.getValue().getClass()).add(entry.getKey());
+ }
+
+ for (Entry<Class<? extends InputFormat>, List<Path>> formatEntry :
+ formatPaths.entrySet()) {
+ Class<? extends InputFormat> formatClass = formatEntry.getKey();
+ InputFormat format = (InputFormat) ReflectionUtils.newInstance(
+ formatClass, conf);
+ List<Path> paths = formatEntry.getValue();
+
+ Map<Class<? extends Mapper>, List<Path>> mapperPaths
+ = new HashMap<Class<? extends Mapper>, List<Path>>();
+
+ // Now, for each set of paths that have a common InputFormat, build
+ // a map of Mappers to the paths they're used for
+ for (Path path : paths) {
+ Class<? extends Mapper> mapperClass = mapperMap.get(path);
+ if (!mapperPaths.containsKey(mapperClass)) {
+ mapperPaths.put(mapperClass, new LinkedList<Path>());
+ }
+
+ mapperPaths.get(mapperClass).add(path);
+ }
+
+ // Now each set of paths that has a common InputFormat and Mapper can
+ // be added to the same job, and split together.
+ for (Entry<Class<? extends Mapper>, List<Path>> mapEntry :
+ mapperPaths.entrySet()) {
+ paths = mapEntry.getValue();
+ Class<? extends Mapper> mapperClass = mapEntry.getKey();
+
+ if (mapperClass == null) {
+ try {
+ mapperClass = job.getMapperClass();
+ } catch (ClassNotFoundException e) {
+ throw new IOException("Mapper class is not found", e);
+ }
+ }
+
+ FileInputFormat.setInputPaths(jobCopy, paths.toArray(new Path[paths
+ .size()]));
+
+ // Get splits for each input path and tag with InputFormat
+ // and Mapper types by wrapping in a TaggedInputSplit.
+ List<InputSplit> pathSplits = format.getSplits(jobCopy);
+ for (InputSplit pathSplit : pathSplits) {
+ splits.add(new TaggedInputSplit(pathSplit, conf, format.getClass(),
+ mapperClass));
+ }
+ }
+ }
+
+ return splits;
+ }
+
+ @Override
+ public RecordReader<K, V> createRecordReader(InputSplit split,
+ TaskAttemptContext context) throws IOException, InterruptedException {
+ return new DelegatingRecordReader<K, V>(split, context);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/multipleinputs/DelegatingMapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/multipleinputs/DelegatingMapper.java b/src/main/java/multipleinputs/DelegatingMapper.java
new file mode 100644
index 0000000..d72d2b5
--- /dev/null
+++ b/src/main/java/multipleinputs/DelegatingMapper.java
@@ -0,0 +1,54 @@
+/**
+ * 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.hadoop.mapreduce.lib.input;
+
+import java.io.IOException;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.hadoop.util.ReflectionUtils;
+
+/**
+ * An {@link Mapper} that delegates behavior of paths to multiple other
+ * mappers.
+ *
+ * @see MultipleInputs#addInputPath(Job, Path, Class, Class)
+ */
+public class DelegatingMapper<K1, V1, K2, V2> extends Mapper<K1, V1, K2, V2> {
+
+ private Mapper<K1, V1, K2, V2> mapper;
+
+ @SuppressWarnings("unchecked")
+ protected void setup(Context context)
+ throws IOException, InterruptedException {
+ // Find the Mapper from the TaggedInputSplit.
+ TaggedInputSplit inputSplit = (TaggedInputSplit) context.getInputSplit();
+ mapper = (Mapper<K1, V1, K2, V2>) ReflectionUtils.newInstance(inputSplit
+ .getMapperClass(), context.getConfiguration());
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public void run(Context context)
+ throws IOException, InterruptedException {
+ setup(context);
+ mapper.run(context);
+ cleanup(context);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/multipleinputs/DelegatingRecordReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/multipleinputs/DelegatingRecordReader.java b/src/main/java/multipleinputs/DelegatingRecordReader.java
new file mode 100644
index 0000000..f0d060e
--- /dev/null
+++ b/src/main/java/multipleinputs/DelegatingRecordReader.java
@@ -0,0 +1,88 @@
+/**
+ * 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.hadoop.mapreduce.lib.input;
+
+import java.io.IOException;
+
+import org.apache.hadoop.mapreduce.InputFormat;
+import org.apache.hadoop.mapreduce.InputSplit;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.hadoop.mapreduce.TaskAttemptContext;
+import org.apache.hadoop.util.ReflectionUtils;
+
+/**
+ * This is a delegating RecordReader, which delegates the functionality to the
+ * underlying record reader in {@link TaggedInputSplit}
+ */
+public class DelegatingRecordReader<K, V> extends RecordReader<K, V> {
+ RecordReader<K, V> originalRR;
+
+ /**
+ * Constructs the DelegatingRecordReader.
+ *
+ * @param split TaggegInputSplit object
+ * @param context TaskAttemptContext object
+ *
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ @SuppressWarnings("unchecked")
+ public DelegatingRecordReader(InputSplit split, TaskAttemptContext context)
+ throws IOException, InterruptedException {
+ // Find the InputFormat and then the RecordReader from the
+ // TaggedInputSplit.
+ TaggedInputSplit taggedInputSplit = (TaggedInputSplit) split;
+ InputFormat<K, V> inputFormat = (InputFormat<K, V>) ReflectionUtils
+ .newInstance(taggedInputSplit.getInputFormatClass(), context
+ .getConfiguration());
+ originalRR = inputFormat.createRecordReader(taggedInputSplit
+ .getInputSplit(), context);
+ }
+
+ @Override
+ public void close() throws IOException {
+ originalRR.close();
+ }
+
+ @Override
+ public K getCurrentKey() throws IOException, InterruptedException {
+ return originalRR.getCurrentKey();
+ }
+
+ @Override
+ public V getCurrentValue() throws IOException, InterruptedException {
+ return originalRR.getCurrentValue();
+ }
+
+ @Override
+ public float getProgress() throws IOException, InterruptedException {
+ return originalRR.getProgress();
+ }
+
+ @Override
+ public void initialize(InputSplit split, TaskAttemptContext context)
+ throws IOException, InterruptedException {
+ originalRR.initialize(((TaggedInputSplit) split).getInputSplit(), context);
+ }
+
+ @Override
+ public boolean nextKeyValue() throws IOException, InterruptedException {
+ return originalRR.nextKeyValue();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/multipleinputs/MultipleInputs.java
----------------------------------------------------------------------
diff --git a/src/main/java/multipleinputs/MultipleInputs.java b/src/main/java/multipleinputs/MultipleInputs.java
new file mode 100644
index 0000000..9140512
--- /dev/null
+++ b/src/main/java/multipleinputs/MultipleInputs.java
@@ -0,0 +1,141 @@
+/**
+ * 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.hadoop.mapreduce.lib.input;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapreduce.InputFormat;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.hadoop.util.ReflectionUtils;
+
+/**
+ * This class supports MapReduce jobs that have multiple input paths with
+ * a different {@link InputFormat} and {@link Mapper} for each path
+ */
+public class MultipleInputs {
+ /**
+ * Add a {@link Path} with a custom {@link InputFormat} to the list of
+ * inputs for the map-reduce job.
+ *
+ * @param job The {@link Job}
+ * @param path {@link Path} to be added to the list of inputs for the job
+ * @param inputFormatClass {@link InputFormat} class to use for this path
+ */
+ @SuppressWarnings("unchecked")
+ public static void addInputPath(Job job, Path path,
+ Class<? extends InputFormat> inputFormatClass) {
+ String inputFormatMapping = path.toString() + ";"
+ + inputFormatClass.getName();
+ Configuration conf = job.getConfiguration();
+ String inputFormats = conf.get("mapred.input.dir.formats");
+ conf.set("mapred.input.dir.formats",
+ inputFormats == null ? inputFormatMapping : inputFormats + ","
+ + inputFormatMapping);
+
+ job.setInputFormatClass(DelegatingInputFormat.class);
+ }
+
+ /**
+ * Add a {@link Path} with a custom {@link InputFormat} and
+ * {@link Mapper} to the list of inputs for the map-reduce job.
+ *
+ * @param job The {@link Job}
+ * @param path {@link Path} to be added to the list of inputs for the job
+ * @param inputFormatClass {@link InputFormat} class to use for this path
+ * @param mapperClass {@link Mapper} class to use for this path
+ */
+ @SuppressWarnings("unchecked")
+ public static void addInputPath(Job job, Path path,
+ Class<? extends InputFormat> inputFormatClass,
+ Class<? extends Mapper> mapperClass) {
+
+ addInputPath(job, path, inputFormatClass);
+ Configuration conf = job.getConfiguration();
+ String mapperMapping = path.toString() + ";" + mapperClass.getName();
+ String mappers = conf.get("mapred.input.dir.mappers");
+ conf.set("mapred.input.dir.mappers", mappers == null ? mapperMapping
+ : mappers + "," + mapperMapping);
+
+ job.setMapperClass(DelegatingMapper.class);
+ }
+
+ /**
+ * Retrieves a map of {@link Path}s to the {@link InputFormat} class
+ * that should be used for them.
+ *
+ * @param job The {@link JobContext}
+ * @see #addInputPath(JobConf, Path, Class)
+ * @return A map of paths to inputformats for the job
+ */
+ @SuppressWarnings("unchecked")
+ static Map<Path, InputFormat> getInputFormatMap(JobContext job) {
+ Map<Path, InputFormat> m = new HashMap<Path, InputFormat>();
+ Configuration conf = job.getConfiguration();
+ String[] pathMappings = conf.get("mapred.input.dir.formats").split(",");
+ for (String pathMapping : pathMappings) {
+ String[] split = pathMapping.split(";");
+ InputFormat inputFormat;
+ try {
+ inputFormat = (InputFormat) ReflectionUtils.newInstance(conf
+ .getClassByName(split[1]), conf);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ m.put(new Path(split[0]), inputFormat);
+ }
+ return m;
+ }
+
+ /**
+ * Retrieves a map of {@link Path}s to the {@link Mapper} class that
+ * should be used for them.
+ *
+ * @param job The {@link JobContext}
+ * @see #addInputPath(JobConf, Path, Class, Class)
+ * @return A map of paths to mappers for the job
+ */
+ @SuppressWarnings("unchecked")
+ static Map<Path, Class<? extends Mapper>>
+ getMapperTypeMap(JobContext job) {
+ Configuration conf = job.getConfiguration();
+ if (conf.get("mapred.input.dir.mappers") == null) {
+ return Collections.emptyMap();
+ }
+ Map<Path, Class<? extends Mapper>> m =
+ new HashMap<Path, Class<? extends Mapper>>();
+ String[] pathMappings = conf.get("mapred.input.dir.mappers").split(",");
+ for (String pathMapping : pathMappings) {
+ String[] split = pathMapping.split(";");
+ Class<? extends Mapper> mapClass;
+ try {
+ mapClass =
+ (Class<? extends Mapper>) conf.getClassByName(split[1]);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ m.put(new Path(split[0]), mapClass);
+ }
+ return m;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/multipleinputs/TaggedInputSplit.java
----------------------------------------------------------------------
diff --git a/src/main/java/multipleinputs/TaggedInputSplit.java b/src/main/java/multipleinputs/TaggedInputSplit.java
new file mode 100644
index 0000000..68bb789
--- /dev/null
+++ b/src/main/java/multipleinputs/TaggedInputSplit.java
@@ -0,0 +1,159 @@
+/**
+ * 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.hadoop.mapreduce.lib.input;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.serializer.Deserializer;
+import org.apache.hadoop.io.serializer.SerializationFactory;
+import org.apache.hadoop.io.serializer.Serializer;
+import org.apache.hadoop.mapreduce.InputFormat;
+import org.apache.hadoop.mapreduce.InputSplit;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.hadoop.util.ReflectionUtils;
+
+/**
+ * An {@link InputSplit} that tags another InputSplit with extra data for use
+ * by {@link DelegatingInputFormat}s and {@link DelegatingMapper}s.
+ */
+class TaggedInputSplit extends InputSplit implements Configurable, Writable {
+
+ private Class<? extends InputSplit> inputSplitClass;
+
+ private InputSplit inputSplit;
+
+ @SuppressWarnings("unchecked")
+ private Class<? extends InputFormat> inputFormatClass;
+
+ @SuppressWarnings("unchecked")
+ private Class<? extends Mapper> mapperClass;
+
+ private Configuration conf;
+
+ public TaggedInputSplit() {
+ // Default constructor.
+ }
+
+ /**
+ * Creates a new TaggedInputSplit.
+ *
+ * @param inputSplit The InputSplit to be tagged
+ * @param conf The configuration to use
+ * @param inputFormatClass The InputFormat class to use for this job
+ * @param mapperClass The Mapper class to use for this job
+ */
+ @SuppressWarnings("unchecked")
+ public TaggedInputSplit(InputSplit inputSplit, Configuration conf,
+ Class<? extends InputFormat> inputFormatClass,
+ Class<? extends Mapper> mapperClass) {
+ this.inputSplitClass = inputSplit.getClass();
+ this.inputSplit = inputSplit;
+ this.conf = conf;
+ this.inputFormatClass = inputFormatClass;
+ this.mapperClass = mapperClass;
+ }
+
+ /**
+ * Retrieves the original InputSplit.
+ *
+ * @return The InputSplit that was tagged
+ */
+ public InputSplit getInputSplit() {
+ return inputSplit;
+ }
+
+ /**
+ * Retrieves the InputFormat class to use for this split.
+ *
+ * @return The InputFormat class to use
+ */
+ @SuppressWarnings("unchecked")
+ public Class<? extends InputFormat> getInputFormatClass() {
+ return inputFormatClass;
+ }
+
+ /**
+ * Retrieves the Mapper class to use for this split.
+ *
+ * @return The Mapper class to use
+ */
+ @SuppressWarnings("unchecked")
+ public Class<? extends Mapper> getMapperClass() {
+ return mapperClass;
+ }
+
+ public long getLength() throws IOException, InterruptedException {
+ return inputSplit.getLength();
+ }
+
+ public String[] getLocations() throws IOException, InterruptedException {
+ return inputSplit.getLocations();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void readFields(DataInput in) throws IOException {
+ inputSplitClass = (Class<? extends InputSplit>) readClass(in);
+ inputFormatClass = (Class<? extends InputFormat<?, ?>>) readClass(in);
+ mapperClass = (Class<? extends Mapper<?, ?, ?, ?>>) readClass(in);
+ inputSplit = (InputSplit) ReflectionUtils
+ .newInstance(inputSplitClass, conf);
+ SerializationFactory factory = new SerializationFactory(conf);
+ Deserializer deserializer = factory.getDeserializer(inputSplitClass);
+ deserializer.open((DataInputStream)in);
+ inputSplit = (InputSplit)deserializer.deserialize(inputSplit);
+ }
+
+ private Class<?> readClass(DataInput in) throws IOException {
+ String className = Text.readString(in);
+ try {
+ return conf.getClassByName(className);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("readObject can't find class", e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void write(DataOutput out) throws IOException {
+ Text.writeString(out, inputSplitClass.getName());
+ Text.writeString(out, inputFormatClass.getName());
+ Text.writeString(out, mapperClass.getName());
+ SerializationFactory factory = new SerializationFactory(conf);
+ Serializer serializer =
+ factory.getSerializer(inputSplitClass);
+ serializer.open((DataOutputStream)out);
+ serializer.serialize(inputSplit);
+ }
+
+ public Configuration getConf() {
+ return conf;
+ }
+
+ public void setConf(Configuration conf) {
+ this.conf = conf;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/spark/MR_rdd.java
----------------------------------------------------------------------
diff --git a/src/main/java/spark/MR_rdd.java b/src/main/java/spark/MR_rdd.java
deleted file mode 100644
index 48f4f92..0000000
--- a/src/main/java/spark/MR_rdd.java
+++ /dev/null
@@ -1,53 +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.mrql;
-
-import java.io.IOException;
-import java.io.DataInput;
-import java.io.DataOutput;
-import org.apache.hadoop.io.*;
-import org.apache.hadoop.fs.*;
-import org.apache.spark.api.java.JavaRDD;
-
-
-/** a wrapper of a JavaRDD<MRData> (stored in HDFS) as an MRData */
-final public class MR_rdd extends MRData {
- public JavaRDD<MRData> rdd;
-
- public MR_rdd ( JavaRDD<MRData> d ) { rdd = d; }
-
- public void materializeAll () {};
-
- public JavaRDD<MRData> rdd () { return rdd; }
-
- final public void write ( DataOutput out ) throws IOException {
- throw new Error("RDDs are not serializable");
- }
-
- public void readFields ( DataInput in ) throws IOException {
- throw new Error("RDDs are not serializable");
- }
-
- public int compareTo ( MRData x ) {
- throw new Error("RDDs cannot be compared");
- }
-
- public boolean equals ( Object x ) {
- throw new Error("RDDs cannot be compared");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/spark/RDDDataSource.java
----------------------------------------------------------------------
diff --git a/src/main/java/spark/RDDDataSource.java b/src/main/java/spark/RDDDataSource.java
deleted file mode 100644
index b0345da..0000000
--- a/src/main/java/spark/RDDDataSource.java
+++ /dev/null
@@ -1,62 +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.mrql;
-
-import java.util.List;
-import java.io.Serializable;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.spark.api.java.JavaRDD;
-import org.apache.spark.api.java.function.Function2;
-
-
-final public class RDDDataSource extends DataSource implements Serializable {
- public JavaRDD<MRData> rdd;
-
- RDDDataSource ( JavaRDD<MRData> rdd ) {
- super();
- this.rdd = rdd;
- }
-
- @Override
- public long size ( Configuration conf ) {
- return rdd.count();
- }
-
- /** return the first num values */
- @Override
- public List<MRData> take ( int num ) {
- return (num < 0) ? rdd.collect() : rdd.take(num);
- }
-
- /** accumulate all dataset values */
- @Override
- public MRData reduce ( final MRData zero, final Function acc ) {
- return rdd.aggregate(zero,new Function2<MRData,MRData,MRData>() {
- Tuple t = new Tuple(new Tuple(),new Tuple());
- public MRData call ( MRData x, MRData y ) {
- t.set(0,x).set(1,y);
- return acc.eval(t);
- }
- },new Function2<MRData,MRData,MRData>() {
- Tuple t = new Tuple(new Tuple(),new Tuple());
- public MRData call ( MRData x, MRData y ) {
- return (y.equals(zero)) ? x : y;
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/1adaa71c/src/main/java/spark/SparkBinaryInputFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/spark/SparkBinaryInputFormat.java b/src/main/java/spark/SparkBinaryInputFormat.java
deleted file mode 100644
index f11c796..0000000
--- a/src/main/java/spark/SparkBinaryInputFormat.java
+++ /dev/null
@@ -1,53 +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.mrql;
-
-import java.io.*;
-import org.apache.hadoop.fs.*;
-import org.apache.hadoop.io.*;
-import org.apache.hadoop.mapred.*;
-
-
-/** Input format for hadoop sequence files */
-final public class SparkBinaryInputFormat extends SparkMRQLFileInputFormat {
- public static class BinaryInputRecordReader extends SequenceFileRecordReader<MRContainer,MRContainer> {
- final MRContainer result = new MRContainer();
-
- public BinaryInputRecordReader ( FileSplit split,
- JobConf job ) throws IOException {
- super(job,split);
- }
-
- @Override
- public synchronized boolean next ( MRContainer key, MRContainer value ) throws IOException {
- boolean b = super.next(key,result);
- value.set(result.data());
- return b;
- }
- }
-
- @Override
- public RecordReader<MRContainer,MRContainer>
- getRecordReader ( InputSplit split,
- JobConf job,
- Reporter reporter ) throws IOException {
- String path = ((FileSplit)split).getPath().toString();
- BinaryDataSource ds = (BinaryDataSource)DataSource.get(path,job);
- return new BinaryInputRecordReader((FileSplit)split,job);
- }
-}