fix(dbt-derived-metrics): Support raw metrics and Jinja syntax #277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
dbt allows the creation of derived metrics with just raw SQL, not involving any other dbt metric:
These would currently fail to sync, as derived metrics don't have a
model
definition, so currently the CLI identifies the desired model by getting the models used by the metrics used in the syntax (which don't exist in this case).To support this flow, the CLI now will get the model's
unique_id
frommeta.superset.model
for such metrics:the
{% raw %}
macro also allows users to use Superset-specific Jinja in their metrics:These were currently failing as we rely on
sqlglot
to parse the derived metrics and replace a metricname
with its sql syntax. This PR changes the logic so that the SQL parsing is skipped in case the derived metric doesn't really include other metrics. In case it's a combination of Superset-Jinja + dbt Jinja (like the second example), the CLI will catch theParseError
exception and will perform a replace with regex for the metric (definitely not as stable as SQL parsing, but hoping to increase compatibility with these types of metrics).These changes are currently aiming older versions of dbt -- going to also perform some tests with
MetricFlow
/new semantic layer to validate if these flows are supported in newer versions, to assess how to also support them with the CLI.