Exemplo n.º 1
0
  /**
   * @param flowProcess
   * @param sourceCall
   * @return
   * @throws IOException
   */
  @Override
  public boolean source(
      FlowProcess<JobConf> flowProcess, SourceCall<BSONWritable[], RecordReader> sourceCall)
      throws IOException {
    Tuple result = new Tuple();

    BSONWritable key = sourceCall.getContext()[0];
    BSONWritable value = sourceCall.getContext()[1];

    if (!sourceCall.getInput().next(key, value)) {
      logger.info("Nothing left to read, exiting");
      return false;
    }

    for (String columnFieldName : columnFieldNames) {
      Object tupleEntry = value.get(columnFieldName);
      if (tupleEntry != null) {
        result.add(tupleEntry);
      } else if (columnFieldName != this.keyColumnName) {
        result.add("");
      }
    }

    sourceCall.getIncomingEntry().setTuple(result);
    return true;
  }
Exemplo n.º 2
0
  /**
   * @param flowProcess
   * @param sourceCall
   */
  @Override
  public void sourcePrepare(
      FlowProcess<JobConf> flowProcess, SourceCall<BSONWritable[], RecordReader> sourceCall) {
    sourceCall.setContext(new BSONWritable[2]);

    sourceCall.getContext()[0] = (BSONWritable) sourceCall.getInput().createKey();
    sourceCall.getContext()[1] = (BSONWritable) sourceCall.getInput().createValue();
  }
Exemplo n.º 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;
  }