Skip to content

Commit

Permalink
Add playground tools read-parquet-file command #5682
Browse files Browse the repository at this point in the history
  • Loading branch information
vdesabou committed Jun 6, 2024
1 parent d8f54af commit 047259d
Show file tree
Hide file tree
Showing 7 changed files with 495 additions and 264 deletions.
538 changes: 275 additions & 263 deletions scripts/cli/completions.bash

Large diffs are not rendered by default.

145 changes: 144 additions & 1 deletion scripts/cli/playground
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ playground_usage() {
printf "%s\n" "$(bold "Tools commands:")"
printf " %s 🧰 Tools commands\n" "$(green "tools") "
printf " %s 🔐 Read provided avro file\n" "$(green "tools read-avro-file") "
printf " %s 🔐 Read provided parquet file\n" "$(green "tools read-parquet-file") "
echo
printf "%s\n" "$(bold "Debug commands:")"
printf " %s 🐞 Debug commands\n" "$(green "debug") "
Expand Down Expand Up @@ -3288,7 +3289,8 @@ playground_tools_usage() {
echo
# :command.usage_commands
printf "%s\n" "$(bold "== Commands ==")"
printf " %s 🔐 Read provided avro file\n" "$(green "read-avro-file")"
printf " %s 🔐 Read provided avro file\n" "$(green "read-avro-file") "
printf " %s 🔐 Read provided parquet file\n" "$(green "read-parquet-file")"
echo

# :command.long_usage
Expand Down Expand Up @@ -3338,6 +3340,41 @@ playground_tools_read_avro_file_usage() {
fi
}

# :command.usage
playground_tools_read_parquet_file_usage() {
if [[ -n $long_usage ]]; then
printf "playground tools read-parquet-file - 🔐 Read provided parquet file\n"
echo

else
printf "playground tools read-parquet-file - 🔐 Read provided parquet file\n"
echo

fi

printf "%s\n" "$(bold "== Usage ==")"
printf " playground tools read-parquet-file [OPTIONS]\n"
printf " playground tools read-parquet-file --help | -h\n"
echo

# :command.long_usage
if [[ -n $long_usage ]]; then
printf "%s\n" "$(bold "== Options ==")"

# :command.usage_flags
# :flag.usage
printf " %s\n" "$(magenta "--file, -f FILE")"
printf " 🔖 Parquet file to read\n \n ❕ It must be absolute full path\n \n 🎓 Tip: use <tab> completion to trigger fzf completion\n"
echo

# :command.usage_fixed_flags
printf " %s\n" "$(magenta "--help, -h")"
printf " Show this help\n"
echo

fi
}

# :command.usage
playground_debug_usage() {
if [[ -n $long_usage ]]; then
Expand Down Expand Up @@ -12211,6 +12248,20 @@ validate_file_exists_and_avro() {
[[ "$real_file" == *.avro ]] || logerror "<$real_file> is not an Avro file. Please provide a file with .avro extension."
}

# src/lib/validations/validate_file_exists_and_parquet.sh
validate_file_exists_and_parquet() {
file="$1"

real_file=$file
if [[ $file == *"@"* ]]
then
real_file=$(echo "$file" | cut -d "@" -f 2)
fi

[[ -f "$real_file" ]] || logerror "<$real_file> does not correspond to the path of an existing file, please make sure to use absolute full path or correct relative path !"
[[ "$real_file" == *.parquet ]] || logerror "<$real_file> is not an Parquet file. Please provide a file with .parquet extension."
}

# src/lib/validations/validate_file_exists_with_trick.sh
validate_file_exists_with_trick() {
file="$1"
Expand Down Expand Up @@ -18443,6 +18494,26 @@ playground_tools_read_avro_file_command() {

}

# :command.function
playground_tools_read_parquet_file_command() {
# src/commands/tools/read-parquet-file.sh
file="${args[--file]}"

if [[ $file == *"@"* ]]
then
file=$(echo "$file" | cut -d "@" -f 2)
fi

filename=$(basename $file)

log "🔖 ${filename}.parquet schema"
docker run --quiet --rm -v ${file}:/tmp/${filename} nathanhowell/parquet-tools schema /tmp/${filename}

log "🔖 ${filename}.parquet content"
docker run --quiet --rm -v ${file}:/tmp/${filename} nathanhowell/parquet-tools cat /tmp/${filename}

}

# :command.function
playground_debug_enable_remote_debugging_command() {
# src/commands/debug/enable-remote-debugging.sh
Expand Down Expand Up @@ -30303,6 +30374,13 @@ playground_tools_parse_requirements() {
shift $#
;;

read-parquet-file)
action="read-parquet-file"
shift
playground_tools_read_parquet_file_parse_requirements "$@"
shift $#
;;

# :command.command_fallback
"")
playground_tools_usage >&2
Expand Down Expand Up @@ -30403,6 +30481,70 @@ playground_tools_read_avro_file_parse_requirements() {

}

# :command.parse_requirements
playground_tools_read_parquet_file_parse_requirements() {
# :command.fixed_flags_filter
while [[ $# -gt 0 ]]; do
case "${1:-}" in
--help | -h)
long_usage=yes
playground_tools_read_parquet_file_usage
exit
;;

*)
break
;;

esac
done

# :command.command_filter
action="tools read-parquet-file"

# :command.parse_requirements_while
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
# :flag.case
--file | -f)

# :flag.case_arg
if [[ -n ${2+x} ]]; then
args['--file']="$2"
shift
shift
else
printf "%s\n" "--file requires an argument: --file, -f FILE" >&2
exit 1
fi
;;

-?*)
printf "invalid option: %s\n" "$key" >&2
exit 1
;;

*)
# :command.parse_requirements_case
# :command.parse_requirements_case_simple
printf "invalid argument: %s\n" "$key" >&2
exit 1

;;

esac
done

# :command.validations
# :flag.validations
if [[ -v args['--file'] && -n $(validate_file_exists_and_parquet "${args['--file']:-}") ]]; then
printf "validation error in %s:\n%s\n" "--file, -f FILE" "$(validate_file_exists_and_parquet "${args['--file']:-}")" >&2
exit 1
fi

}

# :command.parse_requirements
playground_debug_parse_requirements() {
# :command.fixed_flags_filter
Expand Down Expand Up @@ -36288,6 +36430,7 @@ run() {
"tcp-proxy toggle-writes-service") playground_tcp_proxy_toggle_writes_service_command ;;
"tools") playground_tools_command ;;
"tools read-avro-file") playground_tools_read_avro_file_command ;;
"tools read-parquet-file") playground_tools_read_parquet_file_command ;;
"debug") playground_debug_command ;;
"debug enable-remote-debugging") playground_debug_enable_remote_debugging_command ;;
"debug testssl") playground_debug_testssl_command ;;
Expand Down
15 changes: 15 additions & 0 deletions scripts/cli/playground.json
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,21 @@
"description": "🔖 Avro file to read\n\n❕ It must be absolute full path\n\n🎓 Tip: use <tab> completion to trigger fzf completion\n"
}
]
},
{
"name": "read-parquet-file",
"description": "🔐 Read provided parquet file\n",
"usage": "playground tools read-parquet-file [OPTIONS]",
"options": [
{
"names": [
"--file",
"-f"
],
"argument": "FILE",
"description": "🔖 Parquet file to read\n\n❕ It must be absolute full path\n\n🎓 Tip: use <tab> completion to trigger fzf completion\n"
}
]
}
]
},
Expand Down
16 changes: 16 additions & 0 deletions scripts/cli/playground.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,22 @@ subcommands:
🎓 Tip: use <tab> completion to trigger fzf completion
- name: read-parquet-file
description: |
🔐 Read provided parquet file
usage: playground tools read-parquet-file [OPTIONS]
options:
- names:
- --file
- -f
argument: FILE
description: |
🔖 Parquet file to read
❕ It must be absolute full path
🎓 Tip: use <tab> completion to trigger fzf completion
- name: debug
description: |
🐞 Debug commands
Expand Down
18 changes: 18 additions & 0 deletions scripts/cli/src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,24 @@ commands:
🎓 Tip: use <tab> completion to trigger fzf completion
- name: read-parquet-file
help: |-
🔐 Read provided parquet file
flags:
- long: --file
short: -f
required: false
completions:
- $(playground get-specific-file-extension "$cur" --extension "parquet")
validate: file_exists_and_parquet
arg: file
help: |-
🔖 Parquet file to read
❕ It must be absolute full path
🎓 Tip: use <tab> completion to trigger fzf completion
- name: debug
expose: always
group: Debug
Expand Down
14 changes: 14 additions & 0 deletions scripts/cli/src/commands/tools/read-parquet-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
file="${args[--file]}"

if [[ $file == *"@"* ]]
then
file=$(echo "$file" | cut -d "@" -f 2)
fi

filename=$(basename $file)

log "🔖 ${filename}.parquet schema"
docker run --quiet --rm -v ${file}:/tmp/${filename} nathanhowell/parquet-tools schema /tmp/${filename}

log "🔖 ${filename}.parquet content"
docker run --quiet --rm -v ${file}:/tmp/${filename} nathanhowell/parquet-tools cat /tmp/${filename}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## [@bashly-upgrade validations]
validate_file_exists_and_parquet() {
file="$1"

real_file=$file
if [[ $file == *"@"* ]]
then
real_file=$(echo "$file" | cut -d "@" -f 2)
fi

[[ -f "$real_file" ]] || logerror "<$real_file> does not correspond to the path of an existing file, please make sure to use absolute full path or correct relative path !"
[[ "$real_file" == *.parquet ]] || logerror "<$real_file> is not an Parquet file. Please provide a file with .parquet extension."
}

0 comments on commit 047259d

Please sign in to comment.