Ejemplo n.º 1
0
  public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (FormulaMeta) smi;
    data = (FormulaData) sdi;

    Object[] r = getRow(); // get row, set busy!
    if (r == null) { // no more input to be expected...

      setOutputDone();
      return false;
    }

    if (first) {
      first = false;

      data.outputRowMeta = getInputRowMeta().clone();
      meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);

      // Create the context
      data.context = new RowForumulaContext(data.outputRowMeta);
      data.parser = new FormulaParser();

      // Calculate replace indexes...
      //
      data.replaceIndex = new int[meta.getFormula().length];
      for (int i = 0; i < meta.getFormula().length; i++) {
        FormulaMetaFunction fn = meta.getFormula()[i];
        if (!Const.isEmpty(fn.getReplaceField())) {
          data.replaceIndex[i] = getInputRowMeta().indexOfValue(fn.getReplaceField());
          if (data.replaceIndex[i] < 0) {
            throw new KettleException(
                "Unknown field specified to replace with a formula result: ["
                    + fn.getReplaceField()
                    + "]");
          }
        } else {
          data.replaceIndex[i] = -1;
        }
      }
    }

    if (log.isRowLevel()) {
      logRowlevel("Read row #" + getLinesRead() + " : " + r);
    }

    Object[] outputRowData = calcFields(getInputRowMeta(), r);
    putRow(data.outputRowMeta, outputRowData); // copy row to possible alternate rowset(s).

    if (log.isRowLevel()) {
      logRowlevel("Wrote row #" + getLinesWritten() + " : " + r);
    }
    if (checkFeedback(getLinesRead())) {
      logBasic("Linenr " + getLinesRead());
    }

    return true;
  }