node.js - BigQuery 多行在单个作业中更新
问题描述
我有两个数组,一个用于我要更新的值,一个用于 where 语句。这是用户名列表:
[
'4feathersandfur', '4flyman',
'4iisx', '4lergico_',
'4mygal', '4mygal',
'4mygal', '4mygal',
'4mygal', '4mygal',
'4mygal', '4ringzryan',
'4summeror4ever', '5.by',
'5.by', '5.by',
'5.by', '5.by',
'5.vt', '5.vt',
'5.vt', '5.vt',
'5.vt', '5.vt',
'5.vt', '5.vt',
'501_f', '502_nesha',
'5050_therealvito', '50_shades_of_dramatic',
'50_shades_of_dramatic', '50tonsdesono_',
'526ha', '5588fatima',
'5588fatima', '559ac',
'55sommy55', '55sommy55',
'58_q8', '5_alsheh7i.94'
]
这是 new_ig_followers_count 的列表
[
'1001', '1000', '1001', '1000',
'1000', '1000', '1000', '1000',
'1000', '1000', '1000', '1001',
'1001', '1000', '1000', '1000',
'1000', '1000', '1001', '1001',
'1001', '1001', '1001', '1001',
'1001', '1001', '1000', '1000',
'1001', '1001', '1001', '1001',
'1001', '1001', '1001', '1000',
'1001', '1001', '1000', '1001'
]
我想要一项工作来使用这些用户名及其相应的追随者人数更新所有行,是否可以在一项工作中完成。
表的架构是
Field name Type Mode Description
username STRING NULLABLE
website STRING NULLABLE
description STRING NULLABLE
url STRING NULLABLE
followed_by INTEGER NULLABLE
email STRING NULLABLE
new_ig_followers_count INTEGER NULLABLE
updated_at TIMESTAMP NULLABLE
IG_alive BOOLEAN NULLABLE
解决方案
以下是 BigQuery 标准 SQL
UPDATE `instagramdata.instagram.40_50_followers`
SET
new_ig_followers_count = followersCount,
updated_at = CURRENT_TIMESTAMP(),
IG_alive = TRUE
FROM (
SELECT [
'4feathersandfur', '4flyman',
'4iisx', '4lergico_',
'4mygal', '4mygal',
'4mygal', '4mygal',
'4mygal', '4mygal',
'4mygal', '4ringzryan'
] AS usernameArray,
[
'1001', '1000', '1001', '1000',
'1000', '1000', '1000', '1000',
'1000', '1000', '1000', '1001'
] AS followersCountArray
),
UNNEST(usernameArray) AS Name WITH OFFSET
JOIN UNNEST(followersCountArray) AS followersCount WITH OFFSET
USING(OFFSET)
WHERE username = Name
推荐阅读
- spring-webflux - 如果在 Project Reactor 中使用 publishOn,订阅不会打印出任何日志
- xml - Xsl-transformation with grouping,获取祖先属性值
- python - python selenium bs4,不是从 https url 而是从带有服务器目录的 src 下载图像
- matlab - 如何在 Matlab 中从高斯 Copula 生成条件分布?
- python - “manage.py startapp”不创建 db.sqlite3
- matlab - 为什么 Matlab 阶乘函数将整数视为非整数?
- r - Rfast hd.eigen() 返回 NA,但基本 eigen() 不返回
- pentaho - Pentaho / PDI:如果加载作业(在元作业内)失败,则自动将值增加一
- python-3.x - 为什么我不能将布尔运算符分配给变量?
- python - 迁移学习(VGG16)在 CIFAR-10 上表现更差是正常的吗?