This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 61f9981bc3 [ci] Shard Python tests and run interoperability in
parallel (#11325)
61f9981bc3 is described below
commit 61f9981bc3b265da12446bf48eb0db441fb2da86
Author: Jingsong Lee <[email protected]>
AuthorDate: Sun Nov 22 00:15:29 2026 +0800
[ci] Shard Python tests and run interoperability in parallel (#11325)
---
.github/workflows/ci-python.yml | 150 +++++++++++-----------
paimon-python/conftest.py | 40 +++++-
paimon-python/dev/ci_shard_durations.tsv | 142 ++++++++++++++++++++
paimon-python/dev/ci_shards.py | 117 +++++++++++++++++
paimon-python/dev/test_ci_shards.py | 78 +++++++++++
paimon-python/pypaimon/tests/vindex_input_test.py | 13 +-
6 files changed, 457 insertions(+), 83 deletions(-)
diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml
index cddb497d0c..d7c4a32d86 100644
--- a/.github/workflows/ci-python.yml
+++ b/.github/workflows/ci-python.yml
@@ -30,9 +30,8 @@ env:
jobs:
- # Lint + test on selected versions only (3.6 / 3.7 low end, 3.10 / 3.11 /
3.12 / 3.13 current), not every Python version.
- test:
- name: ${{ (matrix.python-version == '3.6.15' || matrix.python-version ==
'3.7') && 'Legacy Python' || 'Native' }} / Python ${{ matrix.python-version }}
+ interoperability:
+ name: ${{ (matrix.python-version == '3.6.15' || matrix.python-version ==
'3.7') && 'Legacy Python' || 'Java/Python interoperability' }} / Python ${{
matrix.python-version }}
env:
PYPAIMON_TEST_EXECUTION: ${{ (matrix.python-version == '3.6.15' ||
matrix.python-version == '3.7') && 'python' || 'native' }}
PYTEST_ADDOPTS: '--durations=20'
@@ -133,7 +132,8 @@ jobs:
mvn -T 2C -B -ntp install -DskipTests \
-pl
paimon-core,paimon-lance,paimon-vortex/paimon-vortex-format,paimon-full-text,paimon-lumina,paimon-vector
-am
- - name: Install Python dependencies
+ - &install-python-dependencies
+ name: Install Python dependencies
shell: bash
run: |
python -m pip install --upgrade pip
@@ -151,7 +151,8 @@ jobs:
fi
python -m pip check
- - name: Verify default execution environment
+ - &verify-execution-environment
+ name: Verify default execution environment
run: |
python - <<'PY'
import importlib.util
@@ -168,11 +169,79 @@ jobs:
assert importlib.util.find_spec('pypaimon_rust') is None
PY
- - name: Run lint-python.sh
+ - name: Run lint and Java/Python interoperability tests
shell: bash
run: |
- chmod +x paimon-python/dev/lint-python.sh
- ./paimon-python/dev/lint-python.sh -e pytest_torch
+ if [[ "$PYPAIMON_TEST_EXECUTION" == native ]]; then
+ bash paimon-python/dev/lint-python.sh -i license,flake8,mixed
+ else
+ bash paimon-python/dev/lint-python.sh -e pytest_torch
+ fi
+
+ pytest-matrix:
+ name: Plan Python test shards
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ outputs:
+ matrix: ${{ steps.matrix.outputs.matrix }}
+ steps:
+ - uses: actions/checkout@v6
+ - id: matrix
+ run: python3 paimon-python/dev/ci_shards.py matrix >> "$GITHUB_OUTPUT"
+
+ pytest-shard:
+ name: ${{ matrix.execution == 'native' && 'Native' || 'Python Execution'
}} / Python ${{ matrix.python-version }} / shard ${{ matrix.shard }}
+ needs: pytest-matrix
+ runs-on: ubuntu-latest
+ container: "python:${{ matrix.python-version }}-slim"
+ timeout-minutes: 40
+ strategy:
+ fail-fast: false
+ matrix:
+ include: ${{ fromJSON(needs.pytest-matrix.outputs.matrix) }}
+ env:
+ PYPAIMON_TEST_EXECUTION: ${{ matrix.execution }}
+ PYTEST_ADDOPTS: ${{ matrix.execution == 'python' && '-m "not
native_plan" --durations=20' || '--durations=20' }}
+ DAFT_RUNNER: 'native'
+ steps:
+ - uses: actions/checkout@v6
+ - name: Install system dependencies
+ run: |
+ apt-get update && apt-get install -y --no-install-recommends \
+ build-essential git curl cmake pkg-config libssl-dev libclang-dev
tzdata \
+ && rm -rf /var/lib/apt/lists/*
+ - *install-python-dependencies
+ - *verify-execution-environment
+ - name: Run pytest shard
+ shell: bash
+ env:
+ PYPAIMON_CI_SHARD: ${{ matrix.shard }}
+ run: |
+ export PYPAIMON_CI_SHARD_REPORT="$PWD/pytest-shard.json"
+ bash paimon-python/dev/lint-python.sh -i pytest
+ - uses: actions/upload-artifact@v6
+ with:
+ name: pytest-shard-${{ matrix.execution }}-${{ matrix.python-version
}}-${{ matrix.shard }}
+ path: pytest-shard.json
+ if-no-files-found: error
+ overwrite: true
+ retention-days: 7
+
+ pytest-coverage:
+ name: Verify Python test coverage
+ needs: pytest-shard
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@v6
+ - uses: actions/download-artifact@v7
+ with:
+ pattern: pytest-shard-*
+ path: pytest-shards
+ - name: Verify shard reports
+ run: |
+ python3 -m unittest discover -s paimon-python/dev -p
test_ci_shards.py
+ python3 paimon-python/dev/ci_shards.py pytest-shards
s3-delete-compatibility:
name: Compatibility / PyArrow ${{ matrix.pyarrow }}
@@ -201,71 +270,6 @@ jobs:
pypaimon/tests/file_io_test.py
pypaimon/tests/filesystem_catalog_test.py \
pypaimon/tests/table_update_arrow_compatibility_test.py
- python-execution:
- name: Python Execution
- timeout-minutes: 90
- runs-on: ubuntu-latest
- container: "python:3.11-slim"
- env:
- PYPAIMON_TEST_EXECUTION: 'python'
- PYTEST_ADDOPTS: "-m 'not native_plan' --durations=20"
- DAFT_RUNNER: 'native'
- steps:
- - name: Checkout code
- uses: actions/checkout@v6
-
- - name: Install system dependencies
- run: |
- apt-get update && apt-get install -y --no-install-recommends \
- build-essential git curl cmake pkg-config libssl-dev libclang-dev
tzdata \
- && rm -rf /var/lib/apt/lists/*
-
- - name: Set up JDK ${{ env.JDK_VERSION }}
- uses: actions/setup-java@v5
- with:
- java-version: ${{ env.JDK_VERSION }}
- distribution: 'temurin'
-
- - name: Set up Maven
- shell: bash
- env:
- MAVEN_VERSION: '3.8.8'
- run: |
-
maven_archive="${RUNNER_TEMP}/apache-maven-${MAVEN_VERSION}-bin.tar.gz"
- curl --fail --location --retry 3 --retry-all-errors --retry-delay 2 \
- --output "$maven_archive" \
-
"https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${MAVEN_VERSION}/apache-maven-${MAVEN_VERSION}-bin.tar.gz"
\
- || curl --fail --location --retry 3 --retry-all-errors
--retry-delay 2 \
- --output "$maven_archive" \
-
"https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz"
- tar -xzf "$maven_archive" -C "$RUNNER_TEMP"
- echo "${RUNNER_TEMP}/apache-maven-${MAVEN_VERSION}/bin" >>
"$GITHUB_PATH"
-
- - name: Cache Maven dependencies
- uses: actions/cache@v5
- with:
- path: ~/.m2/repository
- key: ci-maven-python-${{ runner.os }}-${{ runner.arch }}-${{
hashFiles('**/pom.xml') }}
- restore-keys: |
- ci-maven-python-${{ runner.os }}-${{ runner.arch }}-
-
- - name: Build Java
- run: |
- mvn -T 2C -B -ntp install -DskipTests \
- -pl
paimon-core,paimon-lance,paimon-vortex/paimon-vortex-format,paimon-full-text,paimon-lumina,paimon-vector
-am
-
- - name: Install Python test dependencies
- run: |
- python -m pip install --upgrade pip
- python -m pip install torch --index-url
https://download.pytorch.org/whl/cpu
- python -m pip install -e ./paimon-python --group
./paimon-python/pyproject.toml:dev
- python -m pip check
-
- - name: Run Python execution tests
- shell: bash
- run: |
- bash paimon-python/dev/lint-python.sh -i pytest
-
native-timezones:
name: Native temporal casts
runs-on: ubuntu-latest
diff --git a/paimon-python/conftest.py b/paimon-python/conftest.py
index da8764104d..1da125cd12 100644
--- a/paimon-python/conftest.py
+++ b/paimon-python/conftest.py
@@ -14,8 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import json
import os
+import sys
from functools import wraps
+from pathlib import Path
import pytest
@@ -202,13 +205,25 @@ def pytest_configure(config):
track_update(NativeShardTableUpdator, 'prepare_commit', 'shard')
-def pytest_collection_modifyitems(items):
- if _native_plan_enabled():
- return
- skip_native = pytest.mark.skip(reason="native plan tests run in Native CI")
- for item in items:
- if item.get_closest_marker("native_plan") is not None:
- item.add_marker(skip_native)
[email protected](hookwrapper=True)
+def pytest_collection_modifyitems(config, items):
+ if not _native_plan_enabled():
+ skip_native = pytest.mark.skip(reason="native plan tests run in Native
CI")
+ for item in items:
+ if item.get_closest_marker("native_plan") is not None:
+ item.add_marker(skip_native)
+
+ # Shard the same set of test cases pytest would run after marker selection.
+ yield
+ shard = os.environ.get("PYPAIMON_CI_SHARD")
+ if shard is not None:
+ from dev.ci_shards import select_shard
+
+ version = "{}.{}".format(*sys.version_info[:2])
+ selected, deselected, report = select_shard(items,
os.environ[_EXECUTION_ENV], version, int(shard))
+ config.paimon_shard_report = report
+ items[:] = selected
+ config.hook.pytest_deselected(items=deselected)
@pytest.fixture(autouse=True)
@@ -281,6 +296,17 @@ def enable_native_backends(request, monkeypatch):
def pytest_sessionfinish(session, exitstatus):
if exitstatus == 0:
+ report = getattr(session.config, "paimon_shard_report", None)
+ if report is not None:
+ report["native"] = {
+ "plan": _native_plan_count,
+ "read": _native_read_count,
+ "write": _native_write_count,
+ "commit": _native_commit_count,
+ }
+ report["native"].update(("update." + kind, count) for kind, count
in _native_update_counts.items())
+
Path(os.environ["PYPAIMON_CI_SHARD_REPORT"]).write_text(json.dumps(report),
encoding="utf-8")
+ return
if ((_native_plan_enabled() and _native_plan_count == 0)
or (_native_read_enabled() and _native_read_count == 0)
or (_native_write_enabled() and _native_write_count == 0)
diff --git a/paimon-python/dev/ci_shard_durations.tsv
b/paimon-python/dev/ci_shard_durations.tsv
new file mode 100644
index 0000000000..5575af2995
--- /dev/null
+++ b/paimon-python/dev/ci_shard_durations.tsv
@@ -0,0 +1,142 @@
+# 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.
+
+# Median file durations from CI runs 43561549522, 44858799654 and 44874539862.
+# A zero uses the test-count estimate for that execution mode.
+# Path relative to pypaimon/tests Native seconds Python seconds
+batch_vector_lookup_test.py 5.9 5.1
+blob_table_test.py 21.8 20.3
+concurrent_import_test.py 9.7 9.3
+consumer_manager_test.py 8.0 8.0
+daft/daft_catalog_rest_test.py 13.7 10.2
+daft/daft_on_ray_e2e_test.py 8.6 8.7
+daft/daft_pk_distributed_write_test.py 10.1 8.7
+data_file_creation_time_test.py 11.5 11.3
+deletion_vector_path_test.py 18.4 8.9
+jindo_file_system_test.py 4.0 0
+lerobot_aggregate_test.py 13.1 11.2
+manifest/manifest_manager_test.py 23.3 24.6
+manifest/manifest_sidecar_test.py 5.5 5.6
+mp4_test.py 0 4.1
+multimodal_lance_auth_test.py 6.7 6.5
+multimodal_lerobot_test.py 4.1 0
+multimodal_table_test.py 4.2 4.1
+native_authorized_update_test.py 14.9 14.7
+native_blob_update_test.py 11.4 0
+native_blob_write_test.py 15.2 0
+native_branch_write_test.py 6.2 0
+native_calendar_mask_test.py 5.3 0
+native_cast_completion_test.py 13.3 0
+native_commit_partition_spec_test.py 9.7 9.1
+native_commit_test.py 4.4 0
+native_data_directory_test.py 4.4 0
+native_decimal_cast_test.py 4.8 0
+native_decimal_integer_input_test.py 28.0 0
+native_decimal_predicate_test.py 4.1 0
+native_dv_merge_engine_write_test.py 7.1 0
+native_full_startup_test.py 21.4 0
+native_full_text_search_test.py 64.1 0
+native_generic_index_build_test.py 4.3 0
+native_historical_update_test.py 12.6 4.7
+native_hybrid_search_test.py 8.4 0
+native_iterator_test.py 5.3 0
+native_merge_incremental_test.py 5.7 0
+native_nested_predicate_test.py 14.2 0
+native_nested_update_test.py 5.6 0
+native_nullable_primary_key_test.py 11.9 0
+native_overwrite_indexes_test.py 4.8 4.1
+native_parallel_index_build_test.py 8.0 0
+native_parquet_vector_update_test.py 5.1 0
+native_partition_filter_test.py 6.3 0
+native_pk_full_text_search_test.py 32.9 0
+native_plan_incremental_test.py 5.7 0
+native_plan_resolved_schema_test.py 5.2 0
+native_plan_rest_test.py 67.6 0
+native_predicate_delete_test.py 34.7 0
+native_query_auth_test.py 6.3 0
+native_read_path_completion_test.py 5.1 0
+native_read_snapshot_test.py 4.3 0
+native_schema_cast_test.py 5.7 0
+native_schema_evolution_cast_test.py 22.6 0
+native_search_plan_test.py 13.0 0
+native_sequence_test.py 9.7 0
+native_shard_update_test.py 4.2 0
+native_sorted_index_build_test.py 40.1 0
+native_stream_query_auth_test.py 4.0 0
+native_torch_variant_test.py 49.6 36.7
+native_transform_filter_test.py 16.8 0
+native_update_binary_text_test.py 50.8 0
+native_update_container_casts_test.py 19.0 0
+native_update_encoded_inputs_test.py 82.5 0
+native_update_map_pairs_test.py 30.6 0
+native_update_source_nullability_test.py 4.2 0
+native_update_test.py 17.6 0
+native_upsert_encoded_keys_test.py 8.1 6.5
+native_upsert_key_normalization_test.py 18.5 0
+native_upsert_selected_values_test.py 10.1 0
+native_upsert_temporal_row_keys_test.py 7.7 0
+native_vector_index_build_test.py 10.0 0
+native_vector_search_test.py 17.6 0
+native_write_test.py 4.6 0
+parquet_page_index_test.py 6.7 5.5
+query_auth_filter_test.py 10.9 6.2
+ray_compute_columns_test.py 14.8 12.1
+ray_data_evolution_merge_into_test.py 129.9 128.6
+ray_data_test.py 6.9 7.0
+ray_full_text_search_test.py 8.3 8.0
+ray_integration_test.py 7.7 7.9
+ray_native_row_id_recovery_test.py 45.9 0
+ray_primary_key_vector_search_test.py 8.6 7.3
+ray_read_by_row_id_test.py 31.8 30.8
+ray_repartition_test.py 44.0 45.9
+ray_search_order_test.py 16.3 16.4
+ray_search_result_metadata_test.py 5.2 4.7
+ray_search_result_test.py 8.7 8.4
+ray_update_by_row_id_compaction_test.py 57.0 56.0
+ray_update_by_row_id_test.py 22.9 22.6
+ray_vector_filter_exactness_test.py 7.8 6.9
+ray_vector_index_build_test.py 6.2 5.6
+ray_vector_refinement_test.py 6.5 5.8
+ray_vector_result_conversion_test.py 5.9 5.4
+ray_vector_search_test.py 39.3 38.4
+reader_append_only_test.py 9.9 9.5
+rest/rest_base_test.py 4.3 0
+rest/rest_branch_test.py 20.9 15.7
+rest/rest_branch_transport_test.py 13.0 12.6
+rest/rest_catalog_commit_snapshot_test.py 11.2 8.4
+rest/rest_catalog_test.py 23.3 16.9
+rest/rest_create_partitions_test.py 17.1 12.6
+rest/rest_format_table_test.py 37.6 28.0
+rest/rest_iceberg_table_test.py 11.2 8.5
+rest/rest_list_partitions_fallback_test.py 11.3 8.4
+rest/rest_object_table_test.py 16.5 12.2
+rest/rest_permission_test.py 18.1 13.1
+rest/rest_read_write_test.py 124.9 90.7
+rest/rest_simple_test.py 25.2 20.6
+rest/rest_tag_test.py 21.7 16.6
+rest/rest_version_test.py 38.3 37.2
+s3_delete_compatibility_test.py 5.5 4.7
+search_training_test.py 10.9 9.9
+shard_table_updator_test.py 58.6 67.2
+table_update_test.py 4.3 4.6
+test_sequence_field_write.py 5.8 0
+torch_named_nested_projection_test.py 4.3 0
+torch_named_projection_test.py 17.6 11.9
+vector_filter_exactness_test.py 4.6 0
+write/append_row_kind_test.py 4.0 0
+write/append_writer_lifecycle_test.py 8.3 4.1
+write/direct_writer_execution_test.py 4.4 0
+write/update_execution_protocol_test.py 9.9 10.1
diff --git a/paimon-python/dev/ci_shards.py b/paimon-python/dev/ci_shards.py
new file mode 100644
index 0000000000..e06dc1aafa
--- /dev/null
+++ b/paimon-python/dev/ci_shards.py
@@ -0,0 +1,117 @@
+# 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.
+
+"""Partition the collected pytest suite by file and verify the CI reports."""
+
+from collections import Counter
+from hashlib import sha256
+import json
+from pathlib import Path
+import sys
+
+
+SHARD_COUNTS = {
+ ('native', '3.10'): 4,
+ ('native', '3.11'): 3,
+ ('native', '3.12'): 4,
+ ('native', '3.13'): 4,
+ ('python', '3.11'): 2,
+}
+UPDATE_KINDS = ('row_id', 'grouped', 'predicate', 'upsert', 'incremental',
'merge', 'shard')
+COVERAGE_KEYS = ('plan', 'read', 'write', 'commit') + tuple('update.' + kind
for kind in UPDATE_KINDS)
+
+
+def matrix_entries():
+ return [
+ {'execution': execution, 'python-version': version, 'shard': index}
+ for (execution, version), count in SHARD_COUNTS.items()
+ for index in range(1, count + 1)
+ ]
+
+
+def file_assignments(file_counts, durations, shard_count):
+ # Approximate unprofiled files by the number of tests they contribute.
+ weights = {path: durations.get(path, 0.1 + 0.015 * ntests) for path,
ntests in file_counts.items()}
+ loads = [0.0] * shard_count
+ assignments = {}
+ for path in sorted(weights, key=lambda path: (-weights[path], path)):
+ shard = min(range(shard_count), key=loads.__getitem__)
+ assignments[path] = shard + 1
+ loads[shard] += weights[path]
+ return assignments
+
+
+def select_shard(items, execution, version, index):
+ shard_count = SHARD_COUNTS[execution, version]
+ if not 1 <= index <= shard_count:
+ raise ValueError('Invalid pytest shard {} of {}'.format(index,
shard_count))
+ duration_column = 1 if execution == 'native' else 2
+ durations = {}
+ for line in
Path(__file__).with_name('ci_shard_durations.tsv').read_text().splitlines():
+ if line and not line.startswith('#'):
+ columns = line.split('\t')
+ duration = float(columns[duration_column])
+ if duration > 0:
+ durations['pypaimon/tests/' + columns[0]] = duration
+
+ paths = [item.nodeid.split('::', 1)[0] for item in items]
+ assignments = file_assignments(Counter(paths), durations, shard_count)
+ selected, deselected = [], []
+ for item, path in zip(items, paths):
+ (selected if assignments[path] == index else deselected).append(item)
+ return selected, deselected, {
+ 'execution': execution,
+ 'python': version,
+ 'shard': index,
+ 'collection': sha256('\n'.join(sorted(item.nodeid for item in
items)).encode('utf-8')).hexdigest(),
+ 'collected': len(items),
+ 'selected': len(selected),
+ }
+
+
+def verify_reports(reports):
+ expected = {(item['execution'], item['python-version'], item['shard']) for
item in matrix_entries()}
+ received = [(report['execution'], report['python'], report['shard']) for
report in reports]
+ if len(received) != len(expected) or set(received) != expected:
+ raise ValueError('Expected one report from each pytest shard, received
{}'.format(sorted(received)))
+
+ for execution, version in SHARD_COUNTS:
+ group = [report for report in reports if (report['execution'],
report['python']) == (execution, version)]
+ label = '{} / Python {}'.format(execution, version)
+ collections = {(report['collection'], report['collected']) for report
in group}
+ if len(collections) != 1:
+ raise ValueError('{} shards collected different
tests'.format(label))
+ _, collected = collections.pop()
+ selected = sum(report['selected'] for report in group)
+ if selected != collected or any(report['selected'] <= 0 for report in
group):
+ raise ValueError('{} shards selected {} of {} tests'.format(label,
selected, collected))
+ print('{} exercised {} tests across {} shards'.format(label, selected,
len(group)))
+
+ if execution == 'native':
+ counts = Counter()
+ for report in group:
+ counts.update(report['native'])
+ missing = [key for key in COVERAGE_KEYS if counts[key] <= 0]
+ if missing:
+ raise ValueError('{} did not exercise {}'.format(label, ',
'.join(missing)))
+ print(', '.join('{}={}'.format(key, counts[key]) for key in
COVERAGE_KEYS))
+
+
+if __name__ == '__main__':
+ if sys.argv[1] == 'matrix':
+ print('matrix=' + json.dumps(matrix_entries(), separators=(',', ':')))
+ else:
+ verify_reports([json.loads(path.read_text()) for path in
Path(sys.argv[1]).glob('*/pytest-shard.json')])
diff --git a/paimon-python/dev/test_ci_shards.py
b/paimon-python/dev/test_ci_shards.py
new file mode 100644
index 0000000000..41b7f8491c
--- /dev/null
+++ b/paimon-python/dev/test_ci_shards.py
@@ -0,0 +1,78 @@
+# 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.
+
+from contextlib import redirect_stdout
+import io
+from types import SimpleNamespace
+import unittest
+
+from ci_shards import COVERAGE_KEYS, matrix_entries, select_shard,
verify_reports
+
+
+class CiShardsTest(unittest.TestCase):
+ def test_file_stays_together_and_every_test_is_selected_once(self):
+ items =
[SimpleNamespace(nodeid='pypaimon/tests/test_{}.py::test[{}]'.format(file,
case))
+ for file in range(13) for case in range(file + 1)]
+ selected_by_shard = []
+ fingerprints = set()
+ for index in range(1, 5):
+ ordered = items if index % 2 else list(reversed(items))
+ selected, deselected, report = select_shard(ordered, 'native',
'3.13', index)
+ self.assertEqual(len(selected) + len(deselected), len(items))
+ self.assertEqual(report['selected'], len(selected))
+ self.assertTrue(selected)
+ selected_by_shard.append(selected)
+ fingerprints.add(report['collection'])
+
+ self.assertEqual(len(fingerprints), 1)
+ self.assertCountEqual([item.nodeid for shard in selected_by_shard for
item in shard],
+ [item.nodeid for item in items])
+ assigned_paths = {item.nodeid.split('::')[0] for item in items}
+ self.assertEqual(sum(len({item.nodeid.split('::')[0] for item in
shard})
+ for shard in selected_by_shard),
len(assigned_paths))
+
+ def reports(self):
+ reports = []
+ entries = matrix_entries()
+ for entry in entries:
+ execution, version, shard = entry['execution'],
entry['python-version'], entry['shard']
+ lane_count = sum(other['execution'] == execution and
other['python-version'] == version
+ for other in entries)
+ reports.append({
+ 'execution': execution, 'python': version, 'shard': shard,
+ 'collection': 'same-collection', 'collected': lane_count,
'selected': 1,
+ 'native': dict.fromkeys(COVERAGE_KEYS, int(shard ==
lane_count)),
+ })
+ return reports
+
+ def test_per_version_coverage_can_span_multiple_shards(self):
+ reports = self.reports()
+ reports[0]['native']['update.merge'] = 1
+ reports[3]['native']['update.merge'] = 0
+ with redirect_stdout(io.StringIO()):
+ verify_reports(reports)
+
+ def test_missing_shard_different_collection_and_missing_backend_fail(self):
+ with self.assertRaisesRegex(ValueError, 'one report'):
+ verify_reports(self.reports()[1:])
+ reports = self.reports()
+ reports[0]['collection'] = 'different-collection'
+ with self.assertRaisesRegex(ValueError, 'collected different tests'):
+ verify_reports(reports)
+ reports = self.reports()
+ reports[3]['native']['update.merge'] = 0
+ with redirect_stdout(io.StringIO()),
self.assertRaisesRegex(ValueError, '3.10 did not exercise update.merge'):
+ verify_reports(reports)
diff --git a/paimon-python/pypaimon/tests/vindex_input_test.py
b/paimon-python/pypaimon/tests/vindex_input_test.py
index e3eccca47f..e39a20d56a 100644
--- a/paimon-python/pypaimon/tests/vindex_input_test.py
+++ b/paimon-python/pypaimon/tests/vindex_input_test.py
@@ -15,13 +15,17 @@
# specific language governing permissions and limitations
# under the License.
+from importlib import import_module
import io
+import sys
import tempfile
import threading
import unittest
from concurrent.futures import ThreadPoolExecutor, TimeoutError as
FutureTimeoutError
from unittest import mock
+from pytest import MonkeyPatch
+
from pypaimon.globalindex.global_index_meta import GlobalIndexIOMeta
from pypaimon.globalindex.vindex_input import (
PaimonVindexInput,
@@ -213,9 +217,12 @@ class VindexInputTest(unittest.TestCase):
native.close.side_effect = error
module = mock.Mock()
module.VectorIndexReader.side_effect = open_reader
- with mock.patch.dict("sys.modules", {"paimon_vindex": module}),
mock.patch(
-
'pypaimon.execution.native.read.vindex_reader._native_reader_type',
- return_value=None):
+ # Restore only the mock SDK entry. Keep either backend imported by the
+ # reader cached so subsequent tests can patch the same module.
+ native_reader =
import_module('pypaimon.execution.native.read.vindex_reader')
+ with MonkeyPatch.context() as monkeypatch:
+ monkeypatch.setitem(sys.modules, "paimon_vindex", module)
+ monkeypatch.setattr(native_reader, '_native_reader_type', lambda:
None)
reader = VindexVectorGlobalIndexReader(
io_, "s3://bucket", [GlobalIndexIOMeta(file_name="index",
file_size=2)])
if phase in ("constructor", "initialize"):