Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename directories. #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
rename directories.
  • Loading branch information
lloydtabb committed Oct 25, 2023
commit d13980455a2722e63a28c11ab548fb475b97bf87
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 22 additions & 3 deletions wns/WN-0004/wn-0004.md → wns/WN-0004-sql-dimensions/wn-0004.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,36 @@ LookML models are entirely based on this mechanism. As much as possible, we sho

SQL expressions are always dimensions.

Let's assume a table orders with nested/repeated items.
Assume a table with the following structure

orders:
```
order_id
order_time
shipped_time
status
user_id
items []
product_id
product_description
sale_price
is_returned
product_category
```

## Coorelated Subquery Example
Malloy currently does not support coorelated subqueries. Coorelated subqueries on nested data are more efficient than joining nested data.

The code below returns the count of items that have not been returned.
The code below returns the count of items that have not been returned.

`${TABLE}` references the root alias for the source.

The `!number` lets us know that the return type from sql expression is a number.

```
source: orders is bigquery.table(...) extend {

dimension: item_count is sql("""
dimension: item_count is sql!number("""
(
SELECT count(*) from UNNEST(${TABLE}.items)
WHERE not is_returned
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,29 @@ There are several intrinic functions that return nested sources. These function
group_by: word is description_words.value
aggregate: order_count is count()
}
```

## Re-nesting a nested Source
If a nested computation doesn't have a 'return' block, it is assumed to be a calculation that returns multiple rows, and is of type 'nested source' the result of which is treated as a ....


```
run: orders -> {
select:
order_id
socks is items->{
project: *
where: product_catetory='SOCKS'
}
}

```

The SQL for this would be

```
SELECT
order_id,
ARRAY((SELECT * from UNNEST(items) WHERE product_category='SOCKS)) as socks
FROM 'orders.parquet'
```