From 246cb0f255d61c09331ace3f52c158dd85283026 Mon Sep 17 00:00:00 2001 From: lloyd tabb Date: Tue, 17 Oct 2023 09:10:07 -0700 Subject: [PATCH] Minor cleanup --- src/documentation/patterns/autobin.malloynb | 1 - src/documentation/patterns/foreign_sums.malloynb | 5 ++--- src/documentation/patterns/yoy.malloynb | 8 -------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/documentation/patterns/autobin.malloynb b/src/documentation/patterns/autobin.malloynb index 1d476558..70774f74 100644 --- a/src/documentation/patterns/autobin.malloynb +++ b/src/documentation/patterns/autobin.malloynb @@ -1,7 +1,6 @@ >>>markdown # Automatically Binning Data By examining the range of values over a dataset, we can compute the appropriate histogram bin size, while capturing the data at the same time. We can then pipe the output to another query to display a histogram. - >>>malloy source: airports is duckdb.table('../data/airports.parquet') extend { measure: airport_count is count() diff --git a/src/documentation/patterns/foreign_sums.malloynb b/src/documentation/patterns/foreign_sums.malloynb index c8a93d32..7db205d4 100644 --- a/src/documentation/patterns/foreign_sums.malloynb +++ b/src/documentation/patterns/foreign_sums.malloynb @@ -1,8 +1,7 @@ >>>markdown # Foreign Sums -Malloy allows you to compute sums and averages correctly based on your join tree. Fan-outs based on join relationships will never impact the correctness of these aggregations. This example has `flights`, joining to `aircraft`, joining to `aircraft_model``. +Malloy allows you to compute sums and averages correctly based on your join tree. Fan-outs based on join relationships will never impact the correctness of these aggregations. This example has `flights`, joining to `aircraft`, joining to `aircraft_model`. `aircraft_model` has the number of seats specified on this model of aircraft. Code below computes sums and averages at various places in the join tree. - >>>malloy #(docs) size=large // join 3 tables, flights, aircraft and aircraft models. @@ -34,7 +33,7 @@ run: flights -> { // number of different aircraft_models aircraft_model_count is aircraft.aircraft_models.count() // count each seat once for each flight. - seats_for_sale is sum(aircraft.aircraft_models.seats) + seats_for_sale is source.sum(aircraft.aircraft_models.seats) // count the seat once for each plane seats_on_all_planes is aircraft.sum(aircraft.aircraft_models.seats) // average number of seats on each model by model diff --git a/src/documentation/patterns/yoy.malloynb b/src/documentation/patterns/yoy.malloynb index 13ec9d4c..626a04f1 100644 --- a/src/documentation/patterns/yoy.malloynb +++ b/src/documentation/patterns/yoy.malloynb @@ -6,13 +6,10 @@ There are a couple of different ways to go about this in Malloy. We can compare performance of different years using the same x and y-axes. Line charts take the x-axis, y-axis and dimensional (color) axis as parameters. In this case, the x-axis is `month_of_year`, the y-axis is `flight_count` and the dimensional (color) axis is the year. - >>>malloy source: flights is duckdb.table('../data/flights.parquet') extend { measure: flight_count is count() } ->>>markdown - >>>malloy #(docs) size=small limit=5000 run: flights -> { @@ -23,7 +20,6 @@ run: flights -> { >>>markdown By adding year as the third column, we can display different years on the same chart. Note the `# line_chart` tag above the query. This is a hint to the renderer to display the data as a line chart. Changing the definition of `flight_year` to `year(dep_time)::string` makes the line chart interpret the year as "categorical," giving distinct colors for each year rather than a gradient. - >>>malloy #(docs) size=large limit=5000 # line_chart @@ -36,8 +32,6 @@ run: flights -> { ## Method 2: Filtered Aggregates Filters make it easy to reuse aggregate calculations for trends analysis. - - >>>malloy #(docs) size=large limit=5000 run: flights -> { @@ -55,7 +49,6 @@ run: flights -> { ## Method 3: Calculate with Lag The `calculate:` clause is Malloy's window function equivalent, and allows us to compute year over year calculations using the `lag` function: - >>>malloy #(docs) size=large limit=5000 run: flights -> { @@ -71,7 +64,6 @@ run: flights -> { ## Bonus: Relative timeframes and expression reuse You might like to write queries that automatically adjust based on the current timeframe. The query below uses date arithmetic to filter the data to time frames relative to now. These measures probably aren't generally useful in the model so we use the `extend:` operation to add these measure so they are only locally accessable within the query. - >>>malloy #(docs) size=medium limit=5000 source: inventory_items is duckdb.table('../data/inventory_items.parquet')