Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cpp/src/parquet/arrow/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ class FileWriterImpl : public FileWriter {
chunk_size = this->properties().max_row_group_length();
}

// Cannot write with duplicate field names
std::unordered_set<std::string> s;
for (auto field : table.fields()) {
if (s.count(field->name()) > 0) {
return Status::Invalid("Cannot write parquet table with duplicate field names: ", field->name());
}
s.insert(field->name());
}

auto WriteRowGroup = [&](int64_t offset, int64_t size) {
RETURN_NOT_OK(NewRowGroup(size));
for (int i = 0; i < table.num_columns(); i++) {
Expand Down
11 changes: 11 additions & 0 deletions python/pyarrow/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4182,6 +4182,17 @@ def file_visitor(written_file):
assert pathlib.Path(visited_path) in expected_paths


def test_write_table_duplicate_fields(tempdir):
table = pa.table([
pa.array(range(5)),
pa.array(range(5)),
], names=['a', 'a'])

match = "Cannot write parquet table with duplicate field names: a"
with pytest.raises(pa.ArrowInvalid, match=match):
pq.write_table(table, tempdir / 'file.parquet')


def test_write_table_multiple_fragments(tempdir):
table = pa.table([
pa.array(range(10)), pa.array(np.random.randn(10)),
Expand Down