# Arrays

## Overview

Arrays metadata configures how array attributes are handled in code generation, including table creation, relationships, and aliases. Only applicable to semi-structured data sources with array attributes.

***

## Array Configuration Fields

**Include In Code Gen (`INCLUDE_IN_CODE_GEN`)**

* Boolean for including array in SQL code generation
* **Editable** - `TRUE` = Dynamic Table created, `FALSE` = excluded
* Child attributes only generated if parent array is included (`PARENT_INCLUDE_IN_CODE_GEN = TRUE`)

***

**Create Object Name Alias Name (`CREATE_OBJECT_NAME_ALIAS_NAME`)**

* Custom alias for materialized Dynamic Table created for this array
* **Editable** - Overrides default name (typically `{array_name}_array_object`)
* Example: `orders` → default `orders_array_object`, custom `order_items`

**Semantic Layer Alias Name (`SEMANTIC_LAYER_ALIAS_NAME`)**

* Custom alias for array in semantic layer views
* **Editable** - Overrides materialized table name in views

***

**Relationship Name (`RELATIONSHIP_NAME`)**

* Name of relationship for this array
* **Editable** - Used for documentation

**Relationship Description (`RELATIONSHIP_DESCRIPTION`)**

* Description of relationship
* **Editable** - Documents business logic

**Relationship Type (`RELATIONSHIP_TYPE`)**

* Type of relationship between array and parent
* **Editable** - Values: `'many_to_one'` (most common), `'one_to_one'`

**Join Type (`JOIN_TYPE`)**

* Type of join used in relationship
* **Editable** - Values: `'left_outer'` (include all parents), `'inner'` (only parents with array data)

***

**Array Security Row Level Policy Name Semantic Layer (`ARRAY_SECURITY_ROW_LEVEL_POLICY_NAME_SEMANTIC_LAYER`)**

* Name of row-level security policy for array tables in semantic layer views
* **Editable** - Applied to array tables in generated views
* Requires Security Policy Integration product tier

***

## Reference Fields (Read-only)

Shown for reference in Arrays section:

* `ATTRIBUTE_PATH` - Path to array attribute
* `POLYMORPHIC_ATTRIBUTE_NAME` - Version name
* `ARRAY_TYPE` - `'object'`, `'primitive'`, or `'primitive,object'`
* `SOURCE_DATA_TYPE` - Always `'array'` for array attributes
* `PARENT_ARRAY` - Parent array if nested

***

## Array Table Generation

When `INCLUDE_IN_CODE_GEN = TRUE`:

1. **Root Table** - Contains parent record data
2. **Array Table** - Separate Dynamic Table for array contents
   * Named using `CREATE_OBJECT_NAME_ALIAS_NAME` or default
   * Contains all attributes from array elements
   * Includes foreign key columns (configured in Foreign Keys section)
3. **Relationship** - Foreign key relationship links array table to root table
   * Based on `RELATIONSHIP_TYPE` and `JOIN_TYPE`

***

## Array Types

**Object Arrays (`ARRAY_TYPE = 'object'`):**

* Each element is an object with attributes
* Creates separate table with all element attributes
* Supports foreign key relationships
* Configure: `INCLUDE_IN_CODE_GEN = TRUE`, relationship type/join type, foreign keys

**Primitive Arrays (`ARRAY_TYPE = 'primitive'`):**

* Elements are simple values (strings, numbers, booleans)
* May be stored as VARIANT or ARRAY types in root table
* May be flattened into separate table depending on configuration

**Polymorphic Arrays (`ARRAY_TYPE = 'primitive,object'`):**

* Contains both objects and primitives
* Both `array_primitive` and `array_object` versions may be active
* Configure each version separately

***

## Best Practices

**Naming:**

* Use descriptive, business-friendly names for `CREATE_OBJECT_NAME_ALIAS_NAME`
* Use clear relationship names in `RELATIONSHIP_NAME`

**Relationship configuration:**

* Many-to-One: Standard array relationships (most common)
* One-to-One: Optional single-element arrays (less common)
* Left Outer: Include all parents (most common)
* Inner: Only parents with array data

**Performance:**

* Set `INCLUDE_IN_CODE_GEN = FALSE` for unused arrays
* Reduces table count and improves refresh performance
* Large arrays may impact performance; monitor Dynamic Table refresh times

***

## Common Scenarios

**Configuring order items array:**

1. Set `INCLUDE_IN_CODE_GEN = TRUE`
2. Set `CREATE_OBJECT_NAME_ALIAS_NAME = 'order_items'`
3. Set `RELATIONSHIP_NAME = 'Orders to Items'` (optional)
4. Set `RELATIONSHIP_TYPE = 'many_to_one'`
5. Set `JOIN_TYPE = 'left_outer'`
6. Configure foreign keys in Foreign Keys section

**Excluding unused arrays:**

* Set `INCLUDE_IN_CODE_GEN = FALSE`
* Array table won't be generated; reduces schema complexity and improves performance

**Nested arrays:**

* Configure parent array first
* Configure nested array separately
* `PARENT_ARRAY` reference set automatically
* Configure foreign keys for each level

**Array security:**

* Set `ARRAY_SECURITY_ROW_LEVEL_POLICY_NAME_SEMANTIC_LAYER`
* Create policy in Snowflake
* Policy applied to array table in views


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datapancake.com/core-concepts/attribute-metadata/attribute-metadata-details/arrays.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
