如何在python中寫hive腳本
這篇文章主要介紹了如何在python中寫hive腳本,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
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語(yǔ)句執(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;
或者,使用如下語(yǔ)句:
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()])
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 在python中使用pyspark讀寫Hive數(shù)據(jù)操作
- 使用Python構(gòu)造hive insert語(yǔ)句說(shuō)明
- python 實(shí)現(xiàn) hive中類似 lateral view explode的功能示例
- Python pandas 列轉(zhuǎn)行操作詳解(類似hive中explode方法)
- python 操作hive pyhs2方式
- python處理數(shù)據(jù),存進(jìn)hive表的方法
- python導(dǎo)出hive數(shù)據(jù)表的schema實(shí)例代碼
- Python讀取Hive數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼詳解
相關(guān)文章
Python中三種時(shí)間格式轉(zhuǎn)換的方法
本文主要介紹了Python中三種時(shí)間格式轉(zhuǎn)換的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04
Pytorch之上/下采樣函數(shù)torch.nn.functional.interpolate插值詳解
這篇文章主要介紹了Pytorch之上/下采樣函數(shù)torch.nn.functional.interpolate插值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04
Python簡(jiǎn)單獲取網(wǎng)卡名稱及其IP地址的方法【基于psutil模塊】
這篇文章主要介紹了Python簡(jiǎn)單獲取網(wǎng)卡名稱及其IP地址的方法,結(jié)合實(shí)例形式分析了Python基于psutil模塊針對(duì)本機(jī)網(wǎng)卡硬件信息的讀取操作簡(jiǎn)單使用技巧,需要的朋友可以參考下2018-05-05
python縮進(jìn)長(zhǎng)度是否統(tǒng)一
在本篇內(nèi)容里小編給大家整理的是一篇關(guān)于python縮進(jìn)長(zhǎng)度是否統(tǒng)一的相關(guān)知識(shí)點(diǎn),需要的朋友們可以學(xué)習(xí)下。2020-08-08
Python面試題之統(tǒng)計(jì)哈希列表中最多元素
這篇文章主要為大家講解Python面試題中的如何統(tǒng)計(jì)哈希列表中最多的元素,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家面試成功2021-09-09
Python本地搭建靜態(tài)Web服務(wù)器的實(shí)現(xiàn)
本文主要介紹了Python本地搭建靜態(tài)Web服務(wù)器的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02

