-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update landing page snippets to fit into the box
and add duckplyr example
- Loading branch information
Showing
12 changed files
with
59 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
// Web Service Integration: | ||
// create endpoint to generate numbers | ||
// Create endpoint to generate numbers | ||
import express from "express"; | ||
import { DuckDBInstance } from '@duckdb/node-api'; | ||
const app = express(); | ||
const instance = await DuckDBInstance.create(); | ||
const connection = await instance.connect(); | ||
app.get("/getnumbers", async (req, res) => { | ||
const reader = await connection.runAndReadAll("SELECT random() AS num FROM range(10)"); | ||
const reader = await connection.runAndReadAll( | ||
"SELECT random() AS num FROM range(10)"); | ||
res.end(JSON.stringify(reader.getRows())); | ||
}); | ||
|
||
app.listen(8082, () => console.log("Go to: http://localhost:8082/getnumbers")); | ||
app.listen(8082, () => console.log( | ||
"Go to: http://localhost:8082/getnumbers")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# Create custom user-defined function | ||
import duckdb | ||
|
||
def add_plus_one(x): | ||
def plus_one(x): | ||
return x + 1 | ||
|
||
con = duckdb.connect() | ||
con.create_function('add_plus_one', add_plus_one, | ||
con.create_function('plus_one', plus_one, | ||
['BIGINT'], 'BIGINT', type='native') | ||
|
||
con.sql(""" | ||
SELECT sum(add_plus_one(i)) FROM range(10) tbl(i); | ||
SELECT sum(plus_one(i)) FROM range(10) tbl(i); | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Find the largest sepals/petals in the Iris data set | ||
# using duckplyr | ||
library("duckplyr") | ||
|
||
iris |> | ||
filter(Sepal.Length > 5) |> | ||
group_by(Species) |> | ||
summarize( | ||
num_observations = n(), | ||
max_width = max(Sepal.Width), | ||
max_petal_length = max(Petal.Length), | ||
na.rm = TRUE) |> | ||
collect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Find the largest sepals & petals in the Iris data set | ||
# Find the largest sepals/petals in the Iris data set | ||
library(duckdb) | ||
|
||
con <- dbConnect(duckdb()) | ||
duckdb_register(con, "iris", iris) | ||
|
||
query <- r'( | ||
SELECT count(*) AS num_observations, | ||
max("Sepal.Width") AS max_width, | ||
max("Petal.Length") AS max_petal_length | ||
FROM iris | ||
WHERE "Sepal.Length" > 5 | ||
GROUP BY ALL | ||
)' | ||
SELECT count(*) AS num_observations, | ||
max("Sepal.Width") AS max_width, | ||
max("Petal.Length") AS max_petal_length | ||
FROM iris | ||
WHERE "Sepal.Length" > 5 | ||
GROUP BY ALL | ||
)' | ||
|
||
dbGetQuery(con, query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters