随笔 - 597  文章 - 4  评论 - 445  阅读 - 424万

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 on   别先生  阅读(3237)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

点击右上角即可分享
微信分享提示