Question

LookML tip - arbitrary code folding

  • 12 October 2017
  • 0 replies
  • 190 views

Hopefully this hasn’t been posted before; I did a bit of searching and couldn’t find anything.


I’ve noticed a way to put arbitrary groupings into (new) LookML by using commented-out brackets, allowing you to fold up parts of your LookML code.


Imagine you have a view with lots and lots of dimensions:


  dimension: user_id {
description: "Unique ID for each user that has ordered"
type: number
sql: ${TABLE}.user_id ;;
}

dimension: lifetime_orders {
description: "The total number of orders for each user"
type: number
sql: ${TABLE}.lifetime_orders ;;
}

# ...
# many more dimensions
# ...

dimension_group: most_recent_purchase {
description: "The date when each user last ordered"
type: time
timeframes: [date, week, month, year]
sql: ${TABLE}.most_recent_purchase_at ;;
}

Add commented-out brackets surrounding these dimensions:


 # my long list of dimensions {
dimension: user_id {
description: "Unique ID for each user that has ordered"

# ... (lots more LookML) ...

sql: ${TABLE}.most_recent_purchase_at ;;
}
# } / my long list of dimensions

Now the LookML editor recognises the pair of brackets despite them being inside comments, and lets you fold/collapse the code between to see something like this instead:



Pretty handy when dealing with views with lots of fields, as I’m sure most of us do!


0 replies

Be the first to reply!

Reply