You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/08/23 09:32:43 UTC

[GitHub] [arrow] jorisvandenbossche commented on issue #10935: Readback KeyValueMetadata from Field and Schema in pyarrow from file written in C++

jorisvandenbossche commented on issue #10935:
URL: https://github.com/apache/arrow/issues/10935#issuecomment-903601675


   When doing this in pure python, the field metadata gets preserved:
   
   ```python
   import pyarrow as pa
   import pyarrow.parquet as pq
   
   f = pa.field("a", pa.int64(), metadata={'test': 'value'})
   schema = pa.schema([f])
   table = pa.table({'a': [1, 2, 3]}, schema=schema)
   
   pq.write_table(table, "test_field_metadata.parquet")
   table2 = pq.read_table("test_field_metadata.parquet")
   
   # original table has the field metadata
   >>> table.field('a').metadata
   {b'test': b'value'}
   
   # roundtripped table still has it
   >>> table2.field('a').metadata
   {b'test': b'value'}
   ```
   
   So there is something that is done differently in your C++ example. I think this has to do with the saving of the Arrow schema in the Parquet FileMetaData or not. This is an option in the `ArrowWriterProperties`. In C++ it is set to False by default:
   
   https://github.com/apache/arrow/blob/b220fea6900e964f8fab987e7dacd6ae38c15dca/cpp/src/parquet/properties.h#L661
   
   but in Python we always enable it:
   
   https://github.com/apache/arrow/blob/b220fea6900e964f8fab987e7dacd6ae38c15dca/python/pyarrow/_parquet.pyx#L1294-L1296
   
   You can pass ArrowWriterProperties to the `parquet::arrow::WriteTable` function to enable store_schema in your example.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org