Skip to content
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
1 change: 0 additions & 1 deletion src/documentation/patterns/autobin.malloynb
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
5 changes: 2 additions & 3 deletions src/documentation/patterns/foreign_sums.malloynb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/documentation/patterns/yoy.malloynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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
Expand All @@ -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 -> {
Expand All @@ -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 -> {
Expand All @@ -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')
Expand Down