Malloy Documentation
search

The plugin currently supports US maps and state names. The model and data styles for the subsequent examples are:

document
source: airports is duckdb.table('../data/airports.parquet') extend {
  primary_key: code
  measure: airport_count is count()
  view: by_state is {
    group_by: state
    aggregate: airport_count
  }
  # shape_map
  view: by_state_shaped is by_state
}

Run a query and tag the results as a shape map

We can explicitly return a result as a shape map.

document
# shape_map
run: airports -> by_state
QUERY RESULTS
1,0001,2001,4001,6001,800airport_count
[
  {
    "state": "TX",
    "airport_count": 1845
  },
  {
    "state": "CA",
    "airport_count": 984
  },
  {
    "state": "IL",
    "airport_count": 890
  },
  {
    "state": "FL",
    "airport_count": 856
  },
  {
    "state": "PA",
    "airport_count": 804
  }
]
SELECT 
   airports."state" as "state",
   COUNT( 1) as "airport_count"
FROM '../data/airports.parquet' as airports
GROUP BY 1
ORDER BY 2 desc NULLS LAST

The tag is in the semantic model

In the query below the tag is in the semantic model.

document
run: airports -> by_state_shaped + {where: fac_type='SEAPLANE BASE'}
QUERY RESULTS
406080100airport_count
[
  {
    "state": "AK",
    "airport_count": 104
  },
  {
    "state": "MN",
    "airport_count": 72
  },
  {
    "state": "FL",
    "airport_count": 43
  },
  {
    "state": "ME",
    "airport_count": 38
  },
  {
    "state": "NY",
    "airport_count": 23
  }
]
SELECT 
   airports."state" as "state",
   COUNT( 1) as "airport_count"
FROM '../data/airports.parquet' as airports
WHERE airports."fac_type"='SEAPLANE BASE'
GROUP BY 1
ORDER BY 2 desc NULLS LAST

Run as a trellis

By calling the configured map as a nested subtable, a trellis is formed.

document
run: airports -> {
  group_by: faa_region
  aggregate: airport_count
  # shape_map
  nest: by_state
}
QUERY RESULTS
faa_​regionairport_​countby_​state
AGL4,437
180890airport_count
ASW3,268