1、直接执行.sql脚本

import numpy as np
import pandas as pd
import lightgbm as lgb
from pandas import DataFrame
from sklearn.model_selection import train_test_split
from io import StringIO
import gc
import sys
import os
hive_cmd = "hive -f ./sql/sql.sql"
output = os.popen(hive_cmd)
data_cart_prop = pd.read_csv(StringIO(unicode(output.read(),'utf-8')), sep="\t",header=0)

  

2、Hive语句执行

假如有如下hive sql:
hive_cmd = 'hive -e "select count(*) from hbase.routermac_sort_10;"'
一般在python中按照如下方式执行该hive sql:
os.system(hive_cmd)

---------------------

hive_cmd1 = "hive -f ./user.sql"
output1 = os.popen(hive_cmd1)
test_user = pd.read_csv(StringIO(unicode(output1.read(),'utf-8')), sep="\t",header=0) hive_cmd2 = "hive -f ./action.sql"
output2 = os.popen(hive_cmd2)
test_action = pd.read_csv(StringIO(unicode(output2.read(),'utf-8')), sep="\t",header=0) hive_cmd3 = "hive -f ./click.sql"
output3 = os.popen(hive_cmd3)
test_click = pd.read_csv(StringIO(unicode(output3.read(),'utf-8')), sep="\t",header=0)

为了显示表头,在脚本中加上一句:set hive.cli.print.header=true;

或者,使用如下语句:

hive_cmd = 'hive -e "set hive.cli.print.header=true;SELECT * FROM dev.temp_dev_jypt_decor_user_label_phase_one_view_feature WHERE(dt = "2018-09-17");"'
output = os.popen(hive_cmd)
data_cart_prop = pd.read_csv(StringIO(unicode(output.read(),'utf-8')), sep="\t",header=0)

 

3、tf 显存占用

import tensorflow as tf
tf.enable_eager_execution()
x = tf.get_variable('x', shape=[1], initializer=tf.constant_initializer(3.))
with tf.GradientTape() as tape:
y = tf.square(x)
y_grad = tape.gradient(y, x)
print([y.numpy(), y_grad.numpy()])

  

python 中写hive 脚本的更多相关文章

  1. python中写shell(转)

    python中写shell,亲测可用,转自stackoverflow To run a bash script, copy from stackoverflow def run_script(scri ...

  2. 转--python 中写单例

    原文地址 原文地址2 Python中的单例模式的几种实现方式的及优化 阅读目录(Content) 单例模式 实现单例模式的几种方式 1.使用模块 2.使用装饰器 3.使用类 4.基于__new__方法 ...

  3. python中获取执行脚本路径方法

    1.sys.path[0]:获取执行脚本目录绝对路径 #每次执行脚本时,python会将执行脚本目录加入PYTHONPATH环境变量中(sys.path获取) #!/usr/bin/python3 i ...

  4. [Python]在python中调用shell脚本,并传入参数-02python操作shell实例

    首先创建2个shell脚本文件,测试用. test_shell_no_para.sh 运行时,不需要传递参数 test_shell_2_para.sh 运行时,需要传递2个参数  test_shell ...

  5. 怎样在python中写注释

    python中的注释是以井号: # 开头, 一般会在#后加一个空格. # This is a comment print("Hello, World!") 多行注释的语法是三引号: ...

  6. Python中写一个乒乓球类的游戏

    最近开始学Python,感觉挺好玩的,既有脚本语言的灵活性,又有丰富的类库与面向对象的特点,开发起来很方便. 游戏的规则和乒乓球一样,如果妙蛙种子掉地上了就算输,你可以用蓝色的跷跷板弹它,使他不落到地 ...

  7. ubuntu中写sh脚本

    批量执行命令 https://jingyan.baidu.com/article/3052f5a121c8ac97f21f8661.html 批量执行脚本也是可行的! 如,main.sh内写   sh ...

  8. ASP.NET aspx页面中 写C#脚本; ASP.NET 指令(<%@%>);

    1 <h2>Welcome</h2> <ul> <% for (int i = 0; i <= Convert.ToInt32(ViewData[&qu ...

  9. oozie的shell-action中加入hive脚本命令启动执行shell同时操作hive,抛异常Container killed on request. Exit code is 143 Container exited with a non-zero exit code 143

    使用oozie来调度操作,用shell的action执行命令,其中shell里包含着hive -e 操作执行时,oozie窗口报 WARN ShellActionExecutor: - SERVER[ ...

随机推荐

  1. java开发常用的Linux命令

    原文:https://www.cnblogs.com/not-alone/p/8505925.html 1.查找文件 find / -name filename.txt 根据名称查找/目录下的file ...

  2. 将Linux代码移植到Windows的简单方法

    一.前言 Linux拥有丰富各种源代码资源,但是大部分代码在Windows平台情况是无法正常编译的.Windows平台根本无法直接利用这些源代码资源.如果想要使用完整的代码,就要做移植工作.因为C/C ...

  3. Appium+python自动化55-appium desktop每次启动安装Unlock和Appium Setting问题

    前言 部分真机可能会出现每次运行代码,启动app之前都会重复安装Unlock和Appium Setting这两个小工具,有的手机会自动安装,这个还好. 有的手机每次都会弹出一个安装确认框(如部分小米和 ...

  4. 关于Mantis变更日志(Changelog)和路线图(Roadmap)的说明

    变更日志(Changelog):是已经修改好了问题的日志,需要给项目添加版本号,并且在添加/解决问题时都指定了相应的版本号,才会显示. 路线图(Roadmap):是计划在某个版本修改某些问题的日志,需 ...

  5. Power Desginer系列00【转载】

    绪论 Sybase PowerDesigner(简称PD)是最强大的数据库建模工具,市场占有率第一,功能也确实十分强大,现在最新版本是15.1,已经支持最新的SQL Server 2008等数据库,另 ...

  6. #pragma详细解释(一)

    #pragma详细解释 #pragma详细解释(一) 2010-04-18 14:21:00|  分类: 默认分类 |  标签: |字号大中小订阅     在#Pragma是预处理指令它的作用是设定编 ...

  7. Linux Centos7安装chrome浏览器

    参考:https://blog.csdn.net/u010472499/article/details/72327963 1. 配置yum源 在目录 /etc/yum.repos.d/ 下新建文件 g ...

  8. mysql 下 计算 两点 经纬度 之间的距离

    公式如下,单位米: 第一点经纬度:lng1 lat1 第二点经纬度:lng2 lat2 round(6378.138*2*asin(sqrt(pow(sin( (lat1*pi()/180-lat2* ...

  9. Sqlite清空表数据

    delete from TableName; //清空数据 where name ='TableName';//自增长ID为0

  10. C# 网络斗地主源码开源

    C# 网络斗地主源码开源多线程 讨论交流及  下载地址 可以发送聊天消息