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

# File datasets

> How Reporter reads files that your systems deliver each day: file sources, file datasets, days, and how a report reads them as tables.

> [!WARNING]
>
> This capability is under development. It is available in homologation on Lerian Cloud, and its behavior can change before release. Confirm availability with Lerian before integration.

Some of your data does not sit in a database that Reporter can query. A core system, a partner, or a back office can drop files in a bucket or on a file server instead. A **file dataset** lets Reporter read those files as tables, check them against a contract you write, and keep every accepted delivery. A **file source** is the place where the files arrive.

A template reads a file dataset by its name, the same way it reads a database data source. Reporter checks each delivery before any report uses it.

This page is for the engineer who connects the delivery and the operator who watches it. To write the contract, read [File dataset contract](https://docs.lerian.studio/en/products/reporter/file-dataset-contract.md). To work in the Console, read [Manage file sources and file datasets](https://docs.lerian.studio/en/products/reporter/console/managing-file-datasets.md).

## File sources

***

A file source is one of three kinds: `s3`, `sftp`, or `ftp`. The kind never changes. To change it, create a new source. The name has 1 to 255 characters and is unique among your file sources.

Reporter encrypts the credential of a source and never shows it again. An edit that omits the secret keeps the stored one, and a blank secret is refused. An edit to any SFTP or FTP field, or to the bucket, endpoint, or access key ID of an S3 source that holds an access key, must carry the secret again. Reporter refuses a secret for an S3 source that holds no access key, such as an AWS bucket that you read through a role. You cannot delete a source that a file dataset still uses.

You can test a saved source at any time. The test opens the source, lists the root folder, and closes. It stops after 5 seconds. A failed test returns the status `failed` and one message:

| Message | Meaning |
| - | - |
| `authentication failed` | The source refused the credential, Reporter did not trust the key of the SFTP server, or the S3 role lacks a permission. |
| `timeout` | The source did not answer in time. |
| `host unreachable` | Reporter could not reach the host. |
| `connection failed` | The connection broke for another reason. |
| `host blocked` | The [network rule](#network-access) refused the host. |
| `source misconfigured` | Reporter cannot open the source as you saved it. |

### S3

An S3 source needs a bucket and a region. The endpoint is optional. An empty endpoint, or an endpoint on `amazonaws.com`, means AWS, and it must use `https`. For storage outside AWS, enter an access key ID and its secret key. You can also turn on path-style addressing.

Reporter reads an AWS bucket through a role. It always refuses a static access key for an AWS bucket. To connect one, follow these steps:

**1. Create the source**

Create the source with the bucket and the region. Reporter refuses a role at this point.

**2. Copy two values**

Reporter returns a trusted principal and an external ID. The trusted principal is the AWS role that Reporter runs as. Reporter generates the external ID.

**3. Update your role**

Add the trusted principal to the trust policy of your role. Make the policy require the external ID. Allow the role to list the bucket and read its objects.

**4. Add the role**

Edit the source and enter the role ARN.

Before it saves the role, Reporter tests it. It must fail to assume the role without the external ID, and with a random one. It must succeed with the external ID of the source. A role that fails the test is refused.

An AWS source with no role cannot serve a dataset or a fetch. If the role cannot list the bucket, AWS answers a missing object as an access error. A missing manifest then shows as `authentication failed`. On a deployment that you run yourself, the manager and the worker must run as the same AWS role.

### SFTP

An SFTP source needs a host, a port, a user, an authentication method, and the known hosts of the server. All five are required.

* The authentication method is `password` or `privateKey`. A private key can have a passphrase.
* The known hosts are the public keys of the server, one per line, up to 64 KiB. Each line is a `known_hosts` line or a bare public key. Reporter skips blank lines and lines that start with `#`.
* A key marked `@revoked` is always refused. Any other marker, such as `@cert-authority`, makes the source misconfigured.

Reporter refuses a server whose key is not in the list. That shows `authentication failed`. A list that does not parse shows `source misconfigured`.

### FTP

An FTP source needs a host, a port, a user, a password, and a TLS mode: `none` (plain FTP), `explicit` (upgrades the connection with AUTH TLS), or `implicit` (opens it in TLS). TLS is at least version 1.2. If a public authority did not sign the server certificate, paste the authority certificate in PEM format.

Lerian Cloud and any multi-tenant installation refuse `none`. Use FTP with TLS or SFTP.

## Datasets and schedule

***

A file dataset has a name, a file source, a contract, and a schedule.

The name is the `configName`: 1 to 100 letters, digits, underscores, or hyphens. It is unique among all your data sources and never changes. Templates and regulatory mappings read the dataset by this name. You cannot use `system` or a name that the platform reserves.

You send the contract as the whole text of the contract file. Reporter stores it, byte for byte, as version 1. After that, you change it only by adding a version. Read [Contract versions](https://docs.lerian.studio/en/products/reporter/file-dataset-contract.md#versions). A dataset on an SFTP or FTP source needs a contract with a manifest. Read [Manifest](https://docs.lerian.studio/en/products/reporter/file-dataset-contract.md#manifest).

| Schedule field | What it sets |
| - | - |
| `timezone` | An IANA time zone name, such as `America/Sao_Paulo`. |
| `days` | `business` or `all`. |
| `dueTime` | The cutoff hour, as `HH:MM`, in the time zone of the schedule. |
| `dueOffsetDays` | How many days after the reference date a day is due, from 0 to 366. |
| `startDate` | The first reference date that the dataset expects, as `yyyy-MM-dd`. |
| `reopenWindowDays` | How many days back from today Reporter keeps checking an accepted day for a newer delivery, from 0 to 90. |

The **reference date** of a day is the date the data is about, not the date the file arrives. The start date cannot be more than five calendar years before the day you register the dataset.

Business days follow the Brazilian national calendar: Monday to Friday, minus the national holidays. The holidays include Carnival Monday and Tuesday, Good Friday, and Corpus Christi. Reporter knows no local holiday. The due offset counts business days when `days` is `business`, and calendar days when it is `all`.

### What locks

After Reporter accepts a day, or an operator declares a day without delivery, `days` and `startDate` can no longer change. The time zone, due time, offset, and reopen window stay editable.

After Reporter accepts a delivery, a new contract version can only add. You cannot delete a table or a column. You cannot change the type of a column, or add or drop the offset (`XXX`) of a datetime format. A declaration without delivery does not set this rule.

If you delete a dataset, Reporter keeps its days, files, and contract versions. Reporter refuses the deletion while a template or an active regulatory mapping reads the dataset.

## Days

***

A day is one expected delivery. Reporter adds a record for every day the schedule expects, from the start date to today.

A day has one of four states:

| State | Meaning |
| - | - |
| `waiting` | No delivery is accepted. The last attempt found the day incomplete, or there was none. |
| `accepted` | At least one delivery is accepted, and the last one is current. |
| `refused` | No delivery is accepted. An attempt refused the day. A later attempt that fails keeps the day `refused`. |
| `failed` | No delivery is accepted, no refusal stands, and the last attempt failed. |

An accepted day stays accepted when a later attempt does not succeed. Two marks add to the state. **Overdue** means the due time passed and no delivery is accepted. A day due before you registered the dataset is never overdue. **No delivery** means an operator declared that the sender delivered nothing.

A day keeps its revisions and its last attempt. A revision records the contract version, the files with their SHA-256, and the warnings. An attempt records the trigger (`schedule` or `manual`), the outcome, and the findings. A failed attempt also records one error word, such as `connect failed` or `host blocked`.

### The scheduled fetch

By default, every 300 seconds, Reporter adds the expected days and picks the days to fetch:

1. A day with no accepted delivery, and whose last attempt did not fail, is fetched every cycle, before and after its due time, until seven days after it. Then it is fetched at most once an hour.
2. A day whose last attempt failed is fetched at most once an hour.
3. An accepted day is checked at most once an hour, while its reference date is inside the reopen window.
4. A day declared without delivery is checked at most once an hour for a late delivery.

A fetch ends in one of these outcomes:

* **Accepted:** the day passes every check. Reporter stores the files as a new revision.
* **Unchanged:** the source holds the same files as the current revision. With no manifest in the contract, a fetch also ends unchanged when the source lists none of the files of a day that has a revision. Reporter stores nothing.
* **Incomplete:** With a manifest in the contract: the source has no manifest yet, the manifest is empty or cut short, or it lists no file of the contract. With no manifest in the contract: the source lacks a required file on a day that has no revision. A day with no accepted delivery stays `waiting`.
* **Refused:** a check found a problem. Reporter stores none of the files. The day shows each finding with its check, its table, and up to ten row numbers. A finding of a `total` control shows the totals that it compared.
* **Failed:** Reporter could not read the source.

The scheduler stops fetching a day 90 days after the later of its due time and the registration of the dataset. This covers a day with no accepted delivery and a day declared without delivery. The day keeps its state and its overdue mark. After that, only a fetch that an operator requests reads it.

### A fetch that an operator requests

An operator can request a fetch of any day that the schedule expects, in the past or the future. Reporter answers at once and runs the fetch in the background. It refuses the request when a fetch of the same day is still open, when you already hold the maximum number of open fetches (5 by default), or when the file source is incomplete, such as an AWS source with no role yet.

A requested fetch always compares the source with the current revision. If a newer contract version exists, it reads the day again and can store a new revision. A new contract version does not fetch accepted days again. It applies to new deliveries and to requested fetches.

### Declare no delivery

Sometimes the sender delivers nothing for a day, and nothing is wrong. An operator can declare this for a day that is `waiting` or `failed`, or that has no record yet. The day becomes `accepted` with the **No delivery** mark, and it reads as zero rows. Reporter records who declared it and when. The call needs a token that names who acts. Reporter refuses it for a day with an accepted or a refused delivery.

> [!WARNING]
>
> Do not declare no delivery unless you are sure. Nothing undoes the declaration. It also locks `days` and `startDate`.

### A later delivery

Reporter never refuses a delivery for being late. If a delivery differs from the current revision, it becomes a new revision, and later reports read it.

Outside the reopen window, Reporter sees a newer delivery of an accepted day only when an operator requests a fetch. Reporter checks a day declared without delivery at most once an hour, inside and outside the reopen window, until the scheduler stops fetching the day. A delivery that arrives in that time replaces the declaration. Reporter marks every report that read an older revision as revised. The report keeps showing the revision it read. Nothing brings an earlier revision back.

A new delivery must hold a file for every table of the current revision. Otherwise, Reporter refuses it and keeps the current revision.

## Reading days in a report

***

A template names a table as `<configName>.<table>`, the same way it names a database table. Every table has the contract columns and one more: `reference_date`, the day each row came from, as `yyyy-MM-dd`.

Each table chooses its days with a filter on `reference_date`. These operators work: `eq` for one day, `in` for a list, `between` for a range, and `gte` with `lt` for the days from `gte` up to the day before `lt`. Any other operator is refused when you save the report filter, and again at generation. A selection covers up to 366 days. A table with no filter reads the newest accepted day that is not a no-delivery day.

A report ends in `Error`, never `Partial`, when one of these happens:

* A table with no filter has no accepted day to read.
* A day in the selection has no accepted delivery and the schedule expects it. A future day counts.
* The selection starts before the start date of the dataset.
* The contract in use requires a table, and the accepted day has no file for it.
* The contract in use requires a column that the version which accepted the day did not require.
* A read uses `expand`, or a join does not pair `reference_date`.

For a missing day, the message names the dataset and the day. It tells you to have the sender deliver the day and request its fetch, or to narrow the period of the report. For a missing table or column, it also offers to mark it optional in a new contract version.

A day the schedule does not expect is read only if it has an accepted delivery. A no-delivery day reads zero rows. An optional table that a day lacks reads zero rows, and an optional column reads null. A report reads each day with the contract version that accepted it, and a join matches rows inside the same day.

A report lists every day it read, with the revision and the contract version. It also lists the days revised after the read. The mapping preview of a regulatory document follows the same rules. A filing draft that read a day revised later shows the **Revised** mark. You can still approve it.

## Events

***

Reporter emits four events about days. Every payload holds `datasetId`, `configName`, and `referenceDate`.

| Event | When it leaves |
| - | - |
| `dataset_day.accepted` | A fetch stores a new revision, or an operator declares no delivery. |
| `dataset_day.refused` | A day is refused. The payload lists the findings. |
| `dataset_day.fetch_failed` | Reporter cannot read the source. It does not repeat while the error word stays the same. |
| `dataset_day.overdue` | An expected day passes its due time with no accepted delivery. It leaves once for each day. |

Reporter emits no event when you change a source, a dataset, or a contract version. Events leave only when streaming is on. To learn how Reporter publishes events, read [Reporter events](https://docs.lerian.studio/en/products/reporter/reporter-events.md).

## Settings in your own cloud

***

If you run Reporter in your own cloud, you can change these environment variables. Each limit must be greater than zero, or Reporter does not start.

| Variable | Used by | Default | What it governs |
| - | - | - | - |
| `DATASET_SCHEDULER_INTERVAL_SEC` | Manager | `300` | Seconds between scheduler cycles. |
| `DATASET_FETCH_MAX_OPEN` | Manager | `5` | Open fetches for one client, scheduled and requested together. |
| `DATASET_READ_MAX_DAYS` | Manager and worker | `366` | Days that one table read can cover. Use the same value in both. |
| `AWS_ROLE_ARN` | Manager | empty | The role that your S3 role trusts. Set the full ARN when the role has an IAM path. |
| `DATASET_FETCH_TIMEOUT_SEC` | Worker | `120` | Each fetch stage, and the longest wait for the fetch slot. |
| `DATASET_FETCH_MAX_DAY_BYTES` | Worker | `268435456` | Bytes of all files of one day (256 MiB). |
| `DATASET_FETCH_MAX_FILE_ROWS` | Worker | `1000000` | Rows of one file. |
| `MULTI_TENANT_ENABLED` | Manager and worker | `false` | Turns on the network rule and the plain FTP refusal. |
| `DATASOURCE_CRED_ENC_KEY` | Manager and worker | none | Encrypts file source credentials. It is required. |
| `STREAMING_ENABLED` | Manager and worker | `false` | Publishes the four day events. |

A worker runs one fetch at a time. It copies the files of the day to its temporary directory, which must hold `DATASET_FETCH_MAX_DAY_BYTES`.

## Network access

***

On Lerian Cloud, Reporter connects to your SFTP or FTP server from three fixed addresses:

* `15.229.219.15`
* `18.228.56.71`
* `56.124.7.242`

If you restrict your server by source address, allow these three. The same three serve homologation and production.

Lerian Cloud, and any multi-tenant installation in your own cloud, applies a network rule to every file source. A source cannot point to a private or internal address. The rule refuses loopback, private, link-local, and reserved ranges. It also refuses `100.64.0.0/10`, the name `localhost`, cloud metadata names, and any name that ends in `.local`, `.internal`, or `.cluster.local`.

Reporter makes no exception for a private address. The connection test and a fetch show `host blocked`. A connection that does not complete in 30 seconds fails. On Lerian Cloud, the server needs a public address. In your own cloud, run Reporter single-tenant to read a server on a private address.

## Next steps

***

> [card] [File dataset contract](https://docs.lerian.studio/en/products/reporter/file-dataset-contract.md)
>
> Write the contract: files, columns, formats, manifest, controls, and checks.

> [card] [Manage file datasets in the Console](https://docs.lerian.studio/en/products/reporter/console/managing-file-datasets.md)
>
> Add a file source, create a dataset, and work with days.

> [card] [How report generation works](https://docs.lerian.studio/en/products/reporter/how-report-generation-works.md)
>
> The path a report takes, from request to download.

> [card] [Environment variables](https://docs.lerian.studio/en/products/reporter/reporter-environment-variables.md)
>
> The other Reporter settings.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.