marcosmarxm commented on a change in pull request #15367:
URL: https://github.com/apache/airflow/pull/15367#discussion_r614317645



##########
File path: airflow/providers/google/cloud/operators/bigquery.py
##########
@@ -2039,6 +2039,149 @@ def execute(self, context) -> None:
         )
 
 
+class BigQueryPatchTableSchemaOperator(BaseOperator):
+    """
+    Patch BigQuery Table Schema
+    Updates fields on a table schema based on contents of the supplied schema
+    parameter. The supplied schema does not need to be complete, if the field
+    already exists in the schema you only need to supply a schema with the
+    fields you want to patch and the "name" key set on the schema resource.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:BigQueryPatchTableSchemaOperator`
+
+    :param dataset_id: A dotted
+        ``(<project>.|<project>:)<dataset>`` that indicates which dataset
+        will be updated. (templated)
+    :type dataset_id: str
+    :param schema_fields: a partial schema resource. see
+        
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#TableSchema
+
+    **Example**: ::
+
+        schema_fields=[
+            {"name": "emp_name", "description": "Some New Description"},
+            {"name": "salary", "description": "Some New Description"},
+            {"name": "departments", "fields": [
+                {"name": "name", "description": "Some New Description"},
+                {"name": "type", "description": "Some New Description"}
+            ]},
+        ]
+
+    :type schema_fields: dict
+    :param project_id: The name of the project where we want to update the 
dataset.
+        Don't need to provide, if projectId in dataset_reference.
+    :type project_id: str
+    :param gcp_conn_id: (Optional) The connection ID used to connect to Google 
Cloud.
+    :type gcp_conn_id: str
+    :param bigquery_conn_id: (Deprecated) The connection ID used to connect to 
Google Cloud.
+        This parameter has been deprecated. You should pass the gcp_conn_id 
parameter instead.
+    :type bigquery_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have 
domain-wide
+        delegation enabled.
+    :type delegate_to: str
+    :param location: The location used for the operation.
+    :type location: str
+    :param impersonation_chain: Optional service account to impersonate using 
short-term
+        credentials, or chained list of accounts required to get the 
access_token
+        of the last account in the list, which will be impersonated in the 
request.
+        If set as a string, the account must grant the originating account
+        the Service Account Token Creator IAM role.
+        If set as a sequence, the identities from the list must grant
+        Service Account Token Creator IAM role to the directly preceding 
identity, with first
+        account from the list granting this role to the originating account 
(templated).
+    :type impersonation_chain: Union[str, Sequence[str]]
+    """
+
+    template_fields = (
+        'schema_fields',
+        'dataset_id',
+        'table_id',
+        'project_id',
+        'impersonation_chain',
+    )
+    template_fields_renderers = {"schema_fields": "json"}
+    ui_color = BigQueryUIColors.TABLE.value
+
+    @classmethod
+    def _patch_schema(cls, old_schema, new_schema):
+        # Updates the content of "old_schema" with

Review comment:
       ```suggestion
       def _patch_schema(cls, old_schema: Dict, new_schema: Dict) -> None:
           """
           Updates the content of "old_schema" with
           the fields from new_schema. Makes changes
           in place and hence has no return value.
           Works recursively for sub-records.
   
           Start by turning the schema list of fields into
           a dict keyed on the field name for both the old
           and the new schema.
           
           :param old_schema: Old schema...
           :type old_schema: dict
           """
   ```
   
   This way information about the function itself will be render in Airflow 
website and users have more information about it, take a look [in an example 
here](
   
https://airflow.apache.org/docs/apache-airflow-providers-google/stable/_api/airflow/providers/google/cloud/hooks/bigquery/index.html#airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_schema)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to