Skip to content

Commit 1954616

Browse files
Jeadiey-f-ulukekim
authored
Add DuckDB functions to data-connector docs (#291)
* Add DuckDB functions to data-connector docs * Update spiceaidocs/docs/data-connectors/duckdb.md Co-authored-by: Luke Kim <80174+lukekim@users.noreply.github.com> * Improve clarity --------- Co-authored-by: yfu <fevin86@gmail.com> Co-authored-by: Luke Kim <80174+lukekim@users.noreply.github.com>
1 parent 14df3e8 commit 1954616

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

spiceaidocs/docs/data-connectors/duckdb.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "DuckDB Data Connector"
3-
sidebar_label: "DuckDB Data Connector"
4-
description: "DuckDB Data Connector Documentation"
2+
title: 'DuckDB Data Connector'
3+
sidebar_label: 'DuckDB Data Connector'
4+
description: 'DuckDB Data Connector Documentation'
55
---
66

77
## Dataset Source
@@ -41,3 +41,43 @@ datasets:
4141
params:
4242
open: /my/path/my_database.db
4343
```
44+
45+
## DuckDB Functions
46+
47+
Common [data import](https://duckdb.org/docs/data/overview) DuckDB functions can also define datasets. Instead of a fixed table reference (e.g. `database.schema.table`), a DuckDB function is provided in the `from:` key. For example
48+
49+
```yaml
50+
datasets:
51+
- from: duckdb:database.schema.table
52+
name: my_dataset
53+
params:
54+
open: path/to/duckdb_file.duckdb
55+
56+
- from: duckdb:read_csv('test.csv', header = false)
57+
name: from_function
58+
params:
59+
open: path/to/duckdb_function_file.duckdb
60+
```
61+
62+
Datasets created from DuckDB functions are similar to a standard `SELECT` query. For example:
63+
64+
```yaml
65+
datasets:
66+
- from: read_csv('test.csv', header = false)
67+
```
68+
69+
is equivalent to:
70+
71+
```sql
72+
-- from_function
73+
SELECT * FROM read_csv('test.csv', header = false)
74+
```
75+
76+
Many DuckDB data imports can be rewritten as DuckDB functions, making them usable as Spice datasets. For example:
77+
78+
```sql
79+
SELECT * FROM 'todos.json';
80+
81+
-- As a DuckDB function
82+
SELECT * FROM read_json('todos.json');
83+
```

0 commit comments

Comments
 (0)