# Sources

A source is a reference to raw tables from database that you can use in your models.&#x20;

<figure><img src="/files/dcaGka1Zz0wR7dneorx4" alt=""><figcaption></figcaption></figure>

In traditional SQL transformation, raw tables are typically referenced directly by their names. This leads to a few challenges, such as code readability and dependency management between tables. In contrast, sources introduce a more structured and modular way to reference raw tables, providing several benefits:

* **Clear data lineage**: Sources help you explicitly identify raw tables as external data sources. This helps establish clear data lineage, making it easier to trace data from raw tables to the transformed models.
* **Data testing**: Declaring raw tables as sources allows you to implement data tests. You can validate assumptions about the data quality, ensuring transformations applied later are based on trusted data.
* **Improved communication**: In source metadata, you can add descriptions, owners, and other information to clearly express your use cases. This creates transparency and improves communication across teams.

## Create a source

To create a source, follow these steps:

1. In the **Models** tab, click on the **+** icon and select **Add source**.&#x20;
2. In the opened modal:
   1. Select the connection type. Currently, ReOrc supports referencing from a warehouse.
   2. Select the target connection. If you haven't set up the project connection, refer to: [Project connections](/connections/project-connections.md).
3. Click **Next**. ReOrc then displays all the tables available from the target connection.

<figure><img src="/files/0POYEIKmvIEKp2MByjLW" alt=""><figcaption><p>Select tables from a connection</p></figcaption></figure>

4. Select the desired raw tables or models.
5. Click **Add source**.

The selected tables will then be added to the **sources** folder and grouped by connection name.

<figure><img src="/files/pOjnzJPMRA7gBGjMpiC3" alt=""><figcaption></figcaption></figure>

You can view the schema of a source by opening it in the editor. A schema contains field name (or column name), data type, and comment.&#x20;

## Select from a source

With raw tables organized by sources, you can reference them in a model using the `{{ source() }}` Jinja function. For more details, see: [Models](/data-modeling/models.md).

The function requires two arguments:

* `source_name`: the folder name that contains the source.
* `table_name`: the name of the table.

For example, with the `raw_orders` table added under the `jaffle_shop` folder, we can reference it as follows:

```sql
select 
    id as order_id,
    customer as customer_id,
    ordered_at as order_date

from {{ source("jaffle_shop", "raw_orders") }}
```

The above model is then compiled to:

```sql
SELECT
  id AS order_id,
  customer AS customer_id,
  ordered_at AS order_date
FROM
  `jaffle_shop`.`raw_orders`
```


---

# 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.reorc.com/data-modeling/sources.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.
