Skip to content

Instantly share code, notes, and snippets.

@abicky
Created October 3, 2011 18:51
Show Gist options
  • Save abicky/1259902 to your computer and use it in GitHub Desktop.
Save abicky/1259902 to your computer and use it in GitHub Desktop.
print linenumber where error occurs in Pig
#!/bin/bash
usage() {
cat <<USAGE
usage: $(basename $0) [-p <param_name>=param_value] [-m <file_name>] [-x exectype] <script>
Execute the script with access to grunt environment.
-p <param_name - See parameter substitution for details.
-m <file_name> - See parameter substitution for details.
-x <exectype> - Set execution mode: local|mapreduce, default is mapreduce.
script - Script to be executed.
USAGE
exit 1
}
while getopts p:m:x: OPT; do
case $OPT in
p) param="$param -param $OPTARG";;
m) param_file="$param_file -param_file $OPTARG";;
x) exectype="-x $OPTARG";;
esac
done
shift $(($OPTIND - 1))
[ $# -eq 1 ] || usage
script=$1
tmpfile=$(mktemp /tmp/$(basename $script).XXXXXXXXXX)
# remove characters except ASCII characters
perl -nle 's/[^\x00-\x7F]//g; print' $script >$tmpfile
line_num=$(echo run $param $param_file $tmpfile | pig $exectype | wc -l)
echo at line $(($line_num - 1)) 1>&2
rm $tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment