You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@crunch.apache.org by gr...@apache.org on 2012/07/14 20:14:55 UTC
[10/10] Format all sources according to formatting profile
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/test/Employee.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/test/Employee.java b/crunch/src/test/java/org/apache/crunch/test/Employee.java
index 1a40002..94e7931 100644
--- a/crunch/src/test/java/org/apache/crunch/test/Employee.java
+++ b/crunch/src/test/java/org/apache/crunch/test/Employee.java
@@ -15,31 +15,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.crunch.test;
+package org.apache.crunch.test;
+
@SuppressWarnings("all")
-public class Employee extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
- public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Employee\",\"namespace\":\"org.apache.crunch.test\",\"fields\":[{\"name\":\"name\",\"type\":[\"string\",\"null\"]},{\"name\":\"salary\",\"type\":\"int\"},{\"name\":\"department\",\"type\":[\"string\",\"null\"]}]}");
- @Deprecated public java.lang.CharSequence name;
- @Deprecated public int salary;
- @Deprecated public java.lang.CharSequence department;
- public org.apache.avro.Schema getSchema() { return SCHEMA$; }
- // Used by DatumWriter. Applications should not call.
+public class Employee extends org.apache.avro.specific.SpecificRecordBase implements
+ org.apache.avro.specific.SpecificRecord {
+ public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser()
+ .parse("{\"type\":\"record\",\"name\":\"Employee\",\"namespace\":\"org.apache.crunch.test\",\"fields\":[{\"name\":\"name\",\"type\":[\"string\",\"null\"]},{\"name\":\"salary\",\"type\":\"int\"},{\"name\":\"department\",\"type\":[\"string\",\"null\"]}]}");
+ @Deprecated
+ public java.lang.CharSequence name;
+ @Deprecated
+ public int salary;
+ @Deprecated
+ public java.lang.CharSequence department;
+
+ public org.apache.avro.Schema getSchema() {
+ return SCHEMA$;
+ }
+
+ // Used by DatumWriter. Applications should not call.
public java.lang.Object get(int field$) {
switch (field$) {
- case 0: return name;
- case 1: return salary;
- case 2: return department;
- default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ case 0:
+ return name;
+ case 1:
+ return salary;
+ case 2:
+ return department;
+ default:
+ throw new org.apache.avro.AvroRuntimeException("Bad index");
}
}
- // Used by DatumReader. Applications should not call.
- @SuppressWarnings(value="unchecked")
+
+ // Used by DatumReader. Applications should not call.
+ @SuppressWarnings(value = "unchecked")
public void put(int field$, java.lang.Object value$) {
switch (field$) {
- case 0: name = (java.lang.CharSequence)value$; break;
- case 1: salary = (java.lang.Integer)value$; break;
- case 2: department = (java.lang.CharSequence)value$; break;
- default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ case 0:
+ name = (java.lang.CharSequence) value$;
+ break;
+ case 1:
+ salary = (java.lang.Integer) value$;
+ break;
+ case 2:
+ department = (java.lang.CharSequence) value$;
+ break;
+ default:
+ throw new org.apache.avro.AvroRuntimeException("Bad index");
}
}
@@ -52,7 +74,9 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
/**
* Sets the value of the 'name' field.
- * @param value the value to set.
+ *
+ * @param value
+ * the value to set.
*/
public void setName(java.lang.CharSequence value) {
this.name = value;
@@ -67,7 +91,9 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
/**
* Sets the value of the 'salary' field.
- * @param value the value to set.
+ *
+ * @param value
+ * the value to set.
*/
public void setSalary(java.lang.Integer value) {
this.salary = value;
@@ -82,7 +108,9 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
/**
* Sets the value of the 'department' field.
- * @param value the value to set.
+ *
+ * @param value
+ * the value to set.
*/
public void setDepartment(java.lang.CharSequence value) {
this.department = value;
@@ -92,22 +120,25 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
public static org.apache.crunch.test.Employee.Builder newBuilder() {
return new org.apache.crunch.test.Employee.Builder();
}
-
+
/** Creates a new Employee RecordBuilder by copying an existing Builder */
public static org.apache.crunch.test.Employee.Builder newBuilder(org.apache.crunch.test.Employee.Builder other) {
return new org.apache.crunch.test.Employee.Builder(other);
}
-
- /** Creates a new Employee RecordBuilder by copying an existing Employee instance */
+
+ /**
+ * Creates a new Employee RecordBuilder by copying an existing Employee
+ * instance
+ */
public static org.apache.crunch.test.Employee.Builder newBuilder(org.apache.crunch.test.Employee other) {
return new org.apache.crunch.test.Employee.Builder(other);
}
-
+
/**
* RecordBuilder for Employee instances.
*/
- public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<Employee>
- implements org.apache.avro.data.RecordBuilder<Employee> {
+ public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<Employee> implements
+ org.apache.avro.data.RecordBuilder<Employee> {
private java.lang.CharSequence name;
private int salary;
@@ -117,15 +148,15 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
private Builder() {
super(org.apache.crunch.test.Employee.SCHEMA$);
}
-
+
/** Creates a Builder by copying an existing Builder */
private Builder(org.apache.crunch.test.Employee.Builder other) {
super(other);
}
-
+
/** Creates a Builder by copying an existing Employee instance */
private Builder(org.apache.crunch.test.Employee other) {
- super(org.apache.crunch.test.Employee.SCHEMA$);
+ super(org.apache.crunch.test.Employee.SCHEMA$);
if (isValidValue(fields()[0], other.name)) {
this.name = (java.lang.CharSequence) data().deepCopy(fields()[0].schema(), other.name);
fieldSetFlags()[0] = true;
@@ -144,20 +175,20 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
public java.lang.CharSequence getName() {
return name;
}
-
+
/** Sets the value of the 'name' field */
public org.apache.crunch.test.Employee.Builder setName(java.lang.CharSequence value) {
validate(fields()[0], value);
this.name = value;
fieldSetFlags()[0] = true;
- return this;
+ return this;
}
-
+
/** Checks whether the 'name' field has been set */
public boolean hasName() {
return fieldSetFlags()[0];
}
-
+
/** Clears the value of the 'name' field */
public org.apache.crunch.test.Employee.Builder clearName() {
name = null;
@@ -169,20 +200,20 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
public java.lang.Integer getSalary() {
return salary;
}
-
+
/** Sets the value of the 'salary' field */
public org.apache.crunch.test.Employee.Builder setSalary(int value) {
validate(fields()[1], value);
this.salary = value;
fieldSetFlags()[1] = true;
- return this;
+ return this;
}
-
+
/** Checks whether the 'salary' field has been set */
public boolean hasSalary() {
return fieldSetFlags()[1];
}
-
+
/** Clears the value of the 'salary' field */
public org.apache.crunch.test.Employee.Builder clearSalary() {
fieldSetFlags()[1] = false;
@@ -193,20 +224,20 @@ public class Employee extends org.apache.avro.specific.SpecificRecordBase implem
public java.lang.CharSequence getDepartment() {
return department;
}
-
+
/** Sets the value of the 'department' field */
public org.apache.crunch.test.Employee.Builder setDepartment(java.lang.CharSequence value) {
validate(fields()[2], value);
this.department = value;
fieldSetFlags()[2] = true;
- return this;
+ return this;
}
-
+
/** Checks whether the 'department' field has been set */
public boolean hasDepartment() {
return fieldSetFlags()[2];
}
-
+
/** Clears the value of the 'department' field */
public org.apache.crunch.test.Employee.Builder clearDepartment() {
department = null;
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/test/Person.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/test/Person.java b/crunch/src/test/java/org/apache/crunch/test/Person.java
index aa662e3..fb78ce9 100644
--- a/crunch/src/test/java/org/apache/crunch/test/Person.java
+++ b/crunch/src/test/java/org/apache/crunch/test/Person.java
@@ -15,31 +15,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.crunch.test;
+package org.apache.crunch.test;
+
@SuppressWarnings("all")
-public class Person extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
- public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"org.apache.crunch.test\",\"fields\":[{\"name\":\"name\",\"type\":[\"string\",\"null\"]},{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"siblingnames\",\"type\":{\"type\":\"array\",\"items\":\"string\"}}]}");
- @Deprecated public java.lang.CharSequence name;
- @Deprecated public int age;
- @Deprecated public java.util.List<java.lang.CharSequence> siblingnames;
- public org.apache.avro.Schema getSchema() { return SCHEMA$; }
- // Used by DatumWriter. Applications should not call.
+public class Person extends org.apache.avro.specific.SpecificRecordBase implements
+ org.apache.avro.specific.SpecificRecord {
+ public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser()
+ .parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"org.apache.crunch.test\",\"fields\":[{\"name\":\"name\",\"type\":[\"string\",\"null\"]},{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"siblingnames\",\"type\":{\"type\":\"array\",\"items\":\"string\"}}]}");
+ @Deprecated
+ public java.lang.CharSequence name;
+ @Deprecated
+ public int age;
+ @Deprecated
+ public java.util.List<java.lang.CharSequence> siblingnames;
+
+ public org.apache.avro.Schema getSchema() {
+ return SCHEMA$;
+ }
+
+ // Used by DatumWriter. Applications should not call.
public java.lang.Object get(int field$) {
switch (field$) {
- case 0: return name;
- case 1: return age;
- case 2: return siblingnames;
- default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ case 0:
+ return name;
+ case 1:
+ return age;
+ case 2:
+ return siblingnames;
+ default:
+ throw new org.apache.avro.AvroRuntimeException("Bad index");
}
}
- // Used by DatumReader. Applications should not call.
- @SuppressWarnings(value="unchecked")
+
+ // Used by DatumReader. Applications should not call.
+ @SuppressWarnings(value = "unchecked")
public void put(int field$, java.lang.Object value$) {
switch (field$) {
- case 0: name = (java.lang.CharSequence)value$; break;
- case 1: age = (java.lang.Integer)value$; break;
- case 2: siblingnames = (java.util.List<java.lang.CharSequence>)value$; break;
- default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ case 0:
+ name = (java.lang.CharSequence) value$;
+ break;
+ case 1:
+ age = (java.lang.Integer) value$;
+ break;
+ case 2:
+ siblingnames = (java.util.List<java.lang.CharSequence>) value$;
+ break;
+ default:
+ throw new org.apache.avro.AvroRuntimeException("Bad index");
}
}
@@ -52,7 +74,9 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
/**
* Sets the value of the 'name' field.
- * @param value the value to set.
+ *
+ * @param value
+ * the value to set.
*/
public void setName(java.lang.CharSequence value) {
this.name = value;
@@ -67,7 +91,9 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
/**
* Sets the value of the 'age' field.
- * @param value the value to set.
+ *
+ * @param value
+ * the value to set.
*/
public void setAge(java.lang.Integer value) {
this.age = value;
@@ -82,7 +108,9 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
/**
* Sets the value of the 'siblingnames' field.
- * @param value the value to set.
+ *
+ * @param value
+ * the value to set.
*/
public void setSiblingnames(java.util.List<java.lang.CharSequence> value) {
this.siblingnames = value;
@@ -92,22 +120,22 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
public static org.apache.crunch.test.Person.Builder newBuilder() {
return new org.apache.crunch.test.Person.Builder();
}
-
+
/** Creates a new Person RecordBuilder by copying an existing Builder */
public static org.apache.crunch.test.Person.Builder newBuilder(org.apache.crunch.test.Person.Builder other) {
return new org.apache.crunch.test.Person.Builder(other);
}
-
+
/** Creates a new Person RecordBuilder by copying an existing Person instance */
public static org.apache.crunch.test.Person.Builder newBuilder(org.apache.crunch.test.Person other) {
return new org.apache.crunch.test.Person.Builder(other);
}
-
+
/**
* RecordBuilder for Person instances.
*/
- public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<Person>
- implements org.apache.avro.data.RecordBuilder<Person> {
+ public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<Person> implements
+ org.apache.avro.data.RecordBuilder<Person> {
private java.lang.CharSequence name;
private int age;
@@ -117,15 +145,15 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
private Builder() {
super(org.apache.crunch.test.Person.SCHEMA$);
}
-
+
/** Creates a Builder by copying an existing Builder */
private Builder(org.apache.crunch.test.Person.Builder other) {
super(other);
}
-
+
/** Creates a Builder by copying an existing Person instance */
private Builder(org.apache.crunch.test.Person other) {
- super(org.apache.crunch.test.Person.SCHEMA$);
+ super(org.apache.crunch.test.Person.SCHEMA$);
if (isValidValue(fields()[0], other.name)) {
this.name = (java.lang.CharSequence) data().deepCopy(fields()[0].schema(), other.name);
fieldSetFlags()[0] = true;
@@ -135,7 +163,8 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
fieldSetFlags()[1] = true;
}
if (isValidValue(fields()[2], other.siblingnames)) {
- this.siblingnames = (java.util.List<java.lang.CharSequence>) data().deepCopy(fields()[2].schema(), other.siblingnames);
+ this.siblingnames = (java.util.List<java.lang.CharSequence>) data().deepCopy(fields()[2].schema(),
+ other.siblingnames);
fieldSetFlags()[2] = true;
}
}
@@ -144,20 +173,20 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
public java.lang.CharSequence getName() {
return name;
}
-
+
/** Sets the value of the 'name' field */
public org.apache.crunch.test.Person.Builder setName(java.lang.CharSequence value) {
validate(fields()[0], value);
this.name = value;
fieldSetFlags()[0] = true;
- return this;
+ return this;
}
-
+
/** Checks whether the 'name' field has been set */
public boolean hasName() {
return fieldSetFlags()[0];
}
-
+
/** Clears the value of the 'name' field */
public org.apache.crunch.test.Person.Builder clearName() {
name = null;
@@ -169,20 +198,20 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
public java.lang.Integer getAge() {
return age;
}
-
+
/** Sets the value of the 'age' field */
public org.apache.crunch.test.Person.Builder setAge(int value) {
validate(fields()[1], value);
this.age = value;
fieldSetFlags()[1] = true;
- return this;
+ return this;
}
-
+
/** Checks whether the 'age' field has been set */
public boolean hasAge() {
return fieldSetFlags()[1];
}
-
+
/** Clears the value of the 'age' field */
public org.apache.crunch.test.Person.Builder clearAge() {
fieldSetFlags()[1] = false;
@@ -193,20 +222,20 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
public java.util.List<java.lang.CharSequence> getSiblingnames() {
return siblingnames;
}
-
+
/** Sets the value of the 'siblingnames' field */
public org.apache.crunch.test.Person.Builder setSiblingnames(java.util.List<java.lang.CharSequence> value) {
validate(fields()[2], value);
this.siblingnames = value;
fieldSetFlags()[2] = true;
- return this;
+ return this;
}
-
+
/** Checks whether the 'siblingnames' field has been set */
public boolean hasSiblingnames() {
return fieldSetFlags()[2];
}
-
+
/** Clears the value of the 'siblingnames' field */
public org.apache.crunch.test.Person.Builder clearSiblingnames() {
siblingnames = null;
@@ -220,7 +249,8 @@ public class Person extends org.apache.avro.specific.SpecificRecordBase implemen
Person record = new Person();
record.name = fieldSetFlags()[0] ? this.name : (java.lang.CharSequence) defaultValue(fields()[0]);
record.age = fieldSetFlags()[1] ? this.age : (java.lang.Integer) defaultValue(fields()[1]);
- record.siblingnames = fieldSetFlags()[2] ? this.siblingnames : (java.util.List<java.lang.CharSequence>) defaultValue(fields()[2]);
+ record.siblingnames = fieldSetFlags()[2] ? this.siblingnames
+ : (java.util.List<java.lang.CharSequence>) defaultValue(fields()[2]);
return record;
} catch (Exception e) {
throw new org.apache.avro.AvroRuntimeException(e);
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/PTypeUtilsTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/PTypeUtilsTest.java b/crunch/src/test/java/org/apache/crunch/types/PTypeUtilsTest.java
index 4020691..f9217d5 100644
--- a/crunch/src/test/java/org/apache/crunch/types/PTypeUtilsTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/PTypeUtilsTest.java
@@ -24,10 +24,6 @@ import java.util.Collection;
import org.apache.avro.Schema;
import org.apache.avro.util.Utf8;
-import org.apache.hadoop.io.Text;
-import org.junit.Assert;
-import org.junit.Test;
-
import org.apache.crunch.Tuple3;
import org.apache.crunch.TupleN;
import org.apache.crunch.types.avro.AvroType;
@@ -35,6 +31,9 @@ import org.apache.crunch.types.avro.AvroTypeFamily;
import org.apache.crunch.types.avro.Avros;
import org.apache.crunch.types.writable.WritableTypeFamily;
import org.apache.crunch.types.writable.Writables;
+import org.apache.hadoop.io.Text;
+import org.junit.Assert;
+import org.junit.Test;
public class PTypeUtilsTest {
@Test
@@ -42,11 +41,11 @@ public class PTypeUtilsTest {
assertEquals(Avros.strings(), AvroTypeFamily.getInstance().as(Writables.strings()));
Assert.assertEquals(Writables.doubles(), WritableTypeFamily.getInstance().as(Avros.doubles()));
}
-
+
@Test
public void testTuple3() {
- PType<Tuple3<String, Float, Integer>> t = Writables.triples(Writables.strings(),
- Writables.floats(), Writables.ints());
+ PType<Tuple3<String, Float, Integer>> t = Writables.triples(Writables.strings(), Writables.floats(),
+ Writables.ints());
PType<Tuple3<String, Float, Integer>> at = AvroTypeFamily.getInstance().as(t);
assertEquals(Avros.strings(), at.getSubTypes().get(0));
assertEquals(Avros.floats(), at.getSubTypes().get(1));
@@ -55,8 +54,7 @@ public class PTypeUtilsTest {
@Test
public void testTupleN() {
- PType<TupleN> t = Avros.tuples(Avros.strings(),
- Avros.floats(), Avros.ints());
+ PType<TupleN> t = Avros.tuples(Avros.strings(), Avros.floats(), Avros.ints());
PType<TupleN> wt = WritableTypeFamily.getInstance().as(t);
assertEquals(Writables.strings(), wt.getSubTypes().get(0));
assertEquals(Writables.floats(), wt.getSubTypes().get(1));
@@ -83,7 +81,7 @@ public class PTypeUtilsTest {
Avros.register(Utf8.class, at);
assertEquals(at, Avros.records(Utf8.class));
}
-
+
@Test
public void testWritableBuiltin() {
assertNotNull(Writables.records(Text.class));
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
index d442e9c..d966dfe 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
@@ -21,10 +21,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import org.apache.avro.generic.GenericData.Record;
-import org.junit.Test;
-
import org.apache.crunch.test.Person;
import org.apache.crunch.types.avro.AvroDeepCopier.AvroSpecificDeepCopier;
+import org.junit.Test;
+
import com.google.common.collect.Lists;
public class AvroDeepCopierTest {
@@ -36,8 +36,7 @@ public class AvroDeepCopierTest {
person.setAge(42);
person.setSiblingnames(Lists.<CharSequence> newArrayList());
- Person deepCopyPerson = new AvroSpecificDeepCopier<Person>(Person.class, Person.SCHEMA$)
- .deepCopy(person);
+ Person deepCopyPerson = new AvroSpecificDeepCopier<Person>(Person.class, Person.SCHEMA$).deepCopy(person);
assertEquals(person, deepCopyPerson);
assertNotSame(person, deepCopyPerson);
@@ -50,8 +49,7 @@ public class AvroDeepCopierTest {
record.put("age", 42);
record.put("siblingnames", Lists.newArrayList());
- Record deepCopyRecord = new AvroDeepCopier.AvroGenericDeepCopier(Person.SCHEMA$)
- .deepCopy(record);
+ Record deepCopyRecord = new AvroDeepCopier.AvroGenericDeepCopier(Person.SCHEMA$).deepCopy(record);
assertEquals(record, deepCopyRecord);
assertNotSame(record, deepCopyRecord);
@@ -64,8 +62,8 @@ public class AvroDeepCopierTest {
person.setAge(42);
person.setSiblingnames(Lists.<CharSequence> newArrayList());
- Person deepCopyPerson = new AvroDeepCopier.AvroReflectDeepCopier<Person>(Person.class,
- Person.SCHEMA$).deepCopy(person);
+ Person deepCopyPerson = new AvroDeepCopier.AvroReflectDeepCopier<Person>(Person.class, Person.SCHEMA$)
+ .deepCopy(person);
assertEquals(person, deepCopyPerson);
assertNotSame(person, deepCopyPerson);
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
index 48b1d38..ebd59a5 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
@@ -23,11 +23,11 @@ import static org.junit.Assert.assertSame;
import java.util.List;
-import org.junit.Test;
-
import org.apache.crunch.Pair;
import org.apache.crunch.test.Person;
import org.apache.crunch.types.PGroupedTableType;
+import org.junit.Test;
+
import com.google.common.collect.Lists;
public class AvroGroupedTableTypeTest {
@@ -43,8 +43,8 @@ public class AvroGroupedTableTypeTest {
Iterable<Person> inputPersonIterable = Lists.newArrayList(person);
Pair<Integer, Iterable<Person>> pair = Pair.of(integerValue, inputPersonIterable);
- PGroupedTableType<Integer, Person> groupedTableType = Avros.tableOf(Avros.ints(),
- Avros.reflects(Person.class)).getGroupedTableType();
+ PGroupedTableType<Integer, Person> groupedTableType = Avros.tableOf(Avros.ints(), Avros.reflects(Person.class))
+ .getGroupedTableType();
Pair<Integer, Iterable<Person>> detachedPair = groupedTableType.getDetachedValue(pair);
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
index 9917685..84f6a6d 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
@@ -42,8 +42,7 @@ public class AvroTableTypeTest {
Pair<Integer, Person> pair = Pair.of(integerValue, person);
- AvroTableType<Integer, Person> tableType = Avros.tableOf(Avros.ints(),
- Avros.reflects(Person.class));
+ AvroTableType<Integer, Person> tableType = Avros.tableOf(Avros.ints(), Avros.reflects(Person.class));
Pair<Integer, Person> detachedPair = tableType.getDetachedValue(pair);
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
index c71207b..5946096 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
@@ -106,8 +106,8 @@ public class AvrosTest {
Collection<String> j = Lists.newArrayList();
j.add("a");
j.add("b");
- Schema collectionSchema = Schema.createArray(Schema.createUnion(ImmutableList.of(Avros
- .strings().getSchema(), Schema.create(Type.NULL))));
+ Schema collectionSchema = Schema.createArray(Schema.createUnion(ImmutableList.of(Avros.strings().getSchema(),
+ Schema.create(Type.NULL))));
GenericData.Array<Utf8> w = new GenericData.Array<Utf8>(2, collectionSchema);
w.add(new Utf8("a"));
w.add(new Utf8("b"));
@@ -167,8 +167,7 @@ public class AvrosTest {
@Test
@SuppressWarnings("rawtypes")
public void testTupleN() throws Exception {
- AvroType at = Avros.tuples(Avros.strings(), Avros.strings(), Avros.strings(), Avros.strings(),
- Avros.strings());
+ AvroType at = Avros.tuples(Avros.strings(), Avros.strings(), Avros.strings(), Avros.strings(), Avros.strings());
TupleN j = new TupleN("a", "b", "c", "d", "e");
GenericData.Record w = new GenericData.Record(at.getSchema());
w.put(0, new Utf8("a"));
@@ -199,8 +198,7 @@ public class AvrosTest {
// TODO update this after resolving the o.a.a.m.Pair.equals issue
initialize(at);
assertEquals(j, at.getInputMapFn().map(w));
- org.apache.avro.mapred.Pair converted = (org.apache.avro.mapred.Pair) at.getOutputMapFn()
- .map(j);
+ org.apache.avro.mapred.Pair converted = (org.apache.avro.mapred.Pair) at.getOutputMapFn().map(j);
assertEquals(w.key(), converted.key());
assertEquals(w.value(), converted.value());
}
@@ -234,8 +232,7 @@ public class AvrosTest {
GenericData.Record recordA = new GenericData.Record(schema);
GenericData.Record recordB = new GenericData.Record(schema);
- AvroType<Pair<Record, Record>> pairType = Avros.pairs(Avros.generics(schema),
- Avros.generics(schema));
+ AvroType<Pair<Record, Record>> pairType = Avros.pairs(Avros.generics(schema), Avros.generics(schema));
Pair<Record, Record> pair = Pair.of(recordA, recordB);
pairType.getOutputMapFn().initialize();
pairType.getInputMapFn().initialize();
@@ -251,8 +248,8 @@ public class AvrosTest {
IntWritable intWritableA = new IntWritable(1);
IntWritable intWritableB = new IntWritable(2);
- AvroType<Pair<IntWritable, IntWritable>> pairType = Avros.pairs(
- Avros.reflects(IntWritable.class), Avros.reflects(IntWritable.class));
+ AvroType<Pair<IntWritable, IntWritable>> pairType = Avros.pairs(Avros.reflects(IntWritable.class),
+ Avros.reflects(IntWritable.class));
Pair<IntWritable, IntWritable> pair = Pair.of(intWritableA, intWritableB);
pairType.getOutputMapFn().initialize();
pairType.getInputMapFn().initialize();
@@ -276,8 +273,7 @@ public class AvrosTest {
personB.setName("B");
personB.setSiblingnames(Collections.<CharSequence> emptyList());
- AvroType<Pair<Person, Person>> pairType = Avros.pairs(Avros.records(Person.class),
- Avros.records(Person.class));
+ AvroType<Pair<Person, Person>> pairType = Avros.pairs(Avros.records(Person.class), Avros.records(Person.class));
Pair<Person, Person> pair = Pair.of(personA, personB);
pairType.getOutputMapFn().initialize();
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/writable/WritableGroupedTableTypeTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/writable/WritableGroupedTableTypeTest.java b/crunch/src/test/java/org/apache/crunch/types/writable/WritableGroupedTableTypeTest.java
index 6094152..3596f13 100644
--- a/crunch/src/test/java/org/apache/crunch/types/writable/WritableGroupedTableTypeTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/writable/WritableGroupedTableTypeTest.java
@@ -23,11 +23,11 @@ import static org.junit.Assert.assertSame;
import java.util.List;
+import org.apache.crunch.Pair;
+import org.apache.crunch.types.PGroupedTableType;
import org.apache.hadoop.io.Text;
import org.junit.Test;
-import org.apache.crunch.Pair;
-import org.apache.crunch.types.PGroupedTableType;
import com.google.common.collect.Lists;
public class WritableGroupedTableTypeTest {
@@ -39,16 +39,16 @@ public class WritableGroupedTableTypeTest {
Iterable<Text> inputTextIterable = Lists.newArrayList(textValue);
Pair<Integer, Iterable<Text>> pair = Pair.of(integerValue, inputTextIterable);
- PGroupedTableType<Integer, Text> groupedTableType = Writables.tableOf(Writables.ints(), Writables.writables(Text.class))
- .getGroupedTableType();
-
+ PGroupedTableType<Integer, Text> groupedTableType = Writables.tableOf(Writables.ints(),
+ Writables.writables(Text.class)).getGroupedTableType();
+
Pair<Integer, Iterable<Text>> detachedPair = groupedTableType.getDetachedValue(pair);
-
+
assertSame(integerValue, detachedPair.first());
List<Text> textList = Lists.newArrayList(detachedPair.second());
assertEquals(inputTextIterable, textList);
assertNotSame(textValue, textList.get(0));
-
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/writable/WritableTableTypeTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/writable/WritableTableTypeTest.java b/crunch/src/test/java/org/apache/crunch/types/writable/WritableTableTypeTest.java
index 4c14fc1..f27e7b7 100644
--- a/crunch/src/test/java/org/apache/crunch/types/writable/WritableTableTypeTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/writable/WritableTableTypeTest.java
@@ -21,11 +21,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
+import org.apache.crunch.Pair;
import org.apache.hadoop.io.Text;
import org.junit.Test;
-import org.apache.crunch.Pair;
-
public class WritableTableTypeTest {
@Test
@@ -34,8 +33,7 @@ public class WritableTableTypeTest {
Text textValue = new Text("forty-two");
Pair<Integer, Text> pair = Pair.of(integerValue, textValue);
- WritableTableType<Integer, Text> tableType = Writables.tableOf(Writables.ints(),
- Writables.writables(Text.class));
+ WritableTableType<Integer, Text> tableType = Writables.tableOf(Writables.ints(), Writables.writables(Text.class));
Pair<Integer, Text> detachedPair = tableType.getDetachedValue(pair);
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/writable/WritablesTest.java b/crunch/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
index 593b773..a8699b3 100644
--- a/crunch/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
@@ -28,6 +28,12 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collection;
+import org.apache.crunch.Pair;
+import org.apache.crunch.Tuple3;
+import org.apache.crunch.Tuple4;
+import org.apache.crunch.TupleN;
+import org.apache.crunch.types.PTableType;
+import org.apache.crunch.types.PType;
import org.apache.hadoop.io.BooleanWritable;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.DoubleWritable;
@@ -39,12 +45,6 @@ import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.junit.Test;
-import org.apache.crunch.Pair;
-import org.apache.crunch.Tuple3;
-import org.apache.crunch.Tuple4;
-import org.apache.crunch.TupleN;
-import org.apache.crunch.types.PTableType;
-import org.apache.crunch.types.PType;
import com.google.common.collect.Lists;
public class WritablesTest {
@@ -62,42 +62,42 @@ public class WritablesTest {
Text text = new Text(s);
testInputOutputFn(Writables.strings(), s, text);
}
-
+
@Test
public void testInts() throws Exception {
int j = 55;
IntWritable w = new IntWritable(j);
testInputOutputFn(Writables.ints(), j, w);
}
-
+
@Test
public void testLongs() throws Exception {
long j = 55;
LongWritable w = new LongWritable(j);
testInputOutputFn(Writables.longs(), j, w);
}
-
+
@Test
public void testFloats() throws Exception {
float j = 55.5f;
FloatWritable w = new FloatWritable(j);
testInputOutputFn(Writables.floats(), j, w);
}
-
+
@Test
public void testDoubles() throws Exception {
double j = 55.5d;
DoubleWritable w = new DoubleWritable(j);
testInputOutputFn(Writables.doubles(), j, w);
}
-
+
@Test
public void testBoolean() throws Exception {
boolean j = false;
BooleanWritable w = new BooleanWritable(j);
testInputOutputFn(Writables.booleans(), j, w);
}
-
+
@Test
public void testBytes() throws Exception {
byte[] bytes = new byte[] { 17, 26, -98 };
@@ -105,115 +105,98 @@ public class WritablesTest {
ByteBuffer bb = ByteBuffer.wrap(bytes);
testInputOutputFn(Writables.bytes(), bb, bw);
}
-
+
@Test
public void testCollections() throws Exception {
String s = "abc";
Collection<String> j = Lists.newArrayList();
j.add(s);
GenericArrayWritable<Text> w = new GenericArrayWritable<Text>(Text.class);
- w.set(new Text[]{
- new Text(s)
- });
+ w.set(new Text[] { new Text(s) });
testInputOutputFn(Writables.collections(Writables.strings()), j, w);
}
-
+
@Test
public void testPairs() throws Exception {
Pair<String, String> j = Pair.of("a", "b");
- TupleWritable w = new TupleWritable(new Text[] {
- new Text("a"),
- new Text("b"),
- });
+ TupleWritable w = new TupleWritable(new Text[] { new Text("a"), new Text("b"), });
w.setWritten(0);
w.setWritten(1);
testInputOutputFn(Writables.pairs(Writables.strings(), Writables.strings()), j, w);
}
-
+
@Test
public void testNestedTables() throws Exception {
- PTableType<Long, Long> pll = Writables.tableOf(Writables.longs(), Writables.longs());
- PTableType<Pair<Long, Long>, String> nest = Writables.tableOf(pll, Writables.strings());
- assertNotNull(nest);
+ PTableType<Long, Long> pll = Writables.tableOf(Writables.longs(), Writables.longs());
+ PTableType<Pair<Long, Long>, String> nest = Writables.tableOf(pll, Writables.strings());
+ assertNotNull(nest);
}
-
+
@Test
public void testPairEquals() throws Exception {
- PType<Pair<Long, ByteBuffer>> t1 = Writables.pairs(Writables.longs(), Writables.bytes());
- PType<Pair<Long, ByteBuffer>> t2 = Writables.pairs(Writables.longs(), Writables.bytes());
- assertEquals(t1, t2);
- assertEquals(t1.hashCode(), t2.hashCode());
+ PType<Pair<Long, ByteBuffer>> t1 = Writables.pairs(Writables.longs(), Writables.bytes());
+ PType<Pair<Long, ByteBuffer>> t2 = Writables.pairs(Writables.longs(), Writables.bytes());
+ assertEquals(t1, t2);
+ assertEquals(t1.hashCode(), t2.hashCode());
}
-
+
@Test
@SuppressWarnings("rawtypes")
public void testTriples() throws Exception {
Tuple3 j = Tuple3.of("a", "b", "c");
- TupleWritable w = new TupleWritable(new Text[] {
- new Text("a"),
- new Text("b"),
- new Text("c"),
- });
+ TupleWritable w = new TupleWritable(new Text[] { new Text("a"), new Text("b"), new Text("c"), });
w.setWritten(0);
w.setWritten(1);
w.setWritten(2);
- WritableType<?, ?> wt = Writables.triples(Writables.strings(),
- Writables.strings(), Writables.strings());
+ WritableType<?, ?> wt = Writables.triples(Writables.strings(), Writables.strings(), Writables.strings());
testInputOutputFn(wt, j, w);
}
-
+
@Test
@SuppressWarnings("rawtypes")
public void testQuads() throws Exception {
Tuple4 j = Tuple4.of("a", "b", "c", "d");
- TupleWritable w = new TupleWritable(new Text[] {
- new Text("a"),
- new Text("b"),
- new Text("c"),
- new Text("d"),
- });
+ TupleWritable w = new TupleWritable(new Text[] { new Text("a"), new Text("b"), new Text("c"), new Text("d"), });
w.setWritten(0);
w.setWritten(1);
w.setWritten(2);
w.setWritten(3);
- WritableType<?, ?> wt = Writables.quads(Writables.strings(), Writables.strings(),
- Writables.strings(), Writables.strings());
+ WritableType<?, ?> wt = Writables.quads(Writables.strings(), Writables.strings(), Writables.strings(),
+ Writables.strings());
testInputOutputFn(wt, j, w);
}
-
+
@Test
public void testTupleN() throws Exception {
TupleN j = new TupleN("a", "b", "c", "d", "e");
- TupleWritable w = new TupleWritable(new Text[] {
- new Text("a"),
- new Text("b"),
- new Text("c"),
- new Text("d"),
- new Text("e"),
- });
+ TupleWritable w = new TupleWritable(new Text[] { new Text("a"), new Text("b"), new Text("c"), new Text("d"),
+ new Text("e"), });
w.setWritten(0);
w.setWritten(1);
w.setWritten(2);
w.setWritten(3);
w.setWritten(4);
- WritableType<?, ?> wt = Writables.tuples(Writables.strings(), Writables.strings(),
- Writables.strings(), Writables.strings(), Writables.strings());
+ WritableType<?, ?> wt = Writables.tuples(Writables.strings(), Writables.strings(), Writables.strings(),
+ Writables.strings(), Writables.strings());
testInputOutputFn(wt, j, w);
}
-
+
protected static class TestWritable implements Writable {
String left;
int right;
+
@Override
public void write(DataOutput out) throws IOException {
out.writeUTF(left);
out.writeInt(right);
}
+
@Override
public void readFields(DataInput in) throws IOException {
left = in.readUTF();
right = in.readInt();
}
+
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -232,8 +215,9 @@ public class WritablesTest {
return false;
return true;
}
-
+
}
+
@Test
public void testRecords() throws Exception {
TestWritable j = new TestWritable();
@@ -245,7 +229,7 @@ public class WritablesTest {
WritableType<?, ?> wt = Writables.records(TestWritable.class);
testInputOutputFn(wt, j, w);
}
-
+
@Test
public void testTableOf() throws Exception {
Pair<String, String> j = Pair.of("a", "b");
@@ -260,8 +244,8 @@ public class WritablesTest {
Writables.register(TestWritable.class, wt);
assertSame(Writables.records(TestWritable.class), wt);
}
-
- @SuppressWarnings({"unchecked", "rawtypes"})
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
protected static void testInputOutputFn(PType ptype, Object java, Object writable) {
ptype.getInputMapFn().initialize();
ptype.getOutputMapFn().initialize();
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/crunch/src/test/java/org/apache/crunch/util/DistCacheTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/util/DistCacheTest.java b/crunch/src/test/java/org/apache/crunch/util/DistCacheTest.java
index eda45c4..6784f14 100644
--- a/crunch/src/test/java/org/apache/crunch/util/DistCacheTest.java
+++ b/crunch/src/test/java/org/apache/crunch/util/DistCacheTest.java
@@ -43,10 +43,14 @@ public class DistCacheTest {
private String[] testFileQualifiedPaths;
/**
- * Setup resources for tests. These include:
- * 1. A Hadoop configuration.
- * 2. A directory of temporary files that includes 3 .jar files and 1 other file.
- * 3. Arrays containing the canonical paths and qualified paths to the test files.
+ * Setup resources for tests. These include:
+ * <ol>
+ * <li>A Hadoop configuration.
+ * <li>A directory of temporary files that includes 3 .jar files and 1 other
+ * file.
+ * <li>Arrays containing the canonical paths and qualified paths to the test
+ * files.
+ * </ol>
*/
@Before
public void setup() throws IOException {
@@ -69,12 +73,14 @@ public class DistCacheTest {
/**
* Tests adding jars one-by-one to a job's configuration.
- *
- * @throws IOException If there is a problem adding the jars.
+ *
+ * @throws IOException
+ * If there is a problem adding the jars.
*/
@Test
public void testAddJar() throws IOException {
- // Add each valid jar path to the distributed cache configuration, and verify each was
+ // Add each valid jar path to the distributed cache configuration, and
+ // verify each was
// added correctly in turn.
for (int i = 0; i < testFilePaths.length; i++) {
DistCache.addJarToDistributedCache(testConf, testFilePaths[i]);
@@ -84,10 +90,11 @@ public class DistCacheTest {
}
/**
- * Tests that attempting to add the path to a jar that does not exist to the configuration
- * throws an exception.
- *
- * @throws IOException If the added jar path does not exist. This exception is expected.
+ * Tests that attempting to add the path to a jar that does not exist to the
+ * configuration throws an exception.
+ *
+ * @throws IOException
+ * If the added jar path does not exist. This exception is expected.
*/
@Test(expected = IOException.class)
public void testAddJarThatDoesntExist() throws IOException {
@@ -95,11 +102,13 @@ public class DistCacheTest {
}
/**
- * Tests that adding a directory of jars to the configuration works as expected. .jar files
- * under the added directory should be added to the configuration,
- * and all other files should be skipped.
- *
- * @throws IOException If there is a problem adding the jar directory to the configuration.
+ * Tests that adding a directory of jars to the configuration works as
+ * expected. .jar files under the added directory should be added to the
+ * configuration, and all other files should be skipped.
+ *
+ * @throws IOException
+ * If there is a problem adding the jar directory to the
+ * configuration.
*/
@Test
public void testAddJarDirectory() throws IOException {
@@ -107,24 +116,25 @@ public class DistCacheTest {
// Throw the added jar paths in a set to detect duplicates.
String[] splitJarPaths = StringUtils.split(testConf.get("tmpjars"), ",");
Set<String> addedJarPaths = new HashSet<String>();
- for (String path: splitJarPaths) {
+ for (String path : splitJarPaths) {
addedJarPaths.add(path);
}
- assertEquals("Incorrect number of jar paths added.", testFilePaths.length,
- addedJarPaths.size());
+ assertEquals("Incorrect number of jar paths added.", testFilePaths.length, addedJarPaths.size());
// Ensure all expected paths were added.
for (int i = 0; i < testFileQualifiedPaths.length; i++) {
- assertTrue("Expected jar path missing from jar paths added to tmpjars: " +
- testFileQualifiedPaths[i], addedJarPaths.contains(testFileQualifiedPaths[i]));
+ assertTrue("Expected jar path missing from jar paths added to tmpjars: " + testFileQualifiedPaths[i],
+ addedJarPaths.contains(testFileQualifiedPaths[i]));
}
}
/**
- * Tests that adding a jar directory that does not exist to the configuration throws an
- * exception.
- *
- * @throws IOException If the added jar directory does not exist. This exception is expected.
+ * Tests that adding a jar directory that does not exist to the configuration
+ * throws an exception.
+ *
+ * @throws IOException
+ * If the added jar directory does not exist. This exception is
+ * expected.
*/
@Test(expected = IOException.class)
public void testAddJarDirectoryThatDoesntExist() throws IOException {
@@ -132,10 +142,12 @@ public class DistCacheTest {
}
/**
- * Tests that adding a jar directory that is not a directory to the configuration throws an
- * exception.
- *
- * @throws IOException If the added jar directory is not a directory. This exception is expected.
+ * Tests that adding a jar directory that is not a directory to the
+ * configuration throws an exception.
+ *
+ * @throws IOException
+ * If the added jar directory is not a directory. This exception is
+ * expected.
*/
@Test(expected = IOException.class)
public void testAddJarDirectoryNotDirectory() throws IOException {
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/examples/src/main/java/org/apache/crunch/examples/AverageBytesByIP.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/crunch/examples/AverageBytesByIP.java b/examples/src/main/java/org/apache/crunch/examples/AverageBytesByIP.java
index 930721f..868e38a 100644
--- a/examples/src/main/java/org/apache/crunch/examples/AverageBytesByIP.java
+++ b/examples/src/main/java/org/apache/crunch/examples/AverageBytesByIP.java
@@ -21,12 +21,6 @@ import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.conf.Configured;
-import org.apache.hadoop.util.GenericOptionsParser;
-import org.apache.hadoop.util.Tool;
-import org.apache.hadoop.util.ToolRunner;
-
import org.apache.crunch.CombineFn;
import org.apache.crunch.DoFn;
import org.apache.crunch.Emitter;
@@ -37,16 +31,23 @@ import org.apache.crunch.Pair;
import org.apache.crunch.Pipeline;
import org.apache.crunch.impl.mr.MRPipeline;
import org.apache.crunch.types.writable.Writables;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.util.GenericOptionsParser;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
@SuppressWarnings("serial")
public class AverageBytesByIP extends Configured implements Tool, Serializable {
- static enum COUNTERS {
+ static enum COUNTERS {
NO_MATCH,
CORRUPT_SIZE
}
+
static final String logRegex = "^([\\d.]+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] \"(.+?)\" (\\d{3}) (\\d+) \"([^\"]+)\" \"([^\"]+)\"";
+
public int run(String[] args) throws Exception {
- if(args.length != 2) {
+ if (args.length != 2) {
System.err.println();
System.err.println("Two and only two arguments are accepted.");
System.err.println("Usage: " + this.getClass().getName() + " [generic options] input output");
@@ -60,59 +61,59 @@ public class AverageBytesByIP extends Configured implements Tool, Serializable {
PCollection<String> lines = pipeline.readTextFile(args[0]);
// Combiner used for summing up response size and count
- CombineFn<String, Pair<Long, Long>> stringPairOfLongsSumCombiner =
- CombineFn.pairAggregator(CombineFn.SUM_LONGS, CombineFn.SUM_LONGS);
-
+ CombineFn<String, Pair<Long, Long>> stringPairOfLongsSumCombiner = CombineFn.pairAggregator(CombineFn.SUM_LONGS,
+ CombineFn.SUM_LONGS);
+
// Table of (ip, sum(response size), count)
- PTable<String, Pair<Long, Long>> remoteAddrResponseSize = lines.parallelDo(extractResponseSize,
- Writables.tableOf(Writables.strings(),
- Writables.pairs(Writables.longs(), Writables.longs())))
- .groupByKey()
- .combineValues(stringPairOfLongsSumCombiner);
-
+ PTable<String, Pair<Long, Long>> remoteAddrResponseSize = lines
+ .parallelDo(extractResponseSize,
+ Writables.tableOf(Writables.strings(), Writables.pairs(Writables.longs(), Writables.longs()))).groupByKey()
+ .combineValues(stringPairOfLongsSumCombiner);
+
// Calculate average response size by ip address
- PTable<String, Double> avgs = remoteAddrResponseSize.parallelDo(calulateAverage,
+ PTable<String, Double> avgs = remoteAddrResponseSize.parallelDo(calulateAverage,
Writables.tableOf(Writables.strings(), Writables.doubles()));
-
+
// write the result to a text file
pipeline.writeTextFile(avgs, args[1]);
// Execute the pipeline as a MapReduce.
pipeline.done();
return 0;
}
-
+
// Function to calculate the average response size for a given ip address
//
// Input: (ip, sum(response size), count)
// Output: (ip, average response size)
- MapFn<Pair<String, Pair<Long, Long>>, Pair<String, Double>> calulateAverage =
- new MapFn<Pair<String, Pair<Long, Long>>, Pair<String, Double>>() {
+ MapFn<Pair<String, Pair<Long, Long>>, Pair<String, Double>> calulateAverage = new MapFn<Pair<String, Pair<Long, Long>>, Pair<String, Double>>() {
@Override
public Pair<String, Double> map(Pair<String, Pair<Long, Long>> arg) {
Pair<Long, Long> sumCount = arg.second();
double avg = 0;
- if(sumCount.second() > 0) {
- avg = (double)sumCount.first() / (double)sumCount.second();
+ if (sumCount.second() > 0) {
+ avg = (double) sumCount.first() / (double) sumCount.second();
}
return Pair.of(arg.first(), avg);
}
};
// Function to parse apache log records
- // Given a standard apache log line, extract the ip address and
+ // Given a standard apache log line, extract the ip address and
// response size. Outputs ip and the response size and a count (1) so that
// a combiner can be used.
- //
- // Input: 55.1.3.2 ...... 200 512 ....
- // Output: (55.1.3.2, (512, 1))
+ //
+ // Input: 55.1.3.2 ...... 200 512 ....
+ // Output: (55.1.3.2, (512, 1))
DoFn<String, Pair<String, Pair<Long, Long>>> extractResponseSize = new DoFn<String, Pair<String, Pair<Long, Long>>>() {
transient Pattern pattern;
+
public void initialize() {
pattern = Pattern.compile(logRegex);
}
+
public void process(String line, Emitter<Pair<String, Pair<Long, Long>>> emitter) {
Matcher matcher = pattern.matcher(line);
- if(matcher.matches()) {
+ if (matcher.matches()) {
try {
Long responseSize = Long.parseLong(matcher.group(7));
Pair<Long, Long> sumCount = Pair.of(responseSize, 1L);
@@ -122,12 +123,11 @@ public class AverageBytesByIP extends Configured implements Tool, Serializable {
this.getCounter(COUNTERS.CORRUPT_SIZE).increment(1);
}
} else {
- this.getCounter(COUNTERS.NO_MATCH).increment(1);
+ this.getCounter(COUNTERS.NO_MATCH).increment(1);
}
}
};
-
public static void main(String[] args) throws Exception {
ToolRunner.run(new Configuration(), new AverageBytesByIP(), args);
}
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/examples/src/main/java/org/apache/crunch/examples/TotalBytesByIP.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/crunch/examples/TotalBytesByIP.java b/examples/src/main/java/org/apache/crunch/examples/TotalBytesByIP.java
index 1b168fa..1953e3a 100644
--- a/examples/src/main/java/org/apache/crunch/examples/TotalBytesByIP.java
+++ b/examples/src/main/java/org/apache/crunch/examples/TotalBytesByIP.java
@@ -21,12 +21,6 @@ import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.conf.Configured;
-import org.apache.hadoop.util.GenericOptionsParser;
-import org.apache.hadoop.util.Tool;
-import org.apache.hadoop.util.ToolRunner;
-
import org.apache.crunch.CombineFn;
import org.apache.crunch.DoFn;
import org.apache.crunch.Emitter;
@@ -36,16 +30,23 @@ import org.apache.crunch.Pair;
import org.apache.crunch.Pipeline;
import org.apache.crunch.impl.mr.MRPipeline;
import org.apache.crunch.types.writable.Writables;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.util.GenericOptionsParser;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
@SuppressWarnings("serial")
public class TotalBytesByIP extends Configured implements Tool, Serializable {
- static enum COUNTERS {
+ static enum COUNTERS {
NO_MATCH,
CORRUPT_SIZE
}
+
static final String logRegex = "^([\\d.]+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] \"(.+?)\" (\\d{3}) (\\d+) \"([^\"]+)\" \"([^\"]+)\"";
+
public int run(String[] args) throws Exception {
- if(args.length != 2) {
+ if (args.length != 2) {
System.err.println();
System.err.println("Two and only two arguments are accepted.");
System.err.println("Usage: " + this.getClass().getName() + " [generic options] input output");
@@ -60,34 +61,34 @@ public class TotalBytesByIP extends Configured implements Tool, Serializable {
// Combiner used for summing up response size
CombineFn<String, Long> longSumCombiner = CombineFn.SUM_LONGS();
-
+
// Table of (ip, sum(response size))
- PTable<String, Long> ipAddrResponseSize =
- lines.parallelDo(extractIPResponseSize,
- Writables.tableOf(Writables.strings(),Writables.longs()))
- .groupByKey()
- .combineValues(longSumCombiner);
-
+ PTable<String, Long> ipAddrResponseSize = lines
+ .parallelDo(extractIPResponseSize, Writables.tableOf(Writables.strings(), Writables.longs())).groupByKey()
+ .combineValues(longSumCombiner);
+
pipeline.writeTextFile(ipAddrResponseSize, args[1]);
// Execute the pipeline as a MapReduce.
pipeline.done();
return 0;
}
-
+
// Function to parse apache log records
- // Given a standard apache log line, extract the ip address and
+ // Given a standard apache log line, extract the ip address and
// request size. Outputs the ip and response size.
- //
- // Input: 55.1.3.2 ...... 200 512 ....
- // Output: (55.1.3.2, 512)
+ //
+ // Input: 55.1.3.2 ...... 200 512 ....
+ // Output: (55.1.3.2, 512)
DoFn<String, Pair<String, Long>> extractIPResponseSize = new DoFn<String, Pair<String, Long>>() {
transient Pattern pattern;
+
public void initialize() {
pattern = Pattern.compile(logRegex);
}
+
public void process(String line, Emitter<Pair<String, Long>> emitter) {
Matcher matcher = pattern.matcher(line);
- if(matcher.matches()) {
+ if (matcher.matches()) {
try {
Long requestSize = Long.parseLong(matcher.group(7));
String remoteAddr = matcher.group(1);
@@ -99,7 +100,6 @@ public class TotalBytesByIP extends Configured implements Tool, Serializable {
}
};
-
public static void main(String[] args) throws Exception {
ToolRunner.run(new Configuration(), new TotalBytesByIP(), args);
}
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/examples/src/main/java/org/apache/crunch/examples/WordCount.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/crunch/examples/WordCount.java b/examples/src/main/java/org/apache/crunch/examples/WordCount.java
index 53db14e..e4ce25b 100644
--- a/examples/src/main/java/org/apache/crunch/examples/WordCount.java
+++ b/examples/src/main/java/org/apache/crunch/examples/WordCount.java
@@ -17,13 +17,14 @@
*/
package org.apache.crunch.examples;
+import java.io.Serializable;
+
import org.apache.crunch.DoFn;
import org.apache.crunch.Emitter;
import org.apache.crunch.PCollection;
import org.apache.crunch.PTable;
import org.apache.crunch.Pipeline;
import org.apache.crunch.impl.mr.MRPipeline;
-import org.apache.crunch.lib.Aggregate;
import org.apache.crunch.types.writable.Writables;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
@@ -31,11 +32,9 @@ import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
-import java.io.Serializable;
-
public class WordCount extends Configured implements Tool, Serializable {
public int run(String[] args) throws Exception {
- if(args.length != 3) {
+ if (args.length != 3) {
System.err.println();
System.err.println("Usage: " + this.getClass().getName() + " [generic options] input output");
System.err.println();
@@ -47,7 +46,8 @@ public class WordCount extends Configured implements Tool, Serializable {
// Reference a given text file as a collection of Strings.
PCollection<String> lines = pipeline.readTextFile(args[1]);
- // Define a function that splits each line in a PCollection of Strings into a
+ // Define a function that splits each line in a PCollection of Strings into
+ // a
// PCollection made up of the individual words in the file.
PCollection<String> words = lines.parallelDo(new DoFn<String, String>() {
public void process(String line, Emitter<String> emitter) {
http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/07683711/res/crunch-formatting-styles.xml
----------------------------------------------------------------------
diff --git a/res/crunch-formatting-styles.xml b/res/crunch-formatting-styles.xml
index 928120a..0f84a98 100644
--- a/res/crunch-formatting-styles.xml
+++ b/res/crunch-formatting-styles.xml
@@ -74,7 +74,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/>
+<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
@@ -244,7 +244,7 @@
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="49"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>