gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:39:00 25 4
gpt4 key购买 nike

我不明白在Pentaho Data Integration中使用用户定义的Java类时如何完全删除特定的输入字段。

假设我有输入字段 ABC。假设我想连接 BC 中的值(用空格分隔),将结果写入 C 中,只保留名称为 AC 的字段,没有名称为 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. 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 );
}

``

关于java - 如何在 Pentaho 中完全删除用户定义的 Java 类中的特定输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59982582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com