Public
Edited
Jan 25, 2023
1 fork
Importers
39 stars
Insert cell
Insert cell
Insert cell
Insert cell
dbClient1 = new DuckDBClient()
Insert cell
Insert cell
Insert cell
Inputs.table(await dbClient1.query(query))
Insert cell
Insert cell
dbClient1.table(query)
Insert cell
Insert cell
dbClient1
SELECT
v::INT AS x,
(sin(v/50.0) * 100 + 100)::INT AS y
FROM generate_series(0, 1000) AS t(v)
Insert cell
dbClient1
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
dbClient1.queryRow(`SELECT 1 + 2`)
Insert cell
Insert cell
dbClient1.explain(query)
Insert cell
Insert cell
sequence = dbClient1.query(query)
Insert cell
vl
.markLine()
.data(sequence)
.encode(vl.x().fieldQ("x"), vl.y().fieldQ("y"))
.width(600)
.render()
Insert cell
Plot.plot({
marks: [Plot.line(sequence, { x: "x", y: "y" })]
})
Insert cell
Insert cell
dbClient2 = {
const client = new DuckDBClient()
await client.query('CREATE TABLE professoren (persnr INTEGER, name STRING, rang STRING);');
await client.query('CREATE TABLE studenten (matrnr INTEGER, name STRING, semester INTEGER);');
return client
}
Insert cell
dbClient2.describe()
Insert cell
Insert cell
dbClient2
SHOW TABLES
Insert cell
Insert cell
dbClient2.describe('studenten')
Insert cell
Insert cell
dbClient2
DESCRIBE studenten
Insert cell
Insert cell
dbClient3 = DuckDBClient.of([
FileAttachment("weather.parquet"),
FileAttachment("penguins.csv"),
FileAttachment("cars.json")
])
Insert cell
Insert cell
Insert cell
dbClient3.describe()
Insert cell
Insert cell
dbClient3.table(`
SELECT
species,
avg(flipper_length_mm) as 'Average Flipper length (mm)'
FROM penguins
GROUP BY species
`)
Insert cell
Insert cell
dbClient3.table(`SELECT count(*) FROM weather`)
Insert cell
Insert cell
dbClient3.table(`SELECT count(*) FROM parquet_scan('weather.parquet')`)
Insert cell
Insert cell
dbClient3.table(`
SELECT *
FROM weather
LIMIT 100
`)
Insert cell
Insert cell
Insert cell
dbClient3.table(aggregate)
Insert cell
Insert cell
dbClient3.explain(aggregate)
Insert cell
Insert cell
{
await dbClient3.query(`
CREATE TABLE IF NOT EXISTS weather_aggregate AS
SELECT location, min(temp_min), max(temp_max), avg(wind), avg(precipitation)
FROM weather
GROUP BY location`);
return dbClient3.describe('weather_aggregate');
}
Insert cell
Insert cell
{
const client = new DuckDBClient();
await client.query('CREATE TEMP TABLE temporary AS SELECT 1');
await client.query('CREATE TABLE permanent AS SELECT 1');
const before = await client.describe();
await client.reconnect();
const after = await client.describe();

return md`
Before reconnect:
${before}

After reconnect:
${after}`;
}
Insert cell
Insert cell
dbClient3
SELECT *
FROM penguins
Insert cell
dbClient3
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
dbClient4 = new DuckDBClient()
Insert cell
FileAttachment("weather.parquet").constructor.name
Insert cell
{
const db = await dbClient4.db();
const conn = await db.connect();

const start = performance.now();

const result = await conn.send(`SELECT * FROM generate_series(1, 1000000)`);
const firstBatch = (await result.next()).value;
await conn.close();

const duration = performance.now() - start;

return { size: firstBatch.numRows, time: duration };
}
Insert cell
Insert cell
{
const start = performance.now();
const result = await dbClient4.query(
`SELECT * FROM generate_series(1, 1000000)`
);
const duration = performance.now() - start;

return { size: result.numRows, time: duration };
}
Insert cell
Insert cell
libraryVersion
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more