Skip to content
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

New params in TPT query to indicate #137

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
72 changes: 72 additions & 0 deletions parts/03-query-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,75 @@ summary_statistics() {
get_user_filter() {
echo "(galaxy_user.email = '$1' or galaxy_user.username = '$1' or galaxy_user.id = CAST(REGEXP_REPLACE('$1', '.*\D+.*', '-1') AS INTEGER))"
}

function create_sql_parameters_select() {
local strSelect = ""

if [[ -n $arg_arrSelect1 ]]; then
if [[ $(echo "$arg_arrSelect1" | cut -d';' -f1) == "when" ]]; then
strSelect+=" WHEN" $(echo "$arg_arrSelect1" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect1" | cut -d';' -f3)
else
strSelect+="ELSE" $(echo "$arg_arrSelect1" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrSelect2" | cut -d';' -f1) == "when" ]]; then
strSelect+=" WHEN" $(echo "$arg_arrSelect2" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect2" | cut -d';' -f3)
else
strSelect+=" ELSE" $(echo "$arg_arrSelect2" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrSelect3" | cut -d';' -f1) == "when" ]]; then
strSelect+=" WHEN" $(echo "$arg_arrSelect3" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect3" | cut -d';' -f3)
else
strSelect+=" ELSE" $(echo "$arg_arrSelect3" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrSelect4" | cut -d';' -f1) == "when" ]]; then
strSelect+=" WHEN" $(echo "$arg_arrSelect4" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect4" | cut -d';' -f3)
else
strSelect+=" ELSE" $(echo "$arg_arrSelect4" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrSelect5" | cut -d';' -f1) == "when" ]]; then
strSelect+=" WHEN" $(echo "$arg_arrSelect5" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect5" | cut -d';' -f3)
else
strSelect+=" ELSE" $(echo "$arg_arrSelect5" | cut -d';' -f3)
fi

strSelect="CASE" $strSelect "END"
fi

return $strSelect;
}

function create_sql_parameters_where() {
local strWhere = ""

if [[ -n $arg_arrWhere1 ]]; then
if [[ $(echo "$arg_arrWhere1" | cut -d';' -f1) == "when" ]]; then
strWhere+=" WHEN" $(echo "$arg_arrWhere1" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere1" | cut -d';' -f3)
else
strWhere+="ELSE" $(echo "$arg_arrWhere1" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrWhere2" | cut -d';' -f1) == "when" ]]; then
strWhere+=" WHEN" $(echo "$arg_arrWhere2" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere2" | cut -d';' -f3)
else
strWhere+=" ELSE" $(echo "$arg_arrWhere2" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrWhere3" | cut -d';' -f1) == "when" ]]; then
strWhere+=" WHEN" $(echo "$arg_arrWhere3" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere3" | cut -d';' -f3)
else
strWhere+=" ELSE" $(echo "$arg_arrWhere3" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrWhere4" | cut -d';' -f1) == "when" ]]; then
strWhere+=" WHEN" $(echo "$arg_arrWhere4" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere4" | cut -d';' -f3)
else
strWhere+=" ELSE" $(echo "$arg_arrWhere4" | cut -d';' -f3)
fi
if [[ $(echo "$arg_arrWhere5" | cut -d';' -f1) == "when" ]]; then
strWhere+=" WHEN" $(echo "$arg_arrWhere5" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere5" | cut -d';' -f3)
else
strWhere+=" ELSE" $(echo "$arg_arrWhere5" | cut -d';' -f3)
fi

strWhere="CASE" $strWhere "END"
fi

return $strWhere;
}
24 changes: 21 additions & 3 deletions parts/22-query.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4723,7 +4723,17 @@ query_potentially-duplicated-reclaimable-space() { ##?
EOF
}

query_tpt-tool-cpu() { ##? [--startyear=<YYYY>] [--endyear=<YYYY>] [--formula=avg]: Start year is required. Formula returns sum if blank.
query_tpt-tool-cpu() { ##? [--startyear=<YYYY>] [--endyear=<YYYY>] [--formula=avg] [--arrSelect1={type};{hypothesis};{conclusion}] [--arrSelect2=...] [--arrWhere1={hypothesis};{conclusion}] [--arrWhere2=...]: Start year is required. Formula returns sum if blank. arrSelect maximum inputs is 5. arrWhere maximum inputs is 5.

# Example arguments:
# --startyear=2022
# --endyear=2024
# --formula=sum
# --arrSelect1="when;destination_id LIKE 'stampede%';metric_value"
# --arrSelect2="else; null;metric_value / 1000000000"
# --arrWhere1="destination_id LIKE 'stampede%';metric_name = 'runtime_seconds'"
# --arrWhere2="metric_name = 'cpuacct.usage';null"

meta <<-EOF
AUTHORS: hujambo-dunia
ADDED: 20
Expand Down Expand Up @@ -4760,16 +4770,24 @@ query_tpt-tool-cpu() { ##? [--startyear=<YYYY>] [--endyear=<YYYY>] [--formula=av
sql_formula="SUM"
Copy link
Member

Choose a reason for hiding this comment

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

is this variable not used?

fi

if [[ -n $arg_arrSelect1 ]]; then
sql_select=$(create_sql_parameters_select "$arg_arrSelect1" "$arg_arrSelect2" "$arg_arrSelect3" "$arg_arrSelect4" "$arg_arrSelect5")
fi

if [[ -n $arg_arrWhere1 ]]; then
sql_where=$(create_sql_parameters_where "$arg_arrWhere1" "$arg_arrWhere2" "$arg_arrWhere3" "$arg_arrWhere4" "$arg_arrWhere5")
fi

read -r -d '' QUERY <<-EOF
WITH cpu_usage AS (
SELECT
DISTINCT job_id,
destination_id,
metric_value / 1000000000 AS cpu_usage_seconds
$sql_select cpu_usage_seconds
FROM
job_metric_numeric
WHERE
metric_name = 'cpuacct.usage'
$sql_where
)
SELECT
job.tool_id,
Expand Down