| delta_loading | R Documentation |
delta_export() exports data from tables created with update_snapshot()
in chunks to allow for faster migration of data between sources.
delta_load() import deltas created by delta_export() to rebuild a
historical table.
delta_export(conn, db_table, timestamp_from, timestamp_until = NULL)
delta_load(conn, db_table, delta, logger = NULL)
conn |
( |
db_table |
( |
timestamp_from |
( |
timestamp_until |
( If |
delta |
.data ( A list of "deltas" can also be supplied. |
logger |
( |
This pair of functions is designed to facilitate easy migration or
incremental backups of a historical table (created by update_snapshot()).
To construct the basis of incremental backups, delta_export() can be
called with only timestamp_from at the desired frequency (weekly etc.)
To migrate a historical table in chunks, delta_export() can be
called with timestamp_until to constrain the size of the delta.
In either case, the table can then be re-constructed by "replaying" the
deltas with delta_load().
The order the deltas are replayed does not matter, but all have to be
replayed to achieve the same state as the source table.
delta_export() returns a lazy-query containing the data (and history)
in the source to be used in conjunction with delta_load().
This table is a temporary table that may need cleaning up.
delta_load() returns NULL (called for side effects).
update_snapshot
conn <- get_connection()
data <- dplyr::copy_to(conn, mtcars)
# Copy the first 3 records
update_snapshot(
head(data, 3),
conn = conn,
db_table = "test.mtcars",
timestamp = "2020-01-01"
)
# Create a delta with the current state
delta <- delta_export(
conn,
db_table = "test.mtcars",
timestamp_from = "2020-01-01"
)
# Update with the first 5 records
update_snapshot(
head(data, 5),
conn = conn,
db_table = "test.mtcars",
timestamp = "2021-01-01"
)
dplyr::tbl(conn, "test.mtcars")
# Create a backup using the delta
delta_load(
conn = conn,
db_table = "test.mtcars_backup",
delta = delta
)
dplyr::tbl(conn, "test.mtcars_backup")
close_connection(conn)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.