You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "Fokko (via GitHub)" <gi...@apache.org> on 2023/02/19 20:57:26 UTC

[GitHub] [iceberg] Fokko commented on issue #6647: Issue reading iceberg tables written by Athena with pyiceberg

Fokko commented on issue #6647:
URL: https://github.com/apache/iceberg/issues/6647#issuecomment-1436091339

   @rdblue that's correct.
   
   I took a shortcut and get the schema from the metadata. That should still be the preferred way because it is probably faster (Pydantic without any GIL just going through the JSON document).
   
   However, the fields in Parquet also have metadata, and those contain the `field_id`:
   ```python
   ➜  Desktop python3
   Python 3.10.10 (main, Feb  8 2023, 05:34:50) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
   Type "help", "copyright", "credits" or "license" for more information.
   >>> from pyarrow.fs import LocalFileSystem
   >>> import pyarrow.parquet as pq
   >>> 
   >>> fs = LocalFileSystem()
   >>> 
   >>> path = "/Users/fokkodriesprong/Desktop/00003-4-5e18fe8b-532b-42ec-bdb9-0c7ba7078155-00001.parquet"
   >>> 
   >>> with fs.open_input_file(path) as fout:
   ...     parquet_schema = pq.read_schema(fout)
   ... 
   >>> 
   >>> parquet_schema
   VendorID: int64
     -- field metadata --
     PARQUET:field_id: '1'
   tpep_pickup_datetime: timestamp[us, tz=UTC]
     -- field metadata --
     PARQUET:field_id: '2'
   tpep_dropoff_datetime: timestamp[us, tz=UTC]
     -- field metadata --
     PARQUET:field_id: '3'
   passenger_count: double
     -- field metadata --
     PARQUET:field_id: '4'
   trip_distance: double
     -- field metadata --
     PARQUET:field_id: '5'
   RatecodeID: double
     -- field metadata --
     PARQUET:field_id: '6'
   store_and_fwd_flag: string
     -- field metadata --
     PARQUET:field_id: '7'
   PULocationID: int64
     -- field metadata --
     PARQUET:field_id: '8'
   DOLocationID: int64
     -- field metadata --
     PARQUET:field_id: '9'
   payment_type: int64
     -- field metadata --
     PARQUET:field_id: '10'
   fare_amount: double
     -- field metadata --
     PARQUET:field_id: '11'
   extra: double
     -- field metadata --
     PARQUET:field_id: '12'
   mta_tax: double
     -- field metadata --
     PARQUET:field_id: '13'
   tip_amount: double
     -- field metadata --
     PARQUET:field_id: '14'
   tolls_amount: double
     -- field metadata --
     PARQUET:field_id: '15'
   improvement_surcharge: double
     -- field metadata --
     PARQUET:field_id: '16'
   total_amount: double
     -- field metadata --
     PARQUET:field_id: '17'
   congestion_surcharge: double
     -- field metadata --
     PARQUET:field_id: '18'
   airport_fee: double
     -- field metadata --
     PARQUET:field_id: '19'
   -- schema metadata --
   iceberg.schema: '{"type":"struct","schema-id":0,"fields":[{"id":1,"name":' + 1236
   ```
   
   @amogh-jahagirdar  We could implement a visitor to convert this Arrow schema  back to an Iceberg one with the correct IDs.


-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org