Useful Hadoop Commands

简介:

hadoop

解压 gz 文件到文本文件

$ hadoop fs -text /hdfs_path/compressed_file.gz | hadoop fs -put - /tmp/uncompressed-file.txt

解压本地文件 gz 文件并上传到 hdfs

$ gunzip -c filename.txt.gz | hadoop fs -put - /tmp/filename.txt

使用 awk 处理 csv 文件,参考 Using awk and friends with Hadoop:

$ hadoop fs -cat people.txt | awk -F"," '{ print $1","$2","$3$4$5 }' | hadoop fs -put - people-coalesed.txt

创建 lzo 文件、上传到 hdfs 并添加索引:

$ lzop -Uf data.txt
$ hadoop fs -moveFromLocal data.txt.lzo /tmp/
# 1. 单机
$ hadoop jar /usr/lib/hadoop/lib/hadoop-lzo.jar com.hadoop.compression.lzo.LzoIndexer /tmp/data.txt.lzo

# 2. 运行 mr
$ hadoop jar /usr/lib/hadoop/lib/hadoop-lzo.jar com.hadoop.compression.lzo.DistributedLzoIndexer /tmp/data.txt.lzo

如果 people.txt 通过 lzo 压缩了,则可以使用下面命令解压缩、处理数据、压缩文件:

$ hadoop fs -cat people.txt.lzo | lzop -dc | awk -F"," '{ print $1","$2","$3$4$5 }' | lzop -c | hadoop fs -put - people-coalesed.txt.lzo

hive

后台运行:

$ nohup hive -f sample.hql > output.out 2>&1 & 

$ nohup hive --database "default" -e "select * from tablename;" > output.out 2>&1 & 

替换分隔符:

$ hive --database "default" -f query.hql  2> err.txt | sed 's/[\t]/,/g' 1> output.txt 

打印表头:

$ hive --database "default" -e "SHOW COLUMNS FROM table_name;" | tr '[:lower:]' '[:upper:]' | tr '\n' ',' 1> headers.txt

$ hive --database "default" -e "SET hive.cli.print.header=true; select * from table_name limit 0;" | tr '[:lower:]' '[:upper:]' | sed 's/[\t]/,/g'  1> headers.txt

查看执行时间:

$ hive -e "select * from tablename;"  2> err.txt  1> out.txt 
$ cat err.txt | grep "Time taken:" | awk '{print $3,$6}'

hive 中如何避免用科学计数法表示浮点数?参考 http://www.zhihu.com/question/28887115 

SELECT java_method("String", "format", "%f", my_column) FROM mytable LIMIT 1
目录
相关文章
|
资源调度
yarn 错误:There appears to be trouble with your network connection. Retrying…
yarn 错误:There appears to be trouble with your network connection. Retrying…
1386 0
|
分布式计算 Hadoop 程序员
Hadoop运行报ERROR: Attempting to operate on hdfs as root或者HDFS_ZKFC_USER defined错误的解决方法
Hadoop运行报ERROR: Attempting to operate on hdfs as root或者HDFS_ZKFC_USER defined错误的解决方法
|
分布式计算 资源调度 Scala
《Monitoring the Dynamic Resource Usage of Scala and Python Spark Jobs in Yarn》电子版地址
Monitoring the Dynamic Resource Usage of Scala and Python Spark Jobs in Yarn
88 0
《Monitoring the Dynamic Resource Usage of Scala and Python Spark Jobs in Yarn》电子版地址
|
分布式计算 Hadoop Linux
hadoop异常“could only be replicated to 0 nodes, instead of 1” 解决
异常分析  1、“could only be replicated to 0 nodes, instead of 1”异常 (1)异常描述 上面配置都正确无误,并且,已经完成了如下运行步骤: [root@localhost hadoop-0.
1851 0
|
分布式计算 Hadoop
Hadoop2.0 datanode启动不成功:All specified directories are failed to load
Hadoop2.0 datanode启动不成功:All specified directories are failed to load
|
分布式计算 Hadoop
hadoop_异常_02_ExitCodeException exitCode=1: chmod: changing permissions of `/ray/hadoop/dfs/data': Operation not permitted
一、异常现象 启动hadoop时,datanode启动失败,出现如下异常: 2018-03-23 14:39:09,962 WARN org.apache.hadoop.hdfs.server.
2016 0
|
分布式计算 Hadoop
|
Java
Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the co
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
2904 0