例句sql是链接到hive库进行的查询操作
代码如下
imsis = (‘460020291****15‘, ‘46002029****6391‘)
# 构造新数列
# i = "("
# for s in imsis:
# i = i + s + ","
# i = i.strip(‘,‘) + ")"
items = (‘460020291****15‘, ‘46002029****6391‘)
items_tmp = ",".join(items)
items_str = "%s%s%s" %("(", items_tmp, ")")
if imsis:
sql = "select bill_id, imsi as IMSI from data_tmp.bill_imsi where imsi in %s limit 10" %items_str
else:
sql = "select bill_id, imsi as IMSI from data_tmp.bill_imsi limit 10"
print(sql)
con2hive(sql=sql)
注释:
items_tmp = ",".join(items) 实现对元组items根据,以逗号“,”进行分割组成新字符con2hive(sql=sql) 调用链接hive数据仓库的执行函数
输入内容如下
注:列表或元组中必须为字符串才能使用join进行拼接
原文:https://blog.51cto.com/maoxiaoxiong/2357425