Seven DuckDB views register on session open: long (raw), spending_long and revenue_long (prefix-filtered, NOT is_aggregate per reader-spec §4), canonical_fips_xwalk and summary_categories (identity), spending_annotated and revenue_annotated (LEFT JOIN xwalk + categories for verb composition). File prefix `NN-` enforces creation order so *_annotated views resolve their *_long dependencies. Deviation from plan: series_breaks/cpi_annual/legacy_aggregate_map and *_with_transforms views are deferred — their backing parquets are not in the v0.1 corpus (manifest.files.metadata only lists canonical_fips_xwalk and summary_categories). The verbs will compute CPI adjustment verb-side against a bundled cpi table in a later task.
60 lines
1.8 KiB
R
60 lines
1.8 KiB
R
test_that("all expected views register on session open", {
|
|
skip_if_no_corpus()
|
|
con <- cog_open()
|
|
on.exit(cog_close())
|
|
views <- DBI::dbGetQuery(con,
|
|
"SELECT table_name FROM information_schema.tables
|
|
WHERE table_schema = 'main' AND table_type = 'VIEW'"
|
|
)
|
|
expected <- c(
|
|
"long", "spending_long", "revenue_long",
|
|
"canonical_fips_xwalk", "summary_categories",
|
|
"spending_annotated", "revenue_annotated"
|
|
)
|
|
expect_true(all(expected %in% views$table_name))
|
|
})
|
|
|
|
test_that("spending_long filters to E/F/G/K prefixes and excludes aggregates", {
|
|
skip_if_no_corpus()
|
|
con <- cog_open()
|
|
on.exit(cog_close())
|
|
prefixes <- DBI::dbGetQuery(con,
|
|
"SELECT DISTINCT LEFT(item_code, 1) AS pfx FROM spending_long"
|
|
)$pfx
|
|
expect_true(all(prefixes %in% c("E", "F", "G", "K")))
|
|
|
|
agg_count <- DBI::dbGetQuery(con,
|
|
"SELECT count(*) AS n FROM spending_long WHERE is_aggregate"
|
|
)$n
|
|
expect_equal(agg_count, 0)
|
|
})
|
|
|
|
test_that("revenue_long filters to T/A/U/B/C/D prefixes and excludes aggregates", {
|
|
skip_if_no_corpus()
|
|
con <- cog_open()
|
|
on.exit(cog_close())
|
|
prefixes <- DBI::dbGetQuery(con,
|
|
"SELECT DISTINCT LEFT(item_code, 1) AS pfx FROM revenue_long"
|
|
)$pfx
|
|
expect_true(all(prefixes %in% c("T", "A", "U", "B", "C", "D")))
|
|
|
|
agg_count <- DBI::dbGetQuery(con,
|
|
"SELECT count(*) AS n FROM revenue_long WHERE is_aggregate"
|
|
)$n
|
|
expect_equal(agg_count, 0)
|
|
})
|
|
|
|
test_that("spending_annotated carries category + xwalk columns", {
|
|
skip_if_no_corpus()
|
|
con <- cog_open()
|
|
on.exit(cog_close())
|
|
row <- DBI::dbGetQuery(con,
|
|
"SELECT * FROM spending_annotated LIMIT 1"
|
|
)
|
|
for (nm in c("canonical_govid", "item_code", "amt",
|
|
"xwalk_gov_name", "govs_type", "population_acs",
|
|
"category", "spend_subtype")) {
|
|
expect_true(nm %in% names(row), info = paste("missing column:", nm))
|
|
}
|
|
})
|