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

# Quickstart with clickhouse

export const productName = "Atoti FRTB";

The reference ClickHouse database can be used to get started using DirectQuery quickly. Here we will go over how to get started using DirectQuery against the included reference ClickHouse database in a local environment.

This section will go over how to start the ClickHouse Database locally as well as the configurations needed to connect to the Database.

For an overview of DirectQuery, please see the [DirectQuery Overview](../../../getting-started/directquery) section in the User Guide.

## Reference ClickHouse Implementation Overview

{productName} comes with a reference ClickHouse Database packaged within a Docker Container that can be run locally by using Docker.

### File Structure

The following files can be found within the `frtb-directquery` module under `src/test/resources/database/clickhouse/`:

* clickhouse\_docker\_container/
  * input\_data
  * run\_scripts
  * Dockerfile
  * init-db.sh

#### clickhouse\_docker\_container

This directory contains the entire ClickHouse Docker database along with everything needed to get the ClickHouse database up and running.

#### run\_scripts

Scripts that can be used to build, run and stop the Docker Container. This includes scripts that can be run on Windows or Linux machines. Alternatively you can run the Docker commands directly as outlined in the [Running the Project](#running-the-project) section.

#### input\_data

{productName}'s reference data has been converted into a format that can be loaded directly into ClickHouse. This dataset contains all data for the Tables that DirectQuery requires.

#### Dockerfile

This file is where the Docker Image runs. As a prerequisite, you must have Docker running locally (you can use [Docker Desktop](https://www.docker.com/products/docker-desktop/)). This file performs the following actions:

* Create an empty ClickHouse database in the Docker Container
* Copy the database initialization script init-bd.sh into the Docker Container
* Create and copy the input CSV files from input\_data/ into the Docker Container

The Dockerfile contains some additional documentation on how to start and stop the Docker Container.

#### init-db.sh

This file contains the DDL of the Database. It creates all the Tables required by DirectQuery.

This file creates a Database named `FRTB` as well as a Database Schema named `FRTB`.

## Running the project

To run {productName} connected to the reference ClickHouse implementation will need to:

1. Build the ClickHouse Docker Container
2. Start the ClickHouse Docker Container
3. Start the {productName} Project with DirectQuery enabled and configured for ClickHouse.

### 1. Build Docker Image

First you will need to build the Docker Image either through the command line, or by running the `1_build` script.

#### Script

Script can be run by double-clicking or through the command line:

```shell theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
./1_build.sh
```

#### Command Line

You can build the Docker Image by running the following command from within the `clickhouse_docker_container` folder:

```shell theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
docker build -t frtb-clickhouse-image .
```

This builds your Docker Image with the name `frtb-clickhouse-image`.

### 2. Start ClickHouse Database

Now you can run the ClickHouse Database either through the command line or by running the `2_run` script. You can verify the database is up by going to the URL 'localhost:8123/play'.

#### Script

Script can be run by double-clicking or through the command line:

```shell theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
./2_run.sh
```

#### Command Line

You can start the Docker Container, for your built Docker Image, by running the following command from within the `clickhouse_docker_container` folder:

```shell theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
docker run --rm --name frtb-clickhouse-container --ulimit nofile=262144:262144  -p 8123:8123 frtb-clickhouse-image
```

This runs your Docker Image `frtb-clickhouse-image` in a Docker Container named `frtb-clickhouse-container` on port `8123`.

### 3. Start {productName} with ClickHouse enabled

You are now ready to start the {productName} with DirectQuery enabled and configured for ClickHouse.

#### Property Configuration

Some properties will need to be configured when starting {productName}.

##### application.yaml

Use the following properties in the `application.yaml` file to connect to the ClickHouse Database:

```yaml theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
# Select direct-query deployment type
starter:
  deployment:
    type: direct-query

# All following IMA features are disabled:
ima.drc.disable: true
ima.plat-backtesting.disable: true
ima.stress-calibration.disable: true

# ClickHouse Database Connection Parameters
directquery:
  dates-filter:
    # Load all dates
    dates-to-exclude:
  database:
    type: clickhouse
    clickhouse:
      username:
      password:
      port: 8123
      hostName: localhost
      database: frtb
      schema: frtb

# DLC is needed to load configuration data:
dlc:
  enabled: true
```

### 4. Shutdown ClickHouse Database

When we are finished with the ClickHouse Database, we can shut down the Docker Container either through the command line or by running the `3_kill` script.

#### Script

Script can be run by double-clicking or through the command line:

```shell theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
./3_kill.sh
```

#### Command Line

You can stop the Docker Container by running the following command:

```shell theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
docker stop frtb-clickhouse-container
```

This stops your Docker Container `frtb-clickhouse-container` and frees the port `8123`.
