From d13980455a2722e63a28c11ab548fb475b97bf87 Mon Sep 17 00:00:00 2001 From: lloyd tabb Date: Wed, 25 Oct 2023 10:21:19 -0700 Subject: [PATCH] rename directories. --- wns/{WN-0000 => WN-0000-proposals}/wn-0000.md | 0 .../wn-template.md | 0 .../wn-0001.md | 0 .../wn-0002.md | 0 .../wn-0003.md | 0 .../wn-0004.md | 25 ++++++++++++++++--- wns/{WN-0005 => WN-0005-records}/wn-0005.md | 0 .../WN-0006.md | 0 .../wn-0007.md | 25 +++++++++++++++++++ 9 files changed, 47 insertions(+), 3 deletions(-) rename wns/{WN-0000 => WN-0000-proposals}/wn-0000.md (100%) rename wns/{WN-0000 => WN-0000-proposals}/wn-template.md (100%) rename wns/{WN-0001 => WN-0001-relationships}/wn-0001.md (100%) rename wns/{WN-0002 => WN-0002-parameters}/wn-0002.md (100%) rename wns/{WN-0003 => WN-0003-unknown-func-classes}/wn-0003.md (100%) rename wns/{WN-0004 => WN-0004-sql-dimensions}/wn-0004.md (70%) rename wns/{WN-0005 => WN-0005-records}/wn-0005.md (100%) rename wns/{WN-0006 => WN-0006-trailing-refinements}/WN-0006.md (100%) rename wns/{WN-0007 => WN-0007-nested-computations}/wn-0007.md (92%) diff --git a/wns/WN-0000/wn-0000.md b/wns/WN-0000-proposals/wn-0000.md similarity index 100% rename from wns/WN-0000/wn-0000.md rename to wns/WN-0000-proposals/wn-0000.md diff --git a/wns/WN-0000/wn-template.md b/wns/WN-0000-proposals/wn-template.md similarity index 100% rename from wns/WN-0000/wn-template.md rename to wns/WN-0000-proposals/wn-template.md diff --git a/wns/WN-0001/wn-0001.md b/wns/WN-0001-relationships/wn-0001.md similarity index 100% rename from wns/WN-0001/wn-0001.md rename to wns/WN-0001-relationships/wn-0001.md diff --git a/wns/WN-0002/wn-0002.md b/wns/WN-0002-parameters/wn-0002.md similarity index 100% rename from wns/WN-0002/wn-0002.md rename to wns/WN-0002-parameters/wn-0002.md diff --git a/wns/WN-0003/wn-0003.md b/wns/WN-0003-unknown-func-classes/wn-0003.md similarity index 100% rename from wns/WN-0003/wn-0003.md rename to wns/WN-0003-unknown-func-classes/wn-0003.md diff --git a/wns/WN-0004/wn-0004.md b/wns/WN-0004-sql-dimensions/wn-0004.md similarity index 70% rename from wns/WN-0004/wn-0004.md rename to wns/WN-0004-sql-dimensions/wn-0004.md index 8450ca3..4c7e33b 100644 --- a/wns/WN-0004/wn-0004.md +++ b/wns/WN-0004-sql-dimensions/wn-0004.md @@ -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 diff --git a/wns/WN-0005/wn-0005.md b/wns/WN-0005-records/wn-0005.md similarity index 100% rename from wns/WN-0005/wn-0005.md rename to wns/WN-0005-records/wn-0005.md diff --git a/wns/WN-0006/WN-0006.md b/wns/WN-0006-trailing-refinements/WN-0006.md similarity index 100% rename from wns/WN-0006/WN-0006.md rename to wns/WN-0006-trailing-refinements/WN-0006.md diff --git a/wns/WN-0007/wn-0007.md b/wns/WN-0007-nested-computations/wn-0007.md similarity index 92% rename from wns/WN-0007/wn-0007.md rename to wns/WN-0007-nested-computations/wn-0007.md index 8ee5438..eb7e6cb 100644 --- a/wns/WN-0007/wn-0007.md +++ b/wns/WN-0007-nested-computations/wn-0007.md @@ -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' ``` \ No newline at end of file