Jaa


current_recipient function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 14.2 and above

Important

This feature is in Public Preview.

Returns the property value associated with the specified property key for the current data recipient in a Delta Sharing context. This function allows data providers to dynamically control data access based on recipient-specific properties.

Syntax

current_recipient(key)

Arguments

  • key

    A STRING expression specifying a recipient property key. Recipient properties include predefined properties starting with 'databricks.' and custom properties. See manage recipient properties

Returns

A STRING.

Notes

This function should be used in a view definition when the data provider is creating a shared view. Note that the created view is for sharing only: The data provider is not able to query the view directly because the function evaluation will fail due to missing sharing context.

This function can be successfully evaluated only when the data recipient is querying a delta sharing view.

Examples

-- provider creates view with row filtering
> CREATE VIEW acme.default.my_view AS
    SELECT * FROM acme.default.my_table
    WHERE country = current_recipient('country');

-- provider creates view with column masking
> CREATE VIEW acme.default.my_view AS
    SELECT
      CASE
        WHEN current_recipient('country') = 'US' THEN pii
        ELSE 'REDACTED'
      END AS pii
    FROM acme.default.my_table;

-- set recipient property and share view to the recipient
> ALTER SHARE my_share ADD VIEW acme.default.my_view;
> ALTER RECIPIENT cdc SET PROPERTIES ('country' = 'US');

-- Test recipient by mocking the context
> SET RECIPIENT cdc;
> SELECT * FROM acme_shared.default.my_view;

-- Grant access to shre to recipient
> GRANT SELECT ON SHARE my_share TO RECIPIENT cdc;

-- recipient queries the view, results should be filtered by recipient’s property
> CREATE CATALOG acme_shared USING SHARE acme.my_share;
> SELECT * FROM acme_shared.default.my_view;