Pentaho 输入文本将字段设置为数据之前为空

huangapple go评论70阅读模式
英文:

Pentaho Input Text Set Field Null to Data Before

问题

抱歉,我只会为您提供翻译的部分,不会提供额外的内容。以下是翻译好的内容:

"很难用言语解释这个问题,所以如果标题不匹配,我很抱歉。

所以,我有一个文本文件,内容如下:

Header A     Header B     Header C    Header D
Apple        Red          A           100
                          B           200
                          B           300
             Green        A           400
                          B           500
Eggplant     Purple       A           600
                          B           700
             White        a           800

我想让它读起来像这样:

Header A     Header B     Header C    Header D
Apple        Red          A           100
Apple        Red          B           200
Apple        Red          B           300
Apple        Green        A           400
Apple        Green        B           500
Eggplant     Purple       A           600
Eggplant     Purple       B           700
Eggplant     White        a           800

但我不确定应该使用哪种转换方法。
那么如何在Pentaho中获得这个结果?或者有没有我应该观看的视频教程?
谢谢先前。

我尝试了“如果值为空”和“过滤行”的转换,但似乎不是解决方案。"

英文:

It is hard to explain this in word, so sorry if the title is mismatch.

So I have a file text like this:

Header A     Header B     Header C    Header D
Apple        Red          A           100
                          B           200
                          B           300
             Green        A           400
                          B           500
Eggplant     Purple       A           600
                          B           700
             White        a           800

And I want it to be read like this:

Header A     Header B     Header C    Header D
Apple        Red          A           100
Apple        Red          B           200
Apple        Red          B           300
Apple        Green        A           400
Apple        Green        B           500
Eggplant     Purple       A           600
Eggplant     Purple       B           700
Eggplant     White        a           800

But I confuse what transformation that I have to use.
So how to get this result in Pentaho? Or is there video tutorial I have to watch?
Thanks Before.

I have tried transformation "If Value is null" and "Filter Rows", but it doesn't seems the solution.

答案1

得分: 1

你可以在Pentaho数据集成中使用文本文件输入步骤轻松完成此操作。只需在字段定义中将“Repeat”属性设置为“Y”。

如果字段为空,它将重复上一个非空值,您将获得所需的结果。

英文:

You can do it easily in Pentaho Data Integration with the text file input step. On the definition of fields just set the "Repeat" property to "Y".

If the field is null it will repeat the last non-null value and you get the results you're after.

答案2

得分: -1

以下是您要翻译的内容:

请尝试以下解决方案。
我不使用Postgresql,但我相信这些解决方案也可以在Postgresql中工作,只需进行一些小的更改,例如在末尾使用"top 1 with limit 1"。

如果您有进一步的问题或有些内容您不明白,请向我提问。
如果不是这种情况,请不要在第一个解决方案之后使用更新。

with flo as
(select headera, headerb, row_number () over(order by (select null)) as rn
 from prob1 ), 
flo1 as (
select *, last_value(headera) ignore nulls over(order by rn) as last,
last_value(headerb) ignore nulls over(order by rn) as last1
from flo)
update flo1
set headera = last, headerb = last1
from flo1
where headera is null or headerb is null
select * from prob1
drop table prob1

with flo as
 (select *, row_number () over(order by (select null)) as rn from prob2)
select headera, 
case when headera is null then(select top 1 headera from flo b 
where b.rn < a.rn and b.headera is not null order by b.rn desc) else headera end as headera1,
headerb,
case when headerb is null then(select top 1 headerb from flo c 
where c.rn < a.rn and c.headerb is not null  order by c.rn desc) else headerb end as headerb1
from flo a

with flo as
 (select *, row_number () over(order by (select null)) as rn from prob2),
flo1 as
 (select headera, count(headera) over(order by rn) as cate,
headerb, count(headerb) over(order by rn) as cate1
from flo)
select headera, first_value(headera) over(partition by cate order by cate) as headeracor,
 headerb, first_value(headerb) over(partition by cate1 order by cate1) as headerbcor
from flo1
英文:

Please try one of this solutions.
I don t use Postgresql but i m confident that this solutions will work also in Postgresql with small changes for exemple top 1 with limit 1 at the end.

If you have further questions or is something which you don t understand please ask me.
Do not use that update after the first solution if not the case.

with flo as
(select headera, headerb ,row_number ()over(order by (select null))as rn
 from prob1 ), 
flo1 as (
select *, last_value(headera)ignore nulls over(order by rn)as last,
last_value(headerb)ignore nulls over(order by rn)as last1
from flo)
update flo1
set headera= last , headerb=last1
from flo1
where headera is null or headerb is null
select * from prob1
drop table prob1

with flo as
 (select *, row_number ()over(order by (select null))as rn from prob2)
select headera, 
case when headera is null then(select top 1 headera from flo b 
where b.rn&lt;a.rn and b.headera is not null order by b.rn desc) else headera end as headera1,
headerb,
case when headerb is null then(select top 1 headerb from flo c 
where c.rn&lt;a.rn and c.headerb is not null  order by c.rn desc) else headerb end as headerb1
from flo a

with flo as
 (select *, row_number ()over(order by (select null))as rn from prob2),
flo1 as
 (select headera, count(headera)over(order by rn)as cate ,
headerb, count(headerb)over(order by rn)as cate1
from flo)
select headera, first_value(headera)over(partition by cate order by cate)as headeracor,
 headerb, first_value(headerb)over(partition by cate1 order by cate1)as headerbcor
from flo1

答案3

得分: -1

你可以使用修改后的JavaScript值步骤。

你可以创建两个新列,AltHeaderAAltHeaderB(或者你可以重写 HeaderAHeaderB 列,但在调试时,保留原始值可以更清晰)。

在脚本中,只需输入:

if (HeaderA != null) {
    AltHeaderA = HeaderA;
}
if (HeaderB != null) {
    AltHeaderB = HeaderB;
}
英文:

You can use the Modified JavaScript Value step.

You create two new columns, AltHeaderA and AltHeaderB (or you could rewrite HeaderA and HeaderB columns, but I like keeping the original values for clarity when debugging.

In the script, you just put:

if (HeaderA != null) {
	AltHeaderA = HeaderA;
}
if (HeaderB != null) {
	AltHeaderB = HeaderB;
}

huangapple
  • 本文由 发表于 2023年7月13日 12:25:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76675932.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定