ryanmeowy opened a new issue, #13142: URL: https://github.com/apache/seatunnel/issues/13142
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22) and found no similar issues. ### What happened A File sink job fails on the first row with a `NullPointerException` when a `partition_by` column value is NULL. A nullable column is a legal schema, so a job that reads a nullable column and partitions by it dies at write time instead of writing the row, and it fails again on the same row after a restart. Nothing rejects this configuration up front: `FileSinkConfig` only checks that the partition columns exist in the sink columns, and the `partition_by` documentation does not say that NULL values are unsupported. The connector that shares this writer (Hive) is affected the same way. ### SeaTunnel Version dev (`a3743d7f52e9200a7733857ca813a0836bf66bba`) ### SeaTunnel Config ```hocon env { job.mode = "BATCH" parallelism = 1 } source { FakeSource { plugin_input = "fake" schema { fields { id = int c_null = "null" } } } } sink { LocalFile { plugin_input = "fake" path = "/tmp/out" file_format_type = "text" partition_by = ["c_null"] } } ``` `c_null = "null"` declares a field of SeaTunnel's `NULL` type (`SeaTunnelDataTypeConvertorUtil` maps `SqlType.NULL` to `BasicType.VOID_TYPE`), and `FakeSource` fills that type with null (`FakeDataGenerator#randomColumnValue`, `case NULL: return null`). ### Running Command ```shell ./bin/seatunnel.sh --config job.conf -e local ``` The stack trace below was produced with a small harness that drives the real `TextWriteStrategy` (hence `AbstractWriteStrategy`) with a mocked `FileSinkConfig`. The failure happens while computing the partition directory, before any file I/O, so the harness exercises exactly the same code path as the job above. ### Error Exception ``` java.lang.NullPointerException: Cannot invoke "Object.toString()" because "org.apache.seatunnel.api.table.type.SeaTunnelRow.getFields()[java.lang.Integer.intValue()]" is null at org.apache.seatunnel.connectors.seatunnel.file.sink.writer.AbstractWriteStrategy.generatorPartitionDir(AbstractWriteStrategy.java:529) ``` ### Mechanism `AbstractWriteStrategy.generatorPartitionDir(...)` builds the partition directory with `StringBuilder.append(Object)`, which already renders a null as the text `null`, and then calls `.toString()` on the same raw row field to collect the partition values that go into the commit info: ```java // non-expression branch stringBuilder .append(partitionFieldList.get(i)) .append("=") .append(seaTunnelRow.getFields()[partitionFieldsIndexInRow.get(i)]); // null -> "null" ... vals.add(seaTunnelRow.getFields()[partitionFieldsIndexInRow.get(i)].toString()); // NPE ``` The `partition_dir_expression` branch repeats the same `.toString()` twice (the `${vN}` substitution map and `vals`), so it fails the same way: ``` at ...AbstractWriteStrategy.generatorPartitionDir(AbstractWriteStrategy.java:538) ``` Every format writer reaches it through `SinkWriter.write(row) -> <Format>WriteStrategy.write(row) -> getOrCreateFilePathBeingWritten(row) -> generatorPartitionDir(row)`. ### Expected behavior Writing a row whose partition column is NULL must not throw. Since the directory component already renders the value as the text `null`, the committed partition values should use the same text. If NULL partitions are meant to be unsupported, the sink should reject the config up front with a clear error instead of failing the job on the first row. ### Zeta or Flink or Spark Version Zeta. The code path is inside the connector, so any engine reproduces it. ### Java or Scala Version JDK 21 (`21.0.12.1`) ### Are you willing to submit PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
