DRDataRaft/ docs
GitHub ↗

dr_model()

Create and validate a relational dm model from pinned releases

Usage

dr_model(
  lake,
  tables,
  primary_keys = list(),
  foreign_keys = list(),
  releases = NULL,
  check = TRUE
)

Arguments

lake
Connected lake.


tables
Named character vector of asset ids.


primary_keys
Named list of character vectors, keyed by table alias.


foreign_keys
List of lists containing table, columns, ref_table, ref_columns.


releases
Optional named vector pinning all table releases.


check
Validate all declared keys and relationships.

Value

A dm object containing lazy tables. No automatic flattening is done.

Examples

\dontshow{if (requireNamespace("dataraft.lake", quietly = TRUE) && requireNamespace("duckdb", quietly = TRUE) && requireNamespace("dm", quietly = TRUE)) withAutoprint(\{ # examplesIf}
root <- tempfile("dataraft-example-")
config <- dataraft.lake::dr_lake_config(
  dataraft.lake::dr_registry_duckdb(file.path(root, "lake.db")),
  dataraft.lake::dr_storage_local(file.path(root, "data")),
  landing = file.path(root, "landing"), backend = "duckdb"
)
lake <- dataraft.lake::dr_connect_lake(config)
path <- file.path(root, "orders.csv")
utils::write.csv(data.frame(order_id = 1:2, amount = c(25, 75)), path,
  row.names = FALSE)
source <- dr_source_file("orders.file", path, reader = utils::read.csv)
contract <- dr_contract(
  "orders", version = "1.0.0", columns =
  c(order_id = "integer", amount = "numeric"), key = "order_id"
)
release <- dr_product("orders", contract = contract, code_version = "v1") |>
  dr_add_source(source) |> dr_publish(to = lake)
model <- dr_model(lake, c(orders = "orders"),
  primary_keys = list(orders = "order_id"))
model
dataraft.lake::dr_disconnect_lake(lake)
unlink(root, recursive = TRUE)
\dontshow{\}) # examplesIf}
Documentation source snapshot · View source at d9cb454 ↗
Code examples are documented source examples; they are not executed in this website build.

Search documentation

Search functions, packages and guides.