tb fmt¶
Formats a .datasource or .pipe file. .connection files are not yet supported.
These are the options available for the fmt command:
| Option | Description |
|---|---|
| --line-length INTEGER | A 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-run | Don't ask to overwrite the local file. |
| --yes | Don't ask for confirmation to overwrite the local file. |
| --diff | Outputs 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"
The command formats them as follows:
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 format your files. If the SQL formatting results aren't what you expect, you can exclude specific blocks from formatting. Read how to exclude blocks from formatting.