sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Test sql formatting

Open achicoine-coveo opened this issue 7 months ago • 0 comments

I understand this is more of a stretch, but if sqlmesh format could format the sql included in tests it would be a killer feature.

For example you can define test data like this:

test_attributed_queries:
  model: staging.attributed_queries
  inputs:
    source.query_history:
      # Use sql entry, so we can parse_json the query_tags correctly. Have to put all columns in the right order.
      query: |
        -- no query tag
        SELECT 
        '123' as query_id,
        null as query_type,
        'svc_bob' as user_name,
        null as role_name,
        null as warehouse_id,
        'common' as warehouse_name,
        'X-Small' as warehouse_size,
        'STANDARD' as warehouse_type,
        null as cluster_number,
        null as query_tag,
        cast('2024-06-01 01:05:00 +0000' as timestamptz) as start_time,
        null as total_elapsed_time,
        null as compilation_time,
        5 as execution_time,
        null as credits_used_cloud_services 

It should be possible for the formatter to extract the sql from the test, format it, and put it back.

achicoine-coveo avatar Jul 10 '24 11:07 achicoine-coveo