Skip to content

Commit

Permalink
Update snippet to separate code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nghi-ly committed Mar 29, 2023
1 parent dfc4699 commit 4556b4d
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 207 deletions.
97 changes: 96 additions & 1 deletion website/docs/docs/quickstarts/dbt-cloud/bigquery-qs.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,102 @@ Later, you can connect your business intelligence (BI) tools to these views and

## Build models on top of other models

<Snippet src="quickstarts/build-models-atop-other-models" />
<Snippet src="quickstarts/intro-build-models-atop-other-models" />

1. Create a new SQL file, `models/stg_customers.sql`, with the SQL from the `customers` CTE in our original query.
2. Create a second new SQL file, `models/stg_orders.sql`, with the SQL from the `orders` CTE in our original query.

<File name='models/stg_customers.sql'>

```sql
select
id as customer_id,
first_name,
last_name
from `dbt-tutorial`.jaffle_shop.customers
```

</File>

<File name='models/stg_orders.sql'>

```sql
select
id as order_id,
user_id as customer_id,
order_date,
status
from `dbt-tutorial`.jaffle_shop.orders
```

</File>

3. Edit the SQL in your `models/customers.sql` file as follows:

<File name='models/customers.sql'>

```sql
with customers as (
select * from {{ ref('stg_customers') }}
),
orders as (
select * from {{ ref('stg_orders') }}
),
customer_orders as (
select
customer_id,
min(order_date) as first_order_date,
max(order_date) as most_recent_order_date,
count(order_id) as number_of_orders
from orders
group by 1
),
final as (
select
customers.customer_id,
customers.first_name,
customers.last_name,
customer_orders.first_order_date,
customer_orders.most_recent_order_date,
coalesce(customer_orders.number_of_orders, 0) as number_of_orders
from customers
left join customer_orders using (customer_id)
)
select * from final
```

</File>

4. Execute `dbt run`.

This time, when you performed a `dbt run`, separate views/tables were created for `stg_customers`, `stg_orders` and `customers`. dbt inferred the order to run these models. Because `customers` depends on `stg_customers` and `stg_orders`, dbt builds `customers` last. You do not need to explicitly define these dependencies.

#### FAQs {#faq-2}

<FAQ src="Runs/run-one-model" />
<FAQ src="Models/unique-model-names" />
<FAQ src="Project/structure-a-project" alt_header="As I create more models, how should I keep my project organized? What should I name my models?" />


<Snippet src="quickstarts/test-and-document-your-project" />

Expand Down
97 changes: 96 additions & 1 deletion website/docs/docs/quickstarts/dbt-cloud/databricks-qs.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,102 @@ Later, you can connect your business intelligence (BI) tools to these views and

## Build models on top of other models

<Snippet src="quickstarts/build-models-atop-other-models" />
<Snippet src="quickstarts/intro-build-models-atop-other-models" />

1. Create a new SQL file, `models/stg_customers.sql`, with the SQL from the `customers` CTE in our original query.
2. Create a second new SQL file, `models/stg_orders.sql`, with the SQL from the `orders` CTE in our original query.

<File name='models/stg_customers.sql'>

```sql
select
id as customer_id,
first_name,
last_name
from jaffle_shop_customers
```

</File>

<File name='models/stg_orders.sql'>

```sql
select
id as order_id,
user_id as customer_id,
order_date,
status
from jaffle_shop_orders
```

</File>

3. Edit the SQL in your `models/customers.sql` file as follows:

<File name='models/customers.sql'>

```sql
with customers as (
select * from {{ ref('stg_customers') }}
),
orders as (
select * from {{ ref('stg_orders') }}
),
customer_orders as (
select
customer_id,
min(order_date) as first_order_date,
max(order_date) as most_recent_order_date,
count(order_id) as number_of_orders
from orders
group by 1
),
final as (
select
customers.customer_id,
customers.first_name,
customers.last_name,
customer_orders.first_order_date,
customer_orders.most_recent_order_date,
coalesce(customer_orders.number_of_orders, 0) as number_of_orders
from customers
left join customer_orders using (customer_id)
)
select * from final
```

</File>

4. Execute `dbt run`.

This time, when you performed a `dbt run`, separate views/tables were created for `stg_customers`, `stg_orders` and `customers`. dbt inferred the order to run these models. Because `customers` depends on `stg_customers` and `stg_orders`, dbt builds `customers` last. You do not need to explicitly define these dependencies.

#### FAQs {#faq-2}

<FAQ src="Runs/run-one-model" />
<FAQ src="Models/unique-model-names" />
<FAQ src="Project/structure-a-project" alt_header="As I create more models, how should I keep my project organized? What should I name my models?" />


<Snippet src="quickstarts/test-and-document-your-project" />

Expand Down
96 changes: 95 additions & 1 deletion website/docs/docs/quickstarts/dbt-cloud/redshift-qs.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,101 @@ Later, you can connect your business intelligence (BI) tools to these views and

## Build models on top of other models

<Snippet src="quickstarts/build-models-atop-other-models" />
<Snippet src="quickstarts/intro-build-models-atop-other-models" />

1. Create a new SQL file, `models/stg_customers.sql`, with the SQL from the `customers` CTE in our original query.
2. Create a second new SQL file, `models/stg_orders.sql`, with the SQL from the `orders` CTE in our original query.

<File name='models/stg_customers.sql'>

```sql
select
id as customer_id,
first_name,
last_name
from jaffle_shop.customers
```

</File>

<File name='models/stg_orders.sql'>

```sql
select
id as order_id,
user_id as customer_id,
order_date,
status
from jaffle_shop.orders
```

</File>

3. Edit the SQL in your `models/customers.sql` file as follows:

<File name='models/customers.sql'>

```sql
with customers as (
select * from {{ ref('stg_customers') }}
),
orders as (
select * from {{ ref('stg_orders') }}
),
customer_orders as (
select
customer_id,
min(order_date) as first_order_date,
max(order_date) as most_recent_order_date,
count(order_id) as number_of_orders
from orders
group by 1
),
final as (
select
customers.customer_id,
customers.first_name,
customers.last_name,
customer_orders.first_order_date,
customer_orders.most_recent_order_date,
coalesce(customer_orders.number_of_orders, 0) as number_of_orders
from customers
left join customer_orders using (customer_id)
)
select * from final
```

</File>

4. Execute `dbt run`.

This time, when you performed a `dbt run`, separate views/tables were created for `stg_customers`, `stg_orders` and `customers`. dbt inferred the order to run these models. Because `customers` depends on `stg_customers` and `stg_orders`, dbt builds `customers` last. You do not need to explicitly define these dependencies.

#### FAQs {#faq-2}

<FAQ src="Runs/run-one-model" />
<FAQ src="Models/unique-model-names" />
<FAQ src="Project/structure-a-project" alt_header="As I create more models, how should I keep my project organized? What should I name my models?" />

<Snippet src="quickstarts/test-and-document-your-project" />

Expand Down
Loading

0 comments on commit 4556b4d

Please sign in to comment.