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. Win8系统108个运行命令 你能记住多少?

    Win8运行命令:程序和功能   取消了开始菜单的Win8让人感觉很不习惯,这才发现原来开始菜单可以做这么多事.不过Win8中的一些快捷键还沿用了Windows一直以来的习惯,比如按下Windows ...

  2. GB2312简体中文编码表

    GB2312简体中文编码表 code +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F A1A0 . . · ˉ ˇ ¨ " 々 — - | … ...

  3. Source Insight常用快捷键及注释快捷键设置

    转:http://blog.csdn.net/tlaff/article/details/6536610 在使用SI过程中,我根据自己的使用习惯修改了它的默认快捷键,并且在配置文件中添加了一些人性化功 ...

  4. 【JS】 JS毫秒值转化为正常格式 或者正常格式转化为毫秒值

    1.毫秒值转化为正常时间格式  最简单的方法 new Date(后台传来的毫秒值).toLocaleDateString() 就是这个样子 2.毫秒值转化为自定义的时间格式 本页面重写一下  toLo ...

  5. [Android 新特性] Android 4.3新功能(正式发布前)

    腾讯数码讯(编译:徐萧梓丞)虽然谷歌公司目前尚未正式对外发布最新的Android 4.3果冻豆操作系统,但是在上周我们已经看到了关于三星正 在为原生版Galaxy S4进行Android 4.3系统进 ...

  6. 与多线程结合使用的消息处理类Handler、Message

    1. 消息处理类——Handler 消息处理类(Handler)允许发送和处理Message或Runnable对象到其所在线程的MessageQueue中.Handerl有以下两个主要作用: 将Mes ...

  7. DEDECMS网站管理系统Get Shell漏洞

    漏洞版本: DEDECMS 5.3/5.6 漏洞描述: DedeCms 基于PHP+MySQL的技术开发,支持Windows.Linux.Unix等多种服务器平台,从2004年开始发布第一个版本开始, ...

  8. 如何在android模拟器中导入搜狗输入法?

    1.下载输入法程序,如:sogouinput_android_1.6_sweb.apk 2.然后cmd进入sdk的tools(有的是platform-tools)目录,输入adb install C: ...

  9. SQL 增删字段

    摘自: http://www.cnblogs.com/yiwd/archive/2012/12/25/2831822.html 下面为您介绍使用SQL语句如何增加.删除.修改字段,并判断字段是否存在的 ...

  10. Oracle Spatial 创建空间表、添加空间原表信息、添加删除空间索引

    一.创建空间表 创建一个空间表tbsvrc_buffer_t ,SQL如下: create table tbsvrc_buffer_t(  ID      VARCHAR2(50) not null, ...