joshtemple / lkml

A speedy LookML parser & serializer implemented in pure Python.
MIT License
166 stars 31 forks source link

Parsing *.dashboard.lookml files #79

Closed wsjk closed 1 year ago

wsjk commented 1 year ago

It doesn't seem like this package supports parsing of LookML dashboard files?

Currently getting this error:

Traceback (most recent call last):

  File /opt/anaconda3/envs/flask/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3433 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Cell In [10], line 17
    result = lkml.load(f)

  File /opt/anaconda3/envs/flask/lib/python3.9/site-packages/lkml/__init__.py:50 in load
    tree: DocumentNode = parse(text)

  File /opt/anaconda3/envs/flask/lib/python3.9/site-packages/lkml/__init__.py:29 in parse
    tree: DocumentNode = parser.parse()

  File /opt/anaconda3/envs/flask/lib/python3.9/site-packages/lkml/parser.py:214 in parse
    container = self.parse_container()

  File /opt/anaconda3/envs/flask/lib/python3.9/site-packages/lkml/parser.py:39 in wrapper
    result = fn(self, *args, **kwargs)

  File /opt/anaconda3/envs/flask/lib/python3.9/site-packages/lkml/parser.py:254 in parse_container
    raise SyntaxError(

  File <string>
SyntaxError: Unable to find a matching expression for '<literal>' on line 1
joshtemple commented 1 year ago

I haven't explicitly tested it with LookML dashboard files. If you're able to upload a snippet of LookML that reproduces the error, I can try and work out a fix.

wsjk commented 1 year ago

Sure here's an example you can get when in an Explore and using Get LookML to get the LookML for dashboard tile.

For me it would be really nice if we could parse/extract the explore and model parameter values in dashboard tiles because I'm trying to build a network graph to document lineage from source SQL table to Dashboard using lkml. So far I can only get from SQL Table to Explore/Derived Table.

- name: add_a_unique_name_1683211649
  title: Untitled Visualization
  model: core
  explore: some_explore
  type: looker_grid
  fields: [some_explore.day, some_explore.id]
  filters:
    some_explore.date: 2023/04/30
  sorts: [some_explore.day desc]
  limit: 500
  column_limit: 50
  show_view_names: false
  show_row_numbers: true
  transpose: false
  truncate_text: true
  hide_totals: false
  hide_row_totals: false
  size_to_fit: true
  table_theme: white
  limit_displayed_rows: false
  enable_conditional_formatting: false
  header_text_alignment: left
  header_font_size: 12
  rows_font_size: 12
  conditional_formatting_include_totals: false
  conditional_formatting_include_nulls: false
  defaults_version: 1
mustafahasankhan commented 1 year ago

@wsjk dashboard.lookml are not lkml files, they are simple yaml files.

joshtemple commented 1 year ago

Closing as @mustafahasankhan is right, these are YAML files and can be parsed with any Python YAML parser.