Macros (coming soon)

Macros are blocks which content will be inlined (substituted) into the caller block. This mimic the current behavior of our catalog assets.

Macros are defined using an #+macro directive. Optionally, it could accept arguments.

Macros are called in the same way as block.

In the following example we define countryGroup macro, which return a column expression that we are using inside a SELECT statement to get a country group.

#+macro countryGroup(country)
#+meta {
  :doc "Given a name of the country column returns a CASE statement to get a country group."
}
#+begin
  CASE
    WHEN {{ country }} IN ('US', 'CA') THEN 'NA'
    WHEN {{ country }} IN ('GB', 'FR', 'DE', 'IT', 'PL', 'SE') THEN 'EU'
    WHEN {{ country }} IN ('AU') THEN {{ country }}
    ELSE 'Other'
  END
#+end

SELECT
  country AS country,
  {{ countryGroup(country="country") }} AS country_group,
  device_type AS device_type,
  sum(revenue) AS revenue,
  sum(pageviews) AS pageviews,
  sum(sessions) AS sessions
FROM
  {{ fact.sales() }}
GROUP BY
  country,
  country_group,
  device_type
;
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request