prestodb/presto · error · TableNotFoundException

TABLE_NOT_FOUND

TABLE_NOT_FOUND

Error message

Table '%s' has no supported columns (all %s columns are not supported)

What it means

BaseJdbcClient.getColumns() builds the Presto column list for a JDBC table by filtering remote columns through toPrestoType(). If nothing survives the filter, it throws TableNotFoundException, because Presto cannot represent a table with zero readable columns.

Source

Thrown at presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BaseJdbcClient.java:266

                    JdbcTypeHandle typeHandle = new JdbcTypeHandle(
                            resultSet.getInt("DATA_TYPE"),
                            resultSet.getString("TYPE_NAME"),
                            resultSet.getInt("COLUMN_SIZE"),
                            resultSet.getInt("DECIMAL_DIGITS"));
                    Optional<ReadMapping> readMapping = toPrestoType(session, typeHandle);
                    // skip unsupported column types
                    if (readMapping.isPresent()) {
                        String columnName = resultSet.getString("COLUMN_NAME");
                        boolean nullable = columnNullable == resultSet.getInt("NULLABLE");
                        Optional<String> comment = Optional.ofNullable(emptyToNull(resultSet.getString("REMARKS")));
                        columns.add(new JdbcColumnHandle(connectorId, columnName, typeHandle, readMapping.get().getType(), nullable, comment));
                    }
                }
                if (columns.isEmpty()) {
                    // A table may have no supported columns. In rare cases (e.g. PostgreSQL) a table might have no columns at all.
                    // Throw an exception if the table has no supported columns.
                    // This can occur if all columns in the table are of unsupported types, or in rare cases, if the table has no columns at all.
                    throw new TableNotFoundException(
                            tableHandle.getSchemaTableName(),
                            format("Table '%s' has no supported columns (all %s columns are not supported)", tableHandle.getSchemaTableName(), allColumns));
                }
                return ImmutableList.copyOf(columns);
            }
        }
        catch (SQLException e) {
            throw new PrestoException(JDBC_ERROR, e);
        }
    }

    @Override
    public Optional<ReadMapping> toPrestoType(ConnectorSession session, JdbcTypeHandle typeHandle)
    {
        if (typeHandle.getJdbcType() == java.sql.Types.TIMESTAMP) {
            boolean legacyTimestamp = session.getSqlFunctionProperties().isLegacyTimestamp();
            return Optional.of(legacyTimestamp ? timestampReadMappingLegacy() : timestampReadMapping());
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Add a type mapping for the unsupported column type in the connector (override toPrestoType / add to the connector's type mapping) so at least one column is readable
  2. Verify the table name/schema mapping points at the intended table, not a differently-typed object
  3. Change the table on the remote database so it includes at least one column with a supported type
  4. If the table is truly empty/irrelevant, drop it or exclude it from schema discovery

Example fix

// before: table has only custom type columns -> TableNotFoundException
// after: add a mapping in the connector's JdbcClient subclass
@Override
protected Optional<Type> toPrestoType(ConnectorSession session, JdbcTypeHandle typeHandle) {
    Optional<Type> mapped = super.toPrestoType(session, typeHandle);
    if (mapped.isPresent()) return mapped;
    if (typeHandle.getJdbcTypeCode() == Types.OTHER) { // map custom type
        return Optional.of(VARCHAR);
    }
    return Optional.empty();
}
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on a JDBC table, confirm it exposes supported columns
ResultSet rs = dbMetaData.getColumns(catalog, schema, table, null);
int supported = 0;
while (rs.next()) {
    int jdbcType = rs.getInt("DATA_TYPE");
    if (isSupportedJdbcType(jdbcType)) supported++; // check connector's type mappings
}
if (supported == 0) throw new IllegalStateException("Table " + table + " has no supported columns");

Type guard

boolean hasSupportedColumns(ResultSetMetaData md) throws SQLException {
    for (int i = 1; i <= md.getColumnCount(); i++) {
        if (isSupportedJdbcType(md.getColumnType(i))) return true;
    }
    return false;
}

Try / catch

try {
    TableMetadata md = metadata.getTableMetadata(session, tableHandle);
} catch (TableNotFoundException e) {
    // zero readable columns: adjust mappings or skip this table
    log.warn("Skipping table with no supported columns: %s", e.getTableName());
}

Prevention

When it happens

Trigger: Calling getColumns/getTableMetadata on a table where every column's JDBC type maps to no Presto type (e.g. custom/proprietary SQL types), or a degenerate remote table that genuinely has no columns (rare, e.g. PostgreSQL).

Common situations: Querying tables containing only vendor-specific or geometry/custom typed columns with a connector dialect lacking a type mapping; accidentally pointing a table name mapping at the wrong object; empty tables created by other tools with zero columns.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/9eac2844c3a16066. Report an issue: GitHub.