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 2013/09/06 22:57:24 UTC
[06/18] MRQL-16: correct source files. ASF licenses,
and POMs for release
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/3de9e485/src/main/java/core/SystemFunctions.java
----------------------------------------------------------------------
diff --git a/src/main/java/core/SystemFunctions.java b/src/main/java/core/SystemFunctions.java
index a5ca4a2..ab82998 100644
--- a/src/main/java/core/SystemFunctions.java
+++ b/src/main/java/core/SystemFunctions.java
@@ -34,18 +34,18 @@ final public class SystemFunctions {
final static MR_bool false_value = new MR_bool(false);
private static void error ( String s ) {
- System.err.println("*** "+s);
- throw new Error(s);
+ System.err.println("*** "+s);
+ throw new Error(s);
}
static Random random = new Random();
public static MR_bool synchronize ( MR_string peerName, MR_bool mr_exit ) {
- return Evaluator.synchronize(peerName,mr_exit);
+ return Evaluator.synchronize(peerName,mr_exit);
}
public static Bag distribute ( MR_string peerName, Bag s ) {
- return Evaluator.distribute(peerName,s);
+ return Evaluator.distribute(peerName,s);
}
public static MR_bool lt ( MR_short x, MR_short y ) { return (x.get() < y.get()) ? true_value : false_value; }
@@ -180,8 +180,8 @@ final public class SystemFunctions {
public static MR_double toDouble ( MR_string s ) { return new MR_double(Double.parseDouble(s.get())); }
public static MR_int random ( MR_int n ) {
- int v = random.nextInt(n.get());
- return new MR_int(v);
+ int v = random.nextInt(n.get());
+ return new MR_int(v);
}
public static MR_float log ( MR_float n ) { return new MR_float(Math.log(n.get())); }
@@ -196,272 +196,272 @@ final public class SystemFunctions {
public static MR_string substring ( MR_string x, MR_int b, MR_int e ) { return new MR_string(x.get().substring(b.get(),e.get())); }
public static MR_bool exists ( Bag s ) {
- return (s.iterator().hasNext()) ? true_value : false_value;
+ return (s.iterator().hasNext()) ? true_value : false_value;
}
public static MR_bool some ( Bag x ) {
- for ( MRData e: x )
- if (e instanceof MR_bool)
- if (((MR_bool)e).get())
- return true_value;
- return false_value;
+ for ( MRData e: x )
+ if (e instanceof MR_bool)
+ if (((MR_bool)e).get())
+ return true_value;
+ return false_value;
}
public static MR_bool all ( Bag x ) {
- for ( MRData e: x )
- if (e instanceof MR_bool)
- if (!((MR_bool)e).get())
- return false_value;
- return true_value;
+ for ( MRData e: x )
+ if (e instanceof MR_bool)
+ if (!((MR_bool)e).get())
+ return false_value;
+ return true_value;
}
public static MR_bool member ( MRData e, Bag s ) {
- return (s.contains(e)) ? true_value : false_value;
+ return (s.contains(e)) ? true_value : false_value;
}
public static MR_long count ( Bag s ) {
- if (s.materialized())
- return new MR_long(s.size());
- long i = 0;
- for ( MRData e: s )
- i++;
- return new MR_long(i);
+ if (s.materialized())
+ return new MR_long(s.size());
+ long i = 0;
+ for ( MRData e: s )
+ i++;
+ return new MR_long(i);
}
public static MR_long hash_code ( MRData x ) {
- return new MR_long(x.hashCode());
+ return new MR_long(x.hashCode());
}
public static MRData index ( Bag b, MR_int mi ) {
- int i = mi.get();
- if (i < 0)
- throw new Error("wrong index: "+i);
- if (b.materialized())
- return b.get(i);
- int k = 0;
- for ( MRData e: b )
- if (k++ == i)
- return e;
- throw new Error("wrong index: "+i);
+ int i = mi.get();
+ if (i < 0)
+ throw new Error("wrong index: "+i);
+ if (b.materialized())
+ return b.get(i);
+ int k = 0;
+ for ( MRData e: b )
+ if (k++ == i)
+ return e;
+ throw new Error("wrong index: "+i);
}
public static Bag range ( Bag b, MR_int mi, MR_int mj ) {
- int i = mi.get();
- int j = mj.get();
- if (j < i)
- throw new Error("wrong range indexes: "+i+","+j);
- Bag bag = new Bag(j-i+1);
- int k = 0;
- for ( MRData e: b ) {
- if (k >= i && k <= j)
- bag.add(e);
- k++;
- };
- return bag;
+ int i = mi.get();
+ int j = mj.get();
+ if (j < i)
+ throw new Error("wrong range indexes: "+i+","+j);
+ Bag bag = new Bag(j-i+1);
+ int k = 0;
+ for ( MRData e: b ) {
+ if (k >= i && k <= j)
+ bag.add(e);
+ k++;
+ };
+ return bag;
}
public static Bag union ( Bag x, Bag y ) {
- return x.union(y);
+ return x.union(y);
}
public static Bag intersect ( Bag x, Bag y ) {
- x.materialize();
- Bag s = new Bag();
- for ( MRData e: y )
- if (x.contains(e))
- s.add(e);
- return s;
+ x.materialize();
+ Bag s = new Bag();
+ for ( MRData e: y )
+ if (x.contains(e))
+ s.add(e);
+ return s;
}
public static Bag except ( Bag x, Bag y ) {
- y.materialize();
- Bag s = new Bag();
- for ( MRData e: x )
- if (!y.contains(e))
- s.add(e);
- return s;
+ y.materialize();
+ Bag s = new Bag();
+ for ( MRData e: x )
+ if (!y.contains(e))
+ s.add(e);
+ return s;
}
public static Bag materialize ( Bag x ) {
- x.materialize();
- return x;
+ x.materialize();
+ return x;
}
/** coerce a basic type to a new type indicated by the basic type number */
public static MRData coerce ( MRData from, MR_int type ) {
- byte tp = (byte)type.get();
- if (from instanceof MR_short) {
- if (tp == MRContainer.BYTE)
- return new MR_byte((byte)((MR_short)from).get());
- else if (tp == MRContainer.SHORT)
- return from;
- else if (tp == MRContainer.INT)
- return new MR_int((int)((MR_short)from).get());
- else if (tp == MRContainer.LONG)
- return new MR_long((long)((MR_short)from).get());
- else if (tp == MRContainer.FLOAT)
- return new MR_float((float)((MR_short)from).get());
- else if (tp == MRContainer.DOUBLE)
- return new MR_double((double)((MR_short)from).get());
- } else if (from instanceof MR_int) {
- if (tp == MRContainer.BYTE)
- return new MR_byte((byte)((MR_int)from).get());
- else if (tp == MRContainer.SHORT)
- return new MR_short((short)((MR_int)from).get());
- else if (tp == MRContainer.INT)
- return from;
- else if (tp == MRContainer.LONG)
- return new MR_long((long)((MR_int)from).get());
- else if (tp == MRContainer.FLOAT)
- return new MR_float((float)((MR_int)from).get());
- else if (tp == MRContainer.DOUBLE)
- return new MR_double((double)((MR_int)from).get());
- } else if (from instanceof MR_long) {
- if (tp == MRContainer.BYTE)
- return new MR_byte((byte)((MR_long)from).get());
- else if (tp == MRContainer.SHORT)
- return new MR_short((short)((MR_long)from).get());
- else if (tp == MRContainer.INT)
- return new MR_int((int)((MR_long)from).get());
- else if (tp == MRContainer.LONG)
- return from;
- else if (tp == MRContainer.FLOAT)
- return new MR_float((float)((MR_long)from).get());
- else if (tp == MRContainer.DOUBLE)
- return new MR_double((double)((MR_long)from).get());
- } else if (from instanceof MR_float) {
- if (tp == MRContainer.BYTE)
- return new MR_byte((byte)((MR_float)from).get());
- else if (tp == MRContainer.SHORT)
- return new MR_short((short)((MR_float)from).get());
- else if (tp == MRContainer.INT)
- return new MR_int((int)((MR_float)from).get());
- else if (tp == MRContainer.LONG)
- return new MR_long((long)((MR_float)from).get());
- if (tp == MRContainer.FLOAT)
- return from;
- else if (tp == MRContainer.DOUBLE)
- return new MR_double((double)((MR_float)from).get());
- } else if (from instanceof MR_double) {
- if (tp == MRContainer.BYTE)
- return new MR_byte((byte)((MR_double)from).get());
- else if (tp == MRContainer.SHORT)
- return new MR_short((short)((MR_double)from).get());
- else if (tp == MRContainer.INT)
- return new MR_int((int)((MR_double)from).get());
- else if (tp == MRContainer.LONG)
- return new MR_long((long)((MR_double)from).get());
- if (tp == MRContainer.FLOAT)
- return new MR_float((float)((MR_double)from).get());
- if (tp == MRContainer.DOUBLE)
- return from;
- };
- error("Cannot up-coerce the numerical value "+from);
- return null;
+ byte tp = (byte)type.get();
+ if (from instanceof MR_short) {
+ if (tp == MRContainer.BYTE)
+ return new MR_byte((byte)((MR_short)from).get());
+ else if (tp == MRContainer.SHORT)
+ return from;
+ else if (tp == MRContainer.INT)
+ return new MR_int((int)((MR_short)from).get());
+ else if (tp == MRContainer.LONG)
+ return new MR_long((long)((MR_short)from).get());
+ else if (tp == MRContainer.FLOAT)
+ return new MR_float((float)((MR_short)from).get());
+ else if (tp == MRContainer.DOUBLE)
+ return new MR_double((double)((MR_short)from).get());
+ } else if (from instanceof MR_int) {
+ if (tp == MRContainer.BYTE)
+ return new MR_byte((byte)((MR_int)from).get());
+ else if (tp == MRContainer.SHORT)
+ return new MR_short((short)((MR_int)from).get());
+ else if (tp == MRContainer.INT)
+ return from;
+ else if (tp == MRContainer.LONG)
+ return new MR_long((long)((MR_int)from).get());
+ else if (tp == MRContainer.FLOAT)
+ return new MR_float((float)((MR_int)from).get());
+ else if (tp == MRContainer.DOUBLE)
+ return new MR_double((double)((MR_int)from).get());
+ } else if (from instanceof MR_long) {
+ if (tp == MRContainer.BYTE)
+ return new MR_byte((byte)((MR_long)from).get());
+ else if (tp == MRContainer.SHORT)
+ return new MR_short((short)((MR_long)from).get());
+ else if (tp == MRContainer.INT)
+ return new MR_int((int)((MR_long)from).get());
+ else if (tp == MRContainer.LONG)
+ return from;
+ else if (tp == MRContainer.FLOAT)
+ return new MR_float((float)((MR_long)from).get());
+ else if (tp == MRContainer.DOUBLE)
+ return new MR_double((double)((MR_long)from).get());
+ } else if (from instanceof MR_float) {
+ if (tp == MRContainer.BYTE)
+ return new MR_byte((byte)((MR_float)from).get());
+ else if (tp == MRContainer.SHORT)
+ return new MR_short((short)((MR_float)from).get());
+ else if (tp == MRContainer.INT)
+ return new MR_int((int)((MR_float)from).get());
+ else if (tp == MRContainer.LONG)
+ return new MR_long((long)((MR_float)from).get());
+ if (tp == MRContainer.FLOAT)
+ return from;
+ else if (tp == MRContainer.DOUBLE)
+ return new MR_double((double)((MR_float)from).get());
+ } else if (from instanceof MR_double) {
+ if (tp == MRContainer.BYTE)
+ return new MR_byte((byte)((MR_double)from).get());
+ else if (tp == MRContainer.SHORT)
+ return new MR_short((short)((MR_double)from).get());
+ else if (tp == MRContainer.INT)
+ return new MR_int((int)((MR_double)from).get());
+ else if (tp == MRContainer.LONG)
+ return new MR_long((long)((MR_double)from).get());
+ if (tp == MRContainer.FLOAT)
+ return new MR_float((float)((MR_double)from).get());
+ if (tp == MRContainer.DOUBLE)
+ return from;
+ };
+ error("Cannot up-coerce the numerical value "+from);
+ return null;
}
/** used in avg */
public static MR_double avg_value ( MRData t ) {
- MR_double sum = (MR_double)((Tuple)t).first();
- MR_long count = (MR_long)((Tuple)t).second();
- return new MR_double(sum.get()/count.get());
+ MR_double sum = (MR_double)((Tuple)t).first();
+ MR_long count = (MR_long)((Tuple)t).second();
+ return new MR_double(sum.get()/count.get());
}
public static MR_string text ( Union node ) {
- if (node.tag() == 1)
- return (MR_string)(node.value());
- Bag b = (Bag)((Tuple)node.value()).get(2);
- String s = "";
- for ( MRData e: b )
- if (((Union)e).tag() == 1)
- s += ((MR_string)(((Union)e).value())).get();
- return new MR_string(s);
+ if (node.tag() == 1)
+ return (MR_string)(node.value());
+ Bag b = (Bag)((Tuple)node.value()).get(2);
+ String s = "";
+ for ( MRData e: b )
+ if (((Union)e).tag() == 1)
+ s += ((MR_string)(((Union)e).value())).get();
+ return new MR_string(s);
}
public static MR_string text ( Bag nodes ) {
- MR_string b = new MR_string("");
- for ( MRData e: nodes )
- b = plus(b,text((Union)e));
- return b;
+ MR_string b = new MR_string("");
+ for ( MRData e: nodes )
+ b = plus(b,text((Union)e));
+ return b;
}
public static MR_string tag ( Union node ) {
- if (node.tag() == 1)
- error("Cannot extract the tagname of a CData: "+node);
- return (MR_string)((Tuple) node.value()).get(0);
+ if (node.tag() == 1)
+ error("Cannot extract the tagname of a CData: "+node);
+ return (MR_string)((Tuple) node.value()).get(0);
}
public static MR_string XMLattribute ( MR_string tagname, Union node ) {
- if (node.tag() == 1)
- error("Element "+node+" does not have attributes");
- Tuple t = (Tuple)node.value();
- String tag = tagname.get();
- for ( MRData c: (Bag)t.get(1) ) {
- Tuple p = (Tuple)c;
- if (tag.equals(((MR_string)(p.get(0))).get()))
- return new MR_string(((MR_string)p.get(1)).get());
- };
- error("Element "+node+" does not have attribute "+tagname);
- return null;
+ if (node.tag() == 1)
+ error("Element "+node+" does not have attributes");
+ Tuple t = (Tuple)node.value();
+ String tag = tagname.get();
+ for ( MRData c: (Bag)t.get(1) ) {
+ Tuple p = (Tuple)c;
+ if (tag.equals(((MR_string)(p.get(0))).get()))
+ return new MR_string(((MR_string)p.get(1)).get());
+ };
+ error("Element "+node+" does not have attribute "+tagname);
+ return null;
}
public static Bag XMLattributes ( MR_string tagname, Union node ) {
- if (node.tag() == 1)
- return new Bag();
- Tuple t = (Tuple)node.value();
- Bag b = new Bag();
- String tag = tagname.get();
- for ( MRData c: (Bag)t.get(1) ) {
- Tuple p = (Tuple)c;
- if (tag.equals("*") || tag.equals(((MR_string)(p.get(0))).get()))
- b.add(p.get(1));
- };
- return b;
+ if (node.tag() == 1)
+ return new Bag();
+ Tuple t = (Tuple)node.value();
+ Bag b = new Bag();
+ String tag = tagname.get();
+ for ( MRData c: (Bag)t.get(1) ) {
+ Tuple p = (Tuple)c;
+ if (tag.equals("*") || tag.equals(((MR_string)(p.get(0))).get()))
+ b.add(p.get(1));
+ };
+ return b;
}
public static Bag XMLattributes ( MR_string tagname, Bag nodes ) {
- Bag b = new Bag();
- for ( MRData e: nodes )
- for (MRData c: XMLattributes(tagname,(Union)e))
- b.add(c);
- return b;
+ Bag b = new Bag();
+ for ( MRData e: nodes )
+ for (MRData c: XMLattributes(tagname,(Union)e))
+ b.add(c);
+ return b;
}
public static Bag XMLattribute ( MR_string tagname, Bag nodes ) {
- Bag b = new Bag();
- for ( MRData e: nodes )
- for (MRData c: XMLattributes(tagname,(Union)e))
- b.add(c);
- return b;
+ Bag b = new Bag();
+ for ( MRData e: nodes )
+ for (MRData c: XMLattributes(tagname,(Union)e))
+ b.add(c);
+ return b;
}
public static Bag XMLchildren ( MR_string tagname, Union node ) {
- if (node.tag() == 1)
- return new Bag();
- Tuple t = (Tuple)node.value();
- Bag b = new Bag();
- String tag = tagname.get();
- for ( MRData c: (Bag)t.get(2) )
- if (((Union)c).tag() == 0) {
- Tuple s = (Tuple)(((Union)c).value());
- if (tag.equals("*") || (((MR_string)(s.get(0))).get()).equals(tag))
- b.add(c);
- };
- return b;
+ if (node.tag() == 1)
+ return new Bag();
+ Tuple t = (Tuple)node.value();
+ Bag b = new Bag();
+ String tag = tagname.get();
+ for ( MRData c: (Bag)t.get(2) )
+ if (((Union)c).tag() == 0) {
+ Tuple s = (Tuple)(((Union)c).value());
+ if (tag.equals("*") || (((MR_string)(s.get(0))).get()).equals(tag))
+ b.add(c);
+ };
+ return b;
}
public static Bag XMLchildren ( MR_string tagname, Bag nodes ) {
- Bag b = new Bag();
- for ( MRData e: nodes )
- for (MRData c: XMLchildren(tagname,(Union)e))
- b.add(c);
- return b;
+ Bag b = new Bag();
+ for ( MRData e: nodes )
+ for (MRData c: XMLchildren(tagname,(Union)e))
+ b.add(c);
+ return b;
}
public static MRData fold ( Lambda c, MRData z, Bag s ) {
- MRData v = z;
- for ( MRData e: s )
- z = c.lambda().eval(new Tuple(z,e));
- return z;
+ MRData v = z;
+ for ( MRData e: s )
+ z = c.lambda().eval(new Tuple(z,e));
+ return z;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/3de9e485/src/main/java/core/Test.java
----------------------------------------------------------------------
diff --git a/src/main/java/core/Test.java b/src/main/java/core/Test.java
index 6de5eb0..85598fb 100644
--- a/src/main/java/core/Test.java
+++ b/src/main/java/core/Test.java
@@ -31,85 +31,85 @@ final public class Test {
static PrintStream test_out;
private static int compare ( String file1, String file2 ) throws Exception {
- FileInputStream s1 = new FileInputStream(file1);
- FileInputStream s2 = new FileInputStream(file2);
- int b1, b2;
- int i = 1;
- while ((b1 = s1.read()) == (b2 = s2.read()) && b1 != -1 && b2 != -1)
- i++;
- return (b1 == -1 && b2 == -1) ? 0 : i;
+ FileInputStream s1 = new FileInputStream(file1);
+ FileInputStream s2 = new FileInputStream(file2);
+ int b1, b2;
+ int i = 1;
+ while ((b1 = s1.read()) == (b2 = s2.read()) && b1 != -1 && b2 != -1)
+ i++;
+ return (b1 == -1 && b2 == -1) ? 0 : i;
}
private static void query ( File query ) throws Exception {
- String path = query.getPath();
- if (!path.endsWith(".mrql"))
- return;
- Translator.global_reset();
- String qname = query.getName();
- qname = qname.substring(0,qname.length()-5);
- test_out.print(" Testing "+qname+" ... ");
- String result_file = result_directory+"/"+qname+".txt";
- boolean exists = new File(result_file).exists();
- if (exists)
- System.setOut(new PrintStream(result_directory+"/result.txt"));
- else System.setOut(new PrintStream(result_file));
- try {
- parser = new MRQLParser(new MRQLLex(new FileInputStream(query)));
- Main.parser = parser;
- MRQLLex.reset();
- parser.parse();
- int i;
- if (exists && (i = compare(result_file,result_directory+"/result.txt")) > 0)
- test_out.println("MISMATCH AT "+(i-1));
- else if (exists)
- test_out.println("OK matched");
- else test_out.println("OK created");
- } catch (Error ex) {
- System.err.println(qname+": "+ex);
- ex.printStackTrace(System.err);
- test_out.println("FAILED");
- if (!exists)
- new File(result_file).delete();
- } catch (Exception ex) {
- System.err.println(qname+": "+ex);
- ex.printStackTrace(System.err);
- test_out.println("FAILED");
- if (!exists)
- new File(result_file).delete();
- } finally {
- if (Config.hadoop_mode)
- Plan.clean();
- if (Config.compile_functional_arguments)
- Compiler.clean();
- }
+ String path = query.getPath();
+ if (!path.endsWith(".mrql"))
+ return;
+ Translator.global_reset();
+ String qname = query.getName();
+ qname = qname.substring(0,qname.length()-5);
+ test_out.print(" Testing "+qname+" ... ");
+ String result_file = result_directory+"/"+qname+".txt";
+ boolean exists = new File(result_file).exists();
+ if (exists)
+ System.setOut(new PrintStream(result_directory+"/result.txt"));
+ else System.setOut(new PrintStream(result_file));
+ try {
+ parser = new MRQLParser(new MRQLLex(new FileInputStream(query)));
+ Main.parser = parser;
+ MRQLLex.reset();
+ parser.parse();
+ int i;
+ if (exists && (i = compare(result_file,result_directory+"/result.txt")) > 0)
+ test_out.println("MISMATCH AT "+(i-1));
+ else if (exists)
+ test_out.println("OK matched");
+ else test_out.println("OK created");
+ } catch (Error ex) {
+ System.err.println(qname+": "+ex);
+ ex.printStackTrace(System.err);
+ test_out.println("FAILED");
+ if (!exists)
+ new File(result_file).delete();
+ } catch (Exception ex) {
+ System.err.println(qname+": "+ex);
+ ex.printStackTrace(System.err);
+ test_out.println("FAILED");
+ if (!exists)
+ new File(result_file).delete();
+ } finally {
+ if (Config.hadoop_mode)
+ Plan.clean();
+ if (Config.compile_functional_arguments)
+ Compiler.clean();
+ }
}
public static void main ( String[] args ) throws Exception {
- boolean hadoop = false;
- for ( String arg: args )
- hadoop |= arg.equals("-local") || arg.equals("-dist");
- Config.quiet_execution = true;
- if (hadoop) {
- conf = Evaluator.new_configuration();
- GenericOptionsParser gop = new GenericOptionsParser(conf,args);
- conf = gop.getConfiguration();
- args = gop.getRemainingArgs();
- };
- Config.parse_args(args,conf);
- Config.hadoop_mode = Config.local_mode || Config.distributed_mode;
+ boolean hadoop = false;
+ for ( String arg: args )
+ hadoop |= arg.equals("-local") || arg.equals("-dist");
+ Config.quiet_execution = true;
+ if (hadoop) {
+ conf = Evaluator.new_configuration();
+ GenericOptionsParser gop = new GenericOptionsParser(conf,args);
+ conf = gop.getConfiguration();
+ args = gop.getRemainingArgs();
+ };
+ Config.parse_args(args,conf);
+ Config.hadoop_mode = Config.local_mode || Config.distributed_mode;
Evaluator.init(conf);
- new TopLevel();
- Config.testing = true;
- if (Config.hadoop_mode && Config.bsp_mode)
- Config.write(Plan.conf);
- if (Main.query_file.equals("") || Config.extra_args.size() != 2)
- throw new Error("Must provide a query directory, a result directory, and an error log file");
- File query_dir = new File(Main.query_file);
- result_directory = Config.extra_args.get(0);
+ new TopLevel();
+ Config.testing = true;
+ if (Config.hadoop_mode && Config.bsp_mode)
+ Config.write(Plan.conf);
+ if (Main.query_file.equals("") || Config.extra_args.size() != 2)
+ throw new Error("Must provide a query directory, a result directory, and an error log file");
+ File query_dir = new File(Main.query_file);
+ result_directory = Config.extra_args.get(0);
(new File(result_directory)).mkdirs();
- System.setErr(new PrintStream(Config.extra_args.get(1)));
- test_out = System.out;
- for ( File f: query_dir.listFiles() )
- query(f);
+ System.setErr(new PrintStream(Config.extra_args.get(1)));
+ test_out = System.out;
+ for ( File f: query_dir.listFiles() )
+ query(f);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/3de9e485/src/main/java/core/TopLevel.gen
----------------------------------------------------------------------
diff --git a/src/main/java/core/TopLevel.gen b/src/main/java/core/TopLevel.gen
index fadf321..5c86f37 100644
--- a/src/main/java/core/TopLevel.gen
+++ b/src/main/java/core/TopLevel.gen
@@ -26,27 +26,27 @@ final public class TopLevel extends Interpreter {
static Tree xml_type;
public TopLevel () {
- // XML and JSON are user-defined types:
- datadef("XML",#<union(Node(tuple(string,bag(tuple(string,string)),list(XML))),
- CData(string))>);
- datadef("JSON",#<union(JObject(bag(tuple(string,JSON))),
- JArray(list(JSON)),
- Jstring(string),
- Jlong(long),
- Jdouble(double),
- Jbool(bool),
- Jnull(tuple()))>);
- constant(#<PI>,#<double>,new MR_double(Math.PI));
- xml_type = global_datatype_env.lookup("XML");
- DataSource.loadParsers();
+ // XML and JSON are user-defined types:
+ datadef("XML",#<union(Node(tuple(string,bag(tuple(string,string)),list(XML))),
+ CData(string))>);
+ datadef("JSON",#<union(JObject(bag(tuple(string,JSON))),
+ JArray(list(JSON)),
+ Jstring(string),
+ Jlong(long),
+ Jdouble(double),
+ Jbool(bool),
+ Jnull(tuple()))>);
+ constant(#<PI>,#<double>,new MR_double(Math.PI));
+ xml_type = global_datatype_env.lookup("XML");
+ DataSource.loadParsers();
}
private static boolean memory_parsed_source ( Tree e ) {
- match e {
- case ParsedSource(...): return true;
- case Merge(`x,`y): return memory_parsed_source(x) && memory_parsed_source(y);
- };
- return false;
+ match e {
+ case ParsedSource(...): return true;
+ case Merge(`x,`y): return memory_parsed_source(x) && memory_parsed_source(y);
+ };
+ return false;
}
/** translate and evaluate an MRQL expression into MRData
@@ -55,35 +55,35 @@ final public class TopLevel extends Interpreter {
* @return the result of evaluation (MRData)
*/
public static MRData expression ( Tree e, boolean print ) {
- try {
- Tree plan = translate_expression(e);
- query_plan = plan;
- tab_count = -3;
- if (plan == null)
- return null;
- if (Config.hadoop_mode)
- Evaluator.initialize_query();
- MRData res = evalE(plan,null);
- if (print) {
- if (!Config.quiet_execution)
- System.out.println("Result:");
- if (!Config.hadoop_mode && Config.bsp_mode && memory_parsed_source(plan))
- System.out.println(print(((Tuple)((Bag)res).get(0)).second(),query_type));
- else System.out.println(print(res,query_type));
- } return res;
- } catch (Exception x) {
- if (x.getMessage() != null)
- System.err.println("*** MRQL System Error at line "+Main.parser.line_pos()+": "+x);
- if (Config.trace)
- x.printStackTrace(System.err);
- return null;
- } catch (Error x) {
- if (x.getMessage() != null)
- System.err.println("*** MRQL System Error at line "+Main.parser.line_pos()+": "+x);
- if (Config.trace)
- x.printStackTrace(System.err);
- return null;
- }
+ try {
+ Tree plan = translate_expression(e);
+ query_plan = plan;
+ tab_count = -3;
+ if (plan == null)
+ return null;
+ if (Config.hadoop_mode)
+ Evaluator.initialize_query();
+ MRData res = evalE(plan,null);
+ if (print) {
+ if (!Config.quiet_execution)
+ System.out.println("Result:");
+ if (!Config.hadoop_mode && Config.bsp_mode && memory_parsed_source(plan))
+ System.out.println(print(((Tuple)((Bag)res).get(0)).second(),query_type));
+ else System.out.println(print(res,query_type));
+ } return res;
+ } catch (Exception x) {
+ if (x.getMessage() != null)
+ System.err.println("*** MRQL System Error at line "+Main.parser.line_pos()+": "+x);
+ if (Config.trace)
+ x.printStackTrace(System.err);
+ return null;
+ } catch (Error x) {
+ if (x.getMessage() != null)
+ System.err.println("*** MRQL System Error at line "+Main.parser.line_pos()+": "+x);
+ if (Config.trace)
+ x.printStackTrace(System.err);
+ return null;
+ }
}
/** translate, evaluate, and print the results of an MRQL expression e
@@ -91,46 +91,46 @@ final public class TopLevel extends Interpreter {
* @return the result of evaluation (MRData)
*/
public final static MRData expression ( Tree e ) {
- reset();
- return expression(e,true);
+ reset();
+ return expression(e,true);
}
/** handle the assignment v=e */
public final static void assign ( String v, Tree e ) {
- if (variable_lookup(v,global_env) != null) {
- global_type_env.remove(v);
- remove_global_binding(v);
- };
- global_vars.insert(v,e);
+ if (variable_lookup(v,global_env) != null) {
+ global_type_env.remove(v);
+ remove_global_binding(v);
+ };
+ global_vars.insert(v,e);
}
private final static boolean is_function ( Tree e ) {
- match e {
- case function(...): return true;
- };
- return false;
+ match e {
+ case function(...): return true;
+ };
+ return false;
}
/** handle the assignment v:=e */
public final static Tree store ( String v, Tree e ) {
- reset();
- if (global_vars.lookup(v) != null)
- global_vars.remove(v);
- MRData res = expression(e,false);
- global_type_env.insert(v,query_type);
- if (res instanceof Bag)
- ((Bag)res).materialize();
- new_global_binding(v,res);
- return query_plan;
+ reset();
+ if (global_vars.lookup(v) != null)
+ global_vars.remove(v);
+ MRData res = expression(e,false);
+ global_type_env.insert(v,query_type);
+ if (res instanceof Bag)
+ ((Bag)res).materialize();
+ new_global_binding(v,res);
+ return query_plan;
}
/** define an MRQL constant, such as PI */
private final static void constant ( Tree v, Tree type, MRData value ) {
- String var = v.toString();
- if (global_vars.lookup(var) != null)
- global_vars.remove(var);
- global_type_env.insert(var,type);
- new_global_binding(var,value);
+ String var = v.toString();
+ if (global_vars.lookup(var) != null)
+ global_vars.remove(var);
+ global_type_env.insert(var,type);
+ new_global_binding(var,value);
}
/** define a new function
@@ -140,173 +140,173 @@ final public class TopLevel extends Interpreter {
* @param body function body
*/
public final static void functiondef ( String fnc, Trees params, Tree out_type, Tree body ) {
- reset();
- Trees as = #[];
- Trees ps = #[];
- for ( Tree param: params )
- match param {
- case bind(`v,`tp):
- Tree ntp = normalize_type(tp);
- as = as.append(ntp);
- ps = ps.append(#<bind(`v,`ntp)>);
- case _: type_error(param,"Ill-formed function parameter: "+param);
- };
- out_type = normalize_type(out_type);
- // needed for recursive functions
- global_type_env.insert(fnc,#<arrow(tuple(...as),`out_type)>);
- Tree fname = #<`fnc>;
- if (!is_pure(body))
- impure_functions = impure_functions.append(fname);
- Tree plan = store(fnc,#<function(tuple(...ps),`out_type,`body)>);
- if (plan != null)
- Translator.global_functions.insert(fnc,plan);
- if (Config.hadoop_mode && plan != null)
- Plan.conf.set("mrql.global."+fnc,
- closure(plan,global_env).toString());
+ reset();
+ Trees as = #[];
+ Trees ps = #[];
+ for ( Tree param: params )
+ match param {
+ case bind(`v,`tp):
+ Tree ntp = normalize_type(tp);
+ as = as.append(ntp);
+ ps = ps.append(#<bind(`v,`ntp)>);
+ case _: type_error(param,"Ill-formed function parameter: "+param);
+ };
+ out_type = normalize_type(out_type);
+ // needed for recursive functions
+ global_type_env.insert(fnc,#<arrow(tuple(...as),`out_type)>);
+ Tree fname = #<`fnc>;
+ if (!is_pure(body))
+ impure_functions = impure_functions.append(fname);
+ Tree plan = store(fnc,#<function(tuple(...ps),`out_type,`body)>);
+ if (plan != null)
+ Translator.global_functions.insert(fnc,plan);
+ if (Config.hadoop_mode && plan != null)
+ Plan.conf.set("mrql.global."+fnc,
+ closure(plan,global_env).toString());
}
/** dump the result of evaluating the MRQL query e to a binary file */
private final static void dump ( String file, Tree e ) {
- MRData res = expression(e,false);
- try {
- query_type = make_persistent_type(query_type);
- if (res != null)
- if (Config.hadoop_mode)
- Plan.dump(file,query_type,res);
- else MapReduceAlgebra.dump(file,query_type,res);
- } catch (Exception x) {
- throw new Error(x);
- }
+ MRData res = expression(e,false);
+ try {
+ query_type = make_persistent_type(query_type);
+ if (res != null)
+ if (Config.hadoop_mode)
+ Plan.dump(file,query_type,res);
+ else MapReduceAlgebra.dump(file,query_type,res);
+ } catch (Exception x) {
+ throw new Error(x);
+ }
}
/** dump the result of evaluating the MRQL query e to a text CVS file */
private final static void dump_text ( String file, Tree e ) {
- MRData res = expression(e,false);
- if (res != null)
- try {
- PrintStream out = (Config.hadoop_mode)
- ? Plan.print_stream(file)
- : new PrintStream(file);
- if (res instanceof MR_dataset)
- res = Plan.collect(((MR_dataset)res).dataset());
- int ps = Config.max_bag_size_print;
- Config.max_bag_size_print = -1;
- match query_type {
- case `T(tuple(...ts)):
- for ( MRData x: (Bag)res ) {
- Tuple t = (Tuple)x;
- out.print(print(t.get((short)0),ts.nth(0)));
- for ( short i = 1; i < t.size(); i++ )
- out.print(","+print(t.get(i),ts.nth(i)));
- out.println();
- }
- case `T(`tp):
- for ( MRData x: (Bag)res )
- out.println(print(x,tp));
- case _: out.println(print(res,query_type));
- };
- Config.max_bag_size_print = ps;
- out.close();
- } catch (Exception x) {
- throw new Error(x);
- }
+ MRData res = expression(e,false);
+ if (res != null)
+ try {
+ PrintStream out = (Config.hadoop_mode)
+ ? Plan.print_stream(file)
+ : new PrintStream(file);
+ if (res instanceof MR_dataset)
+ res = Plan.collect(((MR_dataset)res).dataset());
+ int ps = Config.max_bag_size_print;
+ Config.max_bag_size_print = -1;
+ match query_type {
+ case `T(tuple(...ts)):
+ for ( MRData x: (Bag)res ) {
+ Tuple t = (Tuple)x;
+ out.print(print(t.get((short)0),ts.nth(0)));
+ for ( short i = 1; i < t.size(); i++ )
+ out.print(","+print(t.get(i),ts.nth(i)));
+ out.println();
+ }
+ case `T(`tp):
+ for ( MRData x: (Bag)res )
+ out.println(print(x,tp));
+ case _: out.println(print(res,query_type));
+ };
+ Config.max_bag_size_print = ps;
+ out.close();
+ } catch (Exception x) {
+ throw new Error(x);
+ }
}
/** define a new named type (typedef) */
private final static void typedef ( String name, Tree type ) {
- type_names.insert(name,normalize_type(type));
+ type_names.insert(name,normalize_type(type));
}
/** define a new data type, such as XML and JSON */
private final static void datadef ( String name, Tree type ) {
- int i = 0;
- Trees as = #[];
- match type {
- case union(...nl):
- // needed for recursive datatypes
- global_datatype_env.insert(name,#<union(...nl)>);
- for ( Tree n: nl )
- match n {
- case `c(`t):
- if (data_constructors.lookup(c.toString()) == null)
- data_constructors.insert(c.toString(),#<`name(`i,`t)>);
- else type_error(type,"Data constructor "+c+" has already been defined");
- as = as.append(#<`c(`(normalize_type(t)))>);
- i++;
- }
+ int i = 0;
+ Trees as = #[];
+ match type {
+ case union(...nl):
+ // needed for recursive datatypes
+ global_datatype_env.insert(name,#<union(...nl)>);
+ for ( Tree n: nl )
+ match n {
+ case `c(`t):
+ if (data_constructors.lookup(c.toString()) == null)
+ data_constructors.insert(c.toString(),#<`name(`i,`t)>);
+ else type_error(type,"Data constructor "+c+" has already been defined");
+ as = as.append(#<`c(`(normalize_type(t)))>);
+ i++;
+ }
};
- global_datatype_env.remove(name);
- global_datatype_env.insert(name,#<union(...as)>);
+ global_datatype_env.remove(name);
+ global_datatype_env.insert(name,#<union(...as)>);
}
/** define a user aggregation */
private static void aggregation ( String name, Tree type, Tree plus, Tree zero, Tree unit ) {
- reset();
- zero = Simplification.rename(zero);
- plus = Simplification.rename(plus);
- unit = Simplification.rename(unit);
- type = normalize_type(type);
- Tree ztp = TypeInference.type_inference2(zero);
- Tree v1 = new_var();
- type_env.insert(v1.toString(),ztp);
- TypeInference.type_inference2(Normalization.normalize_all(#<apply(`plus,tuple(`v1,`v1))>));
- Tree v2 = new_var();
- type_env.insert(v2.toString(),type);
- Tree utp = TypeInference.type_inference2(Normalization.normalize_all(#<apply(`unit,`v2)>));
- if (unify(utp,ztp) == null)
- type_error(unit,"Wrong type in unit result (expected "+ztp+" found "+utp);
- monoids = monoids.append(#<`name(`type,`plus,`zero,`unit)>);
+ reset();
+ zero = Simplification.rename(zero);
+ plus = Simplification.rename(plus);
+ unit = Simplification.rename(unit);
+ type = normalize_type(type);
+ Tree ztp = TypeInference.type_inference2(zero);
+ Tree v1 = new_var();
+ type_env.insert(v1.toString(),ztp);
+ TypeInference.type_inference2(Normalization.normalize_all(#<apply(`plus,tuple(`v1,`v1))>));
+ Tree v2 = new_var();
+ type_env.insert(v2.toString(),type);
+ Tree utp = TypeInference.type_inference2(Normalization.normalize_all(#<apply(`unit,`v2)>));
+ if (unify(utp,ztp) == null)
+ type_error(unit,"Wrong type in unit result (expected "+ztp+" found "+utp);
+ monoids = monoids.append(#<`name(`type,`plus,`zero,`unit)>);
}
/** the MRQL top-level interfacse to evaluate a single MRQL expression or command */
public final static void evaluate_top_level ( Tree expr ) {
- if (expr == null)
- return;
- match expr {
- case expression(`e):
- long t = System.currentTimeMillis();
- if (expression(e) != null && !Config.quiet_execution)
- System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
- case assign(`v,`e): assign(v.toString(),e);
- case store(`v,`e):
- long t = System.currentTimeMillis();
- if (store(v.toString(),e) != null && !Config.quiet_execution)
- System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
- case dump(`s,`e):
- long t = System.currentTimeMillis();
- dump(s.stringValue(),e);
- if (!Config.quiet_execution)
- System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
- case dump_text(`s,`e):
- long t = System.currentTimeMillis();
- dump_text(s.stringValue(),e);
- if (!Config.quiet_execution)
- System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
- case typedef(`v,`t): typedef(v.toString(),t);
- case datadef(`v,`t): datadef(v.toString(),t);
- case functiondef(`f,params(...p),`tp,`e):
- functiondef(f.toString(),p,tp,e);
- case macrodef(`name,params(...p),`e):
- Translator.global_macros.insert(name.toString(),#<macro(params(...p),`e)>);
- case aggregation(`aggr,`type,`plus,`zero,`unit):
- aggregation(aggr.toString(),type,plus,zero,unit);
- case import(`c):
- ClassImporter.importClass(c.variableValue());
- case import(`c,...l):
- for (Tree m: l)
- ClassImporter.importMethod(c.variableValue(),m.variableValue());
- case include(`file):
- Main.include_file(file.toString());
- case parser(`n,`p):
- try {
- Class<? extends Parser> c = Class.forName(p.toString()).asSubclass(Parser.class);
- DataSource.parserDirectory.put(n.toString(),c);
- } catch (ClassNotFoundException e) {
- throw new Error("Class "+p.toString()+" not found");
- }
- case impure(`fn): // not used
- impure_functions = impure_functions.append(fn);
- case _: throw new Error("Unknown statement: "+expr);
- }
+ if (expr == null)
+ return;
+ match expr {
+ case expression(`e):
+ long t = System.currentTimeMillis();
+ if (expression(e) != null && !Config.quiet_execution)
+ System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
+ case assign(`v,`e): assign(v.toString(),e);
+ case store(`v,`e):
+ long t = System.currentTimeMillis();
+ if (store(v.toString(),e) != null && !Config.quiet_execution)
+ System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
+ case dump(`s,`e):
+ long t = System.currentTimeMillis();
+ dump(s.stringValue(),e);
+ if (!Config.quiet_execution)
+ System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
+ case dump_text(`s,`e):
+ long t = System.currentTimeMillis();
+ dump_text(s.stringValue(),e);
+ if (!Config.quiet_execution)
+ System.out.println("Run time: "+(System.currentTimeMillis()-t)/1000.0+" secs");
+ case typedef(`v,`t): typedef(v.toString(),t);
+ case datadef(`v,`t): datadef(v.toString(),t);
+ case functiondef(`f,params(...p),`tp,`e):
+ functiondef(f.toString(),p,tp,e);
+ case macrodef(`name,params(...p),`e):
+ Translator.global_macros.insert(name.toString(),#<macro(params(...p),`e)>);
+ case aggregation(`aggr,`type,`plus,`zero,`unit):
+ aggregation(aggr.toString(),type,plus,zero,unit);
+ case import(`c):
+ ClassImporter.importClass(c.variableValue());
+ case import(`c,...l):
+ for (Tree m: l)
+ ClassImporter.importMethod(c.variableValue(),m.variableValue());
+ case include(`file):
+ Main.include_file(file.toString());
+ case parser(`n,`p):
+ try {
+ Class<? extends Parser> c = Class.forName(p.toString()).asSubclass(Parser.class);
+ DataSource.parserDirectory.put(n.toString(),c);
+ } catch (ClassNotFoundException e) {
+ throw new Error("Class "+p.toString()+" not found");
+ }
+ case impure(`fn): // not used
+ impure_functions = impure_functions.append(fn);
+ case _: throw new Error("Unknown statement: "+expr);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/3de9e485/src/main/java/core/Translator.gen
----------------------------------------------------------------------
diff --git a/src/main/java/core/Translator.gen b/src/main/java/core/Translator.gen
index acdab08..19a7a5c 100644
--- a/src/main/java/core/Translator.gen
+++ b/src/main/java/core/Translator.gen
@@ -27,8 +27,8 @@ public class Translator extends Printer {
static Trees functions = #[ ];
static {
- ClassImporter.load_classes();
- DataSource.loadParsers();
+ ClassImporter.load_classes();
+ DataSource.loadParsers();
}
/** type environment that binds local variables to types */
@@ -61,7 +61,7 @@ public class Translator extends Printer {
static Trees repeat_variables = #[];
static {
- global_type_env.insert("args",#<list(string)>);
+ global_type_env.insert("args",#<list(string)>);
}
/** expressions with impure functions cannot factored out */
@@ -70,62 +70,62 @@ public class Translator extends Printer {
private static int var_count = 0;
static void reset () {
- var_count = 0;
- type_env = global_type_env;
- st = new SymbolTable();
- type_env = new SymbolTable();
- repeat_variables = #[];
+ var_count = 0;
+ type_env = global_type_env;
+ st = new SymbolTable();
+ type_env = new SymbolTable();
+ repeat_variables = #[];
}
static void global_reset () {
- reset();
- global_type_env = new SymbolTable();
- global_datatype_env = new SymbolTable();
- global_vars = new SymbolTable();
- global_functions = new SymbolTable();
- global_macros = new SymbolTable();
- type_names = new SymbolTable();
- data_constructors = new SymbolTable();
- new TopLevel();
+ reset();
+ global_type_env = new SymbolTable();
+ global_datatype_env = new SymbolTable();
+ global_vars = new SymbolTable();
+ global_functions = new SymbolTable();
+ global_macros = new SymbolTable();
+ type_names = new SymbolTable();
+ data_constructors = new SymbolTable();
+ new TopLevel();
}
static void error ( String msg ) {
- System.err.println("*** MRQL error at line "+Main.parser.line_pos()+": "+msg);
- throw new Error();
+ System.err.println("*** MRQL error at line "+Main.parser.line_pos()+": "+msg);
+ throw new Error();
}
final static Tree identity = #<lambda(x,x)>;
static Tree identity () {
- return Normalization.rename(#<lambda(x,bag(x))>);
+ return Normalization.rename(#<lambda(x,bag(x))>);
}
/** is this type a collection type? */
public static boolean is_collection ( String x ) {
- return x.equals("Bag") || x.equals("bag") || x.equals("List") || x.equals("list");
+ return x.equals("Bag") || x.equals("bag") || x.equals("List") || x.equals("list");
}
/** is this type a collection type? */
public static boolean collection_type ( Tree tp ) {
- match tp {
- case `T(`t1): return is_collection(T);
+ match tp {
+ case `T(`t1): return is_collection(T);
};
- return false;
+ return false;
}
/** is this type a collection type for values stored in HDFS? */
public static boolean is_persistent_collection ( String x ) {
- return x.equals("Bag") || x.equals("List");
+ return x.equals("Bag") || x.equals("List");
}
/** make this collection type a persistent type that is stored in HDFS */
public static String persistent_collection ( String x ) {
- return (x.equals("list")) ? "List" : (x.equals("bag")) ? "Bag" : x;
+ return (x.equals("list")) ? "List" : (x.equals("bag")) ? "Bag" : x;
}
/** make this collection type a transient type stored in memory */
public static String transient_collection ( String x ) {
- return (x.equals("List")) ? "list" : (x.equals("Bag")) ? "bag" : x;
+ return (x.equals("List")) ? "list" : (x.equals("Bag")) ? "bag" : x;
}
/** An aggeregation must be based on a commutative monoid (plus,zero) with a unit:
@@ -133,107 +133,107 @@ public class Translator extends Printer {
* plus: function from (b,b) to b, zero: b, unit: function from a to b
*/
static Trees monoids =
- #[ count(any,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0,long),lambda(x,typed(1,long))),
- sum(int,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0,long),lambda(x,typed(x,long))),
- sum(long,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0,long),`identity),
- sum(float,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0.0,double),lambda(x,typed(x,double))),
- sum(double,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0.0,double),`identity),
- max(int,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Integer.MIN_VALUE),int),`identity),
- max(long,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Long.MIN_VALUE),long),`identity),
- max(float,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Float.MIN_VALUE),float),`identity),
- max(double,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Double.MIN_VALUE),double),`identity),
- min(int,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Integer.MAX_VALUE),int),`identity),
- min(long,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Long.MAX_VALUE),long),`identity),
- min(float,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Float.MAX_VALUE),float),`identity),
- min(double,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Double.MAX_VALUE),double),`identity),
- avg_aggr(int,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
- call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
- tuple(typed(0.0,double),typed(0,long)),
- lambda(x,tuple(typed(x,double),typed(1,long)))),
- avg_aggr(long,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
- call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
- tuple(typed(0.0,double),typed(0,long)),
- lambda(x,tuple(typed(x,double),typed(1,long)))),
- avg_aggr(float,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
- call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
- tuple(typed(0.0,double),typed(0,long)),
- lambda(x,tuple(typed(x,double),typed(1,long)))),
- avg_aggr(double,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
- call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
- tuple(typed(0.0,double),typed(0,long)),
- lambda(x,tuple(typed(x,double),typed(1,long)))),
- all(bool,lambda(x,call(and,nth(x,0),nth(x,1))),true,`identity),
- some(bool,lambda(x,call(or,nth(x,0),nth(x,1))),false,`identity)
- ];
+ #[ count(any,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0,long),lambda(x,typed(1,long))),
+ sum(int,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0,long),lambda(x,typed(x,long))),
+ sum(long,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0,long),`identity),
+ sum(float,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0.0,double),lambda(x,typed(x,double))),
+ sum(double,lambda(x,call(plus,nth(x,0),nth(x,1))),typed(0.0,double),`identity),
+ max(int,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Integer.MIN_VALUE),int),`identity),
+ max(long,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Long.MIN_VALUE),long),`identity),
+ max(float,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Float.MIN_VALUE),float),`identity),
+ max(double,lambda(x,call(max,nth(x,0),nth(x,1))),typed(`(Double.MIN_VALUE),double),`identity),
+ min(int,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Integer.MAX_VALUE),int),`identity),
+ min(long,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Long.MAX_VALUE),long),`identity),
+ min(float,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Float.MAX_VALUE),float),`identity),
+ min(double,lambda(x,call(min,nth(x,0),nth(x,1))),typed(`(Double.MAX_VALUE),double),`identity),
+ avg_aggr(int,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
+ call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
+ tuple(typed(0.0,double),typed(0,long)),
+ lambda(x,tuple(typed(x,double),typed(1,long)))),
+ avg_aggr(long,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
+ call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
+ tuple(typed(0.0,double),typed(0,long)),
+ lambda(x,tuple(typed(x,double),typed(1,long)))),
+ avg_aggr(float,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
+ call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
+ tuple(typed(0.0,double),typed(0,long)),
+ lambda(x,tuple(typed(x,double),typed(1,long)))),
+ avg_aggr(double,lambda(x,tuple(call(plus,nth(nth(x,0),0),nth(nth(x,1),0)),
+ call(plus,nth(nth(x,0),1),nth(nth(x,1),1)))),
+ tuple(typed(0.0,double),typed(0,long)),
+ lambda(x,tuple(typed(x,double),typed(1,long)))),
+ all(bool,lambda(x,call(and,nth(x,0),nth(x,1))),true,`identity),
+ some(bool,lambda(x,call(or,nth(x,0),nth(x,1))),false,`identity)
+ ];
static void print_aggregates () {
- for ( Tree m: monoids )
- match m {
- case `f(`tp,...):
- System.out.print(" "+f+":"+print_type(tp));
- }
- System.out.println();
+ for ( Tree m: monoids )
+ match m {
+ case `f(`tp,...):
+ System.out.print(" "+f+":"+print_type(tp));
+ }
+ System.out.println();
}
static Trees plans_with_distributed_lambdas
- = #[MapReduce,MapAggregateReduce,MapCombineReduce,FroupByJoin,Aggregate,
- MapReduce2,MapCombineReduce2,MapAggregateReduce2,MapJoin,MapAggregateJoin,
- CrossProduct,CrossAggregateProduct,cMap,AggregateMap,BSP,repeat,closure];
+ = #[MapReduce,MapAggregateReduce,MapCombineReduce,FroupByJoin,Aggregate,
+ MapReduce2,MapCombineReduce2,MapAggregateReduce2,MapJoin,MapAggregateJoin,
+ CrossProduct,CrossAggregateProduct,cMap,AggregateMap,BSP,repeat,closure];
static Trees algebraic_operators
- = #[mapReduce,mapReduce2,cmap,join,groupBy,orderBy,aggregate,map,filter];
+ = #[mapReduce,mapReduce2,cmap,join,groupBy,orderBy,aggregate,map,filter];
static Trees plan_names = plans_with_distributed_lambdas.append(algebraic_operators)
- .append(#[Repeat,Closure,Generator,Let,If]);
+ .append(#[Repeat,Closure,Generator,Let,If]);
/** generates new variable names */
public static Tree new_var () {
- return new VariableLeaf("x_"+(Integer.toString(var_count++)));
+ return new VariableLeaf("x_"+(Integer.toString(var_count++)));
}
/** is this expression pure? (does it contain calls to impure functions?) */
static boolean is_pure ( Tree expr ) {
- match expr {
- case call(`f,...al):
- if (impure_functions.member(f))
- return false;
- else fail
- case `f(...al):
- for ( Tree a: al )
- if (!is_pure(a))
- return false;
- };
- return true;
+ match expr {
+ case call(`f,...al):
+ if (impure_functions.member(f))
+ return false;
+ else fail
+ case `f(...al):
+ for ( Tree a: al )
+ if (!is_pure(a))
+ return false;
+ };
+ return true;
}
public static Trees union ( Trees xs, Trees ys ) {
- Trees res = xs;
- for ( Tree y: ys )
- if (!xs.member(y))
- res = res.append(y);
- return res;
+ Trees res = xs;
+ for ( Tree y: ys )
+ if (!xs.member(y))
+ res = res.append(y);
+ return res;
}
/** return the variables of a pattern */
static Trees pattern_variables ( Tree pattern ) {
Trees args = #[];
- match pattern {
- case tuple(...pl):
- for ( Tree p: pl )
- args = union(args,pattern_variables(p));
+ match pattern {
+ case tuple(...pl):
+ for ( Tree p: pl )
+ args = union(args,pattern_variables(p));
case record(...bl):
- for ( Tree b: bl )
- match b {
- case bind(`n,`p):
- args = union(args,pattern_variables(p));
- };
- case typed(`p,_):
- args = pattern_variables(p);
- case `v:
- if (v.is_variable())
- args = #[`v];
- };
- return args;
+ for ( Tree b: bl )
+ match b {
+ case bind(`n,`p):
+ args = union(args,pattern_variables(p));
+ };
+ case typed(`p,_):
+ args = pattern_variables(p);
+ case `v:
+ if (v.is_variable())
+ args = #[`v];
+ };
+ return args;
}
/** replace all occurences of from_expr in expr with to_expr
@@ -243,19 +243,19 @@ public class Translator extends Printer {
* @return equal to expr but with all occurences of from_expr replaced with to_expr
*/
public static Tree subst ( Tree from_expr, Tree to_expr, Tree expr ) {
- if (expr.equals(from_expr))
- return to_expr;
- match expr {
- case lambda(`v,_):
- if (pattern_variables(v).member(from_expr))
- return expr;
- else fail
- case bind(`a,`u):
- return #<bind(`a,`(subst(from_expr,to_expr,u)))>;
- case `f(...al):
- return #<`f(...(subst_list(from_expr,to_expr,al)))>;
- };
- return expr;
+ if (expr.equals(from_expr))
+ return to_expr;
+ match expr {
+ case lambda(`v,_):
+ if (pattern_variables(v).member(from_expr))
+ return expr;
+ else fail
+ case bind(`a,`u):
+ return #<bind(`a,`(subst(from_expr,to_expr,u)))>;
+ case `f(...al):
+ return #<`f(...(subst_list(from_expr,to_expr,al)))>;
+ };
+ return expr;
}
/** replace all occurences of from_expr in el with to_expr
@@ -265,10 +265,10 @@ public class Translator extends Printer {
* @return equal to el but with all occurences of from_expr replaced with to_expr
*/
public static Trees subst_list ( Tree from_expr, Tree to_expr, Trees el ) {
- Trees bl = #[];
- for ( Tree e: el )
- bl = bl.append(subst(from_expr,to_expr,e));
- return bl;
+ Trees bl = #[];
+ for ( Tree e: el )
+ bl = bl.append(subst(from_expr,to_expr,e));
+ return bl;
}
/** replace all occurences of var in expr with to_expr only if to_expr is pure or it is used once only
@@ -278,168 +278,168 @@ public class Translator extends Printer {
* @return equal to expr but with all occurences of from_expr replaced with to_expr
*/
public static Tree subst_var ( Tree var, Tree to_expr, Tree expr ) {
- if (!is_pure(to_expr) && occurences(var,expr) > 1)
- return #<let(`var,`to_expr,`expr)>;
- else return subst(var,to_expr,expr);
+ if (!is_pure(to_expr) && occurences(var,expr) > 1)
+ return #<let(`var,`to_expr,`expr)>;
+ else return subst(var,to_expr,expr);
}
/** used in the MRQL parser to handle templates */
public static Tree template ( Tree s ) {
- match s {
- case template(`parser,...as):
- try {
- Trees args = #[];
- String tx = "";
- int i = 0;
- for ( Tree a: as )
- match a {
- case text(`t): tx += t;
- case _: args = args.append(a);
- tx += "{{"+(i++)+"}}";
- };
- Class<? extends Parser> pc = DataSource.parserDirectory.get(parser.toString());
- if (pc == null)
- throw new Error("Unrecognized parser: "+parser);
- Parser p = pc.newInstance();
- p.initialize(#[]);
- Bag e = p.parse(tx);
- Tree res = Interpreter.reify(e.get(0),p.type());
- for ( int j = 0; j < i; j++ )
- res = subst(new VariableLeaf("t_"+j),args.nth(j),res);
- return res;
- } catch (Exception e) {
- throw new Error("Wrong template: "+s+"\n"+e);
- }
+ match s {
+ case template(`parser,...as):
+ try {
+ Trees args = #[];
+ String tx = "";
+ int i = 0;
+ for ( Tree a: as )
+ match a {
+ case text(`t): tx += t;
+ case _: args = args.append(a);
+ tx += "{{"+(i++)+"}}";
+ };
+ Class<? extends Parser> pc = DataSource.parserDirectory.get(parser.toString());
+ if (pc == null)
+ throw new Error("Unrecognized parser: "+parser);
+ Parser p = pc.newInstance();
+ p.initialize(#[]);
+ Bag e = p.parse(tx);
+ Tree res = Interpreter.reify(e.get(0),p.type());
+ for ( int j = 0; j < i; j++ )
+ res = subst(new VariableLeaf("t_"+j),args.nth(j),res);
+ return res;
+ } catch (Exception e) {
+ throw new Error("Wrong template: "+s+"\n"+e);
+ }
};
- throw new Error("Wrong template: "+s);
+ throw new Error("Wrong template: "+s);
}
/** convert Tree constructions to code that construct these Trees (used in the Compiler) */
public static String reify ( Tree e ) {
- if (e instanceof LongLeaf)
- return "new org.apache.mrql.gen.LongLeaf(" + e + ")";
- else if (e instanceof DoubleLeaf)
- return "new org.apache.mrql.gen.DoubleLeaf(" + e + ")";
- else if (e instanceof VariableLeaf)
- return "new org.apache.mrql.gen.VariableLeaf(\"" + e.variableValue() + "\")";
- else if (e instanceof StringLeaf)
- return "new org.apache.mrql.gen.StringLeaf(" + e.toString().replace("\\","\\\\") + ")";
- else {
- Node n = (Node) e;
- return "new org.apache.mrql.gen.Node(\""+n.name()+"\","+reify(n.children())+")";
- }
+ if (e instanceof LongLeaf)
+ return "new org.apache.mrql.gen.LongLeaf(" + e + ")";
+ else if (e instanceof DoubleLeaf)
+ return "new org.apache.mrql.gen.DoubleLeaf(" + e + ")";
+ else if (e instanceof VariableLeaf)
+ return "new org.apache.mrql.gen.VariableLeaf(\"" + e.variableValue() + "\")";
+ else if (e instanceof StringLeaf)
+ return "new org.apache.mrql.gen.StringLeaf(" + e.toString().replace("\\","\\\\") + ")";
+ else {
+ Node n = (Node) e;
+ return "new org.apache.mrql.gen.Node(\""+n.name()+"\","+reify(n.children())+")";
+ }
}
/** convert Tree constructions to code that construct these Trees (used in the Compiler) */
public static String reify ( Trees ts ) {
- String s = "org.apache.mrql.gen.Trees.nil";
- for ( Tree c: ts )
- s += ".append("+reify(c)+")";
- return s;
+ String s = "org.apache.mrql.gen.Trees.nil";
+ for ( Tree c: ts )
+ s += ".append("+reify(c)+")";
+ return s;
}
/** return the list of free variables in e that are not in exclude list */
public static Trees free_variables ( Tree e, Trees exclude ) {
- if (e == null)
- return #[];
- match e {
- case lambda(`x,`b):
- return free_variables(b,exclude.append(pattern_variables(x)));
- case let(`x,`u,`b):
- return free_variables(b,exclude.append(pattern_variables(x)))
- .append(free_variables(u,exclude));
- case Let(`x,`u,`b):
- return free_variables(b,exclude.append(pattern_variables(x)))
- .append(free_variables(u,exclude));
- case select(`u,from(...bs),`p):
- Trees ex = exclude;
- Trees fs = #[];
- for ( Tree b: bs )
- match b {
- case bind(`v,`x):
- fs = fs.append(free_variables(x,ex));
- ex = ex.append(pattern_variables(v));
- };
- return free_variables(p,ex).append(free_variables(u,ex)).append(fs);
- case `f(...as):
- Trees res = #[];
- for ( Tree a: as )
- res = res.append(free_variables(a,exclude));
- return res;
- case `v:
- if (v.is_variable() && v.toString().startsWith("x_") && !exclude.member(v))
- return #[`v];
- };
- return #[];
+ if (e == null)
+ return #[];
+ match e {
+ case lambda(`x,`b):
+ return free_variables(b,exclude.append(pattern_variables(x)));
+ case let(`x,`u,`b):
+ return free_variables(b,exclude.append(pattern_variables(x)))
+ .append(free_variables(u,exclude));
+ case Let(`x,`u,`b):
+ return free_variables(b,exclude.append(pattern_variables(x)))
+ .append(free_variables(u,exclude));
+ case select(`u,from(...bs),`p):
+ Trees ex = exclude;
+ Trees fs = #[];
+ for ( Tree b: bs )
+ match b {
+ case bind(`v,`x):
+ fs = fs.append(free_variables(x,ex));
+ ex = ex.append(pattern_variables(v));
+ };
+ return free_variables(p,ex).append(free_variables(u,ex)).append(fs);
+ case `f(...as):
+ Trees res = #[];
+ for ( Tree a: as )
+ res = res.append(free_variables(a,exclude));
+ return res;
+ case `v:
+ if (v.is_variable() && v.toString().startsWith("x_") && !exclude.member(v))
+ return #[`v];
+ };
+ return #[];
}
/** count the occurences of x in e */
public static int occurences ( Tree x, Tree e ) {
- if (x.equals(e))
- return 1;
- match e {
- case `f(...as):
- int i = 0;
- for ( Tree a: as )
- i += occurences(x,a);
- return i;
- };
- return 0;
+ if (x.equals(e))
+ return 1;
+ match e {
+ case `f(...as):
+ int i = 0;
+ for ( Tree a: as )
+ i += occurences(x,a);
+ return i;
+ };
+ return 0;
}
/** return true if x is equal to y modulo variable substitution */
public static boolean alpha_equivalent ( Tree x, Tree y, SymbolTable st ) {
- match #<T(`x,`y)> {
- case T(lambda(`vx,`bx),lambda(`vy,`by)):
- if (!vx.equals(vy))
- st.insert(vx.toString(),vy);
- return alpha_equivalent(bx,by,st);
- case T(`f(...xs),`g(...ys)):
- if (!f.equals(g) || xs.length() != ys.length())
- return false;
- for ( ; !xs.is_empty(); xs = xs.tail(), ys = ys.tail() )
- if (!alpha_equivalent(xs.head(),ys.head(),st))
- return false;
- return true;
- case T(`v,`w):
- if (v.is_variable() && w.is_variable())
- return v.equals(w) || (st.lookup(v.toString()) != null
- && st.lookup(v.toString()).equals(w));
- };
- return x.equals(y);
+ match #<T(`x,`y)> {
+ case T(lambda(`vx,`bx),lambda(`vy,`by)):
+ if (!vx.equals(vy))
+ st.insert(vx.toString(),vy);
+ return alpha_equivalent(bx,by,st);
+ case T(`f(...xs),`g(...ys)):
+ if (!f.equals(g) || xs.length() != ys.length())
+ return false;
+ for ( ; !xs.is_empty(); xs = xs.tail(), ys = ys.tail() )
+ if (!alpha_equivalent(xs.head(),ys.head(),st))
+ return false;
+ return true;
+ case T(`v,`w):
+ if (v.is_variable() && w.is_variable())
+ return v.equals(w) || (st.lookup(v.toString()) != null
+ && st.lookup(v.toString()).equals(w));
+ };
+ return x.equals(y);
}
private static SymbolTable alpha_symbol_table = new SymbolTable();
/** return true if x is equal to y modulo variable substitution */
public static boolean alpha_equivalent ( Tree x, Tree y ) {
- alpha_symbol_table.begin_scope();
- boolean b = alpha_equivalent(x,y,alpha_symbol_table);
- alpha_symbol_table.end_scope();
- return b;
+ alpha_symbol_table.begin_scope();
+ boolean b = alpha_equivalent(x,y,alpha_symbol_table);
+ alpha_symbol_table.end_scope();
+ return b;
}
/** translate a simplified select MRQL query to an algebraic form */
public static Tree translate_select ( Tree e ) {
match e {
case select(`u,from(),where(true)):
- return #<bag(`(translate_select(u)))>;
+ return #<bag(`(translate_select(u)))>;
case select(`u,from(),where(`c)):
- return #<if(`(translate_select(c)),bag(`(translate_select(u))),bag())>;
+ return #<if(`(translate_select(c)),bag(`(translate_select(u))),bag())>;
case select(`u,from(bind(`v,`d),...bl),where(`c)):
- Tree n = translate_select(#<select(`u,from(...bl),where(`c))>);
- return #<cmap(lambda(`v,`n),`(translate_select(d)))>;
+ Tree n = translate_select(#<select(`u,from(...bl),where(`c))>);
+ return #<cmap(lambda(`v,`n),`(translate_select(d)))>;
case `f(...al):
- Trees bl = #[];
- for ( Tree a: al )
- bl = bl.append(translate_select(a));
- return #<`f(...bl)>;
+ Trees bl = #[];
+ for ( Tree a: al )
+ bl = bl.append(translate_select(a));
+ return #<`f(...bl)>;
};
return e;
}
/** the MRQL top-level interfacse to evaluate a single MRQL expression or command */
public static void top_level ( Tree expr ) {
- TopLevel.evaluate_top_level(expr);
+ TopLevel.evaluate_top_level(expr);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/3de9e485/src/main/java/core/Tuple.java
----------------------------------------------------------------------
diff --git a/src/main/java/core/Tuple.java b/src/main/java/core/Tuple.java
index dde30d6..9825343 100644
--- a/src/main/java/core/Tuple.java
+++ b/src/main/java/core/Tuple.java
@@ -27,24 +27,24 @@ final public class Tuple extends MRData {
MRData[] tuple;
public Tuple ( int size ) {
- tuple = new MRData[size];
+ tuple = new MRData[size];
}
public Tuple ( final MRData ...as ) {
- tuple = as;
+ tuple = as;
}
/** the number of elements in the tuple */
public short size () { return (short)tuple.length; }
public void materializeAll () {
- for (MRData e: tuple)
- e.materializeAll();
+ for (MRData e: tuple)
+ e.materializeAll();
};
/** the i'th element of the tuple */
public MRData get ( int i ) {
- return tuple[i];
+ return tuple[i];
}
/** the first element of the tuple */
@@ -55,146 +55,146 @@ final public class Tuple extends MRData {
/** replace the i'th element of a tuple with new data and return a new value */
public MRData set ( int i, MRData data, MRData ret ) {
- tuple[i] = data;
- return ret;
+ tuple[i] = data;
+ return ret;
}
/** replace the i'th element of a tuple with new data */
public Tuple set ( int i, MRData data ) {
- tuple[i] = data;
- return this;
+ tuple[i] = data;
+ return this;
}
final public void write ( DataOutput out ) throws IOException {
- if (tuple.length == 0)
- out.writeByte(MRContainer.NULL);
- else if (tuple.length == 2) {
- out.writeByte(MRContainer.PAIR);
- tuple[0].write(out);
- tuple[1].write(out);
- } else if (tuple.length == 3) {
- out.writeByte(MRContainer.TRIPLE);
- tuple[0].write(out);
- tuple[1].write(out);
- tuple[2].write(out);
- } else {
- out.writeByte(MRContainer.TUPLE);
- WritableUtils.writeVInt(out,tuple.length);
- for (short i = 0; i < tuple.length; i++)
- tuple[i].write(out);
- }
+ if (tuple.length == 0)
+ out.writeByte(MRContainer.NULL);
+ else if (tuple.length == 2) {
+ out.writeByte(MRContainer.PAIR);
+ tuple[0].write(out);
+ tuple[1].write(out);
+ } else if (tuple.length == 3) {
+ out.writeByte(MRContainer.TRIPLE);
+ tuple[0].write(out);
+ tuple[1].write(out);
+ tuple[2].write(out);
+ } else {
+ out.writeByte(MRContainer.TUPLE);
+ WritableUtils.writeVInt(out,tuple.length);
+ for (short i = 0; i < tuple.length; i++)
+ tuple[i].write(out);
+ }
}
final public static Tuple read ( DataInput in ) throws IOException {
- int n = WritableUtils.readVInt(in);
- Tuple t = new Tuple(n);
- for ( short i = 0; i < n; i++ )
- t.tuple[i] = MRContainer.read(in);
- return t;
+ int n = WritableUtils.readVInt(in);
+ Tuple t = new Tuple(n);
+ for ( short i = 0; i < n; i++ )
+ t.tuple[i] = MRContainer.read(in);
+ return t;
}
final public static Tuple read2 ( DataInput in ) throws IOException {
- return new Tuple(MRContainer.read(in),MRContainer.read(in));
+ return new Tuple(MRContainer.read(in),MRContainer.read(in));
}
final public static Tuple read3 ( DataInput in ) throws IOException {
- return new Tuple(MRContainer.read(in),MRContainer.read(in),MRContainer.read(in));
+ return new Tuple(MRContainer.read(in),MRContainer.read(in),MRContainer.read(in));
}
public void readFields ( DataInput in ) throws IOException {
- int n = WritableUtils.readVInt(in);
- tuple = new Tuple[n];
- for ( short i = 0; i < n; i++ )
- tuple[i] = MRContainer.read(in);
+ int n = WritableUtils.readVInt(in);
+ tuple = new Tuple[n];
+ for ( short i = 0; i < n; i++ )
+ tuple[i] = MRContainer.read(in);
}
public int compareTo ( MRData x ) {
- assert(x instanceof Tuple);
- Tuple t = (Tuple) x;
- for ( short i = 0; i < tuple.length && i < t.tuple.length; i++ ) {
- int c = get(i).compareTo(t.get(i));
- if (c < 0)
- return -1;
- else if (c > 0)
- return 1;
- };
- if (tuple.length > t.tuple.length)
- return 1;
- else if (tuple.length < t.tuple.length)
- return -1;
- else return 0;
+ assert(x instanceof Tuple);
+ Tuple t = (Tuple) x;
+ for ( short i = 0; i < tuple.length && i < t.tuple.length; i++ ) {
+ int c = get(i).compareTo(t.get(i));
+ if (c < 0)
+ return -1;
+ else if (c > 0)
+ return 1;
+ };
+ if (tuple.length > t.tuple.length)
+ return 1;
+ else if (tuple.length < t.tuple.length)
+ return -1;
+ else return 0;
}
final public static int compare ( byte[] x, int xs, int xl, byte[] y, int ys, int yl, int[] size ) {
- try {
- int n = WritableComparator.readVInt(x,xs);
- int s = WritableUtils.decodeVIntSize(x[xs]);
- for ( short i = 0; i < n; i++ ) {
- int k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
- if (k != 0)
- return k;
- s += size[0];
- };
- size[0] = s+1;
- return 0;
- } catch (IOException e) {
- throw new Error(e);
- }
+ try {
+ int n = WritableComparator.readVInt(x,xs);
+ int s = WritableUtils.decodeVIntSize(x[xs]);
+ for ( short i = 0; i < n; i++ ) {
+ int k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
+ if (k != 0)
+ return k;
+ s += size[0];
+ };
+ size[0] = s+1;
+ return 0;
+ } catch (IOException e) {
+ throw new Error(e);
+ }
}
final public static int compare2 ( byte[] x, int xs, int xl, byte[] y, int ys, int yl, int[] size ) {
- int k = MRContainer.compare(x,xs,xl,y,ys,yl,size);
- if (k != 0)
- return k;
- int s = size[0];
- k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
- if (k != 0)
- return k;
- size[0] += s+1;
- return 0;
+ int k = MRContainer.compare(x,xs,xl,y,ys,yl,size);
+ if (k != 0)
+ return k;
+ int s = size[0];
+ k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
+ if (k != 0)
+ return k;
+ size[0] += s+1;
+ return 0;
}
final public static int compare3 ( byte[] x, int xs, int xl, byte[] y, int ys, int yl, int[] size ) {
- int k = MRContainer.compare(x,xs,xl,y,ys,yl,size);
- if (k != 0)
- return k;
- int s = size[0];
- k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
- if (k != 0)
- return k;
- s += size[0];
- k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
- if (k != 0)
- return k;
- size[0] += s+1;
- return 0;
+ int k = MRContainer.compare(x,xs,xl,y,ys,yl,size);
+ if (k != 0)
+ return k;
+ int s = size[0];
+ k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
+ if (k != 0)
+ return k;
+ s += size[0];
+ k = MRContainer.compare(x,xs+s,xl-s,y,ys+s,yl-s,size);
+ if (k != 0)
+ return k;
+ size[0] += s+1;
+ return 0;
}
public boolean equals ( Object x ) {
- if (!(x instanceof Tuple))
- return false;
- Tuple xt = (Tuple) x;
- if (xt.tuple.length != tuple.length)
- return false;
- for ( short i = 0; i < tuple.length; i++ )
- if (!xt.get(i).equals(get(i)))
- return false;
- return true;
+ if (!(x instanceof Tuple))
+ return false;
+ Tuple xt = (Tuple) x;
+ if (xt.tuple.length != tuple.length)
+ return false;
+ for ( short i = 0; i < tuple.length; i++ )
+ if (!xt.get(i).equals(get(i)))
+ return false;
+ return true;
}
public int hashCode () {
- int h = 127;
- for ( short i = 1; i < tuple.length; i++ )
- h ^= get(i).hashCode();
- return Math.abs(h);
+ int h = 127;
+ for ( short i = 1; i < tuple.length; i++ )
+ h ^= get(i).hashCode();
+ return Math.abs(h);
}
public String toString () {
- if (size() == 0)
- return "()";
- String s = "("+get((short)0);
- for ( short i = 1; i < tuple.length; i++ )
- s += ","+get(i);
- return s+")";
+ if (size() == 0)
+ return "()";
+ String s = "("+get((short)0);
+ for ( short i = 1; i < tuple.length; i++ )
+ s += ","+get(i);
+ return s+")";
}
}