【问题标题】:BigQuery: create view with comments added to the top of the queryBigQuery:创建视图并将注释添加到查询顶部
【发布时间】:2022-12-15 09:28:28
【问题描述】:

我想在 BigQuery 中创建一个视图,该视图还显示 cmets,例如作者、创建日期等。

但是,如果我在 UI 中尝试这样做,cmets 将被排除在外。
有没有办法在 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
;

BigQuery 不会在 UI 中显示 cmets:

【问题讨论】:

    标签: google-cloud-platform google-bigquery


    【解决方案1】:

    我不知道如何在 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多