joshtemple / lkml

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

lkml serializes modern `filter` syntax with curly brackets instead of square brackets #52

Closed fbertsch closed 3 years ago

fbertsch commented 3 years ago

For example:

import lkml
lkml.dump({"dimensions": [{"name": "active_this_week", "type": "yesno", "sql": "${TABLE}.atw"}], "measures": {"name": "active_this_week", "filters": {"active_this_week": "yes"}}})

This results in:

'dimension: active_this_week {\n  type: yesno\n  sql: ${TABLE}.atw ;;\n}\n\nmeasures: active_this_week {\n  filters: {\n    active_this_week: "yes"\n  }\n}'

I would expect:

'dimension: active_this_week {\n  type: yesno\n  sql: ${TABLE}.atw ;;\n}\n\nmeasures: active_this_week {\n  filters: [\n    active_this_week: "yes"\n  ]\n}'

The current version fails LookML validation.

fbertsch commented 3 years ago

Oh I see now - I need to use square brackets around the filters dict:

import lkml
lkml.dump({"dimensions": [{"name": "active_this_week", "type": "yesno", "sql": "${TABLE}.atw"}], "measures": {"name": "active_this_week", "filters": [{"active_this_week": "yes"}]}})

results in

'dimension: active_this_week {\n  type: yesno\n  sql: ${TABLE}.atw ;;\n}\n\nmeasures: active_this_week {\n  filters: [\n    active_this_week: "yes",\n  ]\n}'
fbertsch commented 3 years ago

Might be good to add a section to the docs about this.

fbertsch commented 3 years ago

@joshtemple if you're up for it, I'll put a PR in to update the docs and add some descriptions of how to use filters in the object representation.

joshtemple commented 3 years ago

Hey @fbertsch, thanks for highlighting. You're right, this isn't behavior that's immediately obvious and I'd be very grateful to accept a docs PR!