我正在尝试beeline cli查询配置单元表并将输出结果存储为变量。
使用beeline命令:

beeline -u connection_string -n user_name -w password_file \
-e "select count(*) from db.table_name"

使用此命令,我得到的当前输出结果为:
+---------------+--+
| record_count  |
+---------------+--+
| 80785         |
+---------------+--+

虽然我需要的结果是:Record count:80785
我正在使用的另一个命令是:
beeline -u connection_string -n user_name -w password_file \
-e "select * from db.table_name;” > result.csv

再次显示结果格式为|的表格格式数据。

基本上,默认情况下,beeline返回表头(table_name.column_name),然后返回表格格式的数据。鉴于此,我想消除这种情况并获得类似 hive 式CLI的结果。

最佳答案

您可以使用参数--showHeader=false --outputformat=tsv2阐明这一点。

使用此格式您的命令将像

beeline --showHeader=false --outputformat=tsv2 \
-u connection_string -n user_name -w password_file \
 -e "select count(*) from db.table_name"

考虑tsv2是否使用
id  value   comment
1   Value1  Test comment 1
2   Value2  Test comment 2
3   Value3  Test comment 3

如果使用dsv(定界符为|)
id|value|comment
1|Value1|Test comment 1
2|Value2|Test comment 2
3|Value3|Test comment 3

您的数据将如下所示。如果值中包含特殊字符或换行符,请记住这三个值都用单引号引起来。可以通过将disable.quoting.for.sv设置为true来禁用报价。

使用CSV和TSV的更多选项



使用csv时,数据将如下所示
'id','value','comment'
'1','Value1','Test comment 1'
'2','Value2','Test comment 2'
'3','Value3','Test comment 3'

当使用tsv时
'id'    'value' 'comment'
'1' 'Value1'    'Test comment 1'
'2' 'Value2'    'Test comment 2'
'3' 'Value3'    'Test comment 3'

在使用 csv或tsv 时要当心,您总是将单引号括在值中,并且无法摆脱它,这在少数情况下可能会导致某些问题。

希望以上详细说明能涵盖您想要涵盖的所有可能情况。

有关更多说明,请访问Apache Beeline Wiki page。干杯!!

关于hadoop - 删除直线中输出中的标题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47987097/

10-12 23:44