jorisvandenbossche commented on code in PR #35860:
URL: https://github.com/apache/arrow/pull/35860#discussion_r1212752418
##########
python/pyarrow/tests/test_dataset.py:
##########
@@ -5172,6 +5172,62 @@ def test_dataset_partition_with_slash(tmpdir):
assert encoded_paths == file_paths
+def test_preserve_nullability_parquet(tempdir):
+ # GH-35730
+ schema_nullable = pa.schema([
+ pa.field("x", pa.int64(), nullable=False),
+ pa.field("y", pa.int64(), nullable=True)])
+
+ array = [[1, 2, 3], [None, 5, None]]
+
+ table = pa.Table.from_arrays(array,
+ schema=schema_nullable)
+
+ pq.write_to_dataset(table, tempdir/"nulltest1")
+ dataset = ds.dataset(tempdir/"nulltest1", format="parquet")
+ # nullability of field is preserved
+ assert dataset.to_table().schema.equals(schema_nullable)
+
+ pa.dataset.write_dataset(table, tempdir/"nulltest2", format="parquet")
Review Comment:
```suggestion
ds.write_dataset(table, tempdir/"nulltest2", format="parquet")
```
##########
python/pyarrow/tests/test_dataset.py:
##########
@@ -5172,6 +5172,62 @@ def test_dataset_partition_with_slash(tmpdir):
assert encoded_paths == file_paths
+def test_preserve_nullability_parquet(tempdir):
Review Comment:
```suggestion
def test_write_dataset_preserve_nullability_parquet(tempdir):
```
##########
python/pyarrow/tests/test_dataset.py:
##########
@@ -5172,6 +5172,62 @@ def test_dataset_partition_with_slash(tmpdir):
assert encoded_paths == file_paths
+def test_preserve_nullability_parquet(tempdir):
+ # GH-35730
+ schema_nullable = pa.schema([
+ pa.field("x", pa.int64(), nullable=False),
+ pa.field("y", pa.int64(), nullable=True)])
+
+ array = [[1, 2, 3], [None, 5, None]]
+
+ table = pa.Table.from_arrays(array,
+ schema=schema_nullable)
+
+ pq.write_to_dataset(table, tempdir/"nulltest1")
+ dataset = ds.dataset(tempdir/"nulltest1", format="parquet")
+ # nullability of field is preserved
+ assert dataset.to_table().schema.equals(schema_nullable)
+
+ pa.dataset.write_dataset(table, tempdir/"nulltest2", format="parquet")
+ dataset = ds.dataset(tempdir/"nulltest2", format="parquet")
+ assert dataset.to_table().schema.equals(schema_nullable)
+
+ pa.dataset.write_dataset([table, table], tempdir/"nulltest3",
format="parquet")
Review Comment:
```suggestion
ds.write_dataset([table, table], tempdir/"nulltest3", format="parquet")
```
##########
cpp/src/arrow/dataset/file_base.cc:
##########
@@ -475,16 +475,38 @@ Result<acero::ExecNode*> MakeWriteNode(acero::ExecPlan*
plan,
const WriteNodeOptions write_node_options =
checked_cast<const WriteNodeOptions&>(options);
- const std::shared_ptr<const KeyValueMetadata>& custom_metadata =
- write_node_options.custom_metadata;
+ const std::shared_ptr<Schema>& custom_schema =
write_node_options.custom_schema;
const FileSystemDatasetWriteOptions& write_options =
write_node_options.write_options;
+ const std::shared_ptr<Schema>& input_schema = inputs[0]->output_schema();
+
+ if (custom_schema != nullptr) {
+ if (custom_schema->num_fields() != input_schema->num_fields()) {
+ return Status::Invalid(
+ "The provided custom_schema did not have the same number of fields
as the "
+ "data. The custom schema can only be used to add metadata /
nullability to "
+ "fields and cannot change the type or number of fields.");
+ }
+ for (int field_idx = 0; field_idx < input_schema->num_fields();
field_idx++) {
+ if (!input_schema->field(field_idx)->type()->Equals(
+ custom_schema->field(field_idx)->type())) {
Review Comment:
Should we also test that the names of the fields are equal?
--
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]