温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。

1.文档编写目的

继上一章讲述如何在CDH集群安装Anaconda&搭建Python私有源后,本章节主要讲述如何使用Pyton Impyla客户端连接CDH集群的HiveServer2和Impala Daemon,并进行SQL操作。

内容概述

1.依赖包安装

2.代码编写

3.代码测试

测试环境

1.CM和CDH版本为5.11.2

2.RedHat7.2

前置条件

1.CDH集群环境正常运行

2.Anaconda已安装并配置环境变量

3.pip工具能够正常安装Python包

4.Python版本2.6+ or 3.3+

5.非安全集群环境

2.Impyla依赖包安装

Impyla所依赖的Python包

six

bit_array

thrift (on Python 2.x) orthriftpy (on Python 3.x)

thrift_sasl

sasl

1.首先安装Impyla依赖的Python包

[root@ip-172-31-22-86 ~]# pip install bit_array

[root@ip-172-31-22-86 ~]# pip install thrift==0.9.3

[root@ip-172-31-22-86 ~]# pip install six

[root@ip-172-31-22-86 ~]# pip install thrift_sasl

[root@ip-172-31-22-86 ~]# pip install sasl

注意:thrift的版本必须使用0.9.3,默认安装的为0.10.0版本,需要卸载后重新安装0.9.3版本,卸载命令pip uninstall thrift

2.安装Impyla包

impyla版本,默认安装的是0.14.0,需要将卸载后安装0.13.8版本

[root@ip-172-31-22-86 ec2-user]# pip install impyla==0.13.8

Collecting impyla

Downloading impyla-0.14.0.tar.gz (151kB)

100% |████████████████████████████████| 153kB 1.0MB/s

Requirement already satisfied: six in /opt/cloudera/parcels/Anaconda-4.2.0/lib/python2.7/site-packages (from impyla)

Requirement already satisfied: bitarray in /opt/cloudera/parcels/Anaconda-4.2.0/lib/python2.7/site-packages (from impyla)

Requirement already satisfied: thrift in /opt/cloudera/parcels/Anaconda-4.2.0/lib/python2.7/site-packages (from impyla)

Building wheels for collected packages: impyla

Running setup.py bdist_wheel for impyla ... done

Stored in directory: /root/.cache/pip/wheels/96/fa/d8/40e676f3cead7ec45f20ac43eb373edc471348ac5cb485d6f5

Successfully built impyla

Installing collected packages: impyla

Successfully installed impyla-0.14.0

3.编写Python代码

Python连接Hive(HiveTest.py)

from impala.dbapi importconnect

conn = connect(host='ip-172-31-21-45.ap-southeast-1.compute.internal',port=10000,database='default',auth_mechan

ism='PLAIN')

print(conn)

cursor = conn.cursor()

cursor.execute('show databases')

print cursor.description # prints the result set's schema

results = cursor.fetchall()

print(results)

cursor.execute('SELECT * FROM test limit 10')

print cursor.description # prints the result set's schema

results = cursor.fetchall()

print(results)

Python连接Impala(ImpalaTest.py)

from impala.dbapi importconnect

conn = connect(host='ip-172-31-26-80.ap-southeast-1.compute.internal',port=21050)

print(conn)

cursor = conn.cursor()

cursor.execute('show databases')

print cursor.description # prints the result set's schema

results = cursor.fetchall()

print(results)

cursor.execute('SELECT * FROM test limit 10')

print cursor.description # prints the result set's schema

results = cursor.fetchall()

print(results)

4.测试代码

在shell命令行执行Python代码测试

1.测试连接Hive

_root@ip-172-31-22-86_ec2-user# python HiveTest.py

__

('database_name', 'STRING', None, None, None, None, None)

('default',)

('test.s1', 'STRING',None, None, None, None, None), ('test.s2', 'STRING', None, None, None, None, None)

('name1', 'age1'), ('name2', 'age2'), ('name3', 'age3'), ('name4', 'age4'), ('name5', 'age5'), ('name6', 'age6'), ('name7', 'age7'), ('name8', 'age8'), ('name9', 'age9'), ('name10', 'age10')

[root@ip-172-31-22-86 ec2-user]#

2.测试连接Impala

_root@ip-172-31-22-86_ec2-user# python ImpalaTest.py

__

('name', 'STRING', None, None, None, None, None), ('comment', 'STRING', None, None, None, None, None)

('_impala_builtins', 'Systemdatabase for Impala builtin functions'), ('default', 'Default Hive database')

('s1', 'STRING', None, None, None,None, None), ('s2', 'STRING', None, None, None,None, None)

('name1', 'age1'), ('name2', 'age2'), ('name3', 'age3'), ('name4', 'age4'), ('name5', 'age5'), ('name6', 'age6'), ('name7', 'age7'), ('name8', 'age8'), ('name9', 'age9'), ('name10', 'age10')

[root@ip-172-31-22-86 ec2-user]#

5.常见问题

1.错误一

building 'sasl.saslwrapper' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/sasl

gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Isasl -I/opt/cloudera/parcels/Anaconda/include/python2.7 -c sasl/saslwrapper.cpp -o build/temp.linux-x86_64-2.7/sasl/saslwrapper.o

unable to execute 'gcc': No such file or directory

error: command 'gcc' failed with exit status 1

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

Command "/opt/cloudera/parcels/Anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kD6tvP/sasl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-WJFNeG-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-kD6tvP/sasl/

解决方法:

[root@ip-172-31-22-86 ec2-user]# yum -y install gcc

[root@ip-172-31-22-86 ec2-user]# yum install gcc-c++

2.错误二

gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Isasl -I/opt/cloudera/parcels/Anaconda/include/python2.7 -c sasl/saslwrapper.cpp -o build/temp.linux-x86_64-2.7/sasl/saslwrapper.o

cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]

In file included from sasl/saslwrapper.cpp:254:0:

sasl/saslwrapper.h:22:23: fatal error: sasl/sasl.h: No such file or directory

#include

^

compilation terminated.

error: command 'gcc' failed with exit status 1

解决方法:

[root@ip-172-31-22-86 ec2-user]# yum -y install python-devel.x86_64 cyrus-sasl-devel.x86_64

醉酒鞭名马,少年多浮夸! 岭南浣溪沙,呕吐酒肆下!挚友不肯放,数据玩的花!

温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。

推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。

原创文章,欢迎转载,转载请注明:转载自微信公众号Hadoop实操

python存数据到impala_0039-如何使用Python Impyla客户端连接Hive和Impala相关推荐

  1. 0039-如何使用Python Impyla客户端连接Hive和Impala

    温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看. 1.文档编写目的 继上一章讲述如何在CDH集群安装Anaconda&搭建Python私有源后,本章节主要讲述如何使用Pyton ...

  2. python怎么存数据_五种使用python储存数据的方式

    原标题:五种使用python储存数据的方式 在python编程开发中,总是不可避免的遇到数据储存的问题,下面小卓就介绍python与几种数据储存方式交互的方法. json文件 json是一种轻量级的数 ...

  3. python处理数据的包_在Python中利用Into包整洁地进行数据迁移的教程

    动机 我们花费大量的时间将数据从普通的交换格式(比如CSV),迁移到像数组.数据库或者二进制存储等高效的计算格式.更糟糕的是,许多人没有将数据迁移到高效的格式,因为他们不知道怎么(或者不能)为他们的工 ...

  4. python matplotlib数据可视化教程_matplotlib的Python数据可视化和探索——入门指南

    matplotlib--最受欢迎的Python库,用于数据可视化和探索 我喜欢在Python中使用matplotlib.这是我学会掌握的第一个可视化库,此后一直存在.matplotlib是最受欢迎的用 ...

  5. python实现数据可视化_使用Matplotib python实现数据可视化

    python实现数据可视化 I Feel: 我觉得: In today's digital world data has become as important as air. Machines &a ...

  6. 【蓝桥杯选拔赛真题22】python输出数据 青少年组蓝桥杯python 选拔赛STEMA比赛真题解析

    目录 python输出数据 一.题目要求 1.编程实现 2.输入输出 3.评分标准

  7. python存数据到excel_python爬取的数据--保存数据到excel

    在这里用到的是xlwt import xlwt 如果还未安装此模块,可以执行下面的命令安装: pip install xlwt 接下来就是将数据列表存储到excel当中: def save_to_ex ...

  8. python读取数据文件夹_使用python依次读取文件中的所有csv格式的数据

    使用python依次读取文件中的所有csv格式的数据: #coding=gbk import pandas as pd import os path = r'D:\ml_datasets\PHM\c6 ...

  9. python期货数据 库_如何用python或者基于vnpy框架将期货tick数据聚合成1分钟数据呢?...

    同意楼上一些答主的看法,数据量大的情况下用python或pandas不是很好的solution. DolphinDB应该是目前处理tick级金融数据最好的数据库系统之一,甚至可以拿掉之一.如果题主的t ...

  10. python大数据搜索_python语言-用 Python 实现一个大数据搜索引擎

    搜索是大数据领域里常见的需求.Splunk和ELK分别是该领域在非开源和开源领域里的领导者.本文利用很少的Python代码实现了一个基本的数据搜索功能,试图让大家理解大数据搜索的基本原理. 布隆过滤器 ...

最新文章

  1. 1.SharePoint2010初接触
  2. 零样本性能超越GPT-3!谷歌提出1370亿参数自回归语言模型
  3. 全卷积(FCN)论文阅读笔记:Fully Convolutional Networks for Semantic Segmentation
  4. WebIDE discovery when destination is selected from dropdown list
  5. JDK1.8源码下载及获取、导入IDEA阅读、配置JDK源码
  6. 小学计算机教案 插入艺术字,五年级信息技术《艺术字标题》教学设计
  7. oracle12 group by 拼接字符串
  8. 模块化(1):基本思路
  9. win10电脑一开机提示拒绝访问怎么办
  10. cadence PCB走等长线设置
  11. python批量保存网页为pdf_在chrome中自动打印/保存网页为pdf - python 3.6
  12. php 语言开发,PHP语言开发常用工具
  13. 图像去雨RESCAN论文笔记
  14. Kali Linux工具大全-信息收集
  15. 英语听力计算机教室,每日英语听力电脑版|每日英语听力 v9.2.0 PC客户端
  16. CSP考试 2016年04月第3题 路径解析 C++实现
  17. ldap服务器配置信息错误,ldap服务器概念配置看这一文就够了!
  18. 清华大学计算机陈蓓,清华大学2010级本科生新生代表座谈会举行
  19. 读书笔记《Effective C++》条款40:明智而审慎地使用多重继承
  20. 拨号vps为什么会掉线

热门文章

  1. arccatalog点要素显示不完_初中生到底要不要住校?班主任:不建议,看完这3点你就明白了...
  2. pygame.font.Font().render() 计算基线(baseline)的原点(origin)坐标
  3. android代码混淆作用,Android代码混淆
  4. android设置内存大小,Android Studio内存大小的设置
  5. Python二级题库答案纠正
  6. python的requests库入门必看
  7. python fft函数_python scipy fft.fft用法及代码示例
  8. axios直传阿里云,获取上传进度已以及取消上传
  9. struts2初步学习路线
  10. Tomcat实现Web Socket