tub commented on code in PR #7436: URL: https://github.com/apache/paimon/pull/7436#discussion_r2941798567
########## paimon-python/pypaimon/acceptance/incremental_diff_acceptance_test.py: ########## @@ -0,0 +1,322 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ +""" +Acceptance tests for IncrementalDiffScanner. + +These tests verify that the diff approach (reading 2 base_manifest_lists) +returns the same data as the delta approach (reading N delta_manifest_lists). + +Uses real file I/O with local temp filesystem. +""" + +import asyncio +import os +import shutil +import tempfile +import unittest + +import pyarrow as pa + +from pypaimon import CatalogFactory, Schema +from pypaimon.manifest.manifest_file_manager import ManifestFileManager +from pypaimon.manifest.manifest_list_manager import ManifestListManager +from pypaimon.read.scanner.append_table_split_generator import \ + AppendTableSplitGenerator +from pypaimon.read.scanner.incremental_diff_scanner import \ + IncrementalDiffScanner +from pypaimon.read.streaming_table_scan import AsyncStreamingTableScan +from pypaimon.snapshot.snapshot_manager import SnapshotManager + + +class IncrementalDiffAcceptanceTest(unittest.TestCase): + """Acceptance tests for diff vs delta equivalence with real data.""" + + @classmethod + def setUpClass(cls): + cls.tempdir = tempfile.mkdtemp() + cls.warehouse = os.path.join(cls.tempdir, 'warehouse') + cls.catalog = CatalogFactory.create({'warehouse': cls.warehouse}) + cls.catalog.create_database('default', True) + + cls.pa_schema = pa.schema([ + ('id', pa.int32()), + ('value', pa.string()), + ('partition_col', pa.string()) + ]) + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls.tempdir, ignore_errors=True) + + def _create_table_with_snapshots(self, name, num_snapshots=5, partition_keys=None): + """Create a table and write num_snapshots of data. + + Returns: + Tuple of (table, expected_data_per_snapshot) + """ + schema = Schema.from_pyarrow_schema(self.pa_schema, partition_keys=partition_keys) + self.catalog.create_table(f'default.{name}', schema, False) + table = self.catalog.get_table(f'default.{name}') + + all_data = [] + for snap_id in range(1, num_snapshots + 1): + write_builder = table.new_batch_write_builder() + table_write = write_builder.new_write() + table_commit = write_builder.new_commit() + + data = { + 'id': [snap_id * 10 + i for i in range(5)], + 'value': [f'snap{snap_id}_row{i}' for i in range(5)], + 'partition_col': ['p1' if i % 2 == 0 else 'p2' for i in range(5)] + } + all_data.append(data) + + pa_table = pa.Table.from_pydict(data, schema=self.pa_schema) + table_write.write_arrow(pa_table) + table_commit.commit(table_write.prepare_commit()) + table_write.close() + table_commit.close() + + return table, all_data + + def _read_via_diff(self, table, start_snap_id, end_snap_id): + """Read data using IncrementalDiffScanner between two snapshots.""" + snapshot_manager = SnapshotManager(table) + start_snapshot = snapshot_manager.get_snapshot_by_id(start_snap_id) + end_snapshot = snapshot_manager.get_snapshot_by_id(end_snap_id) + + scanner = IncrementalDiffScanner(table) + plan = scanner.scan(start_snapshot, end_snapshot) + + splits = plan.splits() + if not splits: + # Return empty table with correct schema + return pa.Table.from_pydict({ + 'id': [], + 'value': [], + 'partition_col': [] + }, schema=self.pa_schema) + + table_read = table.new_read_builder().new_read() + return table_read.to_arrow(splits) + + def _read_via_delta(self, table, start_snap_id, end_snap_id): + """Read data by iterating delta_manifest_lists between two snapshots.""" + snapshot_manager = SnapshotManager(table) + manifest_list_manager = ManifestListManager(table) + manifest_file_manager = ManifestFileManager(table) + + all_entries = [] + for snap_id in range(start_snap_id + 1, end_snap_id + 1): + snapshot = snapshot_manager.get_snapshot_by_id(snap_id) + if snapshot and snapshot.commit_kind == 'APPEND': + manifest_files = manifest_list_manager.read_delta(snapshot) + if manifest_files: + entries = manifest_file_manager.read_entries_parallel(manifest_files) + all_entries.extend(entries) + + if not all_entries: + return pa.Table.from_pydict({ Review Comment: Same - Shouldn't this be handled in the individual tests, or in the library itself? ########## paimon-python/pypaimon/acceptance/incremental_diff_acceptance_test.py: ########## @@ -0,0 +1,322 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ +""" +Acceptance tests for IncrementalDiffScanner. + +These tests verify that the diff approach (reading 2 base_manifest_lists) +returns the same data as the delta approach (reading N delta_manifest_lists). + +Uses real file I/O with local temp filesystem. +""" + +import asyncio +import os +import shutil +import tempfile +import unittest + +import pyarrow as pa + +from pypaimon import CatalogFactory, Schema +from pypaimon.manifest.manifest_file_manager import ManifestFileManager +from pypaimon.manifest.manifest_list_manager import ManifestListManager +from pypaimon.read.scanner.append_table_split_generator import \ + AppendTableSplitGenerator +from pypaimon.read.scanner.incremental_diff_scanner import \ + IncrementalDiffScanner +from pypaimon.read.streaming_table_scan import AsyncStreamingTableScan +from pypaimon.snapshot.snapshot_manager import SnapshotManager + + +class IncrementalDiffAcceptanceTest(unittest.TestCase): + """Acceptance tests for diff vs delta equivalence with real data.""" + + @classmethod + def setUpClass(cls): + cls.tempdir = tempfile.mkdtemp() + cls.warehouse = os.path.join(cls.tempdir, 'warehouse') + cls.catalog = CatalogFactory.create({'warehouse': cls.warehouse}) + cls.catalog.create_database('default', True) + + cls.pa_schema = pa.schema([ + ('id', pa.int32()), + ('value', pa.string()), + ('partition_col', pa.string()) + ]) + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls.tempdir, ignore_errors=True) + + def _create_table_with_snapshots(self, name, num_snapshots=5, partition_keys=None): + """Create a table and write num_snapshots of data. + + Returns: + Tuple of (table, expected_data_per_snapshot) + """ + schema = Schema.from_pyarrow_schema(self.pa_schema, partition_keys=partition_keys) + self.catalog.create_table(f'default.{name}', schema, False) + table = self.catalog.get_table(f'default.{name}') + + all_data = [] + for snap_id in range(1, num_snapshots + 1): + write_builder = table.new_batch_write_builder() + table_write = write_builder.new_write() + table_commit = write_builder.new_commit() + + data = { + 'id': [snap_id * 10 + i for i in range(5)], + 'value': [f'snap{snap_id}_row{i}' for i in range(5)], + 'partition_col': ['p1' if i % 2 == 0 else 'p2' for i in range(5)] + } + all_data.append(data) + + pa_table = pa.Table.from_pydict(data, schema=self.pa_schema) + table_write.write_arrow(pa_table) + table_commit.commit(table_write.prepare_commit()) + table_write.close() + table_commit.close() + + return table, all_data + + def _read_via_diff(self, table, start_snap_id, end_snap_id): + """Read data using IncrementalDiffScanner between two snapshots.""" + snapshot_manager = SnapshotManager(table) + start_snapshot = snapshot_manager.get_snapshot_by_id(start_snap_id) + end_snapshot = snapshot_manager.get_snapshot_by_id(end_snap_id) + + scanner = IncrementalDiffScanner(table) + plan = scanner.scan(start_snapshot, end_snapshot) + + splits = plan.splits() + if not splits: Review Comment: Shouldn't this be handled in the individual tests, or in the library itself? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
