-- The following code demonstrates the consumer side of a provider-written UDF in a clean room.
-- For more information, see docs.snowflake.com/user-guide/cleanrooms/demo-flows/custom-code

USE WAREHOUSE app_wh;
USE ROLE SAMOOHA_APP_ROLE;

SET cleanroom_name = 'Provider UDF example';
CALL samooha_by_snowflake_local_db.consumer.install_cleanroom($cleanroom_name, '<provider_locator>');
CALL samooha_by_snowflake_local_db.consumer.is_enabled($cleanroom_name);

SET udf_template_name = 'basic_UDF_template';
SET udtf_template_name = 'basic_UDTF_template';

CALL samooha_by_snowflake_local_db.consumer.run_analysis(
    $cleanroom_name,
    $udf_template_name,
    [], -- No consumer tables used in our example.
    [], -- No provider tables used in our example.
    {}  -- No parameters needed for our example.
);

CALL samooha_by_snowflake_local_db.consumer.run_analysis(
    $cleanroom_name,
    $udtf_template_name,
    [], -- No consumer tables used in our example.
    [], -- No provider tables used in our example.
    {}  -- No parameters needed for our example.
);

-- Clean up when done.
CALL samooha_by_snowflake_local_db.consumer.uninstall_cleanroom($cleanroom_name);
