使用SQL和Jinja的DBT宏
我已经写了DBT宏,并在尝试部署时会出现错误。我认为它不会转换为适当的SQL。
momcalc.sql
{% macro MoMCalc(val,Effectivedate,Frequency) %}
case
when "Frequency" LIKE '%Weekly%' then {{val}} - LAG({{val}}, 4) OVER (Order by '{{Effectivedate}}')
when "Frequency" LIKE '%Monthly%' then {{val}} - LAG({{val}}, 1) OVER (Order by '{{Effectivedate}}')
end
{% endmacro %}
错误 -
syntax error line 32 at position 0 unexpected 'case'.
20:33:23 syntax error line 33 at position 53 unexpected 'Value'.
20:33:23 syntax error line 33 at position 63 unexpected 'OVER'.
20:33:23 syntax error line 33 at position 88 unexpected 'Date'
I have written the DBT macro and getting error when trying to deploy. I think it's not getting converted to proper sql.
MoMCalc.sql
{% macro MoMCalc(val,Effectivedate,Frequency) %}
case
when "Frequency" LIKE '%Weekly%' then {{val}} - LAG({{val}}, 4) OVER (Order by '{{Effectivedate}}')
when "Frequency" LIKE '%Monthly%' then {{val}} - LAG({{val}}, 1) OVER (Order by '{{Effectivedate}}')
end
{% endmacro %}
Error -
syntax error line 32 at position 0 unexpected 'case'.
20:33:23 syntax error line 33 at position 53 unexpected 'Value'.
20:33:23 syntax error line 33 at position 63 unexpected 'OVER'.
20:33:23 syntax error line 33 at position 88 unexpected 'Date'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
target/Commied/
目录中查看编译代码。 (您需要查找调用此宏的模型文件的编译版本)。这会让您了解出了什么问题。我实际上认为,在您在模型文件中调用宏之前,您可能只是缺少逗号?
我的另一个猜测(有限的上下文)是,您没有在宏中使用curlies围绕
频率
的参数使用。假设您需要在SQL 中围绕传递到频率
的值中的双引号:然后调用要使用的宏:
You can view the compiled code in the
target/compiled/
directory. (You'll want to look for the compiled version of the model file where you call this macro). That'll give you a sense for what went wrong.I actually think you might just be missing a comma before you call the macro, in your model file?
My other guess (with limited context) is that you're not using curlies around the argument named
Frequency
in your macro. This should work, assuming you want double quotes in the SQL around the value passed intoFrequency
:Then to call that macro you want to use: