@Override public List<JdbcColumnHandle> getColumns(ConnectorSession session, JdbcTableHandle tableHandle) { try (Connection connection = connectionFactory.openConnection()) { try (ResultSet resultSet = getColumns(tableHandle, connection.getMetaData())) { List<JdbcColumnHandle> columns = new ArrayList<>(); while (resultSet.next()) { JdbcTypeHandle typeHandle = new JdbcTypeHandle( resultSet.getInt("DATA_TYPE"), resultSet.getInt("COLUMN_SIZE"), resultSet.getInt("DECIMAL_DIGITS")); Optional<ReadMapping> columnMapping = toPrestoType(session, typeHandle); // skip unsupported column types if (columnMapping.isPresent()) { String columnName = resultSet.getString("COLUMN_NAME"); columns.add(new JdbcColumnHandle(connectorId, columnName, typeHandle, columnMapping.get().getType())); } } if (columns.isEmpty()) { // In rare cases (e.g. PostgreSQL) a table might have no columns. throw new TableNotFoundException(tableHandle.getSchemaTableName()); } return ImmutableList.copyOf(columns); } } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
@Override public List<JdbcColumnHandle> getColumns(JdbcTableHandle tableHandle) { try (Connection connection = driver.connect(connectionUrl, connectionProperties)) { try (ResultSet resultSet = getColumns(tableHandle, connection.getMetaData())) { List<JdbcColumnHandle> columns = new ArrayList<>(); boolean found = false; while (resultSet.next()) { found = true; Type columnType = toPrestoType(resultSet.getInt("DATA_TYPE")); // skip unsupported column types if (columnType != null) { String columnName = resultSet.getString("COLUMN_NAME"); columns.add(new JdbcColumnHandle(connectorId, columnName, columnType)); } } if (!found) { throw new TableNotFoundException(tableHandle.getSchemaTableName()); } if (columns.isEmpty()) { throw new PrestoException(NOT_SUPPORTED, "Table has no supported column types: " + tableHandle.getSchemaTableName()); } return ImmutableList.copyOf(columns); } } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }