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

Dictionary encode collection and type #45

Open
kylebarron opened this issue Apr 23, 2024 · 2 comments
Open

Dictionary encode collection and type #45

kylebarron opened this issue Apr 23, 2024 · 2 comments

Comments

@kylebarron
Copy link
Collaborator

Collection ID should always be a single value per Parquet table/dataset, so we should ensure we're dictionary-encoding it to save memory.

type: "Feature" can be removed from the table, but if we dictionary encode it, then it's barely using any memory.

@TomAugspurger
Copy link
Collaborator

Do we need to do anything explicitly here?

>>> import requests
>>> import stac_geoparquet.to_arrow
>>> import stac_geoparquet.from_arrow
>>> import stac_geoparquet.to_parquet
>>> import pyarrow.parquet

>>> items = requests.get("https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items").json()["features"]
>>> table = stac_geoparquet.to_arrow.parse_stac_items_to_arrow(items)
>>> stac_geoparquet.to_parquet.to_parquet(table, "items.parquet")

and then

In [68]: pf = pyarrow.parquet.ParquetFile("items.parquet")

In [69]: rg = pf.metadata.row_group(0)

In [70]: [x for x in rg.to_dict()["columns"] if "collection" in x["path_in_schema"]]
Out[70]:
[{'file_offset': 87251,
  'file_path': '',
  'physical_type': 'BYTE_ARRAY',
  'num_values': 10,
  'path_in_schema': 'collection',
  'is_stats_set': True,
  'statistics': {'has_min_max': True,
   'min': 'sentinel-2-l2a',
   'max': 'sentinel-2-l2a',
   'null_count': 0,
   'distinct_count': None,
   'num_values': 10,
   'physical_type': 'BYTE_ARRAY'},
  'compression': 'SNAPPY',
  'encodings': ('PLAIN', 'RLE', 'RLE_DICTIONARY'),
  'has_dictionary_page': True,
  'dictionary_page_offset': 87153,
  'data_page_offset': 87187,
  'total_compressed_size': 98,
  'total_uncompressed_size': 94}]

Does the presence of RLE_DICTIONARY in `encodings mean we're good?

@kylebarron
Copy link
Collaborator Author

I was suggesting to dictionary encode it in memory in the Arrow type; the Parquet writer will automatically try to dictionary encode it in the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants