kettle使用文件导入到Postgresql出现如下几种问题的总结

kettle使用文件导入到Postgresql出现如下几种问题的总结

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         

 

待续......

posted @ 2018-12-27 17:04 别先生 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值