在直线输出中删除 headers
Remove headers in output in beeline
我正在尝试使用 beeline cli 查询配置单元 table 并将输出结果存储为变量。
使用直线命令:
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
再次以 |
分隔的表格格式数据显示结果。
基本上直线,默认情况下,返回 header( table_name.column_name
) 然后是表格格式的数据。然而,我想消除它并获得像 hive CLI 这样的结果。
Beeline 有一堆 command line options.
在您的情况下,您可以使用:
beeline --outputformat=dsv --showheader=false \
-e "select count(*) from db_name.table_name"
您可以使用参数 --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, tsv
These two formats differ only with the delimiter between values, which is comma for csv and tab for 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。干杯!!
我正在尝试使用 beeline cli 查询配置单元 table 并将输出结果存储为变量。 使用直线命令:
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
再次以 |
分隔的表格格式数据显示结果。
基本上直线,默认情况下,返回 header( table_name.column_name
) 然后是表格格式的数据。然而,我想消除它并获得像 hive CLI 这样的结果。
Beeline 有一堆 command line options.
在您的情况下,您可以使用:
beeline --outputformat=dsv --showheader=false \
-e "select count(*) from db_name.table_name"
您可以使用参数 --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, tsv These two formats differ only with the delimiter between values, which is comma for csv and tab for 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。干杯!!