Pentaho:如何将字段(=列)动态添加到OutputRow?
我想动态地将字段(或新列)添加到Kettle中的结果输出行中Pentaho:如何将字段(=列)动态添加到OutputRow?,pentaho,kettle,Pentaho,Kettle,我想动态地将字段(或新列)添加到Kettle中的结果输出行中 在花了几个小时阅读了froum的帖子,而他编写的脚本文档不太好之后,我想知道Stackoverflow是否会有所帮助。您的输入值是如何传递到SQL查询的?如果它们是变量,那么只需将表输入步骤传递到“获取变量”步骤,并以这种方式获取新列 或者,您可以使用计算器或添加常量来添加列 或者,您甚至可以使用“获取系统信息”步骤来获取命令行参数和日期等。首先,让我给您一个代码片段,说明我在用户定义的Java类步骤中拥有的内容: private i
在花了几个小时阅读了froum的帖子,而他编写的脚本文档不太好之后,我想知道Stackoverflow是否会有所帮助。您的输入值是如何传递到SQL查询的?如果它们是变量,那么只需将表输入步骤传递到“获取变量”步骤,并以这种方式获取新列 或者,您可以使用计算器或添加常量来添加列
或者,您甚至可以使用“获取系统信息”步骤来获取命令行参数和日期等。首先,让我给您一个代码片段,说明我在用户定义的Java类步骤中拥有的内容:
private int fieldToHashGeoIndex;
private int fieldToHashHeadIndex;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
Object[] r=getRow();
if (r==null)
{
setOutputDone();
return false;
}
if (first) {
fieldToHashGeoIndex = getInputRowMeta().indexOfValue(getParameter("FIELD_TO_HASH_GEO"));
if (fieldToHashGeoIndex<0) {
throw new KettleException("Field to hash not found in the input row, check parameter 'FIELD_TO_HASH_GEO'!");
}
fieldToHashHeadIndex = getInputRowMeta().indexOfValue(getParameter("FIELD_TO_HASH_HEAD"));
if (fieldToHashHeadIndex<0) {
throw new KettleException("Field to hash not found in the input row, check parameter 'FIELD_TO_HASH_HEAD'!");
}
first=false;
}
Object[] outputRowData = RowDataUtil.resizeArray(r, data.outputRowMeta.size());
int outputIndex = getInputRowMeta().size();
String fieldToHashGeo = getInputRowMeta().getString(r, fieldToHashGeoIndex);
String fieldToHashHead = getInputRowMeta().getString(r, fieldToHashHeadIndex);
outputRowData[outputIndex++] = MurmurHash.hash64(fieldToHashGeo);
outputRowData[outputIndex++] = MurmurHash.hash64(fieldToHashHead);
putRow(data.outputRowMeta, outputRowData);
return true;
}
private int fieldToHashGeoIndex;
私有int-fieldToHashHeadIndex;
公共布尔processRow(StepMetaInterface smi、StepDataInterface sdi)引发异常
{
对象[]r=getRow();
if(r==null)
{
setOutputDone();
返回false;
}
如果(第一){
fieldToHashGeoIndex=getInputRowMeta().indexOfValue(getParameter(“FIELD_TO_HASH_GEO”);
如果(fieldToHashGeoIndex,我们可以使用以下步骤生成动态列生成:
计算器
添加常量
选择表输入中的必填字段,并将这些值作为设置变量分配,第二个转换级别使用get variables hop
我只是投票赞成这个答案,因为它听起来是最有用的答案……在给定的时间和给定的客户为给定的用例评估pentaho之后,我们继续评估其他“产品”,在我们的开发人员驱动的团队中,我们自己构建了一些东西。