Skip to main content
On this page

Kater CLI Build an analysis source

kater source write

Creates a file, or replaces a whole file, with your text.

Use it for a change that no other kater command makes, such as a hand-written query. Kater checks a SQL file before it saves it.

Examples

Terminal window
# Go to the ad_reporting workspace in your local copy of Kater content
cd connections/snowflake_prod_connection/workspaces/ad_reporting
# Create the clicks_by_platform query from the text that follows
kater source write query_contracts/clicks_by_platform.sql --text-file - <<'SQL'
---
name: clicks_by_platform
model_type: query
---
SELECT ad_reporting.platform, ad_reporting.sum__clicks
FROM workspace.ad_reporting AS ad_reporting
GROUP BY ad_reporting.platform
SQL
# Note the revision of the spend_by_platform query before you edit a copy of it
before=$(shasum -a 256 query_contracts/spend_by_platform.sql | cut -d ' ' -f 1)
# Save your edited copy, spend_by_platform_edit.sql, and stop if the query changed since
kater source write query_contracts/spend_by_platform.sql --text-file spend_by_platform_edit.sql --expected-revision "$before"

Arguments

ArgumentDescription
<file>The file to create or replace, by its path from the folder you are in.

Options

OptionDescription
--text-file <file>Required. A file that holds the complete new text. - reads it from standard input.
--expected-revision <sha>The SHA-256 of the file as you read it. Kater refuses the write when the file changed since. shasum -a 256 gives it for a file in your local copy.

It also takes the global options --json, --kater-root, --scope and --help.

What Kater checks before it saves

  • A .sql file is formatted and compiled. Kater declares each parameter that the SQL reads and the file does not declare. A file that does not compile is refused with the compiler’s diagnostics, and nothing is saved.
  • A file in a brainstorm copy of a workspace is saved even when it does not compile. The answer lists its errors.
  • Any other text file is saved as you send it. A YAML file must parse.
  • connection.yaml is saved only when the whole file passes the checks of kater admin connection update.

See also