> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Assignment Tables

> Assignment tables have records of what entities have been assigned what configuration.

When using a feature flag, variants are assigned to entities.
Each such assignment is typically recorded somewhere in a data warehouse.
Assignment tables in Confidence point to a table in your data warehouse that
stores the assignments.
Confidence provides this table if you're using Confidence Flags.
If you're not using Confidence Flags, your internal or third-party feature flagging service provides
the table.
The only requirement for an assignment table in Confidence is that the underlying table has
columns with information about when assignments happened, for whom, and where the assignment came
from.

## Structure

The assignment table in Confidence Flags has the following columns:

| Column                      | Type      | Description                                                                                 |
| --------------------------- | --------- | ------------------------------------------------------------------------------------------- |
| `assignment_time`           | Timestamp | When the assignment was applied.                                                            |
| `resolve_id`                | String    | Unique identifier for the resolve request.                                                  |
| `targeting_key`             | String    | The identifier of the entity that was assigned.                                             |
| `targeting_key_selector`    | String    | The type of entity targeted (for example, `user_id`).                                       |
| `flag`                      | String    | The flag that was resolved.                                                                 |
| `rule`                      | String    | The rule that matched. Null for fall-through assignments.                                   |
| `variant`                   | String    | The variant assigned. Only set for regular assignments, not fall-through.                   |
| `assignment_id`             | String    | Identifier for the treatment group. Used as the variant key when configuring an experiment. |
| `client`                    | String    | The identifier for the client.                                                              |
| `client_credential`         | String    | The identifier for the client credential.                                                   |
| `segment`                   | String    | The segment that matched. Only set for regular assignments.                                 |
| `default_assignment_reason` | String    | Reason for the default assignment (for example, flag archived or no matching rule).         |

Here is an example of what the data in an assignment table looks like:

| `assignment_time`   | `resolve_id` | `targeting_key` | `targeting_key_selector` | `flag`           | `rule`                      | `variant`                          | `assignment_id` | `client`        | `client_credential`                          | `segment`         | `default_assignment_reason` |
| ------------------- | ------------ | --------------- | ------------------------ | ---------------- | --------------------------- | ---------------------------------- | --------------- | --------------- | -------------------------------------------- | ----------------- | --------------------------- |
| 2023-05-20 00:04:25 | abc-123      | user5125        | user\_id                 | flags/test-flag  | flags/test-flag/rules/rule1 | flags/test-flag/variants/control   | control         | clients/web-app | clients/web-app/clientCredentials/prod-key   | segments/us-users |                             |
| 2023-05-20 05:01:21 | def-456      | user7231        | user\_id                 | flags/test-flag  | flags/test-flag/rules/rule1 | flags/test-flag/variants/treatment | treatment       | clients/web-app | clients/web-app/clientCredentials/prod-key   | segments/us-users |                             |
| 2023-05-21 10:22:01 | jkl-012      | user8844        | user\_id                 | flags/other-flag |                             |                                    |                 | clients/ios-app | clients/ios-app/clientCredentials/mobile-key |                   | FLAG\_ARCHIVED              |

<Note>
  A single resolve request can produce multiple rows. Each applied flag produces one row,
  and each fall-through assignment on that flag produces an additional row.
</Note>

When configuring an assignment table, you need to specify the columns that map to the following:

* A **timestamp** column that records the time of the assignment. The `assignment_time` column.
* One or more **entity** columns that hold the identifier of the entity the assignment happened for. The `targeting_key` column.
* An **exposure key** column to use to filter out the assignments that belong to the
  experiment. The `rule` column. You could also use the `flag` column if there is a 1-1 mapping of an experiment to a flag. Confidence
  represents an experiment as a [rule](/docs/how-to-guides/create-conditional-targeting-rule) on the flag.
* A **variant key** column that identifies a specific variant. The `assignment_id` column. Use the `assignment_id` column and not the `variant` column as Confidence supports fall-through variants that allow multiple variants to be part of the same assignment.

## Configuration

### SQL Query

You need to input the SQL that selects your assignment rows. After you've
entered your SQL you can click **Run Query**. Confidence then executes your
query with a limit to check that everything is in order and show you some
sample rows.

You should write resource efficient queries. The result frequency of your experiment
determines how often the queries run. For example, an experiment with hourly calculations runs the
assignment table query once an hour.
Here is a checklist of things to consider when writing the query for your assignment data:

* ✅ Always have an index (also called [Time partitioning](https://cloud.google.com/bigquery/docs/partitioned-tables#date_timestamp_partitioned_tables) in BigQuery) on the timestamp
  column to ensure that Confidence only queries the data within a partition, without
  this each query may require a full table scan.
* ✅ If you can, also set up an index on the entity columns (also called [Clustered Table](https://cloud.google.com/bigquery/docs/clustered-tables) in BigQuery),
  this helps improve the performance of the join that Confidence does between your exposures
  and facts.
* ✅ If you can, perform heavy transformations in an upstream step and store the result in an
  intermediate table to avoid potentially redoing the transformations.

<Note>
  You have some placeholders at your disposal if you need to specify what
  partition you're querying: `{START_TIME}` and `{END_TIME}`. These two
  parameters vary depending on the requirements of the metric that uses
  the assignment table. You don't need
  to use them as Confidence always filters on your timestamp column, but
  sometimes your table format includes the date. These placeholders have the
  same Timestamp type as the timestamp column in your data warehouse.
</Note>

### Data Delivery Cadence

For configuring data delivery cadence, see the
[data delivery cadence](/docs/metrics/delivery-cadence) page.

### Timestamp Column

The timestamp column is the column that identifies the time that the assignment
occurred. This column can either be a timestamp with a specific time point for
the assignment, or you can select a date column. Selecting a date column
means that any exposure calculation that includes the end of this day should include
this assignment. It's the same as specifying a time for the date that is at 23:59:59.

### Entities

You need to specify the entity that this assignment is for. This has to be the
same identifier that you use for the facts.

### Exposure Key and Variant Key Columns

The exposure and variant keys must, at a given time, uniquely identify a single treatment group.

<Tabs>
  <Tab title="Confidence Flags">
    When using Confidence Flags:

    * **exposure key** is the name of the rule
    * the **variant key** is the `assignment_id`
  </Tab>

  <Tab title="External Feature Flagging">
    If you use an external feature flagging system, then often:

    * **exposure key** is the name of the flag
    * **variant key** is the name of the variant the flag returns (for example, true/false)
  </Tab>
</Tabs>

## Related Resources

<CardGroup cols={2}>
  <Card title="Create Assignment Tables" href="/docs/how-to-guides/create-assignment-table">
    Step-by-step assignment table guide
  </Card>

  <Card title="Exposure Reference" href="/docs/metrics/exposure">
    Configure exposure calculations
  </Card>

  <Card title="Analyze Past Experiments" href="/docs/quickstarts/analyze-past-experiment">
    Use assignment data for analysis
  </Card>

  <Card title="Entities Reference" href="/docs/metrics/entities">
    Configure experiment entities
  </Card>
</CardGroup>
