Skip to content

Commit db45887

Browse files
jackye1995claude
andauthored
feat: support custom header for rest namespace (#128)
* feat: support custom header for rest namespace * style: fix code formatting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 78c48f4 commit db45887

File tree

8 files changed

+427
-113
lines changed

8 files changed

+427
-113
lines changed

docs/rest.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Connecting to a Lance REST Namespace
2+
3+
This guide explains how to connect DuckDB to a Lance REST Namespace server (e.g. LanceDB Cloud or Enterprise) using the lance-duckdb extension.
4+
5+
## Overview
6+
7+
A Lance REST Namespace provides a centralized catalog for managing Lance tables. The REST Namespace API allows:
8+
9+
- Listing tables in a namespace
10+
- Creating and dropping tables
11+
- Describing tables (getting location and storage credentials)
12+
- Credential vending for accessing underlying storage (S3, GCS, Azure, etc.)
13+
14+
## Prerequisites
15+
16+
1. A Lance REST Namespace server endpoint available
17+
2. The lance-duckdb extension built and available
18+
3. Authentication credentials (API key, bearer token, etc.)
19+
20+
## ATTACH Syntax
21+
22+
```sql
23+
ATTACH '<namespace_id>' AS <alias> (
24+
TYPE LANCE,
25+
ENDPOINT '<server_url>',
26+
HEADER '<header1>=<value1>;<header2>=<value2>'
27+
);
28+
```
29+
30+
### Parameters
31+
32+
| Parameter | Description | Required |
33+
|-----------|-------------|----------|
34+
| `<namespace_id>` | The namespace identifier to connect to | Yes |
35+
| `<alias>` | Local alias for the attached database | Yes |
36+
| `ENDPOINT` | URL of the REST Namespace server | Yes |
37+
| `HEADER` | Custom HTTP headers (semicolon-separated key=value pairs) | No |
38+
| `DELIMITER` | Namespace delimiter (default: `$`) | No |
39+
| `BEARER_TOKEN` | Bearer token for authentication | No |
40+
| `API_KEY` | API key for authentication | No |
41+
42+
### Custom Headers
43+
44+
The `HEADER` option allows passing custom HTTP headers to the REST Namespace server. Multiple headers can be specified using semicolon separation:
45+
46+
```sql
47+
HEADER 'x-lancedb-database=my_db;x-api-key=sk_xxx;x-custom-header=value'
48+
```
49+
50+
## Example: Connecting to a REST Namespace Server
51+
52+
### 1. Connect from DuckDB
53+
54+
```sql
55+
-- Load the Lance extension
56+
LOAD 'lance.duckdb_extension';
57+
58+
-- Attach to the REST Namespace
59+
ATTACH 'ns1' AS lance_ns (
60+
TYPE LANCE,
61+
ENDPOINT 'http://localhost:10024',
62+
HEADER 'x-lancedb-database=lance_ns;x-api-key=sk_localtest'
63+
);
64+
65+
-- Switch to the attached database
66+
USE lance_ns;
67+
```
68+
69+
### 2. List Tables
70+
71+
```sql
72+
SHOW TABLES;
73+
```
74+
75+
Output:
76+
```
77+
┌─────────┐
78+
│ name │
79+
│ varchar │
80+
├─────────┤
81+
│ 0 rows │
82+
└─────────┘
83+
```
84+
85+
### 3. Create a Table
86+
87+
```sql
88+
CREATE TABLE users (
89+
id INTEGER,
90+
name VARCHAR,
91+
email VARCHAR
92+
);
93+
```
94+
95+
### 4. Insert Data
96+
97+
```sql
98+
INSERT INTO users VALUES
99+
(1, 'Alice', 'alice@example.com'),
100+
(2, 'Bob', 'bob@example.com'),
101+
(3, 'Charlie', 'charlie@example.com');
102+
```
103+
104+
### 5. Query Data
105+
106+
```sql
107+
-- Select all rows
108+
SELECT * FROM users;
109+
```
110+
111+
Output:
112+
```
113+
┌───────┬─────────┬─────────────────────┐
114+
│ id │ name │ email │
115+
│ int32 │ varchar │ varchar │
116+
├───────┼─────────┼─────────────────────┤
117+
│ 1 │ Alice │ alice@example.com │
118+
│ 2 │ Bob │ bob@example.com │
119+
│ 3 │ Charlie │ charlie@example.com │
120+
└───────┴─────────┴─────────────────────┘
121+
```
122+
123+
```sql
124+
-- Select with filter
125+
SELECT * FROM users WHERE id > 1;
126+
```
127+
128+
Output:
129+
```
130+
┌───────┬─────────┬─────────────────────┐
131+
│ id │ name │ email │
132+
│ int32 │ varchar │ varchar │
133+
├───────┼─────────┼─────────────────────┤
134+
│ 2 │ Bob │ bob@example.com │
135+
│ 3 │ Charlie │ charlie@example.com │
136+
└───────┴─────────┴─────────────────────┘
137+
```
138+
139+
```sql
140+
-- Aggregation
141+
SELECT COUNT(*) as total_users FROM users;
142+
```
143+
144+
Output:
145+
```
146+
┌─────────────┐
147+
│ total_users │
148+
│ int64 │
149+
├─────────────┤
150+
│ 3 │
151+
└─────────────┘
152+
```
153+
154+
### 6. Using Fully Qualified Names
155+
156+
You can also use fully qualified table names without switching databases:
157+
158+
```sql
159+
-- Create table with fully qualified name
160+
CREATE TABLE lance_ns.main.my_table (col1 INTEGER, col2 VARCHAR);
161+
162+
-- Query with fully qualified name
163+
SELECT * FROM lance_ns.main.my_table;
164+
```

0 commit comments

Comments
 (0)