如何在python中寫hive腳本
這篇文章主要介紹了如何在python中寫hive腳本,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
1、直接執(zhí)行.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語句執(zhí)行
假如有如下hive sql:
hive_cmd = 'hive -e "select count(*) from hbase.routermac_sort_10;"'
一般在python中按照如下方式執(zhí)行該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()])
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Pytorch之上/下采樣函數(shù)torch.nn.functional.interpolate插值詳解
這篇文章主要介紹了Pytorch之上/下采樣函數(shù)torch.nn.functional.interpolate插值,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-04-04
Python簡單獲取網(wǎng)卡名稱及其IP地址的方法【基于psutil模塊】
這篇文章主要介紹了Python簡單獲取網(wǎng)卡名稱及其IP地址的方法,結合實例形式分析了Python基于psutil模塊針對本機網(wǎng)卡硬件信息的讀取操作簡單使用技巧,需要的朋友可以參考下2018-05-05
Python本地搭建靜態(tài)Web服務器的實現(xiàn)
本文主要介紹了Python本地搭建靜態(tài)Web服務器的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-02-02

