python 中写hive 脚本
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 脚本的更多相关文章
- python中写shell(转)
python中写shell,亲测可用,转自stackoverflow To run a bash script, copy from stackoverflow def run_script(scri ...
- 转--python 中写单例
原文地址 原文地址2 Python中的单例模式的几种实现方式的及优化 阅读目录(Content) 单例模式 实现单例模式的几种方式 1.使用模块 2.使用装饰器 3.使用类 4.基于__new__方法 ...
- python中获取执行脚本路径方法
1.sys.path[0]:获取执行脚本目录绝对路径 #每次执行脚本时,python会将执行脚本目录加入PYTHONPATH环境变量中(sys.path获取) #!/usr/bin/python3 i ...
- [Python]在python中调用shell脚本,并传入参数-02python操作shell实例
首先创建2个shell脚本文件,测试用. test_shell_no_para.sh 运行时,不需要传递参数 test_shell_2_para.sh 运行时,需要传递2个参数 test_shell ...
- 怎样在python中写注释
python中的注释是以井号: # 开头, 一般会在#后加一个空格. # This is a comment print("Hello, World!") 多行注释的语法是三引号: ...
- Python中写一个乒乓球类的游戏
最近开始学Python,感觉挺好玩的,既有脚本语言的灵活性,又有丰富的类库与面向对象的特点,开发起来很方便. 游戏的规则和乒乓球一样,如果妙蛙种子掉地上了就算输,你可以用蓝色的跷跷板弹它,使他不落到地 ...
- ubuntu中写sh脚本
批量执行命令 https://jingyan.baidu.com/article/3052f5a121c8ac97f21f8661.html 批量执行脚本也是可行的! 如,main.sh内写 sh ...
- ASP.NET aspx页面中 写C#脚本; ASP.NET 指令(<%@%>);
1 <h2>Welcome</h2> <ul> <% for (int i = 0; i <= Convert.ToInt32(ViewData[&qu ...
- 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[ ...
随机推荐
- VirtualBox 4.3.18 启动虚拟机时显示不能加载 R3模块并退出故障解决一例
VirtualBox 升级到 4.3.1x后一直问题不断.搜了些资料,发现这货从最近的某个版本开始,为了安全,要校验进程完整性,那些在运行时要注入Virtualbox进程的模块都要进行校验.于是乎出现 ...
- asp动态数组
本文所说的 ASP 数组是指在 ASP 中以默认语言 VBScript 为语言的数组. 样例: Dim MyArray() for i = 0 to 10 ...
- 使用JS在客户端判断当前网络状态
1. navigator.onLine 2. ajax请求 3. 获取网络资源 1. navigator.onLine 通过navigator.onLine判断当前网络状态: 12345 if(nav ...
- InstallShield 2010集成.net Framework 4的安装包制作
InstallShield 2010中制作安装包时,对于集成.net Framework 4以前的版本,如3.5 sp1/3.5/3.0/2.0 sp2/2.0sp1/2.0等提供了现成的prq文件模 ...
- javascript函数中的匿名函数
一般写函数,我们会这样调用: function add(x, y) { return x + y; } alert(add(2, 3)); 或者这样: var add = function(x, y) ...
- Java 3D游戏引擎——JME(java Monkey Engine)
转自:http://bbs.gameres.com/forum.php?mod=viewthread&tid=180732 JME(java Monkey Engine),一个非常棒的Java ...
- 【java web】java运行预编译Groovy脚本
在JVM中执行Groovy类有两种方式: 使用Groovy编译全部的*.groovy为java的*.class文件,把这些*.class文件放在java类路径中,通过java类载入器来载入这些类. 通 ...
- Android:手把手带你深入剖析 Retrofit 2.0 源码
前言 在Andrroid开发中,网络请求十分常用 而在Android网络请求库中,Retrofit是当下最热的一个网络请求库 今天,我将手把手带你深入剖析Retrofit v2.0的源码,希望你们会喜 ...
- (转)Sql Server 快速查看表结构(表描述及字段说明)
--表描述 SELECT tbs.name 表名,ds.value 描述 FROM sys.extended_properties ds LEFT JOIN sysobjects tbs ON ds. ...
- Python学习(六)模块 —— 第三方库
Python 第三方库 安装第三方库 在Python中,安装第三方库包,是通过setuptools这个工具完成的.Python有两个封装了setuptools的包管理工具:easy_install和p ...