querydate.sh
2015-08-18 13:09
134 查看
#!/bin/bash display_help() { cat <<EOF Usage: ./querydate.sh <command> [options]... commands: help display this text --path 数据存储位置 --date 查询某一给定日期的数据 --from 查询该日期以后的数据 --to 与--from配合使用,查询日期在(from, to]的数据 EOF } error() { local msg=$1 local exit_code=$2 echo "Error: $msg" >&2 if [ -n "$exit_code" ] ; then exit $exit_code fi } ################### # Main ################### q_path="" q_date="" q_from="" q_to="" mode=$1 if [ "$mode" = "help" ] || [ "$mode" = "" ]; then display_help exit 0 fi while [ -n "$*" ] ; do arg=$1 shift case "$arg" in --path) [ -n "$1" ] || error "选项 --path 需要指定一个参数" 1 q_path=$1 shift ;; --date) [ -n "$1" ] || error "选项 --date 需要指定一个参数" 1 q_date=$1 shift ;; --from) [ -n "$1" ] || error "选项 --from 需要指定一个参数" 1 q_from=$1 shift ;; --to) [ -n "$1" ] || error "选项 --to 需要指定一个参数" 1 q_to=$1 shift ;; esac done echo $q_path $q_date $q_from $q_to if [ "$q_path" == "" ]; then error "必须指定 --path 属性" exit 1 fi q_path="$q_path/`date '+%Y%m%d'`" sql="insert overwrite local directory '$q_path' row format delimited fields terminated by '\t' select value from xm.log where 1=1 " if [ "$q_date" != "" ]; then condition="and $q_date=date " elif [ "$q_from" != "" ]; then condition="and unix_timestamp(date, 'yyyyMMdd') > unix_timestamp($q_from, 'yyyyMMdd') " if [ "$q_to" != "" ]; then condition="$condition unix_timestamp(date, 'yyyyMMdd') <= unix_timestamp($q_to, 'yyyyMMdd')" fi fi echo "hive -e \"$sql $condition\""
hive -e "insert overwrite local directory '/home/xiaoming/tmp/20150817' row format delimited fields terminated by '\t' select value from xm.log where 1=1 "
转载于:https://my.oschina.net/u/1474514/blog/493906
相关文章推荐
- get_date.sh
- 执行start-dfs.sh后,datenode没有启动
- PL/SQL dev工具 使用for update-->Edit Date 时出错"These query results are not updateable,Include the ROWID to get updateable results."
- Linux:解决Linux中crontab不执行ntpdate问题(成功解决:/bin/sh: ntpdate: command not found)
- SQL Server 2005中Query(查询)Date Time(日期时间)
- SQL Server 2005中Query(查询)Date Time(日期时间)
- Inventory of the materials to teach you how to query a date certain combination of dimensions
- centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件、目录属性 shell数组简单用法 $( ) 和${ } 和$(( )) 与 sh -n sh -x sh -v 第三十五节课
- 使用Date时,出现"Incorrect datetime value: '' for column 'ordertime' at row 1 Query..."时,该怎么解决呢?
- valgrind --leak-check=full --show-reachable=yes --log-file=a.log ./shdaily.fcgi "op=search&date=2011-04-14
- 执行start-dfs.sh后,datenode没有启动
- 执行start-dfs.sh后,datenode没有启动
- 执行start-dfs.sh后,datenode没有启动
- hibernate date query
- 执行start-dfs.sh后,datenode没有启动的解决办法
- 大数据-执行start-dfs.sh后,datenode没有启动
- 执行start-dfs.sh后,datenode没有启动
- Query to check quantity on historical date
- SQL Server 2005中Query(查询)Date Time(日期时间)时select不出record的问题
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?