apache/seatunnel · error · FileConnectorException

TABLE_SCHEMA_GET_FAILED

TABLE_SCHEMA_GET_FAILED

Error message

Get table schema from file [%s] failed

What it means

When no user-defined schema is given, BaseFileSource infers the schema by calling readStrategy.getSeaTunnelRowTypeInfo on the first discovered file. If that read/parse fails with FileConnectorException, the error is rethrown as TABLE_SCHEMA_GET_FAILED with a message naming the file that failed (BaseFileSource.java:139).

Source

Thrown at seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/BaseFileSource.java:139

                default:
                    // never got in there
                    throw new FileConnectorException(
                            CommonErrorCodeDeprecated.ILLEGAL_ARGUMENT,
                            "SeaTunnel does not supported this file format");
            }
        } else {
            if (filePaths.isEmpty()) {
                userDefinedCatalogTable = buildCatalogTableForEmptyPath(path, fileFormat);
            } else {
                try {
                    SeaTunnelRowType rowType =
                            readStrategy.getSeaTunnelRowTypeInfo(filePaths.get(0));
                    userDefinedCatalogTable = CatalogTableUtil.getCatalogTable("default", rowType);
                } catch (FileConnectorException e) {
                    String errorMsg =
                            String.format(
                                    "Get table schema from file [%s] failed", filePaths.get(0));
                    throw new FileConnectorException(
                            CommonErrorCodeDeprecated.TABLE_SCHEMA_GET_FAILED, errorMsg, e);
                }
            }
        }
        this.catalogTable =
                documentRoutingEnabled
                        ? MarkdownKnowledgeSyncMetadata.withMetadata(userDefinedCatalogTable)
                        : userDefinedCatalogTable;
    }

    private CatalogTable buildCatalogTableForEmptyPath(String path, FileFormat fileFormat) {
        if (fileFormat != FileFormat.BINARY
                && fileFormat != FileFormat.MARKDOWN
                && fileFormat != FileFormat.PDF) {
            // Preserve the legacy simple-text fallback for formats that still infer schema from
            // the first concrete file.
            return CatalogTableUtil.buildSimpleTextTable();
        }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Open and validate the named file: confirm it is readable and matches the declared file_format_type.
  2. Replace or remove the corrupt/empty first file from the directory.
  3. Add an explicit user-defined schema (for json/text/csv) to skip inference.
  4. If the file is fine, check connector/format-specific errors in the wrapped cause for the real parse failure.

Example fix

// before
file_format_type = json   # schema inferred from corrupt file
// after
file_format_type = json
schema = { fields { id bigint, name string } }
Defensive patterns

Strategy: try-catch

Validate before calling

// Confirm the first file parses before submitting
Path first = /* first file from listing */;
FileStatus st = fs.getFileStatus(first);
if (st.getLen() == 0) throw new IllegalStateException("First file is empty: " + first);

Try / catch

try {
    // initialize source
} catch (FileConnectorException e) {
    if (CommonErrorCodeDeprecated.TABLE_SCHEMA_GET_FAILED.equals(e.getErrorCode())) {
        // e.getCause() is the per-file FileConnectorException from getSeaTunnelRowTypeInfo
        log.error("Fix or remove the named file, or provide an explicit schema", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Automatic schema inference over the first file at filePaths.get(0) fails — e.g. corrupt or empty file, format mismatch (file is not actually the declared format), unreadable/permission-denied first file, or a parse error inside the format reader.

Common situations: First file in the directory is a partial write or wrong format; encoding issues in text/json files; parquet/ORC metadata corrupt; the first listed file was deleted between listing and read.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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