简述
案例介绍
-u 指定url地址
-n 指定用户
-e 指定查询SQL语句
--showHeader 是否显示表头信息
--outputformat=[table/vertical/csv2/tsv2/dsv/csv/tsv] 输出分隔符
--nullemptystring=[true/false] set to true to get historic behavior of printing null as empty string
复制
标准输入文件(stdin):stdin的文件描述符为0,Unix程序默认从stdin读取数据。
标准输出文件(stdout):stdout 的文件描述符为1,Unix程序默认向stdout输出数据。
标准错误文件(stderr):stderr的文件描述符为2,Unix程序会向stderr流中写入错误信息。
复制
beeline -u jdbc:hive2://bigdata01:10000 -n admin \
--showHeader=true --outputformat=csv --nullemptystring=true \
-e "select * from default.student4 limit 1" 2>>output.txt
复制
'student4.m_id','student4.address_contry','student4.address_province','student4.address_city','student4.info_age','student4.info_birthday','student4.info_company','student4.d_date','student4.p_type'
'10000','测试10000','地址省10000','城市0','年龄10000','生日10000','公司10000','2020-09-03','test'
复制
beeline -u jdbc:hive2://bigdata01:10000 -n admin \
--showHeader=true --outputformat=csv --nullemptystring=true \
-e "select * from default.student4 limit 1" 1>student.txt 2>>output.txt
复制
'student4.m_id','student4.address_contry','student4.address_province','student4.address_city','student4.info_age','student4.info_birthday','student4.info_company','student4.d_date','student4.p_type'
'10000','测试10000','地址省10000','城市0','年龄10000','生日10000','公司10000','2020-09-03','test'
复制
beeline -u jdbc:hive2://bigdata01:10000 -n admin \
--showHeader=true --outputformat=csv --nullemptystring=true \
-e "select * from default.student4 limit 1" 1>student.txt 2>>/dev/null
复制
小技巧
仅输出表头的SQL语句:
select * from 表名 where false
复制
beeline -u jdbc:hive2://bigdata01:10000 -n admin \
--showHeader=true --outputformat=csv --nullemptystring=true \
-e "select * from default.student4 where false" 1>head.txt 2>>/dev/null
复制
'student4.m_id','student4.address_contry','student4.address_province','student4.address_city','student4.info_age','student4.info_birthday','student4.info_company','student4.d_date','student4.p_type'
复制
文章转载自趣说大数据,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。