1、kettle使用文件导入到Postgresql出现如下几种问题的总结:
1 kettle使用文件导入到Postgresql出现如下几种问题的总结:
2 1、第一种错误,报错如ERROR: extra data after last expected column所示。或者报错为报错为0x05,多一列,extra data after last expected column。
3 1)、sql查询语句定位到某个字段:
4 SELECT * from 数据表名称 where 字段名称 like CONCAT('%',char(5),'%')
5 2)、解决方法,使用空替代,原因是出现特殊字符,char(5),这种字符,导致的错误。
6 解决方法如下所示:
7 public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
8 Object[] r = getRow();
9
10 if (r == null) {
11 setOutputDone();
12 return false;
13 }
14
15 // It is always safest to call createOutputRow() to ensure that your output row’s Object[] is large
16 // enough to handle any new fields you are creating in this step.
17 r = createOutputRow(r, data.outputRowMeta.size());
18
19 String 字段名称 = get(Fields.In, "字段名称").getString(r);
20 if(字段名称 != null) {
21 字段名称 = 字段名称.replaceAll((char)5 + "", "");
22 }
23 get(Fields.Out, "字段名称").setValue(r, 字段名称);
24
25 // Send the row on to the next step.
26 putRow(data.outputRowMeta, r);
27
28 return true;
29 }
30
31 2、第二种错误,报错如missing data for column "datastamp"。
32 1)、sql查询语句定位到某个字段:
33 SELECT * from 数据表名称 where 字段名称 like CONCAT('%',char(10),'%')
34 或者
35 SELECT * from 数据表名称 where 字段名称 like CONCAT('%',char(13),'%')
36 2)、解决方法:是字段的值出现了,换行回车,char(10),char(13)。char(10)多一行,少n列,missing data column xxx。解决方法,使用字符替代,然后再替换回来。
37 解决方法如下所示:
38 public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
39 Object[] r = getRow();
40
41 if (r == null) {
42 setOutputDone();
43 return false;
44 }
45
46 // It is always safest to call createOutputRow() to ensure that your output row’s Object[] is large
47 // enough to handle any new fields you are creating in this step.
48 r = createOutputRow(r, data.outputRowMeta.size());
49
50 String 字段名称 = get(Fields.In, "字段名称").getString(r);
51 if(字段名称 != null) {
52 字段名称 = 字段名称.replaceAll("\\r", "@#r;");
53 字段名称 = 字段名称.replaceAll("\\n", "@#n;");
54 }
55 get(Fields.Out, "字段名称").setValue(r, 字段名称);
56
57 // Send the row on to the next step.
58 putRow(data.outputRowMeta, r);
59
60 return true;
61 }
62
63 3、第三种错误,报错如,0x00的解决方法:
64 1)、sql查询语句定位到某个字段:
65 SELECT * from 数据表名称 where 字段名称 like CONCAT('%',char(0),'%')
66 2)、解决方法1
67 public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
68 Object[] r = getRow();
69
70 if (r == null) {
71 setOutputDone();
72 return false;
73 }
74
75 // It is always safest to call createOutputRow() to ensure that your output row’s Object[] is large
76 // enough to handle any new fields you are creating in this step.
77 r = createOutputRow(r, data.outputRowMeta.size());
78
79 // Get the value from an input field
80 String 字段名称 = get(Fields.In, "字段名称").getString(r);
81
82 if(字段名称 != null) {
83 字段名称= 字段名称.replaceAll("\\u0000", "");
84 }
85
86 get(Fields.Out, "字段名称").setValue(r, 字段名称);
87
88 // Send the row on to the next step.
89 putRow(data.outputRowMeta, r);
90
91 return true;
92 }
93
待续......