Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for inability to read some parquet files (issue #816) #817

Merged
merged 13 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions data-processing-lib/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
argparse
mmh3
psutil
polars
touma-I marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
################################################################################

import hashlib
import io
import os
import string
import sys
Expand Down Expand Up @@ -144,8 +145,21 @@ def convert_binary_to_arrow(data: bytes, schema: pa.schema = None) -> pa.Table:
table = pq.read_table(reader, schema=schema)
return table
except Exception as e:
logger.error(f"Failed to convert byte array to arrow table, exception {e}. Skipping it")
return None
logger.warning(f"Could not convert bytes to pyarrow: {e}")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you, please put a comment here about why polars. Just copy the blur from the where you found this solution

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# We have seen this exception before when using pyarrow, but polars does not throw it.
# "Nested data conversions not implemented for chunked array outputs"
# See issue 816 https://github.com/IBM/data-prep-kit/issues/816.
logger.info(f"Attempting read of pyarrow Table using polars")
try:
import polars

df = polars.read_parquet(io.BytesIO(data))
table = df.to_arrow()
except Exception as e:
logger.warning(f"Could not convert bytes to pyarrow using polars: {e}. Skipping.")
touma-I marked this conversation as resolved.
Show resolved Hide resolved
table = None
return table

@staticmethod
def convert_arrow_to_binary(table: pa.Table) -> bytes:
Expand Down
4 changes: 4 additions & 0 deletions transforms/universal/filter/python/src/filter_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def __init__(self, config: dict):
self.logical_operator = config.get(filter_logical_operator_key, filter_logical_operator_default)
self.columns_to_drop = config.get(filter_columns_to_drop_key, filter_columns_to_drop_default)

# Temporarily here to test if this can allow use to process files that are required to be read by polars for mm
touma-I marked this conversation as resolved.
Show resolved Hide resolved
# If this works, we should add as a configurable or always enable (not sure of the downside of enabling this).
# duckdb.execute("SET arrow_large_buffer_size = true")

def transform(self, table: pa.Table, file_name: str = None) -> tuple[list[pa.Table], dict]:
"""
This implementation filters the input table using a SQL statement and
Expand Down
Loading