Local file datasource
Local file datasource
This model binds three CSV columns to an order key and its properties. No database schema or external model is required.
Download sales.csv and files.preql into the same folder. Complete local setup first.
sale_id,channel,amount
1,store,120.0
2,web,80.0
3,store,50.0
key sale_id int;
property sale_id.channel string;
property sale_id.amount float;
datasource sales (
sale_id: sale_id,
channel: channel,
amount: amount
)
grain (sale_id)
file `./sales.csv`;
select channel, sum(amount) as revenue
order by channel asc;
trilogy run files.preql duckdb
| channel | revenue |
|---|---|
| store | 170 |
| web | 80 |
The bindings before grain map physical column names to logical concepts. The key is unique per sale; selecting channel and sum(amount) groups the rows by channel.
For Parquet, use the same bindings and a file address ending in .parquet. For a URL, the executing database must be able to reach it. See file datasource syntax.