Skip to content

Update 'not found' messaging destination in sql get_single_value macro #1049

@Mark-Johnston-Te-Whatu-Ora

Description

Describe the feature

Send Query ... returned no rows message from get_single_value macro to the debug log, consistent with similar logging output for get_column_values - see:

https://github.com/search?q=repo%3Adbt-labs%2Fdbt-utils+%22default+value%22+path%3Asql%2F&type=code

Would entail changing print to log in the get_single_value macro. If required, the macro could be updated with a 'quiet' parameter instead to simply not return any output if no value found.

Describe alternatives you've considered

To get around this we have coded manually using run_query(), replacing the print() statement with a log() statement:

   {% if execute %}
            {% set query_result = run_query(warehouse_query).columns[0].values() %}
            {% set result_count = (query_result | length) %}
            {% if result_count != 0 %}
                {% set warehouse_name = query_result[0] %}
            {% else %}
                {{ log("Query: " ~ warehouse_query ~ " returned zero rows") }}
                {% set warehouse_name = none %}
            {% endif %}
{% endif %}

Additional context

Database-agnostic

Who will this benefit?

Reduces log noise. We use a 'warehouse recommender' script in Snowflake - when it doesn't return records we get messages in the main dbt log:

03:15:05  Query `select lower('db_'||replace(recommended_warehouse,'[ENV]','prd')) from db_prd_stage.audit.warehouse_recommender where lower(dbt_object_name) = 'bring'` returned no rows. Using the default value: None
03:15:05  Query `select lower('db_'||replace(recommended_warehouse,'[ENV]','prd')) from db_prd_stage.audit.warehouse_recommender where lower(dbt_object_name) = 'production'` returned no rows. Using the default value: None
03:15:05  Query `select lower('db_'||replace(recommended_warehouse,'[ENV]','prd')) from db_prd_stage.audit.warehouse_recommender where lower(dbt_object_name) = 'likely'` returned no rows. Using the default value: None
03:15:05  Query `select lower('db_'||replace(recommended_warehouse,'[ENV]','prd')) from db_prd_stage.audit.warehouse_recommender where lower(dbt_object_name) = 'those'` returned no rows. Using the default value: None

Are you interested in contributing this feature?

I can contribute to the feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions