Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 13 additions & 82 deletions presto/scripts/run_integ_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,88 +49,19 @@ EOF

KEEP_TABLES=false

parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
print_help
exit 0
;;
-b|--benchmark-type)
if [[ -n $2 ]]; then
BENCHMARK_TYPE=$2
shift 2
else
echo "Error: --benchmark-type requires a value"
exit 1
fi
;;
-q|--queries)
if [[ -n $2 ]]; then
QUERIES=$2
shift 2
else
echo "Error: --queries requires a value"
exit 1
fi
;;
-k|--keep-tables)
KEEP_TABLES=true
shift
;;
-h|--hostname)
if [[ -n $2 ]]; then
HOST_NAME=$2
shift 2
else
echo "Error: --hostname requires a value"
exit 1
fi
;;
-p|--port)
if [[ -n $2 ]]; then
PORT=$2
shift 2
else
echo "Error: --port requires a value"
exit 1
fi
;;
-u|--user)
if [[ -n $2 ]]; then
USER=$2
shift 2
else
echo "Error: --user requires a value"
exit 1
fi
;;
-s|--schema-name)
if [[ -n $2 ]]; then
SCHEMA_NAME=$2
shift 2
else
echo "Error: --schema-name requires a value"
exit 1
fi
;;
-f|--scale-factor)
if [[ -n $2 ]]; then
SCALE_FACTOR=$2
shift 2
else
echo "Error: --scale-factor requires a value"
exit 1
fi
;;
*)
echo "Error: Unknown argument $1"
print_help
exit 1
;;
esac
done
}
source ../../scripts/helper_functions.sh

declare -A OPTION_MAP=( ["-b"]="--benchmark-type"
["-q"]="--queries"
["-h"]="--hostname"
["-p"]="--port"
["-u"]="--user"
["-s"]="--schema-name"
["-f"]="--scale-factor" )
make_options "OPTION_MAP"

declare -A FLAG_MAP=( ["-k"]="--keep-tables" )
make_flags "FLAG_MAP"

parse_args "$@"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,18 @@ if [[ -z $PRESTO_DATA_DIR ]]; then
exit 1
fi

source ./common_functions.sh
source ../../scripts/helper_functions.sh

wait_for_worker_node_registration
declare -A OPTION_MAP=( ["-b"]="--benchmark-type"
["-d"]="--data-dir-name"
["-s"]="--schema-name" )
make_options "OPTION_MAP"

parse_args() {
custom_parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
print_help
exit 0
;;
-b|--benchmark-type)
if [[ -n $2 ]]; then
BENCHMARK_TYPE=$2
shift 2
else
echo "Error: --benchmark-type requires a value"
exit 1
fi
;;
-s|--schema-name)
if [[ -n $2 ]]; then
SCHEMA_NAME=$2
shift 2
else
echo "Error: --schema-name requires a value"
exit 1
fi
;;
-d|--data-dir-name)
if [[ -n $2 ]]; then
DATA_DIR_NAME=$2
shift 2
else
echo "Error: --data-dir-name requires a value"
exit 1
fi
;;
-h|--help) print_help; exit 0;;
$OPTIONS) parse_option $1 $2; shift 2;;
-c|--convert-decimals-to-floats)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left this one in since it sets it's variable to a custom value, rather than "TRUE"

CONVERT_DECIMALS_TO_FLOATS_ARG="--convert-decimals-to-floats"
shift
Expand All @@ -118,7 +92,11 @@ parse_args() {
done
}

parse_args "$@"
custom_parse_args "$@"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved argument parsing before waiting on worker node so the user can use functions like "--help" without having to wait for a worker registration.


source ./common_functions.sh

wait_for_worker_node_registration

if [[ -z ${BENCHMARK_TYPE} || ! ${BENCHMARK_TYPE} =~ ^tpc(h|ds)$ ]]; then
echo "Error: A valid benchmark type (tpch or tpcds) is required. Use the -b or --benchmark-type argument."
Expand Down
4 changes: 2 additions & 2 deletions presto/scripts/start_presto_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

set -e

source ./start_presto_helper_parse_args.sh
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this up so the user can use "--help" before running into the ENV variable validation.


if [[ -z ${VARIANT_TYPE} || ! ${VARIANT_TYPE} =~ ^(cpu|gpu|java)$ ]]; then
echo "Internal error: A valid variant type (cpu, gpu, or java) is required. Set VARIANT_TYPE to an appropriate value."
exit 1
Expand All @@ -29,8 +31,6 @@ fi
# Validate repo layout using shared script
../../scripts/validate_directories_exist.sh "../../../presto" "../../../velox"

source ./start_presto_helper_parse_args.sh

COORDINATOR_SERVICE="presto-coordinator"
COORDINATOR_IMAGE=${COORDINATOR_SERVICE}:latest
JAVA_WORKER_SERVICE="presto-java-worker"
Expand Down
45 changes: 11 additions & 34 deletions presto/scripts/start_presto_helper_parse_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,25 @@ EOF

NUM_THREADS=$(($(nproc) / 2))

parse_args() {
source ../../scripts/helper_functions.sh
declare -A OPTION_MAP=( ["-b"]="--build-target" ["-j"]="--num-threads" )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed --build to --build-target to match up with the variable being set.

make_options "OPTION_MAP"

custom_parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
print_help
exit 0
;;
-n|--no-cache)
SKIP_CACHE_ARG="--no-cache"
shift
;;
-b|--build)
if [[ -n $2 ]]; then
BUILD_TARGET=$2
shift 2
else
echo "Error: --build requires a value"
exit 1
fi
;;
-j|--num-threads)
if [[ -n $2 ]]; then
NUM_THREADS=$2
shift 2
else
echo "Error: --num-threads requires a value"
exit 1
fi
;;
*)
echo "Error: Unknown argument $1"
print_help
exit 1
;;
-h|--help) print_help; exit 0 ;;
-n|--no-cache) SKIP_CACHE_ARG="--no-cache"; shift ;;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left custom in.

$OPTIONS) parse_option $1 $2; shift 2 ;;
*) echo "Error: Unknown argument $1"; print_help; exit 1 ;;
esac
done
}

parse_args "$@"
custom_parse_args "$@"

if [[ -n ${BUILD_TARGET} && ! ${BUILD_TARGET} =~ ^(coordinator|c|worker|w|all|a)$ ]]; then
echo "Error: invalid --build value."
echo "Error: invalid --build-target value."
print_help
exit 1
fi
Expand Down
43 changes: 10 additions & 33 deletions presto/testing/integration_tests/scripts/generate_test_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,26 @@ EOF
SCALE_FACTOR=0.01
CONVERT_DECIMALS_TO_FLOATS=false

parse_args() {
source ../../scripts/helper_functions.sh
declare -A OPTION_MAP=( ["-b"]="--benchmark-type" ["-f"]="--scale-factor" )
make_options "OPTION_MAP"

custom_parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
print_help
exit 0
;;
-b|--benchmark-type)
if [[ -n $2 ]]; then
BENCHMARK_TYPE=$2
shift 2
else
echo "Error: --benchmark-type requires a value"
exit 1
fi
;;
-s|--scale-factor)
if [[ -n $2 ]]; then
SCALE_FACTOR=$2
shift 2
else
echo "Error: --scale-factor requires a value"
exit 1
fi
;;
-h|--help) print_help; exit 0 ;;
$OPTIONS) parse_option $1 $2; shift 2;;
-c|--convert-decimals-to-floats)
CONVERT_DECIMALS_TO_FLOATS=true
shift
;;
-v|--verbose)
VERBOSE="--verbose"
shift
;;
*)
echo "Error: Unknown argument $1"
print_help
exit 1
;;
-v|--verbose) VERBOSE="--verbose"; shift ;;
*) echo "Error: Unknown argument $1"; print_help; exit 1;;
esac
done
}

parse_args "$@"
custom_parse_args "$@"

if [[ -z $BENCHMARK_TYPE ]]; then
BENCHMARK_TYPES_TO_GENERATE=("tpch" "tpcds")
Expand Down
79 changes: 79 additions & 0 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Copyright (c) 2025, NVIDIA CORPORATION.
#
# Licensed 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.

shopt -s extglob # needed for paramaterized case statement

function make_options() {
local -n LOCAL_OPTION_MAP="$1"
declare -g OPTIONS="@("
SEPARATOR=""
for key in "${!LOCAL_OPTION_MAP[@]}"; do
OPTIONS+="${SEPARATOR}$key|${LOCAL_OPTION_MAP[$key]}"
SEPARATOR="|"
done
OPTIONS+=")"
}

function make_flags() {
local -n LOCAL_FLAG_MAP="$1"
FLAGS="@("
SEPARATOR=""
for key in "${!LOCAL_FLAG_MAP[@]}"; do
FLAGS+="${SEPARATOR}$key|${LOCAL_FLAG_MAP[$key]}"
SEPARATOR="|"
done
FLAGS+=")"
}

function parse_option() {
local option=$1
[[ -v OPTION_MAP["$option"] ]] && option=${OPTION_MAP["$option"]}
[[ $# -lt 2 || -z $2 ]] && echo "Error: $option requires a value" >&2 && exit 1
option=${option//--/} # remove double-dash
option=${option//-/_} # replace dash with underscore
option=$(echo "${option^^}") # capitalize
declare -g "$option=$2"
}

function parse_flag() {
local flag=$1
[[ -v FLAG_MAP["$flag"] ]] && flag=${FLAG_MAP["$flag"]}
flag=${flag//--/} # remove double-dash
flag=${flag//-/_} # replace dash with underscore
flag=$(echo "${flag^^}") # capitalize
declare -g "$flag=true"
}

parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
$OPTIONS) parse_option "$@"; shift 2;;
$FLAGS) parse_flag $1; shift 1;;
-h|--help) print_help; exit 0;;
*) echo "Error: Unknown argument $1"; print_help; exit 1;;
esac
done
}

parse_args_no_flags() {
while [[ $# -gt 0 ]]; do
case $1 in
$OPTIONS) parse_option "$@"; shift 2;;
-h|--help) print_help; exit 0;;
*) echo "Error: Unknown argument $1"; print_help; exit 1;;
esac
done
}
Loading