You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by ti...@apache.org on 2026/07/24 15:09:16 UTC

(datasketches-rust) branch main updated: ci: download snapshots from apache/dataSketches-tck (#160)

This is an automated email from the ASF dual-hosted git repository.

tisonkun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 4dec154  ci: download snapshots from apache/dataSketches-tck (#160)
4dec154 is described below

commit 4dec1541c3387a2975487e7ee88d84f5e47b9857
Author: Phoenix <Ph...@163.com>
AuthorDate: Fri Jul 24 23:09:11 2026 +0800

    ci: download snapshots from apache/dataSketches-tck (#160)
    
    Signed-off-by: Jiawei Zhao <Ph...@163.com>
    Co-authored-by: tison <wa...@gmail.com>
---
 .github/workflows/ci.yml                  |   5 -
 .gitignore                                |   4 -
 CONTRIBUTING.md                           |  16 +-
 tools/generate_serialization_test_data.py | 276 +++++++++++-------------------
 4 files changed, 109 insertions(+), 192 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f9d2c55..aafd7ba 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -91,11 +91,6 @@ jobs:
       - uses: Swatinem/rust-cache@v2
         with:
           cache-bin: "false"
-      - name: Setup Java
-        uses: actions/setup-java@v5
-        with:
-          java-version: "25"
-          distribution: "temurin"
       - name: Prepare test data
         shell: bash
         run: ./tools/generate_serialization_test_data.py
diff --git a/.gitignore b/.gitignore
index 3bd854a..36d5e44 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,7 +36,3 @@
 
 # Build artifacts
 **/target
-
-# Temporary files
-tmp_datasketches_java/
-tmp_datasketches_cpp/
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index dff59fd..4184e90 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -83,32 +83,28 @@ Install the extra tools with:
 cargo install taplo-cli typos-cli hawkeye
 ```
 
-## Serialization snapshots and test data generation
+## Serialization snapshots
 
-Some tests depend on snapshot files under `datasketches/tests/serialization_test_data`. If they are missing, tests will fail. Regenerate them with:
+Some tests depend on snapshot files under `datasketches/tests/serialization_test_data`. If they are missing, tests will fail. Download them with:
 
 ```shell
 python3 ./tools/generate_serialization_test_data.py --all
 ```
 
-The script pulls `datasketches-java` and `datasketches-cpp` and writes files to:
+The script downloads the latest snapshots from the `main` branch of
+[`apache/datasketches-tck`](https://github.com/apache/datasketches-tck) and writes them to:
 
 - `datasketches/tests/serialization_test_data/java_generated_files`
 - `datasketches/tests/serialization_test_data/cpp_generated_files`
 
-You can generate them separately:
+You can download them separately:
 
 ```shell
 python3 ./tools/generate_serialization_test_data.py --java
 python3 ./tools/generate_serialization_test_data.py --cpp
 ```
 
-The script requires these commands on PATH (and network access):
-
-- Java data: `git`, `java`, `mvn`
-- C++ data: `git`, `cmake`, `ctest`
-
-The current `datasketches-java` generation flow requires JDK >= 25 and Maven >= 3.9.11, otherwise Maven Enforcer will fail.
+The script requires Python 3 and network access.
 
 ## Code of Conduct
 
diff --git a/tools/generate_serialization_test_data.py b/tools/generate_serialization_test_data.py
index 3bc9e8d..2e9ba20 100755
--- a/tools/generate_serialization_test_data.py
+++ b/tools/generate_serialization_test_data.py
@@ -17,189 +17,119 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import os
-import subprocess
-import sys
-import shutil
 import argparse
-from pathlib import Path
-
-def check_command_installed(command):
-    """Checks if a command is available in the system path."""
-    if shutil.which(command) is None:
-        print(f"Error: '{command}' is not installed or not in PATH.")
-        sys.exit(1)
-
-
-def run_command(command, cwd=None, shell=False):
-    """Runs a shell command, streaming output to stdout/stderr."""
-    cmd_str = ' '.join(command) if isinstance(command, list) else command
-    print(f"Running: {cmd_str}")
-    sys.stdout.flush() # Ensure 'Running' message appears before command output
-    try:
-        # Don't capture output; let it stream to sys.stdout/sys.stderr
-        subprocess.check_call(command, cwd=cwd, stderr=subprocess.STDOUT, shell=shell)
-    except subprocess.CalledProcessError as e:
-        print(f"Error running command: {e}")
-        print("--- OUTPUT ---")
-        print(e.stdout)
-        print("--- END OUTPUT ---")
-        sys.exit(1)
-
-
-def generate_java_files(workspace_dir, project_dir):
-    print("--- Generating Java Test Data ---")
-
-    # 1. Check prerequisites
-    check_command_installed("git")
-    check_command_installed("java")
-    mvn_cmd_name = "mvn"
-    if os.name == 'nt':
-        mvn_cmd_name = "mvn.cmd"
-    check_command_installed(mvn_cmd_name)
-
-    # 2. Define paths
-    temp_dir = workspace_dir / "tmp_datasketches_java"
-    output_dir = project_dir / "tests" / "serialization_test_data" / "java_generated_files"
-
-    # 3. Setup temporary directory
-    if temp_dir.exists():
-        print(f"Removing existing temporary directory: {temp_dir}")
-        shutil.rmtree(temp_dir)
-
-    temp_dir.mkdir()
-
-    # 4. Clone repository
-    repo_url = "https://github.com/apache/datasketches-java.git"
-    branch = "9.0.0"
-    run_command([
-        "git", "clone",
-        "--depth", "1",
-        "--branch", branch,
-        "--single-branch",
-        repo_url,
-        str(temp_dir)
-    ])
-
-    # 5. Run Maven to generate files
-    mvn_cmd = ["mvn", "test", "-P", "generate-java-files"]
-    use_shell = False
-    if os.name == 'nt': # Windows
-        mvn_cmd[0] = "mvn.cmd"
-        use_shell = True
-
-    run_command(mvn_cmd, cwd=temp_dir, shell=use_shell)
-
-    # 6. Copy generated files
-    generated_files_dir = temp_dir / "serialization_test_data" / "java_generated_files"
-
-    if not generated_files_dir.exists():
-        print(f"Error: Expected generated files directory not found at {generated_files_dir}")
-        sys.exit(1)
-
-    print(f"Copying files from {generated_files_dir} to {output_dir}")
-    output_dir.mkdir(parents=True, exist_ok=True)
-
-    files_copied = 0
-    for file_path in generated_files_dir.glob("*.sk"):
-        shutil.copy2(file_path, output_dir)
-        print(f"Copied: {file_path.name}")
-        files_copied += 1
-
-    if files_copied == 0:
-        print("Warning: No .sk files were found to copy.")
-    else:
-        print(f"Successfully copied {files_copied} files.")
-
-
-def generate_cpp_files(workspace_dir, project_root):
-    print("--- Generating C++ Test Data ---")
-
-    # 1. Check prerequisites
-    check_command_installed("git")
-    check_command_installed("cmake")
-    check_command_installed("ctest")
-
-    # 2. Define paths
-    temp_dir = workspace_dir / "tmp_datasketches_cpp"
-    output_dir = project_root / "tests" / "serialization_test_data" / "cpp_generated_files"
-
-    # 3. Setup temporary directory
-    if temp_dir.exists():
-        print(f"Removing existing temporary directory: {temp_dir}")
-        shutil.rmtree(temp_dir)
-
-    temp_dir.mkdir()
-
-    # 4. Clone repository
-    repo_url = "https://github.com/apache/datasketches-cpp.git"
-    commit = "401423367055acdf7502e8ed3126730a08039d91"
-    run_command([
-        "git", "clone",
-        "--depth", "1",
-        "--revision", commit,
-        "--single-branch",
-        repo_url,
-        str(temp_dir)
-    ])
-
-    # 5. Build and Run CMake
-    build_dir = temp_dir / "build"
-    build_dir.mkdir(exist_ok=True)
-
-    # Configure: Add CMAKE_BUILD_TYPE for single-config generators (Ninja/Make)
-    run_command(["cmake", "..", "-DGENERATE=true", "-DCMAKE_BUILD_TYPE=Release"], cwd=build_dir)
-
-    # Build: Release config
-    run_command(["cmake", "--build", ".", "--config", "Release"], cwd=build_dir)
-
-    # Test: Use ctest which is more portable than 'cmake --target test' (VS uses RUN_TESTS)
-    # --output-on-failure helps debug if a specific test fails
-    run_command(["ctest", "-C", "Release", "--output-on-failure"], cwd=build_dir)
-
-    # 6. Copy generated files
-    # The instructions say: cp datasketches-cpp/build/*/test/*_cpp.sk serialization_test_data/cpp_generated_files
-    # We need to find where they are exactly.
-    # It seems they might be in build/test/ or subdirectories depending on generator.
-
-    print(f"Copying files to {output_dir}")
+import shutil
+import sys
+import tempfile
+import urllib.error
+import urllib.request
+import zipfile
+from pathlib import Path, PurePosixPath
+
+TCK_ARCHIVE_URL = (
+    "https://github.com/apache/datasketches-tck/archive/refs/heads/main.zip"
+)
+OUTPUT_DIRS = {
+    "java": "java_generated_files",
+    "cpp": "cpp_generated_files",
+}
+
+
+def download_archive(destination):
+    print(f"Downloading serialization snapshots from {TCK_ARCHIVE_URL}", flush=True)
+    request = urllib.request.Request(
+        TCK_ARCHIVE_URL,
+        headers={"User-Agent": "apache-datasketches-rust"},
+    )
+    with urllib.request.urlopen(request, timeout=60) as response:
+        with destination.open("wb") as output:
+            shutil.copyfileobj(response, output)
+
+
+def install_snapshots(archive, project_dir, language):
+    source_parts = ("serialization", language, "snapshots")
+    members = []
+
+    for member in archive.infolist():
+        path = PurePosixPath(member.filename)
+        if (
+            not member.is_dir()
+            and path.suffix == ".sk"
+            and path.parent.parts[-3:] == source_parts
+        ):
+            members.append((path.name, member))
+
+    if not members:
+        raise RuntimeError(f"no {language} snapshots found in the TCK archive")
+
+    output_dir = (
+        project_dir
+        / "tests"
+        / "serialization_test_data"
+        / OUTPUT_DIRS[language]
+    )
+    snapshot_root = output_dir.parent
+    if snapshot_root.is_symlink() or output_dir.is_symlink():
+        raise RuntimeError(f"snapshot output path cannot be a symbolic link: {output_dir}")
     output_dir.mkdir(parents=True, exist_ok=True)
 
-    files_copied = 0
-
-    for file_path in build_dir.rglob("*_cpp.sk"):
-        shutil.copy2(file_path, output_dir)
-        print(f"Copied: {file_path.name}")
-        files_copied += 1
-
-
-    if files_copied == 0:
-        print("Warning: No *_cpp.sk files were found to copy.")
-    else:
-        print(f"Successfully copied {files_copied} files.")
+    expected_files = {name for name, _ in members}
+    for existing_file in output_dir.glob("*.sk"):
+        if existing_file.name not in expected_files:
+            existing_file.unlink()
+
+    for name, member in members:
+        temp_path = None
+        try:
+            with tempfile.NamedTemporaryFile(
+                dir=output_dir,
+                prefix=f".{name}.",
+                delete=False,
+            ) as output:
+                temp_path = Path(output.name)
+                source = archive.open(member)
+                with source:
+                    shutil.copyfileobj(source, output)
+            temp_path.replace(output_dir / name)
+        finally:
+            if temp_path is not None and temp_path.exists():
+                temp_path.unlink()
+
+    print(f"Installed {len(members)} {language} snapshots into {output_dir}")
 
 
 def main():
-    parser = argparse.ArgumentParser(description="Generate serialization test data for Java and/or C++.")
-    parser.add_argument("--java", action="store_true", help="Generate Java test data")
-    parser.add_argument("--cpp", action="store_true", help="Generate C++ test data")
-    parser.add_argument("--all", action="store_true", help="Generate both Java and C++ test data")
-
+    parser = argparse.ArgumentParser(
+        description="Download serialization test data from apache/datasketches-tck."
+    )
+    parser.add_argument("--java", action="store_true", help="Download Java test data")
+    parser.add_argument("--cpp", action="store_true", help="Download C++ test data")
+    parser.add_argument("--all", action="store_true", help="Download all test data")
     args = parser.parse_args()
 
-    # Default to all if no arguments provided
-    if not args.java and not args.cpp and not args.all:
-        args.all = True
+    languages = []
+    if args.java or args.all:
+        languages.append("java")
+    if args.cpp or args.all:
+        languages.append("cpp")
+    if not languages:
+        languages = list(OUTPUT_DIRS)
+
+    project_dir = Path(__file__).resolve().parent.parent / "datasketches"
 
-    tools_dir = Path(__file__).resolve().parent
-    workspace_dir = tools_dir.parent
-    project_dir = workspace_dir / "datasketches"
+    try:
+        with tempfile.TemporaryDirectory(prefix="datasketches-tck-") as temp_dir:
+            archive_path = Path(temp_dir) / "datasketches-tck.zip"
+            download_archive(archive_path)
+            with zipfile.ZipFile(archive_path) as archive:
+                for language in languages:
+                    install_snapshots(archive, project_dir, language)
+    except (OSError, RuntimeError, urllib.error.URLError, zipfile.BadZipFile) as error:
+        print(f"Error: {error}", file=sys.stderr)
+        return 1
 
-    if args.java or args.all:
-        generate_java_files(workspace_dir, project_dir)
+    return 0
 
-    if args.cpp or args.all:
-        generate_cpp_files(workspace_dir, project_dir)
 
 if __name__ == "__main__":
-    main()
+    sys.exit(main())


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org