sqlfluff / sqlfluff

A modular SQL linter and auto-formatter with support for multiple dialects and templated code.
https://www.sqlfluff.com
MIT License
7.99k stars 734 forks source link

Support DBT `modules` in jinja templating #6470

Open mroy-seedbox opened 6 days ago

mroy-seedbox commented 6 days ago

Search before asking

Description

DBT exposes a modules variable which can be used to access some python modules: datetime, pytz, re, and itertools.

Is there any way to define a template variable as a callable?

Dialect

Any.

Are you willing to work on and submit a PR to address the issue?

Although I do not have the time at the moment.

Code of Conduct

mroy-seedbox commented 6 days ago

I think it should be doable for SQLFluff to expose these python modules as well.

But in the meantime, a workaround is to wrap the methods that we need in a macro, and them configure the macro in [sqlfluff:templater:jinja:macros].