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

Add ResidualVisitor to compute residuals #1388

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
731542e
Create test_scan_count.py
tusharchou Nov 28, 2024
c6c971e
moved test_scan_count.py to tests
tusharchou Nov 28, 2024
da18837
implemented count in data scan
tusharchou Nov 28, 2024
3104a2f
tested table scan count in test_sql catalog
tusharchou Nov 28, 2024
c2740ea
refactoring
tusharchou Nov 28, 2024
90bca84
make lint
tusharchou Nov 28, 2024
f7202b9
Merge pull request #1 from tusharchou/gh-1223-count-rows-metadata-onl…
tusharchou Nov 28, 2024
c7205b3
Merge branch 'apache:main' into main
tusharchou Dec 2, 2024
09f9c10
Merge branch 'apache:main' into main
tusharchou Dec 11, 2024
1e9da22
Merge branch 'apache:main' into main
tusharchou Dec 18, 2024
3ab20d4
Merge branch 'apache:main' into main
tusharchou Dec 21, 2024
091c0af
implemeted residual_evaluator.py with tests
tusharchou Dec 24, 2024
3cd797d
added license
tusharchou Dec 24, 2024
6b0924e
fixed lint
tusharchou Dec 24, 2024
96cb4e9
fixed lint errors
tusharchou Dec 24, 2024
212c83b
Merge pull request #3 from tusharchou/gh-1223-metadata-only-row-count
tusharchou Dec 24, 2024
8bc65fa
Merge branch 'apache:main' into main
tusharchou Dec 30, 2024
8bb039f
Gh 1223 metadata only row count (#4)
tusharchou Dec 31, 2024
0019f92
Merge branch 'apache:main' into main
tusharchou Jan 4, 2025
a372a93
Merge branch 'apache:main' into main
tusharchou Jan 6, 2025
ab4c000
Gh 1223 metadata only row count (#5)
tusharchou Jan 6, 2025
f5a871b
Merge branch 'apache:main' into main
tusharchou Jan 18, 2025
8262780
Merge branch 'apache:main' into main
tusharchou Jan 27, 2025
899beb1
Merge branch 'apache:main' into main
tusharchou Jan 31, 2025
2575cb8
Resolving review comments (#6)
tusharchou Jan 31, 2025
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
10 changes: 10 additions & 0 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,9 @@ def filter(self: S, expr: Union[str, BooleanExpression]) -> S:
def with_case_sensitive(self: S, case_sensitive: bool = True) -> S:
return self.update(case_sensitive=case_sensitive)

@abstractmethod
def count(self) -> int: ...


class ScanTask(ABC):
pass
Expand Down Expand Up @@ -1493,6 +1496,13 @@ def to_ray(self) -> ray.data.dataset.Dataset:

return ray.data.from_arrow(self.to_arrow())

def count(self) -> int:
res = 0
tasks = self.plan_files()
tusharchou marked this conversation as resolved.
Show resolved Hide resolved
for task in tasks:
res += task.file.record_count
return res
tusharchou marked this conversation as resolved.
Show resolved Hide resolved


@dataclass(frozen=True)
class WriteTask:
Expand Down
52 changes: 52 additions & 0 deletions tests/catalog/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,58 @@ def test_append_table(catalog: SqlCatalog, table_schema_simple: Schema, table_id
assert df == table.scan().to_arrow()


@pytest.mark.parametrize(
"catalog",
[
lazy_fixture("catalog_memory"),
lazy_fixture("catalog_sqlite"),
lazy_fixture("catalog_sqlite_without_rowcount"),
lazy_fixture("catalog_sqlite_fsspec"),
],
)
@pytest.mark.parametrize(
"table_identifier",
[
lazy_fixture("random_table_identifier"),
lazy_fixture("random_hierarchical_identifier"),
lazy_fixture("random_table_identifier_with_catalog"),
],
)
def test_count_table(catalog: SqlCatalog, table_schema_simple: Schema, table_identifier: Identifier) -> None:
table_identifier_nocatalog = catalog._identifier_to_tuple_without_catalog(table_identifier)
namespace = Catalog.namespace_from(table_identifier_nocatalog)
catalog.create_namespace(namespace)
table = catalog.create_table(table_identifier, table_schema_simple)

df = pa.Table.from_pydict(
{
"foo": ["a"],
"bar": [1],
"baz": [True],
},
schema=schema_to_pyarrow(table_schema_simple),
)

table.append(df)

# new snapshot is written in APPEND mode
assert len(table.metadata.snapshots) == 1
assert table.metadata.snapshots[0].snapshot_id == table.metadata.current_snapshot_id
assert table.metadata.snapshots[0].parent_snapshot_id is None
assert table.metadata.snapshots[0].sequence_number == 1
assert table.metadata.snapshots[0].summary is not None
assert table.metadata.snapshots[0].summary.operation == Operation.APPEND
assert table.metadata.snapshots[0].summary["added-data-files"] == "1"
assert table.metadata.snapshots[0].summary["added-records"] == "1"
assert table.metadata.snapshots[0].summary["total-data-files"] == "1"
assert table.metadata.snapshots[0].summary["total-records"] == "1"
assert len(table.metadata.metadata_log) == 1

# read back the data
assert df == table.scan().to_arrow()
assert len(table.scan().to_arrow()) == table.scan().count()


@pytest.mark.parametrize(
"catalog",
[
Expand Down