I have an issue when writing data to parquet files. I tried with different pyarrow versions (both 2.0 and 3.0) but the results look the same.
Examples of how my data looks like:
test_data = {
'dogs': [
{'dog': 'frankie'},
{'dog': 'ricky'}
]
}
other_test_data = {
'dogs': [
{'dog': 'rory'},
{'dog': 'marko'}
]
}
Then, I reformat them to look like this:
dog_data = {
'dogs': [
[{
'dog': 'frankie'
}, {
'dog': 'ricky'
}],
[{
'dog': 'rory'
}, {
'dog': 'marko'
}]
]
}
I define the schema:
dog_fields = [
pa.field('dog', pa.string(), nullable=True)
]
dog_schema = pa.schema([
('dogs', pa.list_(pa.struct(dog_fields)))
])
I convert them to pyarrow.Table using:
pq_table = pa.Table.from_pydict(mapping=dog_data, schema=dog_schema)
Finally, I write to a file:
pq.write_table(pq_table, 'dog_data.parquet')
What I see in the file is this, additional keys called list and item:
{
"dogs": {
"list": [{
"item": {
"dog": "frankie"
}
}, {
"item": {
"dog": "ricky"
}
}]
}
}
Can anyone explain please why the types of the data fields are added as keys to the data?
Is there a way around it?
EDIT
This is how I get the data with the list and item fields.
I install the package with brew install parquet-tools, and then run:
parquet-tools cat --json dog_data.parquet
The reason I chose to load the file like this is that I wanted to inspect what the contents are. The need came from the broken schema I was seeing when loading the data from parquet files to BigQuery. BigQuery doesn't understand the structure of the data and interprets the schema as following:
Annoying .list and .item things are added there.
