@@ -295,13 +295,7 @@ protected List<JdbcColumnHandle> getColumns(ConnectorSession session, Connection
295295 for (int column = 1 ; column <= metadata .getColumnCount (); column ++) {
296296 // Use getColumnLabel method because query pass-through table function may contain column aliases
297297 String name = metadata .getColumnLabel (column );
298- JdbcTypeHandle jdbcTypeHandle = new JdbcTypeHandle (
299- metadata .getColumnType (column ),
300- Optional .ofNullable (metadata .getColumnTypeName (column )),
301- Optional .of (metadata .getPrecision (column )),
302- Optional .of (metadata .getScale (column )),
303- Optional .empty (), // TODO support arrays
304- Optional .of (metadata .isCaseSensitive (column ) ? CASE_SENSITIVE : CASE_INSENSITIVE ));
298+ JdbcTypeHandle jdbcTypeHandle = getColumnTypeHandle (metadata , column );
305299 Type type = toColumnMapping (session , connection , jdbcTypeHandle )
306300 .orElseThrow (() -> new UnsupportedOperationException (format ("Unsupported type: %s of column: %s" , jdbcTypeHandle , name )))
307301 .getType ();
@@ -310,6 +304,18 @@ protected List<JdbcColumnHandle> getColumns(ConnectorSession session, Connection
310304 return columns .build ();
311305 }
312306
307+ protected JdbcTypeHandle getColumnTypeHandle (ResultSetMetaData metadata , int column )
308+ throws SQLException
309+ {
310+ return new JdbcTypeHandle (
311+ metadata .getColumnType (column ),
312+ Optional .ofNullable (metadata .getColumnTypeName (column )),
313+ Optional .of (metadata .getPrecision (column )),
314+ Optional .of (metadata .getScale (column )),
315+ Optional .empty (), // TODO support arrays
316+ Optional .of (metadata .isCaseSensitive (column ) ? CASE_SENSITIVE : CASE_INSENSITIVE ));
317+ }
318+
313319 @ Override
314320 public List <JdbcColumnHandle > getColumns (ConnectorSession session , SchemaTableName schemaTableName , RemoteTableName remoteTableName )
315321 {
@@ -325,13 +331,7 @@ public List<JdbcColumnHandle> getColumns(ConnectorSession session, SchemaTableNa
325331 }
326332 allColumns ++;
327333 String columnName = resultSet .getString ("COLUMN_NAME" );
328- JdbcTypeHandle typeHandle = new JdbcTypeHandle (
329- getInteger (resultSet , "DATA_TYPE" ).orElseThrow (() -> new IllegalStateException ("DATA_TYPE is null" )),
330- Optional .ofNullable (resultSet .getString ("TYPE_NAME" )),
331- getInteger (resultSet , "COLUMN_SIZE" ),
332- getInteger (resultSet , "DECIMAL_DIGITS" ),
333- Optional .empty (),
334- Optional .ofNullable (caseSensitivityMapping .get (columnName )));
334+ JdbcTypeHandle typeHandle = getColumnTypeHandle (resultSet , Optional .ofNullable (caseSensitivityMapping .get (columnName )));
335335 Optional <ColumnMapping > columnMapping = toColumnMapping (session , connection , typeHandle );
336336 log .debug ("Mapping data type of '%s' column '%s': %s mapped to %s" , schemaTableName , columnName , typeHandle , columnMapping );
337337 boolean nullable = (resultSet .getInt ("NULLABLE" ) != columnNoNulls );
@@ -462,15 +462,8 @@ protected RelationColumnsMetadata computeNext()
462462 }
463463
464464 String columnName = resultSet .getString ("COLUMN_NAME" );
465- JdbcTypeHandle typeHandle = new JdbcTypeHandle (
466- getInteger (resultSet , "DATA_TYPE" ).orElseThrow (() -> new IllegalStateException ("DATA_TYPE is null" )),
467- Optional .ofNullable (resultSet .getString ("TYPE_NAME" )),
468- getInteger (resultSet , "COLUMN_SIZE" ),
469- getInteger (resultSet , "DECIMAL_DIGITS" ),
470- // arrayDimensions
471- Optional .<Integer >empty (),
472- // This code doesn't do getCaseSensitivityForColumns. However, this does not impact the ColumnMetadata returned.
473- Optional .<CaseSensitivity >empty ());
465+ // This code doesn't do getCaseSensitivityForColumns. However, this does not impact the ColumnMetadata returned.
466+ JdbcTypeHandle typeHandle = getColumnTypeHandle (resultSet , Optional .<CaseSensitivity >empty ());
474467 boolean nullable = (resultSet .getInt ("NULLABLE" ) != columnNoNulls );
475468 Optional <String > comment = Optional .ofNullable (emptyToNull (resultSet .getString ("REMARKS" )));
476469 toColumnMapping (session , connection , typeHandle ).ifPresent (columnMapping -> {
@@ -527,6 +520,19 @@ private Optional<RelationColumnsMetadata> finishCurrentTable()
527520 }
528521 }
529522
523+ protected JdbcTypeHandle getColumnTypeHandle (ResultSet resultSet , Optional <CaseSensitivity > caseSensitivity )
524+ throws SQLException
525+ {
526+ return new JdbcTypeHandle (
527+ getInteger (resultSet , "DATA_TYPE" ).orElseThrow (() -> new IllegalStateException ("DATA_TYPE is null" )),
528+ Optional .ofNullable (resultSet .getString ("TYPE_NAME" )),
529+ getInteger (resultSet , "COLUMN_SIZE" ),
530+ getInteger (resultSet , "DECIMAL_DIGITS" ),
531+ // arrayDimensions
532+ Optional .<Integer >empty (),
533+ caseSensitivity );
534+ }
535+
530536 private static void cleanupSuppressing (Throwable inflight , CheckedRunnable cleanup )
531537 {
532538 try {
0 commit comments