-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.sql
More file actions
31 lines (25 loc) · 1.22 KB
/
Copy pathquery.sql
File metadata and controls
31 lines (25 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- Query the hello-world service from SQL through the adbc_scanner extension.
--
-- export GRAINLIFT_DRIVER=/absolute/path/to/libadbc_driver_grainlift.dylib # .so on Linux
-- uvx haybarn-cli < examples/query.sql # Haybarn; the DuckDB CLI also works
--
-- The service must be running (grainlift-hello-world). It accepts anonymous
-- clients; for a token-protected service add 'grainlift.auth.bearer_token'.
INSTALL adbc_scanner FROM community;
LOAD adbc_scanner;
SET VARIABLE hello = adbc_connect({
'driver': getenv('GRAINLIFT_DRIVER'),
'entrypoint': 'AdbcDriverGrainliftInit',
'grainlift.uri': 'http://127.0.0.1:8080',
'grainlift.target': 'hello'
});
-- adbc_scan sends the quoted SQL to the service and returns Arrow batches to DuckDB.
SELECT * FROM adbc_scan(getvariable('hello')::BIGINT, 'SELECT ''Hello, world!'' AS message');
-- The results are ordinary DuckDB relations: aggregate, join or export them locally.
SELECT count(*) AS numbers, sum(number) AS total
FROM adbc_scan(getvariable('hello')::BIGINT, 'SELECT * FROM numbers(100000)');
SELECT *
FROM adbc_scan(getvariable('hello')::BIGINT, 'SELECT * FROM running_total(2500)')
ORDER BY number DESC
LIMIT 3;
CALL adbc_disconnect(getvariable('hello')::BIGINT);