更新重复数组Struct BigQuery

时间:2018-01-24 03:46:20

标签: google-bigquery

我(显然有104559行受影响)成功更新了我的session_user重复字段的元素(在表定义中见下文):

UPDATE genderfitnessdev.gfa_talend_dev.gfa_employment_cu
set session_user = ARRAY (
                      SELECT AS STRUCT * REPLACE('399975' as level_0)
                      FROM UNNEST(session_user)
                      )
where true

然后我从表中选择:

select * from `genderfitnessdev.gfa_talend_dev.gfa_employment_cu`

使用以下结果(未填充session_user):??

[
  {
"Emplid": "386957",
"Code": "HR",
"Name_display": "Andrea",
"First_name": "Andrea",
"Last_name": "xxxx",
"EMPL_Status": "T",
"Sex": "F",
"Company": "BET",
"Hire_dt": "2014-05-05",
"Termination_dt": "2015-05-15",
"Tree_node": "BETFAIR",
"allowed_viewer": null,
"allowed_group": null,
"session_user": []
  },
  {
"Emplid": "028308",
"Code": "JJ",
"Name_display": "Trudy",
"First_name": "Trudy",
"Last_name": "xxxxx",
"EMPL_Status": "T",
"Sex": "F",
"Company": "CC",
"Hire_dt": "2002-04-08",
"Termination_dt": "2002-08-10",
"Tree_node": "CROWN F&B",
"allowed_viewer": null,
"allowed_group": null,
"session_user": []
  },
.
.
.
.

表定义:

"schema": {
"fields": [
  {
    "name": "Emplid",
    "type": "STRING"
  },
  {
    "name": "Code",
    "type": "STRING"
  },
  {
    "name": "Name_display",
    "type": "STRING"
  },
  {
    "name": "First_name",
    "type": "STRING"
  },
  {
    "name": "Last_name",
    "type": "STRING"
  },
  {
    "name": "EMPL_Status",
    "type": "STRING"
  },
  {
    "name": "Sex",
    "type": "STRING"
  },
  {
    "name": "Company",
    "type": "STRING"
  },
  {
    "name": "Hire_dt",
    "type": "STRING"
  },
  {
    "name": "Termination_dt",
    "type": "STRING"
  },
  {
    "name": "Tree_node",
    "type": "STRING"
  },
  {
    "mode": "NULLABLE",
    "name": "allowed_viewer",
    "type": "STRING"
  },
  {
    "mode": "NULLABLE",
    "name": "allowed_group",
    "type": "STRING"
  },
  {
    "fields": [
      {
        "mode": "NULLABLE",
        "name": "level_0",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_1",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_2",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_3",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_4",
     "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_5",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_6",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_7",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_8",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_9",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "level_10",
        "type": "STRING"
     }
    ],
    "mode": "REPEATED",
    "name": "session_user",
    "type": "RECORD"
  }
]
   }

是UPDATE或SELECT的问题,因为我希望至少看到session_user.level_0填充了字符串??

1 个答案:

答案 0 :(得分:0)

鉴于您的最新评论,您所做的就是添加一个新的REPEATED RECORD列“session_user”。在这种情况下,它将为所有行提供空数组,因此,使用的UPDATE结构并不会真正影响那些“受影响的104559行”。

如果我已正确理解,并且您的所有行都不包含session_user上的有效值,则可以使用以下语法插入一些虚拟值:

UPDATE `genderfitnessdev.gfa_talend_dev.gfa_employment_cu`set session_user = ARRAY<STRUCT<level_0 string, level_1 string,level_2 string,level_3 string,level_4 string,level_5 string,level_6 string,level_7 string,level_8 string,level_9 string,level_10 string>>
  [('level_0', 'level_1','level_2','level_3','level_4','level_5','level_6','level_7','level_8','level_9','level_10')] where true