没有匹配的签名错误 Google BigQuery

huangapple go评论70阅读模式
英文:

No Matching Signature Error Google BigQuery

问题

我有一个在BigQuery中的表格,设置如下:

Column_A Column_B
project783/north {"baseball": 0.34243,"hockey":0.09348, "basketball":0.0294,"golf":0.45657}
project783/south {"golf": 0.0615,"basketball":0.5165, "baseball":0.15684,"hockey":0.2156}

我试图提取Column B中的最大运动项目,以便返回:

max_B

Column_A Column_B
north golf
south basketball

根据模式,Column B设置为字符串。

我首先尝试确保Column B中的数据可以拆分,以便我可以选择具有最大值的适当行以关联到项目。我尝试了以下查询:

SELECT 
SPLIT(Column_B, ",") as split_column_b

这没有起作用,然后我收到以下错误:"No matching signature for function SPLIT for argument type ARRAY "。

然后我尝试执行以下操作:

SELECT 
SPLIT(ARRAY_TO_STRING(Column_B,":"),",")

然而,结果只是将表格嵌套,好像将Column B转换成了列表,如下所示:

| Column_A           | Column_B              |
| ------------------ | --------------------- |
| project783/north   | {"baseball": 0.34243  |
|                    | "hockey":0.09348      |
|                    | "basketball":0.0294   |
|                    | "golf":0.45657}       |
|--------------------+-----------------------|
| project783/south   | {"golf": 0.0615       |
|                    | "basketball":0.5165   |
|                    | "hockey":0.2156}      |

我不确定接下来该怎么做。当我检查JSON查询结果时,Column B似乎被设置为数组,当我尝试其他方法,如JSON_EXTRACT时,我会收到"没有匹配的签名"错误。

英文:

I have a table in BigQuery with the following set up:

Column_A Column_B
project783/north {"baseball": 0.34243,"hockey":0.09348, "basketball":0.0294,"golf":0.45657}
project783/south {"golf": 0.0615,"basketball":0.5165, "baseball":0.15684,"hockey":0.2156}

I am trying to extract the max sport in Column B such that I return:
max_B

Column_A Column_B
north golf
south basketball

Column B is set up as a String according to the schema.

I first tried to make sure the data in Column B could be split up so I can select the appropiate row with the max value to the associated project. I tried the follow query:

SELECT 
SPLIT(Column_B, ",") as split_column_b

This did not work and I then received the following error: "No matching signature for function SPLIT for argument type ARRAY <STRING>".

I then tried to do

SELECT 
SPLIT(ARRAY_TO_STRING(Column_B,":"),",")

However, all that happens is that the table nests as if it were to turn Column_B into a list such as:

| Column_A           | Column_B              |
| ------------------ | --------------------- |
| project783/north   | {"baseball": 0.34243  |
|                    | "hockey":0.09348      |
|                    | "basketball":0.0294   |
|                    | "golf":0.45657}       |
|--------------------+-----------------------|
| project783/south   | {"golf": 0.0615       |
|                    | "basketball":0.5165   |
|                    | "hockey":0.2156}      |

I am not sure how to proceed. When I check the JSON query results Column_B seems to be set as an array and when I try other approaches such as JSON_EXTRACT I receive the "No matching signature" error.

答案1

得分: 0

以下是翻译好的部分:

假设 Column_B 包含一个 JSON 字符串值,您可以尝试以下操作。

查询结果

没有匹配的签名错误 Google BigQuery

英文:

Assuming Column_B has a json string value, you can try below.

WITH sample_table AS (
  SELECT 'project783/north' Column_A, '{"baseball": 0.34243,"hockey":0.09348, "basketball":0.0294,"golf":0.45657}' Column_B UNION ALL
  SELECT 'project783/south' Column_A, '{"golf": 0.0615,"basketball":0.5165, "baseball":0.15684,"hockey":0.2156}' Column_B
),
splits AS (
  SELECT SPLIT(Column_A, '/')[SAFE_OFFSET(1)] AS Column_A,
         TRIM(kv[SAFE_OFFSET(0)], '" ') AS name,
         CAST(TRIM(kv[SAFE_OFFSET(1)]) AS FLOAT64) AS value
    FROM sample_table,
  UNNEST(SPLIT(TRIM(Column_B, '{}'), ",")) e,
  UNNEST([STRUCT(SPLIT(e, ':') AS kv)])
)
SELECT Column_A, ANY_VALUE(name HAVING MAX value) Column_B 
  FROM splits 
 GROUP BY 1;

Query results

没有匹配的签名错误 Google BigQuery

huangapple
  • 本文由 发表于 2023年2月27日 09:58:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定