Skip to content

Conversation

@tusharchou
Copy link
Contributor

closes issue: Count rows as a metadata-only operation #1223

@jayceslesar
Copy link
Contributor

Question: Does it make sense to expose this as the __len__ dunder method because python? It would just return the self.count()

* added residual evaluator in plan files

* tested counts with positional deletes

* merged main

* implemented batch reader in count

* breaking integration test

* fixed integration test

* git pull main

* revert

* revert

* revert test_partitioning_key.py

* revert test_parser.py

* added residual evaluator in visitor

* deleted residual_evaluator.py

* removed test count from test_sql.py

* ignored lint type

* fixed lint

* working on plan_files

* type ignored

* make lint
@tusharchou
Copy link
Contributor Author

Hi @Fokko @kevinjqliu @gli-chris-hao ,

I have implemented these suggestions with my best understanding.

  • residual evaluator
  • positional deletes
  • batch processing of files larger than 512mb

It would be helpful to get fresh review

@Fokko Fokko changed the title Count rows as a metadata only operation Add ResidualVisitor to compute residuals Jan 13, 2025
* added residual evaluator in plan files

* tested counts with positional deletes

* merged main

* implemented batch reader in count

* breaking integration test

* fixed integration test

* git pull main

* revert

* revert

* revert test_partitioning_key.py

* revert test_parser.py

* added residual evaluator in visitor

* deleted residual_evaluator.py

* removed test count from test_sql.py

* ignored lint type

* fixed lint

* working on plan_files

* type ignored

* make lint

* explicit delete files len is zero

* residual eval only if manifest is true

* default residual is always true

* used projection schema

* refactored residual in plan files

* fixed lint issue with isnan

* simplified count if else conditions

* implemented refactoring comments on residual visitor
@tusharchou tusharchou requested a review from Fokko February 7, 2025 03:48
Fokko added a commit to Fokko/iceberg-python that referenced this pull request Feb 10, 2025
Sometime I'm seeing this:

```
ImportError while loading conftest '/home/runner/work/iceberg-python/iceberg-python/tests/conftest.py'.
tests/conftest.py:52: in <module>
    from pyiceberg.catalog import Catalog, load_catalog
pyiceberg/catalog/__init__.py:51: in <module>
    from pyiceberg.serializers import ToOutputFile
pyiceberg/serializers.py:25: in <module>
    from pyiceberg.table.metadata import TableMetadata, TableMetadataUtil
pyiceberg/table/__init__.py:65: in <module>
    from pyiceberg.io.pyarrow import ArrowScan, schema_to_pyarrow
pyiceberg/io/pyarrow.py:141: in <module>
    from pyiceberg.table.locations import load_location_provider
pyiceberg/table/locations.py:25: in <module>
    from pyiceberg.table import TableProperties
E   ImportError: cannot import name 'TableProperties' from partially initialized module 'pyiceberg.table' (most likely due to a circular import) (/home/runner/work/iceberg-python/iceberg-python/pyiceberg/table/__init__.py)
```

Also observed in: apache#1388

I prefer the imports at the top, but I think this is a small price
to pay to avoid having circular imports.
@Fokko Fokko mentioned this pull request Feb 10, 2025
kevinjqliu pushed a commit that referenced this pull request Feb 10, 2025
Sometime I'm seeing this:

```
ImportError while loading conftest '/home/runner/work/iceberg-python/iceberg-python/tests/conftest.py'.
tests/conftest.py:52: in <module>
    from pyiceberg.catalog import Catalog, load_catalog
pyiceberg/catalog/__init__.py:51: in <module>
    from pyiceberg.serializers import ToOutputFile
pyiceberg/serializers.py:25: in <module>
    from pyiceberg.table.metadata import TableMetadata, TableMetadataUtil
pyiceberg/table/__init__.py:65: in <module>
    from pyiceberg.io.pyarrow import ArrowScan, schema_to_pyarrow
pyiceberg/io/pyarrow.py:141: in <module>
    from pyiceberg.table.locations import load_location_provider
pyiceberg/table/locations.py:25: in <module>
    from pyiceberg.table import TableProperties
E   ImportError: cannot import name 'TableProperties' from partially initialized module 'pyiceberg.table' (most likely due to a circular import) (/home/runner/work/iceberg-python/iceberg-python/pyiceberg/table/__init__.py)
```

Also observed in: #1388

I prefer the imports at the top, but I think this is a small price to
pay to avoid having circular imports.
Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

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

def test_fokko(session_catalog):
    import pyarrow.parquet as pq

    df = pq.read_table("/Users/fokko.driesprong/Downloads/yellow_tripdata_2024-01.parquet")

    session_catalog.drop_table("default.taxis")
    tbl = session_catalog.create_table("default.taxis", schema=df.schema)
    with tbl.update_spec() as spec:
        spec.add_field("tpep_pickup_datetime", DayTransform())
    tbl.append(df)

    # tbl = session_catalog.load_table("default.taxis")

    pred = LessThan("tpep_pickup_datetime", datetime.datetime(2024, 1, 3, 12, 0, 0))

    cnt = tbl.scan(row_filter=pred).count()
    assert cnt == len(df.filter(expression_to_pyarrow(pred.bind(tbl.schema()))))

Works very well:

image

@Fokko Fokko merged commit 4ff1558 into apache:main Feb 11, 2025
7 checks passed
@Fokko
Copy link
Contributor

Fokko commented Feb 11, 2025

Thanks @tusharchou for working on this 🚀

kevinjqliu pushed a commit that referenced this pull request Feb 11, 2025
Seems not being used. Less is more!

Noticed this while reviewing
#1388
@mrutunjay-kinagi
Copy link

🚀

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

Successfully merging this pull request may close these issues.

6 participants