1

我想在不将语句内容回显到标准输出的情况下运行多语句查询。单语句查询不回显语句,如此处所示...

bq query --use_legacy_sql=false --project_id=livescore-sandpit-data <<EOF
select current_timestamp();
EOF

...产生...

+---------------------+
|         f0_         |
+---------------------+
| 2020-04-02 08:02:15 |
+---------------------+

select current_timestamp()不回显,而多语句查询则回显语句......

bq query --use_legacy_sql=false --project_id=livescore-sandpit-data <<EOF
select current_timestamp();
select current_timestamp();
EOF

...产生...

Waiting on bqjob_r1a1fef57eab6f80b_0000017139e86883_1 ... (1s) Current status: DONE   
select current_timestamp(); -- at [1:1]
+---------------------+
|         f0_         |
+---------------------+
| 2020-04-02 08:01:05 |
+---------------------+
select current_timestamp(); -- at [2:1]
+---------------------+
|         f0_         |
+---------------------+
| 2020-04-02 08:01:06 |
+---------------------+

我希望有时能够关闭此功能,这样它就不会弄乱我的输出。(我在命令行上运行多个 bq 查询作为开发测试硬度的一部分)。

这可能吗?

4

2 回答 2

2

到目前为止,没有选项可以跳过这些语句。

参考:

https://cloud.google.com/bigquery/docs/reference/bq-cli-reference#bq_query

于 2020-04-04T11:27:25.020 回答
1

正如@SANN3 和@FelipeHoffa 所提到的,现在没有选择这样做,提交功能请求是正确的方法。

但是,作为一种解决方法,您可以尝试使用正则表达式和 sed,以摆脱输出中的语句,例如:

bq query --use_legacy_sql=false --project_id=livescore-sandpit-data \
"select current_timestamp(); \
select current_timestamp();" | sed -E '/^.*\[[0-9]+:[0-9]+\].*$/d'

通过删除与语句末尾的“[number:number]”模式匹配的所有行来生成以下输出:

+---------------------+
|         f0_         |
+---------------------+
| 2020-04-09 21:42:16 |
+---------------------+
+---------------------+
|         f0_         |
+---------------------+
| 2020-04-09 21:42:16 |
+---------------------+

我不确定这是否适用于更复杂的多语句,因为我不知道它们是如何打印的,但如果你需要摆脱这些语句,那就是这个想法。

于 2020-04-09T21:52:09.760 回答