tools/70-touchstone-gen.R

library(tidyverse)

pre <- 'library(touchstone)

source("tools/30-tpch-export.R")
source("tools/31-tpch-load-qs.R")

branch_install()

'

header <- paste0("# Generated by 60-touchstone-gen.R, ", "do not edit by hand\n\n")

body <- function(sf, test, n) glue::glue('benchmark_run(
  expr_before_benchmark = {{
    library(duckplyr)
    data <- qs::qread("tools/tpch/{sf}.qs")
    .mapply(assign, list(names(data), data), list(pos = .GlobalEnv))

    customer <- as_duckplyr_df(customer)
    lineitem <- as_duckplyr_df(lineitem)
    nation <- as_duckplyr_df(nation)
    orders <- as_duckplyr_df(orders)
    part <- as_duckplyr_df(part)
    partsupp <- as_duckplyr_df(partsupp)
    region <- as_duckplyr_df(region)
    supplier <- as_duckplyr_df(supplier)
  }},
  `{sf}_tpch_{test}` = collect(duckplyr:::tpch_{test}()),
  n = {n}
)\n\n')

footer <- 'benchmark_analyze()'

bodies <-
  crossing(
    tibble(n = c(3, 10, 30), sf = c("100", "010", "001")),
    test = c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22"),
  ) |>
  rowwise() |>
  mutate(code = body(sf, test, n)) |>
  ungroup() |>
  summarize(code = paste(code, collapse = "\n")) |>
  pull(code)

code <- paste0(
  header,
  pre,
  bodies,
  footer
)

writeLines(code, "touchstone/script.R")
duckdblabs/duckplyr documentation built on Nov. 6, 2024, 10 p.m.