Skip to main content

WAII CLI Reference

The WAII CLI provides a command-line interface for interacting with WAII services.

Table of Contents

Available Commands

query

waii query create

Generate a query from text. Pass a question or instructions and receive the query in response.

Parameters

NameTypeDescription
ask - a question or set of instructions to generate the query.

Options

OptionDescription
--formatchoose the format of the response: text or json
--dialectchoose the database backend: snowflake or postgres

Examples

Example 1: Generate a query to count columns

waii query create "How many columns for each table in the database? Include table name and schema name"

SELECT
table_schema,
table_name,
COUNT(*) as num_columns
FROM information_schema.columns
GROUP BY table_schema, table_name
ORDER BY table_schema, table_name;

Example 2: Find customer spending patterns

waii query create "Find customers whose increase in spend from the first month of the year to the last month of the year has increased more in 2001 than in 2000."

WITH customer_spending AS (
SELECT
c_customer_sk,
YEAR(d_date) as year,
SUM(CASE WHEN d_moy = 1 THEN ss_net_paid ELSE 0 END) as first_month_spend,
SUM(CASE WHEN d_moy = 12 THEN ss_net_paid ELSE 0 END) as last_month_spend
FROM store_sales
JOIN date_dim ON ss_sold_date_sk = d_date_sk
WHERE YEAR(d_date) IN (2000, 2001)
GROUP BY c_customer_sk, YEAR(d_date)
)
SELECT
cs1.c_customer_sk
FROM customer_spending cs1
JOIN customer_spending cs2 ON cs1.c_customer_sk = cs2.c_customer_sk
WHERE cs1.year = 2001
AND cs2.year = 2000
AND (cs1.last_month_spend - cs1.first_month_spend) >
(cs2.last_month_spend - cs2.first_month_spend);


waii query update

Update a query from text. Pass a question or instructions and receive the query in response.

Parameters

NameTypeDescription
instructions - a set of instructions to update the query.

Options

OptionDescription
--formatchoose the format of the response: text or json.
--dialectchoose the database backend: snowflake or postgres.
--schemaoptional schema name that the query uses.

waii query explain

Explain a query.

Parameters

NameTypeDescription
query - the query to explain

Options

OptionDescription
--formatchoose the format of the response: text or json.

Examples

Example: Describe a complex query

cat my-complex-query.sql | waii query describe

Query Analysis:
--------------
This query analyzes customer spending patterns by:
1. Calculating monthly spending for each customer in 2000 and 2001
2. Comparing the spending increase between first and last months
3. Finding customers with higher spending growth in 2001 vs 2000

Tables Used:
- store_sales
- date_dim
- customer

Key Operations:
1. Joins store_sales with date_dim to get temporal information
2. Aggregates spending by customer and year
3. Self-joins results to compare year-over-year changes


waii query describe

Compare two queries and explain the differences.

Parameters

NameTypeDescription
qf_1: the first query
qf_2: the second query

Options

OptionDescription
--formatchoose the format of the response: text or json.
--dialectchoose the database backend: snowflake or postgres.
--qf_1filename of a file containing the first query
--qf_2filename of a file containing the second query

waii query rewrite

Rewrite the query in a more readable and performant way.

Options

OptionDescription
--formatchoose the format of the response: text or json
--dialectchoose the database backend: snowflake or postgres

waii query transcode

Translate queries from one dialect to another, if multiple queries are provided, they will be converted one by one.

Parameters

NameTypeDescription
ask - you can specify additional instructions to translate the query, such as 'use the test schema for converted query'

Options

OptionDescription
--formatchoose the format of the response: text or json
--fromchoose the database backend to translate from: snowflake or postgres
--tochoose the database backend to translate to: snowflake or postgres
--split_queriessplit the input into multiple queries and convert them one by one. Default is true.

Examples

Example: Convert PySpark query to Snowflake SQL

cat pyspark.sql | waii query transcode -from pyspark -to snowflake

waii query diff

Compare two queries and explain the differences.

Parameters

NameTypeDescription
qf_1: the first query
qf_2: the second query

Options

OptionDescription
--formatchoose the format of the response: text or json.
--dialectchoose the database backend: snowflake or postgres.
--qf_1filename of a file containing the first query
--qf_2filename of a file containing the second query

waii query run

Execute the query and return the results

Parameters

NameTypeDescription
query - you can specify the query to run as a parameter.

Options

OptionDescription
--formatchoose the format of the response: text or json
--schemause the schema given as the schema for the query. format: <db>.<schema>

Examples

Example: Run a complex query

cat <<EOF | waii query run
WITH joined_data AS (
SELECT
c.name AS country_name,
ci.population AS city_population
FROM tweakit_playground.world.city AS ci
INNER JOIN tweakit_playground.world.country AS c
ON ci.countrycode = c.code
)

SELECT
country_name,
AVG(city_population) AS avg_city_population
FROM joined_data
GROUP BY
country_name
EOF

┌─────────────────┬────────────────────┐
│ country_name │ avg_city_population│
├─────────────────┼────────────────────┤
│ United States │ 286,955 │
│ China │ 842,233 │
│ India │ 534,489 │
└─────────────────┴────────────────────┘


waii query analyze

Analyze query performance.

Parameters

NameTypeDescription
query - you can specify the query to run and analyze as a parameter.

Options

OptionDescription
--formatchoose the format of the response: text or json
--queryYou can specify the query to run and analyze as an option as well
--query_idYou can specify a query that ran already and get performance insights.
--summaryPrint the performance analysis summary.
--recommendationsPrint recommendations on how to improve the query.
--query_textPrint query (useful when you're using query_id)
--timesPrint the query execution and compile time.

waii query generate_question

Generate questions based on the database schema.

Options

OptionDescription
--schemaName of the schema to generate questions for.
--complexityComplexity of the questions to generate: easy, medium, hard
--n_questionsNumber of questions to generate
--formatchoose the format of the response: text or json

database

waii database list

List all the configured databases.

Options

OptionDescription
--formatchoose the format of the response: text or json.
--all_userslist all database connections (for admins)
--user_idlist database connections by impersonating another user

Examples

Example: List all databases

waii database list

┌──────────────────┬────────────────────┬────────────┬───────────────────┬──────────────┐
│ account_name │ database │ warehouse │ role │ username │
├──────────────────┼────────────────────┼────────────┼───────────────────┼──────────────┤
│ gq.........91428 │ TWEAKIT_PLAYGROUND │ COMPUTE_WH │ TWEAKIT_USER_ROLE │ TWEAKIT_USER │
└──────────────────┴────────────────────┴────────────┴───────────────────┴──────────────┘


waii database add

Add a database connection.

Options

OptionDescription
--formatchoose the format of the response: text or json.
--db_typetype of database (snowflake, postgresql, mysql, oracle, etc.)
--connect_stringspecify connection string instead of individual fields
--accountaccount name (required for snowflake)
--dbdatabase name
--warehousewarehouse name (required for snowflake)
--rolerole name (required for snowflake)
--useruser name
--passwordpassword
--hosthost name (required for postgresql, mysql, oracle, etc.)
--portport number (optional for postgresql, mysql, oracle, etc.)
--pathpath (used for sqlite)
--no_column_samplesif set, will not sample columns

Examples

Example: Add a snowflake database

waii database add --account 'xxxxx-yyyyy' --db '<DB>' --warehouse '<COMPUTE_WH>' --role '<YOUR_SNOWFLAKE_ROLE>' --user '<YOUR_SNOWFLAKE_USER>' --password '********'

Example: Add a PostgreSQL database

waii database add --db_type postgresql --host 'localhost' --db 'mydatabase' --user 'dbuser' --password 'password'

Example: Add a database using connection string

waii database add --connect_string 'postgresql://user:password@localhost:5432/mydatabase'

waii database delete

Delete a database connection.

Parameters

NameTypeDescription
url - the database key to be deleted.

Options

OptionDescription
--formatchoose the format of the response: text or json.
--all_usersdelete all database connections (for admins)
--user_iddelete database connections by impersonating another user

waii database activate

Activate a database for use in generating queries and getting table information.

Parameters

NameTypeDescription
url - URL of the database to activate (can be found by running 'waii database list')

Examples

Example: Activate a database

waii database activate <url_of_the_database>

Note: The URL can be found by running 'waii database list'


waii database describe

Describe the current database.

Options

OptionDescription
--formatchoose the format of the response: text or json.

waii database extract_doc

Extract database documentation.

Options

OptionDescription
--urlWeb URL to extract documentation from.
--fileFile path to extract documentation from.
--doc_typeContent type of the file, text/html, etc.
--schemasComma separated list of schemas to extract documentation from. If not provided, will search in all schemas.
--tablesComma separated list of tables to extract documentation from. If schema is not provided, will search in all tables.
--updateIf set to true, will update the existing semantic context, default is false.

Examples

Example: Extract documentation from a web page

waii database extract_doc --url "https://fleetdm.com/tables/chrome_extensions" --update true

Example: Extract documentation from a text file

waii database extract_doc --file "path/to/file.txt" --doc_type text --update false

Example: Extract documentation from a local HTML file

waii database extract_doc --file "path/to/file.html" --doc_type html --update true

Options:

  • --file: The URL of the web page or the path to the text file.
  • --doc_type: The type of the documentation (only applies to file). It can be html, text. Default is text.
  • --url: The URL of the web page. (Note that you can only use --file or --url at a time)
  • --update: If set to true, the extracted documentation will be updated in the database. If set to false, the extracted documentation will be displayed in the console.
  • --tables: The name of the tables where the documentation will be mapped to. By default we will search all the tables in the database.
  • --schemas: The name of the schemas where the documentation will be mapped to. By default we will search all the schemas in the database.

context

waii context list

List all semantic context of the current database.

Options

OptionDescription
--limitHow many statements to fetch
--offsetWhich statement to start with
--searchWhich string to search for in the statements
--always_includeFilter that decides which type of statement to fetch
--formatChoose the format of the response: text or json.

waii context add

Create a new semantic statement in the semantic context.

Parameters

NameTypeDescription

Options

OptionDescription
--formatchoose the format of the response: text or json.
--scopeThe scope of the statement: [[[[<db>].<schema>].<table>].<column>]
--labelsComma separated list of labels for the statement: 'performance, finance'
--always_includeWhether the statement should be dynamically selected by query or always included.
--lookup_summariesComma separated list of summaries to use.
--summarization_promptPrompt to be used to extract information when the statement is used.

waii context delete

Delete a statement from the semantic context.

Parameters

NameTypeDescription
uuid of the statement to be deleted.

Options

OptionDescription
--formatchoose the format of the response: text or json.

waii context import

Import semantic statements in bulk. Duplicates will be ignored.


waii context delete_all

Delete all added semantic contexts from the database


schema

waii schema describe

Get a generated description of a schema.

Parameters

NameTypeDescription
schema_name - name of the schema to describe

Options

OptionDescription
--formatchoose the format of the response: text or json

Examples

Example: Describe a schema

waii schema describe RETAIL_DATA

Schema:
-------
TWEAKIT_PLAYGROUND.RETAIL_DATA

Description:
------------
The TWEAKIT_PLAYGROUND.RETAIL_DATA schema contains tables related to retail data analysis, including
information about call centers, customers, addresses, demographics, dates, household demographics,
income bands, inventory, items, promotions, reasons, stores, store returns, store sales, time
dimensions, and warehouses.

Tables:
-------
┌────────────────────────┐
│ table │
├────────────────────────┤
│ PROMOTION │
│ STORE_SALES │
│ ITEM │


waii schema list

Show all available schemas.

Options

OptionDescription
--formatchoose the format of the response: text or json.

waii schema update

Update the textual description of a schema.

Parameters

NameTypeDescription
<db>.<schema> - name of the schema to change
description - description to use.

waii schema update_questions

Update the common questions stored for a schema.

Parameters

NameTypeDescription
<db>.<schema> - name of the schema to change
questions - three individual questions to use.

waii schema update_summary

Update the textual summary of a schema.

Parameters

NameTypeDescription
<db>.<schema> - name of the schema to change
description - description to use.

waii schema migrate

Create SQL statement that migrates all table of a schema from one database to another.

Parameters

NameTypeDescription
<db>.<schema> - name of the schema to migrate
<db>.<schema> - destination schema.

Options

OptionDescription
--sourcekey of the source database, see 'waii database list' for options
--destinationkey of the destination database.

table

waii table describe

Show the details of a table.

Parameters

NameTypeDescription
<db>.<schema>.<table> - table name of the table to describe.

Options

OptionDescription
--formatchoose the format of the response: text or json.

waii table list

List all tables in the current database.

Options

OptionDescription
--formatchoose the format of the response: text or json

Examples

Example: List all tables in the current database

waii table list

Output:
┌──────────────────────────────────────────────────────────────────────────────────────┐
│ INFORMATION_SCHEMA │
├──────────────────────────────────────────────────────────────────────────────────────┤
│ ENABLED_ROLES TABLES COLUMNS │
│ SEQUENCES VIEWS TABLE_PRIVILEGES │
│ DATABASES REPLICATION_DATABASES REPLICATION_GROUPS │
└──────────────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────────────┐
│ RETAIL_DATA │
├──────────────────────────────────────────────────────────────────────────────────────┤
│ PROMOTION STORE_SALES ITEM STORE │
│ DATE_DIM HOUSEHOLD_DEMOGRAPHICS TIME_DIM CUSTOMER │
└──────────────────────────────────────────────────────────────────────────────────────┘


waii table update

Update the textual description of a table.

Parameters

NameTypeDescription
<db>.<schema>.<table> - name of the table to change
description - description to use.

waii table migrate

Create SQL statement that migrates a table from one database to another.

Parameters

NameTypeDescription
<db>.<schema>.<table> - name of the table to migrate
<db>.<schema> - destination schema.

Options

OptionDescription
--sourcekey of the source database, see 'waii database list' for options
--destinationkey of the destination database.

waii table ddl

Convert from table definition to ddl


history

waii history list

Show the query history.

Options

OptionDescription
--formatchoose the format of the response: text or json.
--limitchoose how many items to list.
--likedonly display liked queries

user

waii user create_access_key

Create a new access key for a user.

Parameters

NameTypeDescription
namestringThe name of the access key to create.

waii user list_access_keys

List all access keys for the user.


waii user delete_access_key

Delete specified access keys for the user.

Parameters

NameTypeDescription
namesstring[]An array of strings denoting the names of the access keys to be deleted.

waii user info

Retrieve information about the user.


waii user update_config

Update the user's configuration settings.

Options

OptionDescription
--key=valueSpecify key-value pairs to update in the configuration.
--key=deleteSpecify keys to delete from the configuration.

waii user create

Create a new user.

Parameters

NameTypeDescription
userIdstringThe unique ID of the user to be created.

Options

OptionDescription
--nameThe display name of the user.
--tenant_idThe tenant ID of the user.
--org_idThe organization ID of the user.
--variablesA JSON string representing the user's variables.
--rolesA comma-separated list of roles assigned to the user.

waii user delete

Delete an existing user.

Parameters

NameTypeDescription
userIdstringThe user ID of the user to be deleted.

waii user update

Update information about an existing user.

Parameters

NameTypeDescription
userIdstringThe unique ID of the user to be updated.

Options

OptionDescription
--nameThe display name of the user.
--tenant_idThe tenant ID of the user.
--org_idThe organization ID of the user.
--variablesA JSON string representing the user's variables.
--rolesA comma-separated list of roles assigned to the user.

waii user list

Retrieve a list of users.

Options

OptionDescription
--lookup_org_idThe organization ID for which the users are to be retrieved.

waii user create_tenant

Create a new tenant.

Parameters

NameTypeDescription
tenantIdstringThe unique ID of the tenant to be created.

Options

OptionDescription
--nameThe display name of the tenant.
--org_idThe organization ID of the tenant.
--variablesA JSON string representing the tenant's variables.

waii user update_tenant

Update an existing tenant.

Parameters

NameTypeDescription
tenantIdstringThe unique ID of the tenant to be updated.

Options

OptionDescription
--nameThe display name of the tenant.
--org_idThe organization ID of the tenant.
--variablesA JSON string representing the tenant's variables.

waii user delete_tenant

Delete an existing tenant.

Parameters

NameTypeDescription
tenantIdstringThe ID of the tenant to be deleted.

waii user list_tenant

Retrieve a list of tenants.

Options

OptionDescription
--lookup_org_idThe organization ID for which the tenants are to be retrieved.

waii user create_org

Create a new organization.

Parameters

NameTypeDescription
organizationIdstringThe unique ID of the organization to be created.

Options

OptionDescription
--nameThe display name of the organization.
--variablesA JSON string representing key-value pairs of organization variables.

waii user update_org

Update an existing organization.

Parameters

NameTypeDescription
organizationIdstringThe unique ID of the organization to be updated.

Options

OptionDescription
--nameThe display name of the organization.
--variablesA JSON string representing key-value pairs of organization variables.

waii user delete_org

Delete an existing organization.

Parameters

NameTypeDescription
organizationIdstringThe unique ID of the organization to be deleted.

waii user list_org

List all organizations.


semantic-layer

waii semantic-layer export

Export semantic layer configuration for a database connection.

Options

OptionDescription
--db_conn_keyRequired. Database connection key
--filePath to the output file. If not specified, prints to stdout.
--formatOutput format: yaml (default) or json.
--search_contextOptional JSON string with search context parameters
--poll_intervalInterval in ms to poll for export status (default: 1000)
--timeoutTimeout in ms for export operation (default: 300 seconds)
--max_retriesMaximum number of retries when operation status returns 'not_exists' (default: 3). This can happen when the server has already processed and cleared the operation.
--verboseShow verbose debug information and display neatly formatted statistics

waii semantic-layer import

Import semantic layer configuration for a database connection.

Options

OptionDescription
--db_conn_keyRequired. Database connection key
--fileRequired. Path to the input file containing the configuration
--formatInput format: auto (default), yaml, or json
--schema_mappingOptional JSON string with schema mapping
--database_mappingOptional JSON string with database mapping
--strict_modeEnable strict validation of the import configuration (default: false)
--dry_run_modeSimulate the import without making actual changes and show detailed output (default: false)
--detailedShow full JSON response from server
--poll_intervalInterval in ms to poll for import status (default: 1000)
--timeoutTimeout in ms for import operation (default: 5 minutes)
--max_retriesMaximum number of retries when operation status returns 'not_exists' (default: 5).
--verboseShow verbose debug information and display detailed import statistics

docs

waii docs generate

Generate CLI documentation


Common Examples

waii database list
waii database list --format json
waii context list
waii context list --format json
waii schema describe schema_name
waii table describe schema_name.table_name
waii history
waii history list --format json