I'm using the jinja functions run_query and execute.
https://docs.getdbt.com/reference/dbt-jinja-functions/run_query
But when sqlfluff lint I get the following error:
Undefined jinja template variable: 'run_query'
I'm trying to add it to the .sqlfluff config but there doesn't seem to be any guidance anywhere on how to add this to the config file.
Any help would be greatly appreciated!
Thanks
Add templater=dbt in your .sqlfluff config file.
More info here.
I have managed to figure out how to add run_query:
run_query = {% macro run_query(query) %}'query'{% endmacro %}
But I am still unsure on how to add execute to the .sqlfluff config. Figured it!
execute = {% macro execute() %}True{% endmacro %}
Related
I am trying to dynamically create HTTP Request body for a POST by using JSR223 Preprocessor. Below is the code that I tried. But it is not working. Request body is populating as empty. Can anyone help?
def arg= new HTTPArgument("", dataToBePosted, null, true);
arg.setAlwaysEncoded(false);
sampler.getArguments().addArgument(arg);
I also tried
sampler.getArguments().removeAllArguments();
sampler.addNonEncodedArgument('',dataToBePosted,'');
Take a look at jmeter.log file, it might be the case you have a problem in your Groovy code, i.e. I fail to see dataToBePosted declared/initialized anywhere
Even if it is good it won't survive first iteration, I would suggest using Arguments class instance instead
Example code:
def data = new org.apache.jmeter.config.Arguments()
def body = new org.apache.jmeter.protocol.http.util.HTTPArgument('', 'dataToBePosted', '', false)
body.setAlwaysEncoded(false)
data.addArgument(body)
sampler.setArguments(data)
and demo:
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?
I'm trying to configure a DBT model as materialized='incremental', which is failing as DBT seems to be wrapping my model with a check on (None) or (None) is null which causes the model to throw a SQL exception against the target (Bigquery). The (None) checks don't seem to get added for non-incremental models, or when running with --full-refresh which just re-create the table.
According to the docs, incremental models are supposed to be wrapped as follows:
merge into {{ destination_table }} DEST
using ({{ model_sql }}) SRC
...
However what I'm seeing is:
merge into {{ destination_table }} DEST
using ( select * from( {{ model_sql }} ) where (None) or (None) is null) SRC
...
It's not clear to me where the (None) check are coming from, what it's actually trying to achieve by wrapping the query, and what (if any) model config would need to be set to correct this.
My model's config is set as {{ config(materialized='incremental', alias='some_name') }}, and I've tried also setting unique_key just in case with no luck.
I'm running the model with dbt run --profiles-dir dbt_profiles --models ${MODEL} --target development, and can confirm the compiled model is fine and the (None) checks get added for the model run.
I'm running dbt 0.11.1 (old repo version).
Any help would be most appreciated!
Managed to resolve this by looking into the DBT codebase on github for my target version - incremental macro 0.11
Seems like in 0.11 DBT expects a sql_where config flag to be set, which is used to select which records you want to use for the incremental load (pre-cursor to is_incremental() macro).
In my case, as I just want to load all rows in each incremental run and tag with the load timestamp, Setting sql_where='TRUE' generates valid sequel and doesn't filter my results (ie. WHERE TRUE OR TRUE IS NULL)
have you had an incremental model configured beforehand with 0.11.1? I'm pretty sure you need to use {{ this }} but maybe that didn't exist in version 0.11.1. docs on this
According to DBT's docs on modules to use within jinja functions - https://docs.getdbt.com/reference/dbt-jinja-functions/modules - modules.re should be available. However, there is this macro I am working with:
{% macro camel_to_snake_case(camel_case_string) -%}
{{ modules.re.sub('([A-Z][a-z]|[A-Z]*[0-9]+)', '_\\1', modules.re.sub('([A-Z]+[A-Z]([a-z]|$))', '_\\1', camel_case_string)) | trim('_') | lower() }}
{%- endmacro %}
and whenever a script is run that uses this macro, i receive the error:
Running with dbt=0.17.0
Encountered an error:
Compilation Error in model model_using_macro (models/model_using_macro.sql)
'dict object' has no attribute 're'
Do I need to install something in order to access the modules.re function? Maybe the base dbt I have installed doesn't have this modules at all? Perhaps there is a way I can check the output for modules to see why re is missing, and what else might be available / missing? I'm not sure why else this error could be happening?
Try upgrading dbt, re was added in 0.19.0 (source)
Good day!
Please advice, is it possible to evaluate previously defined variable in further block. Example showed below.
host:
url: https://example.com
config: |
some data
some data
{{ host.url }}/api/v1/
Thank you in advance!
Following the answer on How to define custom configuration variables in rails, I am trying to set up a configuration settings for different environments in config/environments/{env}.rb
e.g. in development.rb I set
config.elvis = 'alive'
and then in my haml template I can use this variable, e.g.
Elvis is #{Rails.configuration.elvis}.
However, when I want to wrap this in a condition:
- if Rails.configuration.elvis
<p>Elvis is #{Rails.configuration.elvis}</p>
it also works, but if the configuration isn't set, it throws a undefined method error.
If I try instead:
- if defined? Rails.configuration.elvis
<p>Elvis is #{Rails.configuration.elvis}</p>
it seems to always evaluate as false, even with the configuration defined.
Still very new to rails/ruby, so apologies if it's a very dumb question
You could use respond_to?:
- if Rails.configuration.respond_to?(:elvis)
<p>Elvis is #{Rails.configuration.elvis}</p>