如何用以前的非空值替换空值
How to replace null values with previous non null values
我有一个类似这样的专栏
A
B
Value1
Some Value
null
Some Value
null
Some Value
Value2
Some Value
Value3
Some Value
null
Some Value
null
Some Value
我想要
A
B
Value1
Some Value
Value1
Some Value
Value1
Some Value
Value2
Some Value
Value3
Some Value
Value3
Some Value
Value3
Some Value
我用过tjava_row但遇到了某些错误。我使用了下面给出的代码,或者我应该使用 python(ffill) 或 pyspark 来设计 elt 作业:
if (row2.A==null) {
row2.A = row1.A
} else {
row2.A=row2.A;
借助 Talend,您可以使用带有内部变量的 tMap 来使用以前的值。
您需要三个变量(来自 tMap 的中央选项卡):
当前:row1.yourValue
// cache your input data for current line
上一个:Relational.ISNULL(Var.current)?Var.previous:Var.current
//if current line is null, keep the previous one. Otherwise replace 'previous' with current line.
getPreviousIfNull : Relational.ISNULL(row1.yourValue)?Var.previous:Var.current
//if your input data is null : get the previous one. Otherwise get the current
一个.
row1.yourValue是你的输入数据。
然后将 Var.getPreviousIfNull 提取到输出中。
我有一个类似这样的专栏
A | B |
---|---|
Value1 | Some Value |
null | Some Value |
null | Some Value |
Value2 | Some Value |
Value3 | Some Value |
null | Some Value |
null | Some Value |
我想要
A | B |
---|---|
Value1 | Some Value |
Value1 | Some Value |
Value1 | Some Value |
Value2 | Some Value |
Value3 | Some Value |
Value3 | Some Value |
Value3 | Some Value |
我用过tjava_row但遇到了某些错误。我使用了下面给出的代码,或者我应该使用 python(ffill) 或 pyspark 来设计 elt 作业:
if (row2.A==null) {
row2.A = row1.A
} else {
row2.A=row2.A;
借助 Talend,您可以使用带有内部变量的 tMap 来使用以前的值。 您需要三个变量(来自 tMap 的中央选项卡):
当前:
row1.yourValue
// cache your input data for current line
上一个:
Relational.ISNULL(Var.current)?Var.previous:Var.current
//if current line is null, keep the previous one. Otherwise replace 'previous' with current line.
getPreviousIfNull :
Relational.ISNULL(row1.yourValue)?Var.previous:Var.current
//if your input data is null : get the previous one. Otherwise get the current
一个.
row1.yourValue是你的输入数据。
然后将 Var.getPreviousIfNull 提取到输出中。