|
20 | 20 | import com.dtstack.flink.sql.sink.IStreamSinkGener; |
21 | 21 | import com.dtstack.flink.sql.sink.rdb.JDBCOptions; |
22 | 22 | import com.dtstack.flink.sql.sink.rdb.RdbSink; |
23 | | -import com.dtstack.flink.sql.sink.rdb.dialect.JDBCDialect; |
24 | 23 | import com.dtstack.flink.sql.sink.rdb.format.JDBCUpsertOutputFormat; |
25 | 24 |
|
26 | 25 | /** |
@@ -53,190 +52,4 @@ public JDBCUpsertOutputFormat getOutputFormat() { |
53 | 52 | .setAllReplace(allReplace) |
54 | 53 | .setUpdateMode(updateMode).build(); |
55 | 54 | } |
56 | | - |
57 | | - |
58 | | - // @Override |
59 | | -// public RetractJDBCOutputFormat getOutputFormat() { |
60 | | -// return new ExtendOutputFormat(); |
61 | | -// } |
62 | | -// |
63 | | -// @Override |
64 | | -// public void buildSql(String scheam, String tableName, List<String> fields) { |
65 | | -// buildInsertSql(scheam, tableName, fields); |
66 | | -// } |
67 | | -// |
68 | | -// private void buildInsertSql(String scheam, String tableName, List<String> fields) { |
69 | | -// tableName = DtStringUtil.getTableFullPath(scheam, tableName); |
70 | | -// String columns = fields.stream() |
71 | | -// .map(this::quoteIdentifier) |
72 | | -// .collect(Collectors.joining(", ")); |
73 | | -// |
74 | | -// String placeholders = fields.stream() |
75 | | -// .map(f -> "?") |
76 | | -// .collect(Collectors.joining(", ")); |
77 | | -// this.sql = "INSERT INTO " + tableName + "(" + columns + ")" + " VALUES (" + placeholders + ")"; |
78 | | -// } |
79 | | -// |
80 | | -// /** |
81 | | -// * use MERGE INTO build oracle replace into sql |
82 | | -// * @param tableName |
83 | | -// * @param fieldNames create table contained column columns |
84 | | -// * @param realIndexes <key: indexName, value: index contains columns > |
85 | | -// * @param fullField real columns , query from db |
86 | | -// * @return |
87 | | -// */ |
88 | | -// @Override |
89 | | -// public String buildUpdateSql(String scheam, String tableName, List<String> fieldNames, Map<String, List<String>> realIndexes, List<String> fullField) { |
90 | | -// tableName = DtStringUtil.getTableFullPath(scheam, tableName); |
91 | | -// |
92 | | -// StringBuilder sb = new StringBuilder(); |
93 | | -// |
94 | | -// sb.append("MERGE INTO " + tableName + " T1 USING " |
95 | | -// + "(" + makeValues(fieldNames) + ") T2 ON (" |
96 | | -// + updateKeySql(realIndexes) + ") "); |
97 | | -// |
98 | | -// |
99 | | -// String updateSql1 = buildUpdateSqlForAllValue(fieldNames, fullField, "T1", "T2", keyColList(realIndexes)); |
100 | | -// String updateSql = buildUpdateSqlForNotnullValue(fieldNames, fullField, "T1", "T2", keyColList(realIndexes)); |
101 | | -// |
102 | | -// if (StringUtils.isNotEmpty(updateSql)) { |
103 | | -// sb.append(" WHEN MATCHED THEN UPDATE SET "); |
104 | | -// sb.append(updateSql); |
105 | | -// } |
106 | | -// |
107 | | -// sb.append(" WHEN NOT MATCHED THEN " |
108 | | -// + "INSERT (" + quoteColumns(fieldNames) + ") VALUES (" |
109 | | -// + quoteColumns(fieldNames, "T2") + ")"); |
110 | | -// |
111 | | -// return sb.toString(); |
112 | | -// } |
113 | | -// |
114 | | -// |
115 | | -// public String quoteColumns(List<String> column) { |
116 | | -// return quoteColumns(column, null); |
117 | | -// } |
118 | | -// |
119 | | -// public String quoteColumns(List<String> column, String table) { |
120 | | -// String prefix = StringUtils.isBlank(table) ? "" : DtStringUtil.addQuoteForStr(table) + "."; |
121 | | -// List<String> list = new ArrayList<>(); |
122 | | -// for (String col : column) { |
123 | | -// list.add(prefix + DtStringUtil.addQuoteForStr(col)); |
124 | | -// } |
125 | | -// return StringUtils.join(list, ","); |
126 | | -// } |
127 | | -// |
128 | | -// /** |
129 | | -// * extract all distinct index column |
130 | | -// * @param realIndexes |
131 | | -// * @return |
132 | | -// */ |
133 | | -// protected List<String> keyColList(Map<String, List<String>> realIndexes) { |
134 | | -// List<String> keyCols = new ArrayList<>(); |
135 | | -// for (Map.Entry<String, List<String>> entry : realIndexes.entrySet()) { |
136 | | -// List<String> list = entry.getValue(); |
137 | | -// for (String col : list) { |
138 | | -// if (!containsIgnoreCase(keyCols,col)) { |
139 | | -// keyCols.add(col); |
140 | | -// } |
141 | | -// } |
142 | | -// } |
143 | | -// return keyCols; |
144 | | -// } |
145 | | -// |
146 | | -// /** |
147 | | -// * build update sql , such as UPDATE SET "T1".A="T2".A |
148 | | -// * @param updateColumn create table contained column columns |
149 | | -// * @param fullColumn real columns , query from db |
150 | | -// * @param leftTable alias |
151 | | -// * @param rightTable alias |
152 | | -// * @param indexCols index column |
153 | | -// * @return |
154 | | -// */ |
155 | | -// public String buildUpdateSqlForAllValue(List<String> updateColumn, List<String> fullColumn, String leftTable, String rightTable, List<String> indexCols) { |
156 | | -// String prefixLeft = StringUtils.isBlank(leftTable) ? "" : DtStringUtil.addQuoteForStr(leftTable) + "."; |
157 | | -// String prefixRight = StringUtils.isBlank(rightTable) ? "" : DtStringUtil.addQuoteForStr(rightTable) + "."; |
158 | | -// |
159 | | -// String sql = fullColumn.stream().filter(col -> { |
160 | | -// return !(indexCols == null || indexCols.size() == 0 || containsIgnoreCase(indexCols, col)); |
161 | | -// }).map(col -> { |
162 | | -// String leftCol = prefixLeft + DtStringUtil.addQuoteForStr(col); |
163 | | -// String rightCol = prefixRight + DtStringUtil.addQuoteForStr(col); |
164 | | -// |
165 | | -// if (containsIgnoreCase(updateColumn, col)) { |
166 | | -// return (leftCol + "=" + rightCol); |
167 | | -// } else { |
168 | | -// return (leftCol + "=null"); |
169 | | -// } |
170 | | -// }).collect(Collectors.joining(",")); |
171 | | -// |
172 | | -// return sql; |
173 | | -// } |
174 | | -// |
175 | | -// public String buildUpdateSqlForNotnullValue(List<String> updateColumn, List<String> fullColumn, String leftTable, String rightTable, List<String> indexCols) { |
176 | | -// String prefixLeft = StringUtils.isBlank(leftTable) ? "" : DtStringUtil.addQuoteForStr(leftTable) + "."; |
177 | | -// String prefixRight = StringUtils.isBlank(rightTable) ? "" : DtStringUtil.addQuoteForStr(rightTable) + "."; |
178 | | -// |
179 | | -// String sql = fullColumn.stream().filter(col -> { |
180 | | -// return !(indexCols == null || indexCols.size() == 0 || containsIgnoreCase(indexCols, col)); |
181 | | -// }).map(col -> { |
182 | | -// String leftCol = prefixLeft + DtStringUtil.addQuoteForStr(col); |
183 | | -// String rightCol = prefixRight + DtStringUtil.addQuoteForStr(col); |
184 | | -// |
185 | | -// if (containsIgnoreCase(updateColumn, col)) { |
186 | | -// return leftCol + "= nvl(" + rightCol + "," + leftCol + ")"; |
187 | | -// } |
188 | | -// return ""; |
189 | | -// }).collect(Collectors.joining(",")); |
190 | | -// |
191 | | -// return sql; |
192 | | -// } |
193 | | -// |
194 | | -// |
195 | | -// |
196 | | -// |
197 | | -// /** |
198 | | -// * build connect sql by index column, such as T1."A"=T2."A" |
199 | | -// * @param updateKey |
200 | | -// * @return |
201 | | -// */ |
202 | | -// public String updateKeySql(Map<String, List<String>> updateKey) { |
203 | | -// List<String> exprList = new ArrayList<>(); |
204 | | -// for (Map.Entry<String, List<String>> entry : updateKey.entrySet()) { |
205 | | -// List<String> colList = new ArrayList<>(); |
206 | | -// for (String col : entry.getValue()) { |
207 | | -// colList.add("T1." + DtStringUtil.addQuoteForStr(col) + "=T2." + DtStringUtil.addQuoteForStr(col)); |
208 | | -// } |
209 | | -// exprList.add(StringUtils.join(colList, " AND ")); |
210 | | -// } |
211 | | -// return StringUtils.join(exprList, " OR "); |
212 | | -// } |
213 | | -// |
214 | | -// /** |
215 | | -// * build select sql , such as (SELECT ? "A",? "B" FROM DUAL) |
216 | | -// * |
217 | | -// * @param column destination column |
218 | | -// * @return |
219 | | -// */ |
220 | | -// public String makeValues(List<String> column) { |
221 | | -// StringBuilder sb = new StringBuilder("SELECT "); |
222 | | -// for (int i = 0; i < column.size(); ++i) { |
223 | | -// if (i != 0) { |
224 | | -// sb.append(","); |
225 | | -// } |
226 | | -// sb.append("? " + DtStringUtil.addQuoteForStr(column.get(i))); |
227 | | -// } |
228 | | -// sb.append(" FROM DUAL"); |
229 | | -// return sb.toString(); |
230 | | -// } |
231 | | -// |
232 | | -// public boolean containsIgnoreCase(List<String> l, String s) { |
233 | | -// Iterator<String> it = l.iterator(); |
234 | | -// while (it.hasNext()) { |
235 | | -// if (it.next().equalsIgnoreCase(s)) |
236 | | -// return true; |
237 | | -// } |
238 | | -// return false; |
239 | | -// } |
240 | | - |
241 | | - |
242 | 55 | } |
0 commit comments