bigframes.pandas.remote_function#

bigframes.pandas.remote_function(input_types: None | type | Sequence[type] = None, output_type: type | None = None, dataset: str | None = None, *, bigquery_connection: str | None = None, reuse: bool = True, name: str | None = None, packages: Sequence[str] | None = None, cloud_function_service_account: str, cloud_function_kms_key_name: str | None = None, cloud_function_docker_repository: str | None = None, max_batching_rows: int | None = 1000, cloud_function_timeout: int | None = 600, cloud_function_max_instances: int | None = None, cloud_function_vpc_connector: str | None = None, cloud_function_vpc_connector_egress_settings: Literal['all', 'private-ranges-only', 'unspecified'] | None = None, cloud_function_memory_mib: int | None = 1024, cloud_function_ingress_settings: Literal['all', 'internal-only', 'internal-and-gclb'] = 'internal-only', cloud_build_service_account: str | None = None)[source]#

Decorator to turn a user defined function into a BigQuery remote function. Check out the code samples at: https://cloud.google.com/bigquery/docs/remote-functions#bigquery-dataframes.

Note

input_types=Series scenario is in preview. It currently only supports dataframe with column types Int64/Float64/boolean/ string/binary[pyarrow].

Warning

To use remote functions with Bigframes 2.0 and onwards, please (preferred) set an explicit user-managed cloud_function_service_account or (discouraged) set cloud_function_service_account to use the Compute Engine service account by setting it to “default”.

See, https://cloud.google.com/functions/docs/securing/function-identity.

Note

Please make sure following is setup before using this API:

  1. Have the below APIs enabled for your project:

    • BigQuery Connection API

    • Cloud Functions API

    • Cloud Run API

    • Cloud Build API

    • Artifact Registry API

    • Cloud Resource Manager API

    This can be done from the cloud console (change PROJECT_ID to yours): https://console.cloud.google.com/apis/enableflow?apiid=bigqueryconnection.googleapis.com,cloudfunctions.googleapis.com,run.googleapis.com,cloudbuild.googleapis.com,artifactregistry.googleapis.com,cloudresourcemanager.googleapis.com&project=PROJECT_ID

    Or from the gcloud CLI:

    $ gcloud services enable bigqueryconnection.googleapis.com cloudfunctions.googleapis.com run.googleapis.com cloudbuild.googleapis.com artifactregistry.googleapis.com cloudresourcemanager.googleapis.com

  2. Have following IAM roles enabled for you:

    • BigQuery Data Editor (roles/bigquery.dataEditor)

    • BigQuery Connection Admin (roles/bigquery.connectionAdmin)

    • Cloud Functions Developer (roles/cloudfunctions.developer)

    • Service Account User (roles/iam.serviceAccountUser) on the service account PROJECT_NUMBER-compute@developer.gserviceaccount.com

    • Storage Object Viewer (roles/storage.objectViewer)

    • Project IAM Admin (roles/resourcemanager.projectIamAdmin) (Only required if the bigquery connection being used is not pre-created and is created dynamically with user credentials.)

  3. Either the user has setIamPolicy privilege on the project, or a BigQuery connection is pre-created with necessary IAM role set:

    1. To create a connection, follow https://cloud.google.com/bigquery/docs/reference/standard-sql/remote-functions#create_a_connection

    2. To set up IAM, follow https://cloud.google.com/bigquery/docs/reference/standard-sql/remote-functions#grant_permission_on_function

      Alternatively, the IAM could also be setup via the gcloud CLI:

      $ gcloud projects add-iam-policy-binding PROJECT_ID –member=”serviceAccount:CONNECTION_SERVICE_ACCOUNT_ID” –role=”roles/run.invoker”.

Parameters:
Returns:

A remote function object pointing to the cloud assets created in the background to support the remote execution. The cloud assets can be located through the following properties set in the object:

bigframes_cloud_function - The google cloud function deployed for the user defined code.

bigframes_remote_function - The bigquery remote function capable of calling into bigframes_cloud_function.

Return type:

collections.abc.Callable