@Test
  public void runMultiValue() {
    Tap source =
        new MemorySourceTap(
            Arrays.asList(
                new Tuple(1, 1),
                new Tuple(1, 2),
                new Tuple(1, 1),
                new Tuple((Integer) null, (Integer) 2)),
            new Fields("key", "value"));

    Pipe pipe = new Pipe("pipe");
    pipe =
        new IncrementForFieldValues(
            pipe,
            "Group",
            "CounterA",
            new Fields("key", "value"),
            Lists.<Integer>newArrayList(1, 1));
    pipe =
        new IncrementForFieldValues(
            pipe,
            Counter.B,
            new Fields("key", "value"),
            Lists.<Object>newArrayList((Object) null, 2));

    Flow f = CascadingUtil.get().getFlowConnector().connect(source, new NullTap(), pipe);
    f.complete();

    Assert.assertEquals(2l, Counters.get(f, "Group", "CounterA").longValue());
    Assert.assertEquals(1l, Counters.get(f, Counter.B).longValue());
  }
Esempio n. 2
0
  @Test
  public void checkLimits() throws IOException {
    Tap<JobConf, ?, ?> output =
        new Hfs(new SequenceFile(new Fields("a", "b", "d")), getTestRoot() + "/output");

    Pipe lhs = new Pipe("lhs");

    Pipe rhs = new Pipe("rhs");

    Pipe joined =
        new CoGroup(lhs, new Fields("a"), rhs, new Fields("c"), new LimitJoin(new long[] {2, 1}));

    Map<String, Tap> sources = new HashMap<String, Tap>();
    sources.put("lhs", inputLhs);
    sources.put("rhs", inputRhs);

    CascadingUtil.get().getFlowConnector().connect(sources, output, joined).complete();

    // These would be the results of an ordinary inner join
    Set<Tuple> allowedResults =
        new HashSet<Tuple>(
            Arrays.asList(
                new Tuple("1", "A", "E"),
                new Tuple("1", "B", "E"),
                new Tuple("1", "C", "E"),
                new Tuple("2", "D", "F"),
                new Tuple("2", "D", "G"),
                new Tuple("2", "H", "F"),
                new Tuple("2", "H", "G"),
                new Tuple("2", "I", "F"),
                new Tuple("2", "I", "G")));

    /*

    Example good output:
      1 A E
      1 B E
      2 D F
      2 H F

     */

    // Read the results and make sure we saw two results from allowedResults with 1 as the key, and
    // two with 2 as the key
    Set<Tuple> results = new HashSet<Tuple>(TapHelper.getAllTuples(output));
    Assert.assertEquals(4, results.size());
    int key1 = 0;
    int key2 = 0;
    for (Tuple result : results) {
      Assert.assertTrue(allowedResults.contains(result));
      String key = result.getString(0);
      if (key.equals("1")) {
        key1++;
      } else if (key.equals("2")) {
        key2++;
      } else {
        throw new IllegalStateException("Key should be 1 or 2");
      }
    }
    Assert.assertEquals(2, key1);
    Assert.assertEquals(2, key2);
  }