简体   繁体   English

如何从保存到 bigquery 的顶点 ml 结果中查询/展平

[英]How to query / flatten from vertex ml results saved to bigquery

This is driving me bonkers so any help greatly appreciated.这让我发疯,所以非常感谢任何帮助。

I am using Google's Vertex ML.我正在使用谷歌的 Vertex ML。 I have exported a batch prediction to BigQuery.我已将批量预测导出到 BigQuery。

The schema is I believe a record with repeat fields.该模式是我相信具有重复字段的记录。

So I think it would like this in JSON:所以我认为它会在 JSON 中这样:

[{"category":true,"score":.9999},{"category":false,"score",.05}]

I can not figure out how to either unnest or narrow a search where a category is true.我无法弄清楚如何取消嵌套或缩小类别为真的搜索。

I need to have a flat select that has the correct category column and score value我需要一个具有正确类别列和分值的平面 select

123 | true | .9999
123 | false | .05

or a select with a where clause to only get true values或带有 where 子句的 select 仅获取真值

123 | .9999

The following unnests everything but it creates four rows joining both the true and false to both the scores.以下内容将所有内容都取消嵌套,但它会创建四行,将两个分数的真假连接起来。

SELECT
  row_id,
  classes,
  scores
FROM
  `database`
cross JOIN
  UNNEST(exported.classes) AS classes,
  UNNEST(exported.scores) AS scores
LIMIT
  10

creates rows like:创建如下行:

123 | true | .9999
123 | false | .9999
123 | true | .05
123 | false | .05

This does select the values I need but it's still a nested field...这确实是 select 我需要的值,但它仍然是一个嵌套字段......

select
row_id,
classes.classes,
classes.scores
from (
SELECT
  voter_id,
  ARRAY_CONCAT([predicted_results]) as the_results
FROM
  `data`
LIMIT
  10
),
unnest(the_results) as classes

creates rows like创建类似的行

123 | [true:.9999,false:.05]

I have conveyed that this query is a more direct approach to flatten input json and filter the true value based on the JSON file you have given.我已经传达了这个查询是一种更直接的方法来展平输入 json 并根据您提供的 JSON 文件过滤true值。

select 
 primary_key, 
  predicted_supports.classes[SAFE_OFFSET(index)] as class,
  predicted_supports.scores[SAFE_OFFSET(index)] as score,
FROM `tiph-janpoalaastrid.bqml_lab.flatten`,
unnest(generate_array(0,array_length(predicted_supports.classes)-1)) as index

Here is the ouput:这是输出:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM