尝试通过bq cli运行查询时出错

时间:2017-07-27 21:15:24

标签: google-bigquery

尝试执行bq查询时出现以下错误:

Private Sub DoStuff()

Application.DisplayAlerts = False

'Create New Workbook

Dim Count As Integer

CurrentFile = "June_Files_macros_new.xlsm"
NewFile = "Train" & CStr(Cells(2, 13)) & "_" & CStr(Cells(2, 3)) & ".xls"

Workbooks.Add


'Save New Workbook
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & NewFile

'Select top row of data and insert into spreadsheed!!!!!
Workbooks(CurrentFile).Worksheets("Sheet1").Rows(2).Copy
Workbooks(NewFile).Worksheets("Sheet1").Rows(2).PasteSpecial xlPasteValues


Count = 3



For i = 3 To 12802

'if Date and Train Number are equal, Then copy and paste the i th row
'else, save new file, create another new file, save

    If Cells(i, 3) = Cells(i - 1, 3) And Cells(i, 13) = Cells(i - 1, 13) Then
            Workbooks(CurrentFile).Worksheets("Sheet1").Rows(i).Copy
            Workbooks(NewFile).Worksheets("Sheet1").Rows(Count).PasteSpecial xlPasteValues
            Count = Count + 1

    Else: Workbooks(CurrentFile).Worksheets("Sheet1").Rows(1).Copy
          Workbooks(NewFile).Worksheets("Sheet1").Rows(1).PasteSpecial xlPasteValues
          Workbooks(NewFile).SaveAs ThisWorkbook.Path & "\" & "Train" & CStr(Cells(i - 1, 13)) & "_" & CStr(Cells(i - 1, 3)) & ".xls"
          Workbooks(NewFile).Close

          Workbooks.Add
          NewFile = "Train" & CStr(Cells(i, 13)) & "_" & CStr(Cells(i, 3)) & ".xls"
          ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & NewFile

          Workbooks(CurrentFile).Worksheets("Sheet1").Rows(i).Copy
          Workbooks(NewFile).Worksheets("Sheet1").Rows(2).PasteSpecial xlPasteValues

          Count = 3
   End If

Next i

Workbooks(CurrentFile).Worksheets("Sheet1").Rows(1).Copy
Workbooks(NewFile).Worksheets("Sheet1").Rows(1).PasteSpecial xlPasteValues

ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & NewFile

Workbooks(NewFile).Close

查询很简单,我认为问题出在concat函数中,因为我正在尝试连接curl命令,并且我有一个-v标志,查询如下:

FATAL Flags parsing error: Unknown command line flag '-v'

如何将-v转义为不会出现此错误?

由于

1 个答案:

答案 0 :(得分:1)

尝试运行:

bq query "select concat('curl -v https://api.com.br/push.json  -H \"Content-Type: application/json\" -H \"x_application: WebApp\" -H -X POST -d \'{\"pushes\":[\'',string_agg(to_json_string(t)),']}\'') as json"

为了防止字符串中的bash解释,也许从文件中读取查询也可能有所帮助。如果您的查询类似于:

WITH data AS(
select [1, 2] AS t
)

select
concat('curl -v https://api.com.br/push.json  -H \"Content-Type: application/json\" -H \"x_application: WebApp\" -H -X POST -d \'{\"pushes\":[\'',string_agg(to_json_string(t)),']}\'') as json
FROM
data

您可以将其保存在例如“query.sql”文件中,然后运行命令:

cat query.sql | bq query --use_legacy_sql=False