def bq_view_prep_ddl()

in analytics-hub/snippets/create_listing_python/main.py [0:0]


def bq_view_prep_ddl(project_id: str, dataset_id: str, source_table_id: str, dst_table_id: str, privacy_unit_column: str):
    """Generates the BigQuery DDL statement for creating a view with privacy policy."""
    create_view_ddl_template = Template(
        """CREATE OR REPLACE VIEW $project_id.$dataset_id.$dst_table_id
        OPTIONS(
          privacy_policy= '{"aggregation_threshold_policy": {"threshold": 3, "privacy_unit_column": "$privacy_unit_column"}}'
        )
        AS ( SELECT * FROM $project_id.$dataset_id.$source_table_id );"""
    )

    ddl_statement = create_view_ddl_template.substitute(
        project_id=project_id,
        dataset_id=dataset_id,
        source_table_id=source_table_id,
        dst_table_id=dst_table_id,
        privacy_unit_column=privacy_unit_column,
    )

    return ddl_statement