Search in sources :

Example 1 with Tuple4

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);
}
Also used : Tuple4(org.apache.crunch.Tuple4) Utf8(org.apache.avro.util.Utf8) GenericData(org.apache.avro.generic.GenericData) Test(org.junit.Test)

Example 2 with Tuple4

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);
}
Also used : Tuple4(org.apache.crunch.Tuple4) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 3 with Tuple4

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());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Tuple4(org.apache.crunch.Tuple4) PTypeFamily(org.apache.crunch.types.PTypeFamily) GroupingOptions(org.apache.crunch.GroupingOptions) Pair(org.apache.crunch.Pair)

Aggregations

Tuple4 (org.apache.crunch.Tuple4)3 Test (org.junit.Test)2 GenericData (org.apache.avro.generic.GenericData)1 Utf8 (org.apache.avro.util.Utf8)1 GroupingOptions (org.apache.crunch.GroupingOptions)1 Pair (org.apache.crunch.Pair)1 PTypeFamily (org.apache.crunch.types.PTypeFamily)1 Configuration (org.apache.hadoop.conf.Configuration)1 Text (org.apache.hadoop.io.Text)1