hdfs官网:http://hdfscli.readthedocs.io/en/latest/api.html

一个非常好的博客:http://blog.csdn.net/gamer_gyt/article/details/52446757

hdfs库中自带avro序列化与反序列化模块,不需要单独做

#!/usr/bin/env python
# encoding: utf-8 """Avro extension example.""" from hdfs import Config
from hdfs.ext.avro import AvroReader, AvroWriter # Get the default alias' client.
client = Config().get_client() # Some sample data.
records = [
{'name': 'Ann', 'age': 23},
{'name': 'Bob', 'age': 22},
] # Write an Avro File to HDFS (since our records' schema is very simple, we let
# the writer infer it automatically, otherwise we would pass it as argument).
with AvroWriter(client, 'names.avro', overwrite=True) as writer:
for record in records:
writer.write(record) # Read it back.
with AvroReader(client, 'names.avro') as reader:
schema = reader.schema # The inferred schema.
content = reader.content # The remote file's HDFS content object.
assert list(reader) == records # The records match!

遍历hdfs目录

from hdfs import *
import os
from hdfs.ext.avro import AvroReader, AvroWriter def main():
client=Client("http://127.0.0.1:50070")
path = "/test/tmp_data"
for root, dir, files in client.walk(path):
for file in files:
full_path = os.path.join(root, file)
print full_path
with AvroReader(client, full_path) as reader:
schema = reader.schema # The inferred schema.
content = reader.content # The remote file's HDFS content object.
#assert list(reader) == records
for user in list(reader):
print user main()

【hadoop】python通过hdfs模块读hdfs数据的更多相关文章

  1. python之psutil模块(获取系统性能数据)

    psutil模块 1.介绍 psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等) ...

  2. 大数据技术hadoop入门理论系列之二—HDFS架构简介

    HDFS简单介绍 HDFS全称是Hadoop Distribute File System,是一个能运行在普通商用硬件上的分布式文件系统. 与其他分布式文件系统显著不同的特点是: HDFS是一个高容错 ...

  3. Hadoop第三天---分布式文件系统HDFS(大数据存储实战)

    1.开机启动Hadoop,输入命令:  检查相关进程的启动情况: 2.对Hadoop集群做一个测试:   可以看到新建的test1.txt和test2.txt已经成功地拷贝到节点上(伪分布式只有一个节 ...

  4. Hadoop(八)Java程序访问HDFS集群中数据块与查看文件系统

    前言 我们知道HDFS集群中,所有的文件都是存放在DN的数据块中的.那我们该怎么去查看数据块的相关属性的呢?这就是我今天分享的内容了 一.HDFS中数据块概述 1.1.HDFS集群中数据块存放位置 我 ...

  5. 云计算分布式大数据Hadoop实战高手之路第七讲Hadoop图文训练课程:通过HDFS的心跳来测试replication具体的工作机制和流程

    这一讲主要深入使用HDFS命令行工具操作Hadoop分布式集群,主要是通过实验的配置hdfs-site.xml文件的心跳来测试replication具体的工作和流程. 通过HDFS的心跳来测试repl ...

  6. Hadoop基础-HDFS集群中大数据开发常用的命令总结

    Hadoop基础-HDFS集群中大数据开发常用的命令总结 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本盘博客仅仅列出了我们在实际生成环境中常用的hdfs命令,如果想要了解更多, ...

  7. Hadoop集群-HDFS集群中大数据运维常用的命令总结

    Hadoop集群-HDFS集群中大数据运维常用的命令总结 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客会简单涉及到滚动编辑,融合镜像文件,目录的空间配额等运维操作简介.话 ...

  8. 大数据入门第五天——离线计算之hadoop(下)hadoop-shell与HDFS的JavaAPI入门

    一.Hadoop Shell命令 既然有官方文档,那当然先找到官方文档的参考:http://hadoop.apache.org/docs/current/hadoop-project-dist/had ...

  9. Hive数据分析——Spark是一种基于rdd(弹性数据集)的内存分布式并行处理框架,比于Hadoop将大量的中间结果写入HDFS,Spark避免了中间结果的持久化

    转自:http://blog.csdn.net/wh_springer/article/details/51842496 近十年来,随着Hadoop生态系统的不断完善,Hadoop早已成为大数据事实上 ...

随机推荐

  1. (Arrays.sort() 或 map) Ignatius and the Princess IV hdu1029

    Ignatius and the Princess IV 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 借鉴链接:https://blog.csd ...

  2. 在tomcat集群下利用redis实现单点登陆

    场景:比如说我们要实现一个集群环境,无非是把多个项目部署到多个tomcat下,然后按照一定的算法,轮询什么的随机访问多个tomcat服务器,但是问题也会有许多,比如说,我们最开始是把登陆人的信息存放到 ...

  3. Win记录-配置Windows Server R 2008多用户远程连接(仅做参考)

    1.计算机管理下用户组下新建用户 2.系统属性下远程控制加入用户,设置允许运行任何远程桌面 3.运行->gpedit.msc->计算机配置->管理模板->windows 组件- ...

  4. html 高亮显示表格当前行【转】

    html在线模拟网:http://www.w3school.com.cn/tiy/t.asp?f=html_basic 高亮显示表格当前行 <html> <head> < ...

  5. python 代码模板

    命令[python3 -m pydoc -p 1234]   通过http://localhost:1234来访问查看文档 # -*- coding: utf-8 -*-""&qu ...

  6. oracle乱码记录

    plsql中显示正常,查询到的结果乱码 1.获得服务端编码 select * from nls_database_parameters where parameter ='NLS_CHARACTERS ...

  7. SysTick_CLKSourceConfig 这个函数

    systick的寄存器说明是在<Cortex M3权威指南>里说明了! 其实是有选择的,只是默认是AHB/8.通过设置systick的CTRL寄存器的bit2来设置时钟,设置如下: bit ...

  8. fastreport报表中出现十字线

    问题描述:经常有十字线出现在报表中,出现在报表中不同的频带,在预览和运行时都会显示,不能点击和删除它. 解决方法:这是一个线控制,因太小而不能被渲染,所以fastreport使用十字线来表示其位置.通 ...

  9. Mybatis中的StatementType

    原文:http://luoyu-ds.iteye.com/blog/1517607 要实现动态传入表名.列名,需要做如下修改 添加属性statementType=”STATEMENT” 同时sql里的 ...

  10. logback配置按天产生日志文件

    1 依赖Jar包 pom配置 也可以根据自己的版本来 <dependency> <groupId>org.slf4j</groupId> <artifactI ...