https://dagster.io/ logo
Title
m

Martin O'Leary

09/23/2022, 5:38 PM
I've created a feature request here but I've since dug into the docs and found that I might be able to use MetadataValue for what I need. Is there any way to use the
MetadataValue
class to emit compiled SQL and have it print nicely in the asset catalog?
o

owen

09/23/2022, 6:35 PM
hi @Martin O'Leary! The raw sql renders nicely because we automatically render asset descriptions as markdown in the asset details page. The description we attach to the asset is generated here (basically just wrap it in triple back ticks). By default, if you just attach a bit of metadata like
{"compiled_sql": "<compiled sql goes here>"}
, this will just be formatted as normal text (even if you wrap it in triple backticks). Your intuition about using MetadataValue is totally correct though -- if instead have your metadata value be
MetadataValue.md
(md = markdown), then things will render properly. So the full solution would be passing `{"compiled_sql": MetadataValue.md("```<compiled sql goes here>```")}`
🙌 1
m

Martin O'Leary

09/26/2022, 7:44 AM
Thanks @owen - I was losing the start of my SQL somehow trying to do it via `MetadataValue.md(f"```{compiled_sql}```")` but copying your approach exactly with the indent first and then `MetadataValue.md(f"```\n{compiled_sql}\n```")` (additional newlines added) makes it work perfectly - thanks!
:rainbow-daggy: 1