create_join_plan: Create a Plan for Aggregating and Merging Tables

View source: R/join_plan.R

create_join_planR Documentation

Create a Plan for Aggregating and Merging Tables

Description

This function acts as a "planner." It takes a user's request for a final dataset, finds a path using a join map, and creates a structured plan (or "recipe") of the necessary steps.

Usage

create_join_plan(
  base_table,
  selections,
  metadata_dt,
  join_map = NULL,
  tables_dis = NULL
)

Arguments

base_table

A character string specifying the main table.

selections

A named list specifying the columns or aggregations to include.

metadata_dt

The master metadata data.table.

join_map

An optional "Join Map" data.table produced by map_join_paths(). If NULL (the default), the map will be generated automatically from the metadata.

tables_dis

An optional named list of data.tables used for data‑driven (inferred) join discovery. If NULL, only metadata‑driven joins are used. If NULL (the default), the map will be generated automatically from the metadata.

Value

A list object representing the "join plan."

Examples

# --- 1. Define Metadata (Prerequisite) ---
customers_meta <- table_info(
 table_name = "customers",
 source_identifier = "customers.csv",
 identifier_columns = "customer_id",
 key_outcome_specs = list(
   list(OutcomeName = "CustomerCount", ValueExpression = 1, AggregationMethods = list(
     list(AggregatedName = "CountByRegion", AggregationFunction = "sum", 
GroupingVariables = "region")
   ))
 )
)
transactions_meta <- table_info(
  "transactions", "t.csv", "tx_id",
  key_outcome_specs = list(list(OutcomeName = "Revenue", ValueExpression = quote(r),
  AggregationMethods = list(list(AggregatedName = "RevenueByCustomer",
  AggregationFunction = "sum", GroupingVariables = "customer_id"))))
)
master_metadata <- data.table::rbindlist(list(customers_meta, transactions_meta))

# --- 2. Define the Desired Output ---
user_selections <- list(
  customers = "region",
  transactions = "RevenueByCustomer"
)

# --- 3. Create the Join Plan WITHOUT providing the join_map ---
# The function will now generate it automatically.
join_plan <- create_join_plan(
  base_table = "customers",
  selections = user_selections,
  metadata_dt = master_metadata
)

# --- 4. Inspect the Plan ---
str(join_plan)


DBmaps documentation built on Sept. 9, 2025, 5:44 p.m.