From 63411b6190325f3cbf6a9d3a1b40457a6246c3a2 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 30 Oct 2023 16:57:30 +0100 Subject: [PATCH] Some stuff --- code_thingies/database/README.md | 4 ++-- .../dbtlearn/models/src/src_listings.sql | 20 +++++++++++++++++++ .../dbtlearn/models/src/src_reviews.sql | 11 ++++++++++ notes/8.md | 7 +++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 code_thingies/dbtlearn/models/src/src_listings.sql create mode 100644 code_thingies/dbtlearn/models/src/src_reviews.sql create mode 100644 notes/8.md diff --git a/code_thingies/database/README.md b/code_thingies/database/README.md index a57615e..4dba9cd 100644 --- a/code_thingies/database/README.md +++ b/code_thingies/database/README.md @@ -16,7 +16,7 @@ CREATE DATABASE airbnb; CREATE SCHEMA raw; --- The following tables should be created in the `raw` schema +-- The following tables should be created in the `src` schema CREATE TABLE raw_listings ( id INTEGER, @@ -53,7 +53,7 @@ CREATE SCHEMA dev; -- Create a user for dbt activity CREATE USER transformation_user WITH ENCRYPTED PASSWORD 'transformation_user_password'; --- Allow dbt user to read from raw schema +-- Allow dbt user to read from src schema GRANT CONNECT ON DATABASE airbnb TO transformation_user; GRANT USAGE ON SCHEMA raw TO transformation_user; GRANT SELECT ON ALL TABLES IN SCHEMA raw TO transformation_user; diff --git a/code_thingies/dbtlearn/models/src/src_listings.sql b/code_thingies/dbtlearn/models/src/src_listings.sql new file mode 100644 index 0000000..c68838c --- /dev/null +++ b/code_thingies/dbtlearn/models/src/src_listings.sql @@ -0,0 +1,20 @@ +WITH raw_listings AS ( + SELECT * + FROM raw.raw_listings +) +SELECT + id AS listing_id, + name AS listing_name, + listing_url, + room_type, + minimum_nights, + host_id, + price AS price_str, + created_at, + updated_at +FROM + raw_listings + + + + diff --git a/code_thingies/dbtlearn/models/src/src_reviews.sql b/code_thingies/dbtlearn/models/src/src_reviews.sql new file mode 100644 index 0000000..59d8167 --- /dev/null +++ b/code_thingies/dbtlearn/models/src/src_reviews.sql @@ -0,0 +1,11 @@ +WITH raw_reviews AS ( + SELECT * + FROM raw.raw_reviews +) +SELECT + listing_id, + date AS review_date, + comments AS review_text, + sentiment AS review_sentiment +FROM + raw_reviews \ No newline at end of file diff --git a/notes/8.md b/notes/8.md new file mode 100644 index 0000000..a2b0b27 --- /dev/null +++ b/notes/8.md @@ -0,0 +1,7 @@ +## Models + +Models are the fundamental concept behind dbt. + +They are stored as SQL files in the `models` folder. + +Models can be related between themselves to map dependencies. \ No newline at end of file