# Azure Datalake Gen 2

This data source connector loads a single or multiple CSV files from a filesystem in Azure Datalake Gen2 and stores them in tables 
in Keboola Storage.

After creating a new configuration, select the files you want to extract from Azure Datalake Gen 2 and determine how
you save them to Keboola Storage. 

**Before you start**

You need:

- **The storage account name and an account key** of the Azure storage account, and the name of the file system (container) with your CSV files.
- **Account key access (shared key authorization) allowed** on the storage account. The connector signs in only with the account key, so it fails when **Allow storage account key access** is off.
- **Keboola's IP addresses allowed,** if the storage account's firewall limits access. See IP addresses (/components/ip-addresses/). IP rules have no effect on requests from the same Azure region, so this doesn't work for a storage account in your stack's region (North Europe for the Azure stack).

What each tab needs:

- **Prompt tab:** Kai, the **Kai Agent** button in the top bar, on supported stacks. A new Free Plan project has it from the start; elsewhere an organization admin turns it on once: Get started with Kai (/kai/getting-started/).
- **UI tab:** a browser.
- **CLI / API tab:** kbagent (/cli/getting-started/), connected to your project. The checks only read.

## Configuration
[Create a new configuration](https://help.keboola.com/components/configurations/#create-a-configuration) of the **Azure Datalake Gen 2** connector.

### Authentication 
Fill in the Account name, key and file system you wish to retrieve data from.

![Screenshot - Azure Datalake Gen2 Credentials](https://help.keboola.com/components/extractors/storage/azure-datalake-gen2/auth.png)

## Add Tables
To create a new table, click the **New Table** button and assign it a name.
It will be used to create the destination table name in Storage and can be modified.

![Screenshot - Create table](https://help.keboola.com/components/extractors/storage/azure-datalake-gen2/new_table.png)

Configured tables are stored as [configuration rows](https://help.keboola.com/components/#configuration-rows).
Each table has different settings (key, load type, etc.) but they all share the same credentials.

### Source

![Screenshot - Azure Datalake Gen2 Settings](https://help.keboola.com/components/extractors/storage/azure-datalake-gen2/source.png)

For each table you have to specify the folder in the Azure Datalake Gen2 and a **Search Key**.
The **Search Key** can be a path to a single file or a prefix to multiple files
(omit the wildcard character and use the **Wildcard** checkbox instead).

The **additional source settings** section allows you to set up the following:

 - **New Files Only**: The connector will keep track of the downloaded files and will continue with the unprocessed files
 on the next run. To reset the state which keeps track of the progress and enables to continue with new files, 
 use the **Reset State** button or uncheck the **New Files Only** option and run the connector again. 
 - **Wildcard**: **Search Key** is used as a prefix, and all available files matching the prefix will be downloaded.
 - **Subfolders**: Available only with **Wildcard** turned on. The connector will also process all subfolders.
 

### CSV Settings

![Screenshot - Azure Datalake Gen2 Settings](https://help.keboola.com/components/extractors/storage/azure-datalake-gen2/csv_settings.png)

- **Delimiter** and **Enclosure** specify the CSV format settings.
- **Header** specifies how the destination table column names are obtained:
  - **CSV file(s) contain(s) a header row**: All downloaded files contain a row with the CSV header. The connector obtains 
  the header from a randomly selected downloaded file. 
  - **Set column names manually**: None of the downloaded files does contain a header row and you will use the **Column Names**
  input to specify the headers manually.
  - **Generate column names as col_1, col_2, etc.**: None of the downloaded files contains a header row, and 
  the connector will generate the column names automatically as a sequential number with the `col_` prefix.
                 
### Destination

![Screenshot - Azure Datalake Gen2 Settings](https://help.keboola.com/components/extractors/storage/azure-datalake-gen2/destination.png)

- The initial value in **Storage Table Name** is derived from the configuration table name. You can change it at any time; however,
the [Storage bucket](https://help.keboola.com/storage/buckets/) where the table will be saved cannot be changed.
- **Incremental Load** will turn on [incremental loading to Storage](https://help.keboola.com/storage/tables/incremental-loading/#incremental-loading). The result of the
incremental load depends on other settings (mainly **Primary Key**).
- **Primary Key** can be used to specify the primary key in Storage; it can be used with **Incremental Load**
and **New Files Only** to create a configuration that incrementally loads all new files into a table in Storage.

## Processing Settings

![Screenshot - Azure Datalake Gen2 Settings](https://help.keboola.com/components/extractors/storage/azure-datalake-gen2/processing_settings.png)

 - **Decompress**: All downloaded files will be decompressed (currently supporting ZIP and GZIP). All files in all archives
 will be imported into a single Storage table.
 - **Add Filename Column**: A new column `azure_filename` is added to the table and will contain the original filename 
 including the relative path to the **Search Key**.
 - **Add Row Number Column**: A new column `azure_row_filename` is added to the table and will contain the row number in each 
 of the downloaded files.

Save the table and click **Run Component**.

**Check:**

### Prompt

```text title="Prompt" wrap
Did the latest job of my Azure Data Lake Gen2 configuration succeed, and which tables did it load, with row counts?
```

Kai only reads here, so it asks for no approval, and its answer links to what it found in your project.

### UI

The job ends with status **Success** and Storage has a table with the **Storage Table Name** you set, with
the rows of the matched files.

### CLI / API

```bash
kbagent job list --component-id kds-team.ex-azure-data-lake-gen2 --config-id 123456789 --limit 1
kbagent storage tables --bucket-id in.c-kds-team-ex-azure-data-lake-gen2-123456789
```

Replace `123456789` with your configuration ID: `status` shows whether the job succeeded, and `id` and `rows_count` list the tables it loaded.

---
