Skip to content

Instantly share code, notes, and snippets.

@matt2000
Created September 16, 2019 17:39
Show Gist options
  • Save matt2000/a1860b95c9df53346143410d27271bce to your computer and use it in GitHub Desktop.
Save matt2000/a1860b95c9df53346143410d27271bce to your computer and use it in GitHub Desktop.
---
tv_shows: # This is the base table for a given entity.
label: "TV Show" # A Human readable name for the entity.
autofilter: "tv_shows.is_test = False" # Optional. A condition added to every WHERE clause generated for this entity.
alias_for: mydb.mychema.tv_shows # Optional, in case the top-level key is not a real table name.
fields:
show_id: # Column Name or alias for a metric.
label: "TV Show ID" # Human-readable name for the field.
type: int # Data type, for use by software that validates or builds UIs.
alias_for: id # Optional, if parent key is not the real column name.
is_awesome:
label: "Is this row awesome?"
type: bool
expression: "CASE WHEN magic_number > 4 THEN True ELSE False END as awesome"
follower_count:
label: "Number of Followers"
type: int
expression: "count(user_follows.user_id)" # SQL fragment for the SELECT clause.
is_aggregate: true # Tells the query builder to GROUP BY non-aggregate fields.
joins:
# => LEFT JOIN user_follows ON tv_shows.id = user_follows.show_id AND user_follows.test = False
- [LEFT JOIN, user_follows, tv_shows.id, user_follows.show_id, "user_follows.test = False"]
# query([tv_shows.show_id, tv_shows.follower_count])
# =>
# SELECT tv_shows.id, user_follows.user_id
# FROM mydb.myschema.tv_shows tv_shows
# LEFT JOIN mydb.myschema.user_follows user_follows
# ON tv_shows.id = user_follows.show_id AND user_follows.test = False
# WHERE tv_shows.is_test = False
# GROUP BY tv_shows.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment