-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: add the latest tag to the docker image #79
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
58ace76
Add the latest tag to the Docker image if it is the main branch
prmoore77 4c761c0
Fixed client-demo for Docker / K8s
prmoore77 df03fa4
Ruff format
prmoore77 b5b8b7f
Ruff lint fixes
prmoore77 7e982b7
Added license header
prmoore77 f439bba
Used file.stem instead of splitting the name - per recommendation by …
prmoore77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
helm-chart | ||
tls | ||
.github | ||
Dockerfile | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This script starts the Spark Substrait Gateway demo server. | ||
# It will create demo TPC-H (Scale Factor 1GB) data, and start the server. | ||
|
||
set -e | ||
|
||
if [ $(echo "${GENERATE_CLIENT_DEMO_DATA}" | tr '[:upper:]' '[:lower:]') == "true" ]; then | ||
echo "Generating client demo TPC-H data..." | ||
spark-substrait-create-client-demo-data | ||
fi | ||
|
||
spark-substrait-gateway-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""A utility module for generating TPC-H parquet data for the client demo.""" | ||
|
||
import logging | ||
import os | ||
import shutil | ||
import sys | ||
from pathlib import Path | ||
|
||
import click | ||
import duckdb | ||
|
||
from .client_demo import CLIENT_DEMO_DATA_LOCATION | ||
|
||
# Setup logging | ||
logging.basicConfig( | ||
format="%(asctime)s - %(levelname)-8s %(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S %Z", | ||
level=getattr(logging, os.getenv("LOG_LEVEL", "INFO")), | ||
stream=sys.stdout, | ||
) | ||
_LOGGER = logging.getLogger() | ||
|
||
|
||
def execute_query(conn: duckdb.DuckDBPyConnection, query: str): | ||
"""Execute and log a query with a DuckDB connection.""" | ||
_LOGGER.info(msg=f"Executing SQL: '{query}'") | ||
conn.execute(query=query) | ||
|
||
|
||
def get_printable_number(num: float): | ||
"""Return a number in a printable format.""" | ||
return f"{num:.9g}" | ||
|
||
|
||
def generate_tpch_parquet_data( | ||
tpch_scale_factor: int, data_directory: str, overwrite: bool | ||
) -> Path: | ||
"""Generate a TPC-H parquet dataset.""" | ||
_LOGGER.info( | ||
msg=( | ||
"Creating a TPC-H parquet dataset - with parameters: " | ||
f"--tpch-scale-factor={tpch_scale_factor} " | ||
f"--data-directory='{data_directory}' " | ||
f"--overwrite={overwrite}" | ||
) | ||
) | ||
|
||
# Output the database version | ||
_LOGGER.info(msg=f"Using DuckDB Version: {duckdb.__version__}") | ||
|
||
# Get an in-memory DuckDB database connection | ||
conn = duckdb.connect() | ||
|
||
# Load the TPCH extension needed to generate the data... | ||
conn.load_extension(extension="tpch") | ||
|
||
# Generate the data | ||
execute_query(conn=conn, query=f"CALL dbgen(sf={tpch_scale_factor})") | ||
|
||
# Export the data | ||
target_directory = Path(data_directory) | ||
|
||
if target_directory.exists(): | ||
if overwrite: | ||
_LOGGER.warning(msg=f"Directory: {target_directory.as_posix()} exists, removing...") | ||
shutil.rmtree(path=target_directory.as_posix()) | ||
else: | ||
raise RuntimeError(f"Directory: {target_directory.as_posix()} exists, aborting.") | ||
|
||
target_directory.mkdir(parents=True, exist_ok=True) | ||
execute_query( | ||
conn=conn, query=f"EXPORT DATABASE '{target_directory.as_posix()}' (FORMAT PARQUET)" | ||
) | ||
|
||
_LOGGER.info(msg=f"Wrote out parquet data to path: '{target_directory.as_posix()}'") | ||
|
||
# Restructure the contents of the directory so that each file is in its own directory | ||
for filename in target_directory.glob(pattern="*.parquet"): | ||
file = Path(filename) | ||
table_name = file.stem | ||
table_directory = target_directory / table_name | ||
table_directory.mkdir(parents=True, exist_ok=True) | ||
|
||
if file.name not in ("nation.parquet", "region.parquet"): | ||
new_file_name = f"{table_name}.1.parquet" | ||
else: | ||
new_file_name = file.name | ||
|
||
file.rename(target=table_directory / new_file_name) | ||
|
||
_LOGGER.info(msg="All done.") | ||
|
||
return target_directory | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--tpch-scale-factor", | ||
type=float, | ||
default=1, | ||
show_default=True, | ||
required=True, | ||
help="The TPC-H scale factor to generate.", | ||
) | ||
@click.option( | ||
"--data-directory", | ||
type=str, | ||
default=CLIENT_DEMO_DATA_LOCATION.as_posix(), | ||
show_default=True, | ||
required=True, | ||
help="The target output data directory to put the files into", | ||
) | ||
@click.option( | ||
"--overwrite/--no-overwrite", | ||
type=bool, | ||
default=False, | ||
show_default=True, | ||
required=True, | ||
help="Can we overwrite the target directory if it already exists...", | ||
) | ||
def click_generate_tpch_parquet_data(tpch_scale_factor: int, data_directory: str, overwrite: bool): | ||
"""Provide a click interface for generating TPC-H parquet data.""" | ||
generate_tpch_parquet_data(**locals()) | ||
|
||
|
||
if __name__ == "__main__": | ||
click_generate_tpch_parquet_data() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also want to include the TPC-DS data or would we rather keep the footprint of the image small?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could potentially add it - I just targeted to TPC-H b/c that is what the client-demo file needed. Would doing it in a later PR be ok, if needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, no need to overbuild this.