{"record":{"id":"a5a033cd69c7c3dc","repo":"apache/seatunnel","slug":"cannot-determine-source-type-for-bytes-field-defa","errorCode":null,"errorMessage":"Cannot determine source type for BYTES field, defaulting to VARBINARY. If this causes errors, please provide databaseTableSchema.","messagePattern":"Cannot determine source type for BYTES field, defaulting to VARBINARY\\. If this causes errors, please provide databaseTableSchema\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlserverJdbcRowConverter.java","lineNumber":118,"sourceCode":"    /**\n     * Resolves the appropriate JDBC type for SQL Server binary columns when the value is null.\n     *\n     * <p>SQL Server has multiple binary types, each mapping to a different JDBC type:\n     *\n     * <ul>\n     *   <li>IMAGE → LONGVARBINARY (legacy large binary type)\n     *   <li>VARBINARY(*) → VARBINARY\n     *   <li>VARBINARY(MAX) → VARBINARY\n     *   <li>BINARY(*) → BINARY (fixed-length)\n     *   <li>other → VARBINARY\n     * </ul>\n     *\n     * @param sourceType the SQL Server column type (e.g., \"IMAGE\", \"VARBINARY\", \"BINARY\")\n     * @return the JDBC type constant from {@link java.sql.Types}\n     */\n    private int resolveSqlServerBytesNullType(@Nullable String sourceType) {\n        if (sourceType == null) {\n            log.warn(\n                    \"Cannot determine source type for BYTES field, defaulting to VARBINARY. \"\n                            + \"If this causes errors, please provide databaseTableSchema.\");\n            return java.sql.Types.VARBINARY;\n        }\n\n        if (SqlServerTypeConverter.SQLSERVER_IMAGE.equals(sourceType)) {\n            return java.sql.Types.LONGVARBINARY;\n        }\n        if (sourceType.startsWith(SqlServerTypeConverter.SQLSERVER_VARBINARY)) {\n            return java.sql.Types.VARBINARY;\n        }\n        if (sourceType.startsWith(SqlServerTypeConverter.SQLSERVER_BINARY)) {\n            return java.sql.Types.BINARY;\n        }\n\n        // Unknown type, log warning and use conservative LONGVARBINARY\n        log.warn(\n                \"Unknown SQLServer binary type: {}, defaulting to LONGVARBINARY. \"","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlserverJdbcRowConverter.java#L100-L136","documentation":"When binding a NULL for a BYTES field, the JDBC row converter needs the SQL Server column type (IMAGE vs VARBINARY/BINARY) to pick the right java.sql.Types null marker. If the source type metadata is null (no databaseTableSchema provided), it logs a warning and defaults to Types.VARBINARY, which may fail on IMAGE columns.","triggerScenarios":"resolveSqlServerBytesNullType is invoked from setNullToStatementByDataType with sourceType == null — i.e., the sink writes NULL bytes without the source column's type string, typically when databaseTableSchema is not configured.","commonSituations":"SQL Server CDC/sync jobs writing NULL image/blob columns without schema info; upgrading pipelines where null typing previously worked because the target column was VARBINARY.","solutions":["Configure databaseTableSchema so the connector knows the actual column type (IMAGE/VARBINARY/BINARY).","If the target column is already VARBINARY, ignore the warning — the default is correct.","Alter the SQL Server column to VARBINARY(MAX) (IMAGE is deprecated) so the VARBINARY null binding always works.","Patch resolveSqlServerBytesNullType to pass a specific type when known from table metadata."],"exampleFix":"// before (no schema info)\nsource {\n  Jdbc { url = \"jdbc:sqlserver://...\" }\n}\n// after\nsource {\n  Jdbc {\n    url = \"jdbc:sqlserver://...\"\n    databaseTableSchema = \"dbo\"\n    databaseTableName = \"my_table\"\n  }\n}","handlingStrategy":"fallback","validationCode":"// Ensure schema metadata is configured so BYTES nulls bind with the right type:\nassert config.hasPath(\"databaseTableSchema\") : \"databaseTableSchema required when syncing image/varbinary columns\";","typeGuard":"int bytesNullType(String sourceType) { return \"IMAGE\".equals(sourceType) ? java.sql.Types.BINARY : java.sql.Types.VARBINARY; }","tryCatchPattern":"try { ps.setNull(i, resolveSqlServerBytesNullType(sourceType)); } catch (SQLException e) { log.warn(\"Null bind failed for BYTES column; consider VARBINARY(MAX) instead of IMAGE\", e); throw e; }","preventionTips":["Always set databaseTableSchema/databaseTableName when tables contain binary columns","Migrate IMAGE columns to VARBINARY(MAX) — IMAGE is deprecated","Test pipelines with NULL blob values before production runs"],"tags":["jdbc","sqlserver","bytes","null-binding"],"backgroundTag":"incompatible-source-type","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}