通过表名和时间查看hive分区表的数据

[linux-]$  /home/script/listHive.py  ta_name_1002_user_search_log_day  20180626

#!/usr/bin/env python
# -*- coding: utf-8 -*-
##########################################
# 通过表名和时间查看hive分区表的数据 
# len(sys.argv)--输入参数个数
# sys.argv[1] -- 表名
# sys.argv[2] -- 时间 
# 创建者:df    
# 创建日期:2018年06月25日
###############################################
import os
import sys

ll = len(sys.argv)
def pri(com):
    print("command: '%s'" % com)
    os.system(com)
    sys.exit(0) 

if ll < 2:
    print('no parameter !')
    print('Please enter the format !')
    print("./l_hive.py tableName  [date]")
    sys.exit(1)
#获取表名
v_tablename = sys.argv[1]
command = "hadoop fs -ls  /apps/hive/warehouse/*/%s" % v_tablename
if ll == 2:
    pri(command)

v_time = sys.argv[2]
if ll > 2:
    # 获取时间长度
    len = len(v_time)
    if len <4:
        pri(command)
    else:
        num = len / 2 - 3 + 1
        for i in range(num):
            sublen = 6 + i * 2
            command = "%s/*=%s" % (command, v_time[0:sublen]) 
        pri(command)
else:
    print('Please enter the format !')
    print("./l_hive.py tableName  [date]")
    sys.exit(1)
View Code

猜你喜欢

转载自www.cnblogs.com/coding2018/p/9229806.html
今日推荐