Análise executada pelo provedor¶
Overview¶
A configuração padrão da clean room permite que apenas o consumidor execute uma análise na clean room. No entanto, o provedor pode solicitar a permissão do consumidor para executar modelos usando dados do consumidor em uma clean room específica. A análise executada pelo provedor pode ser ativada e executada usando a UI ou o código de clean rooms.
The following diagram shows the data flow and the main components in a basic provider-run analysis:
In a basic provider-run analysis, the consumer and provider both link their data into the clean room. Source data is linked into the clean room as private views in the account where the data lives.
When the provider runs an analysis, the provider’s data is shared with the clean room app in the consumer’s account. The analysis runs on the consumer’s account.
The encrypted results are temporarily written to the consumer DB in the consumer’s account.
The encrypted results are copied to the analysis results back share on the provider’s account (also called the governance back share) and decrypted. Because the analysis runs on the consumer’s account, the consumer is billed for the analysis.
For more information, see Snowflake Data Clean Rooms: objetos instalados.
Templates that support provider-run analyses¶
The following templates support provider-run analyses:
Audience Overlap & Segmentation
SQL Query (UI only)
Modelos personalizados (somente na API)
Billing and cost details¶
Provider-run analyses run in the consumer’s account, and consumers are billed for a provider-run analysis. To stop incurring costs from provider-run analyses, the consumer must uninstall the clean room.
A consumer can estimate the number of credits consumed by the provider within the last N days by executing the following query. Specify the number of previous days as a negative number.
-- Estimate the number of credits consumed in the past 5 days.
SELECT * FROM TABLE(SAMOOHA_BY_SNOWFLAKE_LOCAL_DB.LIBRARY.PRA_CONSUMPTION_UDTF(-5));
When a provider runs an analysis in the clean rooms UI, the clean room uses auto-scaling logic based on dataset sizes to choose a warehouse for your analysis.
When a provider creates and runs a clean room using the API, the provider can explicitly choose a warehouse size using the API. The consumer can limit the size and type of warehouses available to the provider when running a given template.
General notes¶
Providers can activate results to their own account using the UI or the API, or to third-party providers if using the UI. For information about how to enable activation and view results, see Implementação da ativação em sua clean room.
Se o consumidor e provedor estiverem em regiões de nuvem diferentes, você precisará ativar o preenchimento automático entre nuvens em ambas as contas e para ambas as clean rooms.
Note that provider-run cross-cloud queries can take some time to run because provider source data must be replicated from the provider to the consumer, and query results from the consumer to the provider, all across cloud regions.
Any templates run by the provider require column names or aliases for all columns generated in the results. If a column is aggregated (for example,
SUM(col1)) or calls a custom function (for example,cleanroom.my_function(p.hashed_email)), you must explicitly specify an alias for the column name as shown here:SELECT SUM(col1) AS TOTAL FROM my_db.my_sch.T; -- Correct SELECT SUM(col1) FROM my_db.my_sch.T; -- Error: aggregated column needs an explicit alias.
Provider-run analyses in the UI¶
Here is how to enable provider-run analysis in a new clean room using the clean rooms UI:
The provider creates and configures a clean room, using one of the supported templates. Configure the clean room up to the Share Clean Room step.
In the Share Clean Room step of clean room configuration, the provider selects Enable run analysis & query next to their own account to enable them to run all templates in this clean room that support provider-run analysis.
Essa configuração não pode ser alterada após a criação de uma sala limpa; se você quiser alterar a permissão de uma conta específica para executar consultas em uma sala limpa publicada, deverá excluir a sala limpa e criar uma nova.
The consumer joins and configures the clean room as is usual for all templates in the clean room, including any templates that support provider analysis. If the consumer does not want to enable a provider to run a specific template, they can omit required details for that template.
Quando o consumidor ingressa na sala limpa, ele é avisado antes de ingressar que a análise executada pelo provedor está ativada para essa sala limpa.
The consumer can run queries as soon as the clean room is joined, but there is a delay of up to 30 minutes before the provider can run the template. This setup delay is only occurs during the initial join step; if the provider later adds other provider-run templates, the provider can run them as soon as the consumer configures their clean room for that template.
After the join step completes, the clean room is available for both provider run analyses and consumer run analyses.
Important:
Providers must wait about 10 minutes after the consumer installs the clean room before they can run an analysis. The delay is for additional background configuration required for provider-run analyses.
O consumidor é cobrado por todas as análises nesta sala limpa, sejam elas executadas pelo provedor ou pelo consumidor.
Provider-run analyses in the API¶
Here is how to enable provider-run analysis in a new clean room using the clean rooms API:
Provedor
Crie e configure sua clean room e seus dados e políticas da maneira padrão.
Adicione consumidores da maneira padrão.
Enable provider-run analysis for specific consumer accounts in the clean room by calling
provider.enable_provider_run_analysis.Important:
You must call
provider.enable_provider_run_analysisafter adding consumers to a clean room, but before any consumer installs the clean room. Each consumer account must approve this request for their data to be accessible for provider-run analyses in this clean room.Any time the provider changes the provider-run analysis setting for a clean room, the clean room must be re-installed by all consumers for the change to take effect. Because it can be difficult to force all collaborators to re-install a clean room, it is more reliable for the provider to delete a published, shared clean room when changing the analysis permissions, then create a new clean room with the desired permissions.
Publique a clean room.
Informe aos seus consumidores que a clean room está disponível, o nome da clean room e quais modelos você deseja executar na clean room.
Consumidor
Instale a sala limpa e vincule seus dados da maneira padrão.
Set any join and column policies needed on your data.
Permita a análise do provedor para modelos específicos na sala limpa chamando
consumer.enable_templates_for_provider_run(para vários modelos) ouconsumer.approve_template(para um modelo).Nota
Se o provedor alterar um modelo após o consumidor aprová-lo, o consumidor deverá aprová-lo novamente. Até que o modelo seja reaprovado, a versão antiga em cache do modelo aprovado será executada pelo provedor.
(Optional) Provider-run analyses are billed to the consumer. A consumer can limit the warehouse type or sizes available for provider-run analyses: see Restricting warehouse size and type limits.
Informe ao provedor que você instalou a clean room e aprovou as análises realizadas pelo provedor.
Provedor
Depois que o consumidor instalar a sala limpa, você deverá permitir que suas análises acessem os dados do consumidor habilitando o compartilhamento de dados do consumidor com a conta do provedor. O processo para isso depende se o provedor e o consumidor estão na mesma região de nuvem ou em regiões diferentes:
If the provider and consumer are in the same cloud region, the provider calls
provider.mount_request_logs_for_all_consumersonce. If a new consumer account installs the clean room later and you want to use their data in this template, you must re-run this procedure to be able to access that data.If the provider and consumer are in different cloud regions, the provider and consumer must enable cross-cloud auto-fulfillment. When a provider runs an analysis across regions, the query can take some time to complete, because query data is sent from the provider’s region to the consumer’s region and back.
Call
provider.view_warehouse_sizes_for_templateto see if the consumer has limited the type and size of warehouse used for the analysis. If the consumer has limited your warehouse selection, you must provide supportedwarehouse_typeandwarehouse_sizevalues in your analysis request in the next step. If the consumer has not specified warehouse limits, those fields are optional in your request. For more information, see Restricting warehouse size and type limits.Run the analysis by calling
provider.submit_analysis_requestwith the template name, the table names, and the template arguments. If the consumer has specified limits on warehouse sizes or types, you must also specify the warehouse size and type in your request.Save the request ID returned by
provider.submit_analysis_request; the ID is needed to check the status and results of the analysis.
Check the status of the analysis by calling
provider.check_analysis_status. When status is reported asCOMPLETED, callprovider.get_analysis_resultto get the analysis results.
Restricting warehouse size and type limits¶
Here is how a consumer sets a warehouse size and type limitation, and how a provider chooses a warehouse size and type when running an analysis:
O consumidor chama
consumer.set_provider_run_configuratione especifica quais tamanhos e tipos de warehouse um provedor pode usar para um modelo especificado.CALL samooha_by_snowflake_local_db.consumer.set_provider_run_configuration( $cleanroom_name, { $template_name: { 'warehouse_type': 'STANDARD', 'warehouse_size': ['MEDIUM', 'LARGE']} });
O provedor chama
provider.view_warehouse_sizes_for_templatepara ver quais tamanhos e tipos de warehouse são permitidos para análises executadas pelo provedor naquele modelo.CALL samooha_by_snowflake_local_db.provider.view_warehouse_sizes_for_template( $cleanroom_name, $template_name, $consumer_account_loc );
The provider specifies which supported warehouse size and type to use in their analysis run request.
CALL samooha_by_snowflake_local_db.provider.submit_analysis_request( $cleanroom_name, $consumer_locator_id, $template_name, ['SAMOOHA_SAMPLE_DATABASE.DEMO.CUSTOMERS'], ['SAMOOHA_SAMPLE_DATABASE.DEMO.CUSTOMERS'], object_construct( 'dimensions', ['c.REGION_CODE'], 'measure_type', ['AVG'], 'measure_column', ['c.DAYS_ACTIVE'], 'warehouse_type', 'STANDARD', -- Any other value would cause the request to fail. 'warehouse_size', 'LARGE' -- Only MEDIUM and LARGE supported. ) );
Install and run the code example¶
You can download and install a complete running example to create and run a provider-run analysis. To run this example, you need two Snowflake accounts in the same organization and cloud hosting region with the Snowflake Data Clean Room environment installed.
Instale o notebook nas suas contas de provedor e consumidor.
Para carregar um notebook, faça o seguinte:
No menu de navegação, selecione Projects » Notebooks.
Selecione + Notebook » Import .ipynb file.
Selecione o arquivo .ipynb que você baixou.
Dê ao arquivo o nome que desejar e escolha um banco de dados e um esquema.
Mantenha o warehouse padrão
APP_WH.Selecione Create.
Abra o notebook na conta de provedor e preencha a parte do provedor para criar a clean room.
Abra o notebook na conta de consumidor e conclua a parte do consumidor para instalar e configurar a clean room e executar o modelo.
Dica
Os procedimentos a seguir gerenciam o lado que pode executar uma análise na clean room:
Análise executada pelo consumidor (permitida por padrão): as alterações são aplicadas imediatamente.
provider.enable_consumer_run_analysis
provider.disable_consumer_run_analysis
Análise executada pelo provedor (desabilitada por padrão): as alterações exigem reinstalação pelo consumidor.
provider.enable_provider_run_analysis(requires the consumer to approve by calling consumer.enable_templates_for_provider_run)
provider.disable_provider_run_analysis