You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python] Reading parquet file with map without annotated map keys #37389
Describe the bug, including details regarding any error messages, version, and platform.
Hello,
While reading a generated parquet file from AWS Athena (Trino engine behind) we have the following error:
File "pypoetry/virtualenvs/lib/python3.10/site-packages/pyarrow/parquet/core.py", line 308, in __init__
self.reader.open(
File "pyarrow/_parquet.pyx", line 1239, in pyarrow._parquet.ParquetReader.open
File "pyarrow/error.pxi", line 100, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Map keys must be annotated as required.
(parquet-tools give the same error if you want to reproduce)
We don't have this error will reading it with spark. Is it Spark that's being lax with parquet spec? Or an issue with Arrow?
Athena Query if you want to reproduce
UNLOAD (
SELECT ARRAY [
MAP(ARRAY['key_1', 'key_2'], ARRAY['value_1', 'value_2']),
MAP(ARRAY['key_1', 'key_2'], ARRAY['value_2', 'value_2']),
MAP(ARRAY['key_1', 'key_2'], ARRAY['value_3', 'value_2'])
] AS array_map
)
TO 'path'
WITH (format ='PARQUET')
Would you mind print the schema using Python SDK? Personally I think it's a schema problem. Spark cannot produce "nonnull" field, but maybe we expect the map-key with nonnull.
Technically this can be fixed by postponing the exception until a real null map key data has been caught. But personally I am not in favor of this kind of non-standard fix.
@wgtmac my argument for the change is -
the data is precious and its source might be never available again. The code is secondary. Therefore the code must make every effort to read the data that is imperfect. Otherwise it is like refusing to read a good book because the table of contents has a typo :)
Depending on where the error is thrown it might be possible to provide an override arrow schema that uses a list of key-value pairs, it seems like this approach or delaying error until null might be best
While I agree data is precious maintaining loop holes for technically invalid files has a cost as well.
Technically this can be fixed by postponing the exception until a real null map key data has been caught.
That sounds like quite a bit of additional maintenance. Also, I'm not sure delaying the error until actual nulls are read is really user-friendly...
I think whether we can regard that as a List<Struct<Key, Value>> and Cast to a Map
This has the same problem of additional maintenance and delaying the error until much later.
This might not be an immediate solution, but perhaps a third-party utility could be created to "fix" non-conforming Parquet files by rewriting them? It could address a growing number of non-conformity issues while not forcing mainline implementations to reimplement compatibility hacks.
@pitrou 3rd party utility will work for our case but I was not able to find one so far. Most of the parquet-manipulating projects I saw are using pyarrow :)
Activity
mapleFU commentedon Aug 25, 2023
Would you mind print the schema using Python SDK? Personally I think it's a schema problem. Spark cannot produce "nonnull" field, but maybe we expect the map-key with nonnull.
Max0u commentedon Aug 25, 2023
Sure here the schema produce by pyspark:
I assume you meant pyspark by Python SDK, but let me know if I'm wrong, and I'll be more than pleased to help you!
mapleFU commentedon Aug 26, 2023
Emmm I found that:
Which the key is optional. cc @wgtmac do we need to support file like this?
wgtmac commentedon Aug 29, 2023
IMO, this is something that the writer should fix. optional map key is ill-formed as per the spec.
negrusti commentedon Aug 31, 2023
@wgtmac is there a downside of supporting this as we are encountering such files in the wild and can't influence the writer in any way?
wgtmac commentedon Aug 31, 2023
Technically this can be fixed by postponing the exception until a real null map key data has been caught. But personally I am not in favor of this kind of non-standard fix.
WDYT? @pitrou @emkornfield
mapleFU commentedon Aug 31, 2023
Maybe we can find the version of PySpark and found how other user solve this problem, since PySpark is so widely used?
wgtmac commentedon Aug 31, 2023
BTW, is there any open issue in the Trino community? @negrusti
negrusti commentedon Aug 31, 2023
@wgtmac we are having this problem with this dataset:
https://github.com/OvertureMaps/data/tree/main
Opened an issue there OvertureMaps/data#61
wgtmac commentedon Aug 31, 2023
cc @theosib-amazon Not sure if you are still working at AWS Athena.
negrusti commentedon Aug 31, 2023
@wgtmac my argument for the change is -
the data is precious and its source might be never available again. The code is secondary. Therefore the code must make every effort to read the data that is imperfect. Otherwise it is like refusing to read a good book because the table of contents has a typo :)
emkornfield commentedon Sep 1, 2023
Depending on where the error is thrown it might be possible to provide an override arrow schema that uses a list of key-value pairs, it seems like this approach or delaying error until null might be best
While I agree data is precious maintaining loop holes for technically invalid files has a cost as well.
mapleFU commentedon Sep 1, 2023
If already have some solving methods we can use that, otherwise I think whether we can regard that as a
List<Struct<Key, Value>>andCastto a Map?Since maintaining read a invalid schema from parquet is really dirty.
pitrou commentedon Sep 4, 2023
That sounds like quite a bit of additional maintenance. Also, I'm not sure delaying the error until actual nulls are read is really user-friendly...
This has the same problem of additional maintenance and delaying the error until much later.
This might not be an immediate solution, but perhaps a third-party utility could be created to "fix" non-conforming Parquet files by rewriting them? It could address a growing number of non-conformity issues while not forcing mainline implementations to reimplement compatibility hacks.
negrusti commentedon Sep 4, 2023
@pitrou 3rd party utility will work for our case but I was not able to find one so far. Most of the parquet-manipulating projects I saw are using pyarrow :)
pitrou commentedon Sep 4, 2023
Yeah, I know. I was suggesting that perhaps someone would want to work on such a project :-)
wgtmac commentedon Sep 4, 2023
It seems that these rewriting work can be done via Apache Spark?
negrusti commentedon Sep 4, 2023
@wgtmac did not find a way to manipulate the column metadata with Spark, do you know one?
wgtmac commentedon Sep 4, 2023
Could you please provide one "corrupted" file?
negrusti commentedon Sep 4, 2023
@wgtmac
aws s3 cp --no-sign-request s3://overturemaps-us-west-2/release/2023-07-26-alpha.0/theme=transportation/type=connector/20230726_134827_00007_dg6b6_01b086fc-f35b-487c-8d4e-5cdbbdc1785d test.parquet
wgtmac commentedon Sep 6, 2023
@negrusti Sorry for the late reply. I have tried to use Apache Spark to rewrite the file and it seems worked.
The original schema using parquet-cli from parquet-mr
The schema in the rewritten file is
negrusti commentedon Sep 6, 2023
@wgtmac wow thanks a lot for this - I didn't realize that I just need to write the data without applying any specific modifications!
wgtmac commentedon Sep 7, 2023
If this works for you, feel free to close this issue or let me know if anything wrong happens. @negrusti @Max0u