[英]BigQuery: create view with comments added to the top of the query
我想在 BigQuery 中创建一个视图,该视图还显示作者、创建日期等评论。
但是如果我在 UI 中尝试这样做,评论就会被排除在外。
有没有办法在 BigQuery UI 中执行此操作?
或者还有其他使用 bq 客户端或 python 的方法,或者......?
例如,如果我运行这个:
CREATE OR REPLACE VIEW `my_project_id.my_dataset.my_view_name`
AS
-- this is my important comment. This will be a long and extensive comment.
SELECT 1 as column_a
;
当使用 UI 创建视图时,BigQuery 不会在视图中显示评论:
Bigquery 正在跳过“----这是我的重要评论。这将是一个冗长而广泛的评论。” 因为它被视为对 SQL 查询的注释,而不是被视为要包含在视图创建中的单独字符串。
另一种选择是使用bq
命令,如下所示。
bq mk \
--use_legacy_sql=false \
--expiration 3600 \
--description "This is my view" \
--label organization:development \
--view \
'-- this is my important comment. This will be a long and extensive comment.
SELECT 1 as column_a ' \
your-dataset.your-view
我不知道如何在 UI 中执行此操作,但使用 python API 可以执行以下操作:
from google.cloud import bigquery
bq_client = bigquery.Client()
view_id = "my_project_id.my_dataset.my_view_name"
view = bigquery.Table(view_id)
query = """
-- this is my important comment. This will be a long and extensive comment.
SELECT 1 as column_a
"""
view.view_use_legacy_sql = False
view.view_query = query
# if your view already exists
bq_client.delete_table(view)
# your query will now show the comment at the top
bq_client.create_table(view)
这导致以下视图:
另请参阅: https ://cloud.google.com/bigquery/docs/views#python
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.