tb fmt

Formats a .datasource or .pipe file. .connection files are not yet supported.

These are the options available for the fmt command:

OptionDescription
--line-length INTEGERA number indicating the maximum characters per line in the node SQL, lines split based on the SQL syntax and the number of characters passed as a parameter.
--dry-runDon't ask to overwrite the local file.
--yesDon't ask for confirmation to overwrite the local file.
--diffOutputs correctly formatted block (if differs from local file) and prompts to apply correction to local file.

This command applies opinionated formatting rules and may reorder file properties for consistency. For example, these properties:

ENGINE "MergeTree"
ENGINE_SORTING_KEY "name"
ENGINE_PARTITION_KEY "name"

will be formatted as:

ENGINE MergeTree
ENGINE_PARTITION_KEY name
ENGINE_SORTING_KEY name

This command removes comments starting with # from the file, so use DESCRIPTION or a comment block instead:

Example comment block
%
{% comment this is a comment and fmt keeps it %}

SELECT
  {% comment this is another comment and fmt keeps it %}
  count() c
FROM stock_prices_1m

You can add tb fmt to your git pre-commit hook to have your files properly formatted. If the SQL formatting results aren't what you expect, you can disable it just for the blocks needed. Read how to disable fmt.

Updated