jacg opened a new issue, #39143:
URL: https://github.com/apache/arrow/issues/39143
### Describe the usage question you have. Please include as many useful
details as possible.
```python
import pyarrow as pa
import pyarrow.parquet as pq
# Want a table containing one field of lists, containing *NON-NULLABLE*
elements
element_type = pa.int32() ; element_field = pa.field("item" ,
element_type, False)
list_type = pa.list_(element_field); list_field = pa.field("items",
list_type, True)
# Build an array with the data to be placed in the table
array = pa.array(([0, 1], [2], [3,4,5], [6,7,8,9]), type=list_type)
schema = pa.schema([list_field])
table = pa.table([array], schema=schema); print(table)
# Try to write the table to parquet
print("PYTHON HAS NO TROUBLE WRITING THE TABLE")
with pa.OSFile("out-py.parquet", 'wb') as outfile:
pq.write_table(table, outfile)
print("TABLE WRITTEN")
```
```c++
#include <arrow/api.h>
#include <arrow/io/api.h>
#include <parquet/arrow/writer.h>
#include <iostream>
#include <memory>
#include <vector>
using namespace arrow;
#define DBG(stuff) std::cout << stuff << std::endl;
auto pool = default_memory_pool();
Status arrow_main() {
// Want a table containing one field of lists, containing *NON-NULLABLE*
elements
auto element_type = int32() ; auto element_field = field("item"
, element_type, false);
auto list_type = list(element_field); auto list_field =
field("items", list_type, true);
// Build an array with the data to be placed in the table
auto int_builder = std::make_shared<Int32Builder>(pool);
auto list_builder = ListBuilder{pool, int_builder};
std::vector<std::vector<int>> all_values{{0, 1}, {2}, {3,4,5}, {6,7,8,9}};
for (const auto& values : all_values) {
ARROW_RETURN_NOT_OK(list_builder. Append());
ARROW_RETURN_NOT_OK( int_builder->AppendValues(values));
}
ARROW_ASSIGN_OR_RAISE(auto array, list_builder.Finish());
auto schema = std::make_shared<Schema>(FieldVector{list_field});
auto table = Table::Make(schema, {array}); DBG(table -> ToString());
// Try to write the table to parquet
ARROW_ASSIGN_OR_RAISE(auto outfile,
io::FileOutputStream::Open("out-cpp.parquet"));
DBG("C++ CRASHES WHEN WRITING THE TABLE, BECAUSE OF INCONSISTENCY IN THE
NULLABILITY OF THE LIST ELEMENTS");
PARQUET_THROW_NOT_OK(parquet::arrow::WriteTable(*table, pool, outfile));
DBG("TABLE WRITTEN");
return Status::OK();
}
int main() {
auto status = arrow_main();
if (!status.ok()) {
std::cerr << status.ToString() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
```
### Component(s)
C++, Parquet
--
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]