如何在 Pentaho 中完全删除用户定义 Java Class 中的特定输入字段

How to completely remove specific input fields in User Defined Java Class in Pentaho

我不明白在 Pentaho 数据中使用 用户定义 Java Class 时如何完全删除特定输入字段积分.

假设我有输入字段 ABC。假设我想连接 BC 中的值(由 space 分隔),将结果写入 C,仅保留名称为 AC 的字段,不保留名称为 [=17= 的字段]B(实际问题要复杂得多)。我知道如何在字段 C 中写入结果,但我不知道如何完全删除字段 B.

private String outFieldName1;
private String outFieldName2;
private String removeFieldName;

private int outFieldIndex1;
private int outFieldIndex2;
private int removeFieldIndex;

private Object[] inputRow;

private int inputRowMetaSize;
private int outputRowMetaSize;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
    inputRow = getRow();
    if (inputRow == null) {
        setOutputDone();
        return false;
    }

    if (first) processMetadata();

    pushOutputRow( get(Fields.In, removeFieldName).getString(inputRow) + " "
                 + get(Fields.In, outFieldName2).getString(inputRow));

    return true;
}

private void processMetadata() throws KettleException {
    outFieldName1 = getParameter("OUT1");
    outFieldName2 = getParameter("OUT2");
    removeFieldName = getParameter("REMOVE");

    outFieldIndex1 = getInputRowMeta().indexOfValue(outFieldName1);
    outFieldIndex2 = getInputRowMeta().indexOfValue(outFieldName2);
    removeFieldIndex = getInputRowMeta().indexOfValue(removeFieldName);

    inputRowMetaSize = data.inputRowMeta.size();
    outputRowMetaSize = data.outputRowMeta.size();

    first=false;
}


private void pushOutputRow(String content) throws KettleException {
    Object[] outRow = RowDataUtil.allocateRowData(outputRowMetaSize);

    for (int fieldN=0; fieldN < inputRow.length; ++fieldN) {
        if(fieldN == outFieldIndex1) {
            outRow[fieldN] = inputRow[fieldN];
        } else if(fieldN == outFieldIndex2) {
            outRow[fieldN] = content;
        } else if(fieldN == removeFieldIndex) {
            outRow[fieldN] = "";
            // Unable to delete this row!
        }

    }

    putRow( data.outputRowMeta, outRow );
}

只需要:

  1. data.outputRowMeta 保存在 RowMetaInterface 类型的变量中(在我的例子中 rowMeta);
  2. 使用要删除的字段的名称或索引调用rowMeta.removeValueMeta方法;
  3. 使用rowMeta而不是getInputRowMeta();
  4. 搜索输出字段的索引和输出数据量
  5. putRow()方法中,使用rowMeta作为第一个参数。

``

private String outFieldName1;
private String outFieldName2;
private String removeFieldName;

private int outFieldIndex1;
private int outFieldIndex2;

private Object[] inputRow;

private int inputRowMetaSize;
private int outputRowMetaSize;
private RowMetaInterface rowMeta;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
    inputRow = getRow();
    if (inputRow == null) {
        setOutputDone();
        return false;
    }

    if (first) processMetadata();

    pushOutputRow( get(Fields.In, removeFieldName).getString(inputRow) + " "
                 + get(Fields.In, outFieldName2).getString(inputRow));

    return true;
}

private void processMetadata() throws KettleException {
    outFieldName1 = getParameter("OUT1");
    outFieldName2 = getParameter("OUT2");
    removeFieldName = getParameter("REMOVE");

    inputRowMetaSize = data.inputRowMeta.size();
    outputRowMetaSize = data.outputRowMeta.size();

    rowMeta = data.outputRowMeta;
    rowMeta.removeValueMeta(removeFieldName);

    outFieldIndex1 = rowMeta.indexOfValue(outFieldName1);
    outFieldIndex2 = rowMeta.indexOfValue(outFieldName2);

    outputRowMetaSize = rowMeta.size();

    first=false;
}

private void pushOutputRow(String content) throws KettleException {
    Object[] outRow = RowDataUtil.allocateRowData(outputRowMetaSize);

    for (int fieldN=0; fieldN < inputRow.length; ++fieldN) {

        if(fieldN == outFieldIndex1) {
            outRow[fieldN] = inputRow[fieldN];
        } else if(fieldN == outFieldIndex2) {
            outRow[fieldN] = content;
        }
    }

    putRow( rowMeta, outRow );
}

``