bigquery 备份所有视图定义 [英] bigquery backup all view definitions
本文介绍了bigquery 备份所有视图定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 bigquery,并且已经创建了数百个视图.其中大部分未使用,应删除.但是,有机会使用一些,我不能盲目地删除所有.因此,我需要在删除它们之前以某种方式备份所有视图定义.
I am working with bigquery, and there have been a few hundred views created. Most of these are not used and should be deleted. However, there is a chance that some are used and I cannot just blindly delete all. Therefore, I need to backup all view definitions somehow before deleting them.
有谁知道一个好方法吗?我不是要保存数据,而是要保存视图定义查询及其名称.
Does anyone know of a good way? I am not trying to save the data, just the view definition queries and their names.
感谢阅读!
推荐答案
建立在 现有答案,您可以通过使用jq
解析bq
的输出来自动备份所有视图:>
Building off the existing answer, you can automate the backing up of all views by parsing the output of bq
with jq
:
#!/bin/bash
DATASETS=$(bq ls --format=sparse | tail -n+3)
for d in $DATASETS; do
TABLES=$(bq ls --format=prettyjson "$d" | jq '.[] | "(.id), (.type)"')
IFS=$'
'
for table in $TABLES; do
[[ ! "$table" == *VIEW* ]] && continue
view=$(echo "$table" | sed -e 's/"//g' | cut -d , -f 1)
query=$(bq show --format=prettyjson "$view" | jq -r '.view.query')
echo -e "$query" > "$view.sql"
done
done
这篇关于bigquery 备份所有视图定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文