方法一: 使用execute on every row

使用csv定义循环的step步长,然后分步执行。

step,
1,
2,
3,
4,
5,
6,
1
2
3
4
5
6
7

创建读取csv的transformation

创建读取csv的transformation,使用copy rows to result组件

image

创建读取csv的transformation

在这个transformation,使用Get rows from result组件

image

创建job依次执行

image

注意在execute这个transformation,选中execute on every row选项

image

测试

运行日志如下,可以看到是按照csv定义的格式顺序执行。


2019/01/15 16:41:14 - Spoon - Starting job...
2019/01/15 16:41:14 - loop - Start of job execution
2019/01/15 16:41:14 - loop - Starting entry [read cvs to result]
2019/01/15 16:41:14 - read cvs to result - Loading transformation from XML file [file:///C:/Users/Mars/Desktop/printStep.ktr]
2019/01/15 16:41:14 - read cvs to result - Using run configuration [Pentaho local]
2019/01/15 16:41:14 - read cvs to result - Using legacy execution engine
2019/01/15 16:41:14 - printStep - Dispatching started for transformation [printStep]
2019/01/15 16:41:14 - CSV file input.0 - Header row skipped in file 'C:\Users\Mars\Desktop\date.csv'
2019/01/15 16:41:14 - CSV file input.0 - Finished processing (I=7, O=0, R=0, W=6, U=0, E=0)
2019/01/15 16:41:14 - Copy rows to result.0 - Finished processing (I=0, O=0, R=6, W=6, U=0, E=0)
2019/01/15 16:41:14 - loop - Starting entry [execute]
2019/01/15 16:41:14 - execute - Loading transformation from XML file [file:///C:/Users/Mars/Desktop/printstep2.ktr]
2019/01/15 16:41:14 - execute - Using run configuration [Pentaho local]
2019/01/15 16:41:14 - execute - Using legacy execution engine
2019/01/15 16:41:14 - printstep2 - Dispatching started for transformation [printstep2]
2019/01/15 16:41:14 - Get rows from result.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - Add constants.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - Get System Info.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - Write to log.0 - 
2019/01/15 16:41:14 - Write to log.0 - ------------> Linenr 1------------------------------
2019/01/15 16:41:14 - Write to log.0 - startDate = 2018/01/01 00:00:00.000
2019/01/15 16:41:14 - Write to log.0 - endDate = 2018/01/02 00:00:00.000
2019/01/15 16:41:14 - Write to log.0 - 
2019/01/15 16:41:14 - Write to log.0 - ====================
2019/01/15 16:41:14 - Calculator.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - Calculator 2.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - Write to log.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - execute - Using run configuration [Pentaho local]
2019/01/15 16:41:14 - execute - Using legacy execution engine
2019/01/15 16:41:14 - printstep2 - Dispatching started for transformation [printstep2]
2019/01/15 16:41:14 - Get rows from result.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - Add constants.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:41:14 - Write to log.0 - 
2019/01/15 16:41:14 - Write to log.0 - ------------> Linenr 1------------------------------
2019/01/15 16:41:14 - Write to log.0 - startDate = 2018/01/02 00:00:00.000
2019/01/15 16:41:14 - Write to log.0 - endDate = 2018/01/03 00:00:00.000
2019/01/15 16:41:14 - Write to log.0 - 
2019/01/15 16:41:14 - Write to log.0 - ====================
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

方法二: 使用变量定义loop

使用变量定义loop,执行完毕transformation后,对loop自增,然后使用simple evaluate判断条件是否停止执行

概览

image

  • init loop :在job中设定变量初始值
  • set loop:用于evaluation失败后设定变量,以及从读出后再次设定变量
  • increment loop:增加循环次数
  • simple evaluation:比较条件,判断是否退出执行。

在使用这种方式中,真正的transformation可以放在set loop和increment loop之间。

init loop

image

set loop

image

increment loop

image

evaluation loop

image

测试

设定初始值为1,evaluation小于或者等于5, 运行日志如下,可以看到set loop一共执行了5次。

2019/01/15 16:51:58 - Spoon - Starting job...
2019/01/15 16:51:58 - loop - Start of job execution
2019/01/15 16:51:58 - loop - Starting entry [init loop]
2019/01/15 16:51:58 - loop - Starting entry [set loop]
2019/01/15 16:51:58 - set loop - Loading transformation from XML file [file:///C:/Users/Mars/Desktop/setLoop.ktr]
2019/01/15 16:51:58 - set loop - Using run configuration [Pentaho local]
2019/01/15 16:51:58 - set loop - Using legacy execution engine
2019/01/15 16:51:58 - setLoop - Dispatching started for transformation [setLoop]
2019/01/15 16:51:58 - Set Variables.0 - Setting environment variables...
2019/01/15 16:51:58 - Get Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:58 - Set Variables.0 - Set variable loop to value [1]
2019/01/15 16:51:58 - Set Variables.0 - Finished after 1 rows.
2019/01/15 16:51:58 - Set Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:58 - loop - Starting entry [JavaScript]
2019/01/15 16:51:58 - loop - Starting entry [Simple evaluation]
2019/01/15 16:51:58 - loop - Starting entry [set loop]
2019/01/15 16:51:58 - set loop - Loading transformation from XML file [file:///C:/Users/Mars/Desktop/setLoop.ktr]
2019/01/15 16:51:58 - set loop - Using run configuration [Pentaho local]
2019/01/15 16:51:58 - set loop - Using legacy execution engine
2019/01/15 16:51:58 - setLoop - Dispatching started for transformation [setLoop]
2019/01/15 16:51:59 - Get Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - Set Variables.0 - Setting environment variables...
2019/01/15 16:51:59 - Set Variables.0 - Set variable loop to value [2]
2019/01/15 16:51:59 - Set Variables.0 - Finished after 1 rows.
2019/01/15 16:51:59 - Set Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - loop - Starting entry [JavaScript]
2019/01/15 16:51:59 - loop - Starting entry [Simple evaluation]
2019/01/15 16:51:59 - loop - Starting entry [set loop]
2019/01/15 16:51:59 - set loop - Loading transformation from XML file [file:///C:/Users/Mars/Desktop/setLoop.ktr]
2019/01/15 16:51:59 - set loop - Using run configuration [Pentaho local]
2019/01/15 16:51:59 - set loop - Using legacy execution engine
2019/01/15 16:51:59 - setLoop - Dispatching started for transformation [setLoop]
2019/01/15 16:51:59 - Get Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - Set Variables.0 - Setting environment variables...
2019/01/15 16:51:59 - Set Variables.0 - Set variable loop to value [3]
2019/01/15 16:51:59 - Set Variables.0 - Finished after 1 rows.
2019/01/15 16:51:59 - Set Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - loop - Starting entry [JavaScript]
2019/01/15 16:51:59 - loop - Starting entry [Simple evaluation]
2019/01/15 16:51:59 - loop - Starting entry [set loop]
2019/01/15 16:51:59 - set loop - Loading transformation from XML file [file:///C:/Users/Mars/Desktop/setLoop.ktr]
2019/01/15 16:51:59 - set loop - Using run configuration [Pentaho local]
2019/01/15 16:51:59 - set loop - Using legacy execution engine
2019/01/15 16:51:59 - setLoop - Dispatching started for transformation [setLoop]
2019/01/15 16:51:59 - Get Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - Set Variables.0 - Setting environment variables...
2019/01/15 16:51:59 - Set Variables.0 - Set variable loop to value [4]
2019/01/15 16:51:59 - Set Variables.0 - Finished after 1 rows.
2019/01/15 16:51:59 - Set Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - loop - Starting entry [JavaScript]
2019/01/15 16:51:59 - loop - Starting entry [Simple evaluation]
2019/01/15 16:51:59 - loop - Starting entry [set loop]
2019/01/15 16:51:59 - set loop - Loading transformation from XML file [file:///C:/Users/Mars/Desktop/setLoop.ktr]
2019/01/15 16:51:59 - set loop - Using run configuration [Pentaho local]
2019/01/15 16:51:59 - set loop - Using legacy execution engine
2019/01/15 16:51:59 - setLoop - Dispatching started for transformation [setLoop]
2019/01/15 16:51:59 - Get Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - Set Variables.0 - Setting environment variables...
2019/01/15 16:51:59 - Set Variables.0 - Set variable loop to value [5]
2019/01/15 16:51:59 - Set Variables.0 - Finished after 1 rows.
2019/01/15 16:51:59 - Set Variables.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0)
2019/01/15 16:51:59 - loop - Starting entry [JavaScript]
2019/01/15 16:51:59 - loop - Starting entry [Simple evaluation]
2019/01/15 16:51:59 - loop - Starting entry [Success]
2019/01/15 16:51:59 - loop - Finished job entry [Success] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [Simple evaluation] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [JavaScript] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [set loop] (result=[true]) *第一次*
2019/01/15 16:51:59 - loop - Finished job entry [Simple evaluation] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [JavaScript] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [set loop] (result=[true]) *第二次*
2019/01/15 16:51:59 - loop - Finished job entry [Simple evaluation] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [JavaScript] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [set loop] (result=[true]) *第三次*
2019/01/15 16:51:59 - loop - Finished job entry [Simple evaluation] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [JavaScript] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [set loop] (result=[true]) *第四次*
2019/01/15 16:51:59 - loop - Finished job entry [Simple evaluation] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [JavaScript] (result=[true])
2019/01/15 16:51:59 - loop - Finished job entry [set loop] (result=[true]) *第五次*
2019/01/15 16:51:59 - loop - Finished job entry [init loop] (result=[true])
2019/01/15 16:51:59 - loop - Job execution finished
2019/01/15 16:51:59 - Spoon - Job has ended.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83