apache/seatunnel · warning

Could not query table schema, using inferred schema from dat

Error message

Could not query table schema, using inferred schema from data

What it means

DatabendSinkWriter (initializePreparedStatement, called from processTraditionalRow) first tries queryTableSchema() to build the INSERT SQL from the real Databend table schema. When the query returns null it logs 'Could not query table schema, using inferred schema from data' at WARN and falls back to inferring the row type from the first row. Inferred types may mismatch the actual table columns and cause later insert failures or data type coercion issues.

Source

Thrown at seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/sink/DatabendSinkWriter.java:541

            throw new RuntimeException("Failed to convert row to JSON", e);
        }
    }

    private void initializePreparedStatement(SeaTunnelRow row) throws SQLException {
        log.info("Initializing PreparedStatement based on row data");

        // use sinkTablePath to get Schema
        String database = sinkTablePath.getDatabaseName();
        String table = sinkTablePath.getTableName();

        log.info("Querying target table schema for {}.{}", database, table);
        SeaTunnelRowType actualTableSchema = queryTableSchema(database, table);

        if (actualTableSchema != null) {
            log.info("Using actual table schema: {}", actualTableSchema);
            this.insertSql = generateInsertSql(database, table, actualTableSchema);
        } else {
            log.warn("Could not query table schema, using inferred schema from data");
            SeaTunnelRowType inferredRowType = inferRowTypeFromRow(row);
            log.info("Inferred row type from data: {}", inferredRowType);
            this.insertSql = generateInsertSql(database, table, inferredRowType);
        }

        log.info("Generated insert SQL from schema: {}", insertSql);

        // create PreparedStatement
        this.preparedStatement = connection.prepareStatement(insertSql);
        this.preparedStatement.setQueryTimeout(executeTimeoutSec);
        log.info("PreparedStatement initialized successfully");
    }

    private SeaTunnelRowType queryTableSchema(String database, String table) {
        try {
            connection.createStatement().execute("USE " + database);
            String describeSQL = String.format("DESCRIBE %s.%s", database, table);
            log.info("Executing describe table SQL: {}", describeSQL);

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Ensure the target Databend table exists and the sink user can query its schema before running the job.
  2. Verify database/table names (including case) in the sink config match the actual Databend table.
  3. Check connectivity/credentials used by queryTableSchema(); the WARN is a fallback, so fix its null cause.
  4. If the fallback must be used, confirm the inferred types from the first row actually match the table's column types.
Defensive patterns

Strategy: fallback

Validate before calling

// pre-check the target table exists and is describable
// in Databend: DESCRIBE TABLE my_db.my_table;
// run it with the sink user before starting the job

Try / catch

try {
    schema = queryTableSchema(database, table);
} catch (Exception e) {
    log.warn("schema query failed, falling back to inferred schema", e);
    schema = null;
}
// if schema == null, verify inferred types against expected column types

Prevention

When it happens

Trigger: queryTableSchema() returns null because the Databend connection cannot describe the table: table does not exist yet, insufficient privileges to run the schema query, database/table name case mismatch, or transient connectivity failure.

Common situations: Sink writes to a table that has not been created; Databend user lacks permission to query metadata; catalog/database configured incorrectly; case-sensitivity mismatch between configured table name and actual table.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/008bf026204d46b4. Report an issue: GitHub.