Example #1
0
  // where outgoing fields are SWAP
  @Test
  public void testSelectorSwap() {
    //    if( getOutputSelector().isSwap() )
    //      {
    //      if( remainderFields.size() == 0 ) // the same as Fields.RESULTS
    //        return output;
    //      else
    //        return inputEntry.selectTuple( remainderFields ).append( output );
    //      }

    Fields incomingFields = new Fields("1", "2", "3", "4");
    Tuple incoming = new Tuple(1, 2, 3, 4);

    Fields remainderFields = new Fields("1", "4");

    Tuple bottomView = TupleViews.createNarrow(incomingFields.getPos(remainderFields), incoming);

    assertEquals(new Tuple(1, 4), bottomView);
    assertEquals(new Tuple(1, 4), new Tuple(bottomView));

    Fields resultFields = new Fields("5", "6", "7");
    Tuple result = new Tuple(5, 6, 7);

    Tuple view = TupleViews.createComposite(bottomView, result);

    assertEquals(new Tuple(1, 4, 5, 6, 7), view);
    assertEquals(new Tuple(1, 4, 5, 6, 7), new Tuple(view));

    Tuple fieldView = TupleViews.createComposite(remainderFields, resultFields);

    TupleViews.reset(fieldView, view, result);

    assertEquals(new Tuple(1, 4, 5, 6, 7), fieldView);
    assertEquals(new Tuple(1, 4, 5, 6, 7), new Tuple(fieldView));
  }
Example #2
0
  // tests actual swap algebra
  @Test
  public void testSelectorSwap2() {
    Fields incomingFields = new Fields("0", "1", 2, 3);
    Tuple incoming = new Tuple(0, 1, 2, 3);

    Fields resultFields = new Fields("0", "1");
    Tuple result = new Tuple(0, 1);

    Fields remainderFields = incomingFields.subtract(resultFields);

    Tuple remainderView = createNarrow(incomingFields.getPos(remainderFields));
    Tuple outgoingTuple = createComposite(Fields.asDeclaration(remainderFields), resultFields);

    TupleViews.reset(remainderView, incoming);
    TupleViews.reset(outgoingTuple, remainderView, result);

    assertEquals(new Tuple(2, 3, 0, 1), outgoingTuple);
    assertEquals(new Tuple(2, 3, 0, 1), new Tuple(outgoingTuple));
  }
Example #3
0
  @Override
  public boolean source(
      FlowProcess<? extends Properties> flowProcess,
      SourceCall<LineNumberReader, InputStream> sourceCall)
      throws IOException {
    String line = sourceCall.getContext().readLine();

    if (line == null) return false;

    if (skipHeader && sourceCall.getContext().getLineNumber() == 1) // todo: optimize this away
    line = sourceCall.getContext().readLine();

    if (line == null) return false;

    Object[] split = delimitedParser.parseLine(line);

    // assumption it is better to re-use than to construct new
    Tuple tuple = sourceCall.getIncomingEntry().getTuple();

    TupleViews.reset(tuple, split);

    return true;
  }