|
| 1 | +--- |
| 2 | +title: "User Data Filters" |
| 3 | +linkTitle: "User Data Filters" |
| 4 | +weight: 4 |
| 5 | +--- |
| 6 | + |
| 7 | +User Data Filter (UDF) provisioning allows you to manage user data filters in your GoodData environment. |
| 8 | + |
| 9 | +UDFs can currently be managed only in full load mode, meaning your input will overwrite existing UDFs for each workspace contained within the input data. |
| 10 | + |
| 11 | +Note that this tool currently supports only creation of UDFs in `{column} in (udf_value)` MAQL pattern. UDFs using more complex MAQL expressions will have to be set up manually. |
| 12 | + |
| 13 | +{{% alert color="info" %}} Visit [Set Up Data Filters for Users](https://www.gooddata.com/docs/cloud/workspaces/user-data-filters/) to learn more about User Data Filters setup and use cases in GoodData. {{% /alert %}} |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Start by importing and initializing the UserDataFilterProvisioner. |
| 18 | + |
| 19 | +```python |
| 20 | +from gooddata_pipelines import UserDataFilterProvisioner |
| 21 | + |
| 22 | +host = "http://localhost:3000" |
| 23 | +token = "some_user_token" |
| 24 | + |
| 25 | +# Initialize the provisioner with GoodData credentials |
| 26 | +provisioner = UserDataFilterProvisioner.create(host=host, token=token) |
| 27 | + |
| 28 | +``` |
| 29 | + |
| 30 | +Then, set the values for LDM and MAQL column names to be used in the UDF: |
| 31 | + |
| 32 | +```python |
| 33 | +provisioner.set_ldm_column_name("ldm_column_name") |
| 34 | +provisioner.set_maql_column_name("{attribute/dataset.field_name}") |
| 35 | + |
| 36 | +``` |
| 37 | + |
| 38 | + |
| 39 | +Further, you need to validate the input data using the `UserDataFilterFullLoad` model. |
| 40 | + |
| 41 | +The models expect the following fields: |
| 42 | + |
| 43 | +| name | description | |
| 44 | +|---------------|---------------------------------------------------------------------------------------------| |
| 45 | +| workspace_id | ID of the workspace where the UDF will be applied. | |
| 46 | +| udf_id | ID of the UDF to be created. Should be equal to the ID of the user the UDF will be applied to. | |
| 47 | +| udf_value | Value for the UDF. | |
| 48 | + |
| 49 | +{{% alert color="info" title="Note on IDs"%}} |
| 50 | +Each ID can only contain allowed characters. See [Workspace Object Identification](https://www.gooddata.com/docs/cloud/create-workspaces/objects-identification/) to learn more about object identifiers. |
| 51 | +{{% /alert %}} |
| 52 | + |
| 53 | +Add the model to your import statement and create instances validated data: |
| 54 | + |
| 55 | +```python |
| 56 | +# Add the model to the imports |
| 57 | +from gooddata_pipelines import UserDataFilterFullLoad, UserDataFilterProvisioner |
| 58 | + |
| 59 | +host = "http://localhost:3000" |
| 60 | +token = "some_user_token" |
| 61 | + |
| 62 | +# Initialize the provisioner with GoodData credentials |
| 63 | +provisioner = UserDataFilterProvisioner.create(host=host, token=token) |
| 64 | + |
| 65 | +# Validate your data |
| 66 | +validated_data = [ |
| 67 | + UserDataFilterFullLoad( |
| 68 | + workspace_id="workspace_id_1", |
| 69 | + udf_id="user_id_1", |
| 70 | + udf_value="udf_value_1", |
| 71 | + ) |
| 72 | + ] |
| 73 | + |
| 74 | +``` |
| 75 | + |
| 76 | +Now with the provisioner initialized and your data validated, you can run the provisioner: |
| 77 | + |
| 78 | +```python |
| 79 | +# Import, initialize, validate... |
| 80 | +... |
| 81 | + |
| 82 | +# Run the provisioning method |
| 83 | +provisioner.full_load(validated_data) |
| 84 | + |
| 85 | +``` |
| 86 | + |
| 87 | +## Examples |
| 88 | + |
| 89 | +Here is the full example of a full load UDF provisioning workflow: |
| 90 | + |
| 91 | +```python |
| 92 | +import logging |
| 93 | + |
| 94 | +from gooddata_pipelines import UserDataFilterFullLoad, UserDataFilterProvisioner |
| 95 | + |
| 96 | +host = "http://localhost:3000" |
| 97 | +token = "some_user_token" |
| 98 | + |
| 99 | +# Initialize the provisioner |
| 100 | +provisioner = UserDataFilterProvisioner.create(host=host, token=token) |
| 101 | + |
| 102 | +# Set the colum names to be used in the UDF |
| 103 | +provisioner.set_ldm_column_name("ldm_column_name") |
| 104 | +provisioner.set_maql_column_name("{attribute/dataset.field_name}") |
| 105 | + |
| 106 | +# Optional: set up logging and subscribe to logs emitted by the provisioner |
| 107 | +logging.basicConfig(level=logging.INFO) |
| 108 | +logger = logging.getLogger(__name__) |
| 109 | + |
| 110 | +provisioner.logger.subscribe(logger) |
| 111 | + |
| 112 | +# Prepare your data |
| 113 | +raw_data = [ |
| 114 | + { |
| 115 | + "workspace_id": "workspace_id_1", |
| 116 | + "udf_id": "user_id_1", |
| 117 | + "udf_value": "udf_value_1" |
| 118 | + }, |
| 119 | + { |
| 120 | + "workspace_id": "workspace_id_1", |
| 121 | + "udf_id": "user_id_2", |
| 122 | + "udf_value": "udf_value_2" |
| 123 | + }, |
| 124 | +] |
| 125 | + |
| 126 | +# Validate the data |
| 127 | +validated_data = [ |
| 128 | + UserDataFilterFullLoad( |
| 129 | + workspace_id=item["workspace_id"], |
| 130 | + udf_id=item["udf_id"], |
| 131 | + udf_value=item["udf_value"], |
| 132 | + ) |
| 133 | + for item in raw_data |
| 134 | +] |
| 135 | + |
| 136 | +# Run the provisioning with the validated data |
| 137 | +provisioner.full_load(validated_data) |
| 138 | + |
| 139 | +``` |
0 commit comments