rittmananalytics / droughty

Droughty helps keep your workflow dry
https://droughty.readthedocs.io/en/latest/
MIT License
62 stars 6 forks source link

Issue 83 | Droughty updated to handle nested fields for Looker #85

Closed LydiaB123 closed 2 months ago

LydiaB123 commented 2 months ago

Issue: Droughty LookML does not work with BigQuery Records #83

Updates to Code

Overall this PR includes updates to allow LookML to handle nested fields.

This PR includes updates to the following files:

lookml_base_dict.py

Added function flatten_dict:

lookml_module.py

Logic added to handle nested fields, this include:

Testing

This new code has been tested on a repo which contains a data warehouse using dbt and lookml.

Here is an example of new lookml that has been created:

view: wh_utilisation__jira_users_dim {
sql_table_name: wh_utilisation__jira_users_dim ;;
set: wh_utilisation__jira_users_dim_set {
  fields: [
    jira_user_pk,
    user_locale,
    user_id,
    user_name,
    user_is_actives_shared,
    user_time_zone,
    user_email,
    user_group_names,
  ]
}
dimension: jira_user_pk {
  primary_key: yes
  hidden: yes
  type: string
  sql: ${TABLE}.jira_user_pk ;;
  description: "not available"
}
dimension: user_id {
  type: string
  sql: ${TABLE}.user_id ;;
  description: "not available"
  drill_fields: [wh_utilisation__jira_users_dim_set*]
}
dimension: user_name {
  type: string
  sql: ${TABLE}.user_name ;;
  description: "not available"
  drill_fields: [wh_utilisation__jira_users_dim_set*]
}
dimension: user_email {
  type: string
  sql: ${TABLE}.user_email ;;
  description: "not available"
  drill_fields: [wh_utilisation__jira_users_dim_set*]
}
dimension: user_locale {
  type: string
  sql: ${TABLE}.user_locale ;;
  description: "not available"
  drill_fields: [wh_utilisation__jira_users_dim_set*]
}
dimension: user_time_zone {
  type: string
  sql: ${TABLE}.user_time_zone ;;
  description: "not available"
  drill_fields: [wh_utilisation__jira_users_dim_set*]
}
dimension: user_is_actives_shared {
  type: yesno
  sql: ${TABLE}.user_is_actives_shared ;;
  description: "not available"
  drill_fields: [wh_utilisation__jira_users_dim_set*]
}
dimension: user_group_names {
  type: string
  sql: ${TABLE}.user_group_names ;;
  description: "not available"
  drill_fields: [wh_utilisation__jira_users_dim_set*]
}
}
view: wh_utilisation__jira_users_dim__user_group_names {
sql_table_name: wh_utilisation__jira_users_dim ;;
dimension: user_group_name {
  type: string
  sql: ${TABLE}.user_group_name ;;
  description: ""
}
}
explore: wh_utilisation__jira_users_dim
{hidden: yes

join: wh_utilisation__jira_users_dim__user_group_names {
  view_label: "wh_utilisation__jira_users_dim: Wh Utilisation  Jira Users Dim  User Group Names"
  sql: left join unnest($wh_utilisation__jira_users_dim.jira_users_dim) AS wh_utilisation__jira_users_dim__user_group_names ;;
  relationship: one_to_many
}
}

Here is a screenshot to show the validation of LookML code:

Screenshot 2024-07-17 at 12 20 33 Screenshot 2024-07-17 at 12 20 26