-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathduckdb_and_arrow.R
executable file
·72 lines (50 loc) · 1.2 KB
/
duckdb_and_arrow.R
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env Rscript
#library
library(DBI)
library(duckdb)
library(dplyr)
library(microbenchmark)
library(data.table)
library(arrow)
library(here)
#load data and create duckdb connection
fp <- here::here("measurements.csv")
measurement_tbl <- data.table::fread(fp)
con <- DBI::dbConnect(duckdb::duckdb())
duckdb::duckdb_register(con,name = "measurement_db",measurement_tbl)
measurement_db <- dplyr::tbl(con,"measurement_db")
measurements_ar <- measurement_db |> arrow::to_arrow()
# create function to simulate results
duckdb <- function(){
out <- measurement_db |>
group_by(state) |>
summarize(
min=min(measurement,na.rm=TRUE)
,max=max(measurement,na.rm=TRUE)
,mean=mean(measurement,na.rm=TRUE)
) |> ungroup() |>
collect()
return(out)
}
# arrow <- function(){
#
# out <- measurements_ar |>
# group_by(state) |>
# summarize(
# min=min(measurement,na.rm=TRUE)
# ,max=max(measurement,na.rm=TRUE)
# ,mean=mean(measurement,na.rm=TRUE)
# ) |>
# ungroup() |>
# collect()
#
# return(out)
#
# }
bmarks <- microbenchmark(
duckdb=duckdb()
# ,arrow=arrow()
,times = 10
, unit = "s"
)
write.csv(bmarks,"duckdb_and_arrow_bmarks.csv")