简体   繁体   English

如何在BigQuery中构造NULL数组和STRUCT

[英]How to construct NULL array and STRUCT in BigQuery

I have a table that has an array field.我有一个包含数组字段的表。 Here is the DDL on a temp table I made with just the field in question:这是我用相关字段制作的临时表上的 DDL:

CREATE TABLE `project.dataset.table`
(
  field ARRAY<STRUCT<value STRUCT<float_val FLOAT64, int_val INT64, string_val STRING>>>
)

How would I explicitly insert a NULL value for the field?我将如何为该字段显式插入 NULL 值?

I tried:我试过了:

SELECT
  ARRAY(
    SELECT AS STRUCT(
      SELECT AS STRUCT(
        CAST(NULL AS FLOAT64) AS float_val,
        CAST(NULL AS INTEGER) AS int_val,
        CAST(NULL AS STRING) AS string_val
      )
    )
  AS field)

But I get the error: Syntax error: Parenthesized expression cannot be parsed as an expression, struct constructor, or subquery at [5:9]但我收到错误: Syntax error: Parenthesized expression cannot be parsed as an expression, struct constructor, or subquery at [5:9]

Try below试试下面

SELECT
  ARRAY(
    SELECT AS STRUCT(
      SELECT AS STRUCT 
        CAST(NULL AS FLOAT64) AS float_val,
        CAST(NULL AS INTEGER) AS int_val,
        CAST(NULL AS STRING) AS string_val
    ) as value)
  AS field           

which produces below schema产生以下模式

[{
  "field": [{
    "value": {
      "float_val": null,
      "int_val": null,
      "string_val": null
    }
  }]
}]

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

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