google-bigquery - 如何知道我的表中有哪些属于 bigQuery 中的长期存储?
问题描述
我目前在一个项目中有多个数据集,我想知道是否有办法一次性知道过去 90 天内未更新的表是什么,这意味着它属于 bigquery 中的长期存储桶。有一些 sql 语法吗?
谢谢
解决方案
不是 SQL,而是一个可能的解决方案是使用该bq
工具。描述一个表将返回长期存储字节数 ( numLongTermBytes
):
$ bq show --format=prettyjson dataset.table
...
"kind": "bigquery#table",
"lastModifiedTime": "1534845362446",
"location": "US",
"numBytes": "56",
"numLongTermBytes": "56",
"numRows": "3",
...
因此,您可以将其扩展为列出每个数据集中的所有表,并从每个表中获取所需的信息。基于此,我做了一个简单的例子:
#!/bin/bash
project=PROJECT_ID
dataset=DATASET_NAME
max_results=100
# get list of tables
tables=$(bq ls --max_results $max_results "$project:$dataset" | awk '{print $1}' | tail -n +3)
# get LTS bytes for each table
for table in $tables
do
printf '%-35s %-50s\n' "$table" "$(bq show --format prettyjson $project:$dataset.$table | grep numLongTermBytes)"
done
您将获得类似于以下内容的输出:
Dfp "numLongTermBytes": "0",
SO_55506947 "numLongTermBytes": "144",
SO_55506947_bis "numLongTermBytes": "144",
a "numLongTermBytes": "7",
a1 "numLongTermBytes": "399",
aaa "numLongTermBytes": "8",
adaptive "numLongTermBytes": "1085",
adaptive_view "numLongTermBytes": "0",
audience_segment_map_exp_test "numLongTermBytes": "300",
b "numLongTermBytes": "7",
...
推荐阅读
- ms-access - 将 MS Access 2003 Unicode 字符串读入 VB6
- elasticsearch - 弹性搜索 | 如何搜索嵌套对象?
- javascript - 来自 JSON 文件的 innerHTML
- python - Pandas 中的条形图颜色处理
- angular - Angular 路由器似乎工作但不加载组件
- reactjs - React:如何在应用程序中的功能中重定向?
- bash - Conda 4.7 如何在 bash 脚本中激活 env
- php - Laravel 6.x 迁移失败,使用 Maria DB
- javascript - 在 jquery 插件中仅更改一种选择样式
- php - CodeIgniter - 如何在没有内存泄漏的情况下选择大表中的所有行