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         

 

待續......


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM