我试图使用SQL来执行一些查询,但由于某些原因,我不能使用BigQuery函数。我一直使用的端点如下:
https://bigquery.googleapis.com/bigquery/v2/projects/{project-id}/queries后
这适用于常规查询(没有函数),但是如果我尝试使用提取函数或FORMAT_DATE函数,我总是会收到400个不好的请求。
示例
有效载荷:
{
"query": "SELECT user_id, timestamp, (EXTRACT(ISOWEEK FROM timestamp)) as week FROM table_name WHERE DATE(_PARTITIONTIME) >= '2022-01-01' ORDER BY week DESC"
}
响应:
{
"error": {
"code": 400,
"message": "Encountered \" \"FROM\" \"FROM \"\" at line 1, column 45.\nWas expecting:\n \")\" ...\n[Try using standard SQL (https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)]",
"errors": [
{
"message": "Encountered \" \"FROM\" \"FROM \"\" at line 1, column 45.\nWas expecting:\n \")\" ...\n[Try using standard SQL (https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)]",
"domain": "global",
"reason": "invalidQuery",
"location": "q",
"locationType": "parameter"
}
],
"status": "INVALID_ARGUMENT"
}
}
第二有效载荷:
{
"query": "SELECT user_id, timestamp, FORMAT_DATE('%Y%W',timestamp) as week FROM table_name WHERE DATE(_PARTITIONTIME) >= '2022-01-01' ORDER BY week DESC"
}
响应:
{
"error": {
"code": 400,
"message": "1.39 - 1.56: Unrecognized function format_date\n[Try using standard SQL (https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)]",
"errors": [
{
"message": "1.39 - 1.56: Unrecognized function format_date\n[Try using standard SQL (https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)]",
"domain": "global",
"reason": "invalidQuery",
"location": "q",
"locationType": "parameter"
}
],
"status": "INVALID_ARGUMENT"
}
}
REST中有什么特殊的方法来转义BigQuery函数吗?
谢谢,
发布于 2022-06-27 18:31:19
我怀疑(请直接提及其他端点)是在不使用客户端库的情况下构建请求。
尝试将"useLegacySQL“字段设置为false,作为请求的一部分:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#QueryRequest
由于有历史先例,并且为了避免在标准SQL方言的演变过程中破坏用户,此字段的默认值为true。各种BigQuery客户端库倾向于自动为您处理这个问题。
https://stackoverflow.com/questions/72775672
复制相似问题