Skip to content

Instantly share code, notes, and snippets.

@Stiivi
Last active December 17, 2015 11:29
Show Gist options
  • Save Stiivi/5602392 to your computer and use it in GitHub Desktop.
Save Stiivi/5602392 to your computer and use it in GitHub Desktop.
Brewery2 pipelines – revival or former "forking forks" [1], now using operation kernel and virtual data objects. In this example: just denormalizing two tables into one dimension with field selection. Note that target table does not contain detail keys used for join. References: [1] http://blog.databrewery.org/posts/forking-forks-with-higher-ord…
from brewery2 import Pipeline, open_store
stores = {
"source": open_store("sql", "postgres://localhost/crm", schema="app"),
"target": open_store("sql", connectable=source_store.connectable, schema="cubes")
}
p = Pipeline(stores=stores)
p.source("source", "crm_contact")
p.field_filter(keep=["id",
"contact_type",
"first_name",
"last_name",
"display_name",
"sort_name",
"is_deleted"])
p2 = Pipeline(stores=stores)
p2.source("source", "crm_address")
p2.field_filter(keep=["contact_id",
"is_primary",
"city",
"postal_code" ])
p.join_details(p2.result, "id", "contact_id")
p.create("target", "dim_contact", replace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment