|
17 | 17 | package io.cdap.plugin.util; |
18 | 18 |
|
19 | 19 | import com.google.common.base.Preconditions; |
20 | | -import io.cdap.cdap.api.data.schema.Schema; |
21 | 20 | import io.cdap.cdap.api.plugin.PluginProperties; |
22 | 21 | import io.cdap.cdap.etl.api.PipelineConfigurer; |
23 | 22 | import io.cdap.cdap.etl.api.validation.InvalidConfigPropertyException; |
24 | | -import io.cdap.plugin.db.ColumnType; |
25 | 23 | import io.cdap.plugin.db.ConnectionConfig; |
26 | 24 | import io.cdap.plugin.db.JDBCDriverShim; |
27 | | -import io.cdap.plugin.db.batch.source.AbstractDBSource; |
28 | 25 | import org.slf4j.Logger; |
29 | 26 | import org.slf4j.LoggerFactory; |
30 | 27 |
|
|
37 | 34 | import java.sql.Driver; |
38 | 35 | import java.sql.DriverManager; |
39 | 36 | import java.sql.ResultSet; |
40 | | -import java.sql.ResultSetMetaData; |
41 | 37 | import java.sql.SQLException; |
42 | 38 | import java.sql.Types; |
43 | | -import java.util.ArrayList; |
44 | 39 | import java.util.Hashtable; |
45 | 40 | import java.util.List; |
46 | 41 | import java.util.Objects; |
@@ -189,60 +184,6 @@ public static Class<? extends Driver> getDriverClass(PipelineConfigurer pipeline |
189 | 184 | jdbcPluginId, PluginProperties.builder().build()); |
190 | 185 | } |
191 | 186 |
|
192 | | - /** |
193 | | - * Checks if fields from schema are compatible to be written into database. |
194 | | - * |
195 | | - * @param actualSchema schema from db. |
196 | | - * @param configSchema schema from config. |
197 | | - */ |
198 | | - public static void validateSourceSchema(Schema actualSchema, Schema configSchema) { |
199 | | - if (configSchema == null) { |
200 | | - throw new InvalidConfigPropertyException("Schema should not be null or empty", |
201 | | - AbstractDBSource.DBSourceConfig.SCHEMA); |
202 | | - } |
203 | | - for (Schema.Field field : configSchema.getFields()) { |
204 | | - Schema.Field actualField = actualSchema.getField(field.getName()); |
205 | | - if (actualField == null) { |
206 | | - throw new InvalidConfigPropertyException(String.format("Schema field '%s' is not present in actual record", |
207 | | - field.getName()), |
208 | | - AbstractDBSource.DBSourceConfig.SCHEMA); |
209 | | - } |
210 | | - Schema actualFieldSchema = actualField.getSchema().isNullable() ? |
211 | | - actualField.getSchema().getNonNullable() : actualField.getSchema(); |
212 | | - Schema expectedFieldSchema = field.getSchema().isNullable() ? |
213 | | - field.getSchema().getNonNullable() : field.getSchema(); |
214 | | - |
215 | | - if (!actualFieldSchema.equals(expectedFieldSchema)) { |
216 | | - throw new IllegalArgumentException( |
217 | | - String.format("Schema field '%s' has type '%s' but found '%s' in input record", |
218 | | - field.getName(), expectedFieldSchema.getType(), actualFieldSchema.getType())); |
219 | | - } |
220 | | - } |
221 | | - } |
222 | | - |
223 | | - /** |
224 | | - * Compare columns from schema with columns in table and returns list of matched columns in {@link ColumnType} format. |
225 | | - * |
226 | | - * @param resultSetMetadata result set metadata from table. |
227 | | - * @param columns list of columns from schema. |
228 | | - * @return list of matched columns. |
229 | | - */ |
230 | | - public static List<ColumnType> getMatchedColumnTypeList(ResultSetMetaData resultSetMetadata, List<String> columns) |
231 | | - throws SQLException { |
232 | | - List<ColumnType> columnTypes = new ArrayList<>(columns.size()); |
233 | | - // JDBC driver column indices start with 1 |
234 | | - for (int i = 0; i < resultSetMetadata.getColumnCount(); i++) { |
235 | | - String name = resultSetMetadata.getColumnName(i + 1); |
236 | | - String columnTypeName = resultSetMetadata.getColumnTypeName(i + 1); |
237 | | - int type = resultSetMetadata.getColumnType(i + 1); |
238 | | - String schemaColumnName = columns.get(i); |
239 | | - Preconditions.checkArgument(schemaColumnName.toLowerCase().equals(name.toLowerCase()), |
240 | | - "Missing column '%s' in SQL table", schemaColumnName); |
241 | | - columnTypes.add(new ColumnType(schemaColumnName, columnTypeName, type)); |
242 | | - } |
243 | | - return columnTypes; |
244 | | - } |
245 | | - |
246 | 187 | /** |
247 | 188 | * Shuts down a cleanup thread com.mysql.jdbc.AbandonedConnectionCleanupThread that mysql driver fails to destroy |
248 | 189 | * If this is not done, the thread keeps a reference to the classloader, thereby causing OOMs or too many open files |
|
0 commit comments