use of org.apache.crunch.Tuple4 in project crunch by cloudera.
the class AvrosTest method testQuads.
@Test
@SuppressWarnings("rawtypes")
public void testQuads() throws Exception {
AvroType at = Avros.quads(Avros.strings(), Avros.strings(), Avros.strings(), Avros.strings());
Tuple4 j = Tuple4.of("a", "b", "c", "d");
GenericData.Record w = new GenericData.Record(at.getSchema());
w.put(0, new Utf8("a"));
w.put(1, new Utf8("b"));
w.put(2, new Utf8("c"));
w.put(3, new Utf8("d"));
testInputOutputFn(at, j, w);
}
use of org.apache.crunch.Tuple4 in project crunch by cloudera.
the class WritablesTest method testQuads.
@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") });
w.setWritten(0);
w.setWritten(1);
w.setWritten(2);
w.setWritten(3);
WritableType<?, ?> wt = Writables.quads(Writables.strings(), Writables.strings(), Writables.strings(), Writables.strings());
testInputOutputFn(wt, j, w);
}
use of org.apache.crunch.Tuple4 in project crunch by cloudera.
the class Sort method sortQuads.
/**
* Sorts the {@link PCollection} of {@link Tuple4}s using the specified column
* ordering.
*
* @return a {@link PCollection} representing the sorted collection.
*/
public static <V1, V2, V3, V4> PCollection<Tuple4<V1, V2, V3, V4>> sortQuads(PCollection<Tuple4<V1, V2, V3, V4>> collection, ColumnOrder... columnOrders) {
PTypeFamily tf = collection.getTypeFamily();
PType<Tuple4<V1, V2, V3, V4>> pType = collection.getPType();
@SuppressWarnings("unchecked") PTableType<Tuple4<V1, V2, V3, V4>, Void> type = tf.tableOf(tf.quads(pType.getSubTypes().get(0), pType.getSubTypes().get(1), pType.getSubTypes().get(2), pType.getSubTypes().get(3)), tf.nulls());
PTable<Tuple4<V1, V2, V3, V4>, Void> pt = collection.parallelDo(new DoFn<Tuple4<V1, V2, V3, V4>, Pair<Tuple4<V1, V2, V3, V4>, Void>>() {
@Override
public void process(Tuple4<V1, V2, V3, V4> input, Emitter<Pair<Tuple4<V1, V2, V3, V4>, Void>> emitter) {
emitter.emit(Pair.of(input, (Void) null));
}
}, type);
Configuration conf = collection.getPipeline().getConfiguration();
GroupingOptions options = buildGroupingOptions(conf, tf, pType, columnOrders);
PTable<Tuple4<V1, V2, V3, V4>, Void> sortedPt = pt.groupByKey(options).ungroup();
return sortedPt.parallelDo(new DoFn<Pair<Tuple4<V1, V2, V3, V4>, Void>, Tuple4<V1, V2, V3, V4>>() {
@Override
public void process(Pair<Tuple4<V1, V2, V3, V4>, Void> input, Emitter<Tuple4<V1, V2, V3, V4>> emitter) {
emitter.emit(input.first());
}
}, collection.getPType());
}
Aggregations