cshuo commented on code in PR #20621: URL: https://github.com/apache/hudi/pull/20621#discussion_r4640502483
########## hudi-lakehouse/docker/scripts/seed.py: ########## @@ -0,0 +1,101 @@ +# 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. + +"""Initialize missing demo tables; preserve existing tables and all user changes.""" +import argparse +import signal + +DEMO_TABLES = { + 'drivers': """CREATE TABLE default.drivers USING hudi + TBLPROPERTIES (type = 'cow', primaryKey = 'driver_id') AS + SELECT * FROM VALUES + ('driver_1', 'Ananya', 'chennai', 'sedan', DATE '2024-01-01'), + ('driver_2', 'Alex', 'san_francisco', 'sedan', DATE '2024-01-01'), + ('driver_3', 'Ana', 'sao_paulo', 'sedan', DATE '2024-01-01') + AS drivers(driver_id, driver_name, home_city, vehicle_type, onboarded_date)""", + 'trips': """CREATE TABLE default.trips USING hudi PARTITIONED BY (trip_date) + TBLPROPERTIES (type = 'cow', primaryKey = 'trip_id', preCombineField = 'ts') AS + SELECT concat('trip_', CAST(id AS STRING)) AS trip_id, + concat('rider_', CAST(id AS STRING)) AS rider_id, + concat('driver_', CAST(CAST(id / 3 AS INT) + 1 AS STRING)) AS driver_id, + element_at(array('chennai', 'san_francisco', 'sao_paulo'), + CAST(id / 3 AS INT) + 1) AS city, + CASE WHEN id % 3 = 2 THEN 'cancelled' ELSE 'completed' END AS trip_status, + CAST(10 * (CAST(id / 3 AS INT) + 1) + (id % 3) * 10 AS DECIMAL(10,2)) AS fare_amount, + CAST(CAST(id / 3 AS INT) + 1 + id % 3 AS DECIMAL(10,2)) AS tip_amount, + CAST(5 + id AS DOUBLE) AS distance_km, + CAST(date_sub(current_date(), 1) AS TIMESTAMP) AS pickup_ts, + CAST(date_sub(current_date(), 1) AS TIMESTAMP) + INTERVAL 15 MINUTES AS dropoff_ts, + unix_millis(CAST(date_sub(current_date(), 1) AS TIMESTAMP)) AS ts, + date_sub(current_date(), 1) AS trip_date + FROM range(9)""", +} + + +def seed(spark): + for table, create_sql in DEMO_TABLES.items(): + if spark.catalog.tableExists(f'spark_catalog.default.{table}'): + print(f'Preserving existing table default.{table}; skipping sample initialization.', flush=True) + continue + # Create and populate together rather than leaving an empty table between + # separate CREATE and INSERT operations. Never repair an existing table. + spark.sql(create_sql).collect() + verify(spark, (table,)) + + +def verify(spark, expected_tables=('drivers', 'trips')): + assert spark.conf.get("spark.sql.catalog.spark_catalog") == ( + "org.apache.spark.sql.hudi.catalog.HoodieCatalog" + ) + tables = {row.tableName for row in spark.sql("SHOW TABLES IN spark_catalog.default").collect()} + assert set(expected_tables) <= tables, f'Missing demo tables: {set(expected_tables) - tables}' + for table in expected_tables: + expected_count = 3 if table == 'drivers' else 9 + actual_count = spark.sql(f'SELECT count(*) FROM default.{table}').collect()[0][0] + assert actual_count == expected_count, ( + f'default.{table} no longer matches the demo dataset: ' + f'expected {expected_count} rows, found {actual_count}. Data was not modified.' + ) + if 'trips' in expected_tables: + rows = spark.sql("""SELECT city, SUM(fare_amount + tip_amount) AS gross_bookings + FROM default.trips WHERE trip_status = 'completed' GROUP BY city ORDER BY city""").collect() + actual = [(row.city, str(row.gross_bookings)) for row in rows] + assert actual == [("chennai", "33.00"), ("san_francisco", "55.00"), ("sao_paulo", "77.00")], ( + f'default.trips totals no longer match the demo dataset: {actual}. Data was not modified.' + ) + assert spark.sql("SHOW PARTITIONS default.trips").collect(), 'Missing default.trips partitions' + print('PASS: sample Hudi data in ' + ', '.join(expected_tables), flush=True) + + +def main(): + from pyspark.sql import SparkSession + + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--verify-only', action='store_true') + args = parser.parse_args() + signal.alarm(600) Review Comment: Fixed in `0943ddd424c`: cancel Spark queries on timeout with bounded cleanup. Verified cancellation and interrupted-CTAS behavior; documented recovery. ########## .github/workflows/hudi_lakehouse_docker_live.yml: ########## @@ -0,0 +1,52 @@ +name: Hudi Lakehouse Docker live acceptance + +# Explicit opt-in: builds containers and runs real Spark SQL, no API key required. +on: Review Comment: [Passed](https://github.com/cshuo/hudi/actions/runs/44706350662) on `0943ddd424c` in 4m 34s, including fresh builds and persistence checks. PR description updated. ########## hudi-lakehouse/docker/compose.yaml: ########## @@ -0,0 +1,168 @@ +# 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. + +name: hudi-lakehouse + +# Six default services and one optional Ollama service. Startup order: +# minio -> minio-init -> hive-metastore -> spark-connect -> seed -> gateway. +# minio-init and seed exit after completing their work; the other services stay running. +services: + # S3-compatible storage for Hudi data, log files and timelines. + # S3 is internal at http://minio:9000; the console defaults to localhost:9001. + minio: + image: ${MINIO_IMAGE:-cgr.dev/chainguard/minio:latest@sha256:fb893e36fc369d41e92f678b17ec27378fa5bf0576aeef7ac15460c13629ab5a} + command: [server, /data, --console-address, ':9001'] + environment: + MINIO_ROOT_USER: admin + MINIO_ROOT_PASSWORD: password + volumes: + - minio-data:/data + ports: + - '127.0.0.1:${MINIO_CONSOLE_PORT:-9001}:9001' + + # One-shot job: wait for MinIO, then create the warehouse bucket if absent. + minio-init: + image: ${MINIO_CLIENT_IMAGE:-cgr.dev/chainguard/minio-client:latest-dev@sha256:fe649f71872c299489deb3cb9e057e5d2f76a45c85b7599f7c21616ac80b5e63} + depends_on: + minio: + condition: service_started + entrypoint: [/bin/sh, -ec] + command: + - | + for attempt in $$(seq 1 60); do + if mc alias set local http://minio:9000 admin password; then + mc mb --ignore-existing local/warehouse + exit 0 + fi + sleep 2 + done + echo 'MinIO did not become ready' >&2 + exit 1 + + # Stores database/table schemas, locations and partition metadata in persistent + # Derby storage. Serves the internal Hive Metastore Thrift endpoint on port 9083. + hive-metastore: + image: apache/hive:3.1.3 Review Comment: Pinned the digest and added a documented `HIVE_IMAGE` override in `0943ddd424c`. ########## hudi-lakehouse/docker/lakehouse.sh: ########## @@ -0,0 +1,153 @@ +#!/usr/bin/env bash +# 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. + +set -euo pipefail +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ACTION= +BUILD=0 +LOCAL_LLM=0 +CHAT_CONFIG_ERROR= +usage() { + cat <<'HELP' +Usage: lakehouse.sh <up|down|status|logs|test> [--build] [--local-llm] + up Start services, seed demo data, verify MCP and report chat readiness. + --build Build Spark Connect and Gateway images in Docker from this checkout. + --local-llm Start containerized Ollama and pull GATEWAY_LLM_MODEL (default qwen3:8b). + test Verify sample data and gateway MCP without reseeding. + down Remove containers/network; preserve all named data volumes. + status|logs Inspect this Compose installation. + -h, --help Show this help (also shown when no arguments are supplied). +Set COMPOSE_PROJECT_NAME to isolate an installation; configure ports/provider in .env. +An unavailable chat LLM does not fail startup; MCP clients use their own model. +HELP +} +if [[ $# -eq 0 ]]; then + usage + exit 0 +fi +while [[ $# -gt 0 ]]; do + case "$1" in + up|down|status|logs|test) + if [[ -n "$ACTION" ]]; then + echo 'Specify exactly one command.' >&2; usage >&2; exit 2 + fi + ACTION="$1" ;; + --build) BUILD=1 ;; + --local-llm) LOCAL_LLM=1 ;; + -h|--help) usage; exit 0 ;; + *) echo "Unknown argument: $1" >&2; usage >&2; exit 2 ;; + esac + shift +done +if [[ -z "$ACTION" ]]; then + echo 'Specify a command, for example: lakehouse.sh up' >&2 + usage >&2 + exit 2 +fi +command -v docker >/dev/null || { echo 'Install Docker with Compose 2.27.2 or newer first.' >&2; exit 1; } +COMPOSE_VERSION="$(docker compose version --short)" || { + echo 'Docker Compose 2.27.2 or newer is required.' >&2; exit 1; +} +# config --environment was introduced in 2.27.2. Allow Docker Desktop suffixes. +if [[ ! "$COMPOSE_VERSION" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)([-+].*)?$ ]] || + (( 10#${BASH_REMATCH[1]} < 2 || + (10#${BASH_REMATCH[1]} == 2 && (10#${BASH_REMATCH[2]} < 27 || + (10#${BASH_REMATCH[2]} == 27 && 10#${BASH_REMATCH[3]} < 2))) )); then + echo "Docker Compose 2.27.2 or newer is required; found '$COMPOSE_VERSION'. Upgrade Docker Compose and retry." >&2 + exit 1 +fi +MEMORY="$(docker info --format '{{.MemTotal}}')" || { + echo 'Docker is not running or is inaccessible. Start Docker and retry.' >&2; exit 1; +} +COMPOSE=(docker compose --project-directory "$HERE" -f "$HERE/compose.yaml") +if [[ -f "$HERE/.env" ]]; then + COMPOSE+=(--env-file "$HERE/.env") +fi +if [[ "$BUILD" == 1 ]]; then + COMPOSE+=(-f "$HERE/compose.build.yaml") +fi +if [[ "$LOCAL_LLM" == 1 ]]; then + export GATEWAY_LLM_PROVIDER=ollama GATEWAY_OLLAMA_BASE_URL=http://ollama:11434 Review Comment: Fixed in `0943ddd424c`: reject conflicting provider configuration before startup with a clear error. Tests cover shell and `.env` settings. -- 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]
