6

bigquery CLIで入力ファイルを使用することは可能ですか?

bq query < my_query.sql
4

3 に答える 3

14

UNIXを使用している(またはWindowsにcygwinをインストールしている)場合は、xargsを使用できます。

xargs -a my_query.sql -0 bq query

または、バックティックを使用することもできます。

bq query `cat my_query.sql`

bqは一度に1つのコマンドしか処理できないことに注意してください。.sqlスクリプトに複数のクエリがある場合は、;でファイルを分割する必要があります。

于 2012-09-07T21:12:45.850 に答える
2

他のソリューション、特に引用符が含まれている非常に長く複雑なクエリを処理することはできませんでした。ファイルをbqツールにパイプする運が良かった

cat test.sql | bq query
于 2020-01-31T14:48:21.727 に答える
0

Windowsでは、この方法を使用しています。前提条件は、各コマンドを1行にリストすることです。これにより、bqを使用して行の各コマンドが1つずつ処理されます。

C:\temp>for /F "tokens=*" %A in (batch_query.sql) do bq query %A

C:\temp>bq query select count+1 from cmdwh_bq_prod.newtable ;
Waiting on bqjob_r63bf8c82_00000163004c7fd0_1 ... (0s) Current status: DONE
+-------+
|  f0_  |
+-------+
| 20136 |
+-------+

C:\temp>bq query select count+2 from cmdwh_bq_prod.newtable ;
Waiting on bqjob_r7ffd9b2a_00000163004c9348_1 ... (0s) Current status: DONE
+-------+
|  f0_  |
+-------+
| 20137 |
+-------+

C:\temp>bq query select count+3 from cmdwh_bq_prod.newtable ;
Waiting on bqjob_r223c57a3_00000163004ca682_1 ... (0s) Current status: DONE
+-------+
|  f0_  |
+-------+
| 20138 |
+-------+

C:\temp>
C:\temp>type batch_query.sql
select count+1 from cmdwh_bq_prod.newtable ;
select count+2 from cmdwh_bq_prod.newtable ;
select count+3 from cmdwh_bq_prod.newtable ;

C:\temp>bq query select * from cmdwh_bq_prod.newtable
Waiting on bqjob_r3a363e1b_00000163004f4dba_1 ... (0s) Current status: DONE
+-------+
| count |
+-------+
| 20135 |
+-------+

C:\temp>
于 2018-04-26T04:57:45.933 に答える