-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14a9f8a
commit 88c46f8
Showing
5 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: censobr | ||
Title: Download Data from Brazil's Population Census | ||
Version: 0.4.0 | ||
Version: 0.4.0999 | ||
Authors@R: | ||
c(person(given="Rafael H. M.", family="Pereira", | ||
email="[email protected]", | ||
|
@@ -38,7 +38,6 @@ Imports: | |
DBI, | ||
dplyr, | ||
duckdb, | ||
duckplyr, | ||
fs, | ||
tools | ||
Suggests: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#' Performs left_join with duckdb | ||
#' | ||
#' @param con A db connection | ||
#' @param x String. Name of a table present in con | ||
#' @param y String. Name of a table present in con | ||
#' @param output_tb Name of the new table to be written in con | ||
#' @param key_cols Vector. Vector with the names of columns to perform left join | ||
#' | ||
#' @return Writes the result of the left join as a new table in con | ||
#' | ||
#' @keywords internal | ||
duckdb_left_join <- function(con, x, y, output_tb, key_cols){ | ||
|
||
# x = 'df' | ||
# y = 'df_household' | ||
# output_tb = 'df_geo' | ||
# key_cols <- key_vars | ||
|
||
# Create dynamic ON condition for matching key columns between `x` and `y` | ||
match_conditions <- paste( | ||
paste0(x, ".", key_cols, " = ", y, ".", key_cols), | ||
collapse = " AND " | ||
) | ||
|
||
# Construct the SQL match query | ||
query_match_case <- sprintf(" | ||
CREATE TEMPORARY TABLE %s AS | ||
SELECT * | ||
FROM %s | ||
LEFT JOIN %s | ||
ON %s;", | ||
output_tb, # Name of output table | ||
x, # Left table | ||
y, # Right table | ||
match_conditions # Dynamic matching conditions based on key columns | ||
) | ||
|
||
# parse(query_match_case) | ||
DBI::dbExecute(con, query_match_case) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.