Saturno is a Visual Studio Code extension designed to facilitate connectivity and querying of Impala databases using ODBC. It provides a suite of tools to execute SQL queries, visualize results, and manage database interactions directly within the VS Code environment.
Features
- Impala Connectivity: Seamlessly connect to Impala databases using an ODBC Data Source Name (DSN), with the ability to add or remove DSNs as needed.
- Connection Management: Monitor and manage connection status via a status bar indicator, with manual connect and disconnect options.
- SQL Execution: Execute entire
.sql files or individual SQL queries with highlighted code execution.
- SQL Explain Queries: Execute EXPLAIN queries on SQL statements without manually typing the EXPLAIN keyword, providing query execution plan analysis.
- Result Visualization: View query results in an interactive, sortable table powered by DataTables with features including column sorting, search filtering, pagination, and copy-to-clipboard functionality for individual cells or entire datasets.
- CSV Export: Export query results from individual queries to CSV format.
- Query History: Access a reverse chronological list of executed queries with the ability to copy them to the clipboard.
- Database Explorer: Browse Impala databases, tables, and fields in a tree view, with options to copy table names and column lists to avoid using
SELECT * .
- Parameterized Queries: Define and manage parameters in a dedicated view, using them in queries with
{param} syntax for dynamic SQL execution.
- SQL Best Practices Validation: Automatically or manually validate SQL queries against a set of best practices to ensure code quality and performance standards.
- Snippets: Includes a collection of SQL snippets for common Impala commands, such as
CREATE , INSERT , SELECT , and more, to speed up development.
- Keyboard Shortcuts: Provides convenient keyboard shortcuts for quick access to commands, enhancing productivity.
- Logs: Access Saturno logs for debugging and monitoring purposes.
Requirements
- An installed ODBC driver for Impala compatible with your system.
- A properly configured ODBC Data Source Name (DSN) for your Impala database connection.
- Visual Studio Code version 1.87.0 or higher.
Installation
- Install the extension from the Visual Studio Code Marketplace.
- Configure the ODBC DSN in the VS Code settings (see Configuration below).
Configuration
Saturno can be configured through VS Code settings:
saturno.dsn : Specifies the ODBC DSN used to connect to Impala.
- Type: String
- Default:
"impala-prod"
- Description: The DSN configured in your ODBC driver for Impala connectivity.
To configure:
- Open VS Code settings (
Ctrl+, or Cmd+, on macOS).
- Search for
saturno.dsn and enter your DSN value.
Usage
Connect to Impala:
- Click the status bar icon (
$(plug) Impala: Desconectado ) to establish a connection.
- Alternatively, use
Alt + . to connect.
Disconnect from Impala:
- Use
Alt + , to close the active connection.
Execute Queries:
- Open any file in the editor.
Saturno: Ejecutar archivo SQL : Runs all queries in the file, separated by ; , in sequence. Use Ctrl + Shift + Enter .
Saturno: Ejecutar query SQL : Executes the SQL query at the cursor position and displays results in a table. Use Ctrl + Enter .
Saturno: Exportar query SQL a CSV : Executes the SQL query at the cursor and exports results to a CSV file. Use Alt + Enter .
Saturno: Explicar query SQL : Shows the query execution plan for the SQL query at the cursor position. Use Ctrl + Alt + Enter .
Manage Parameters:
- Open the "Saturno" view in the Activity Bar and go to the "Parameters" section.
- Add parameters using the "+" button, edit, or delete them as needed.
- Use parameters in your queries with the
{param} syntax, e.g., SELECT field1, field2 FROM table WHERE year = {anio} .
Manage DSN:
- Use
Saturno: Cambiar DSN to update the DSN manually.
Explore Database:
- Open the "Saturno" view in the Activity Bar:
- Tree: Navigate through databases, tables, and fields.
- Fields: View fields of a selected table and copy the list of fields to the clipboard.
- Copy Table Name: Right-click on a table to copy its name.
Review Query History:
- Access the "Saturno" view in the Activity Bar and navigate to the "Query History" section.
- Browse through previously executed queries in reverse chronological order.
- Click on any query to copy it to the clipboard for reuse.
SQL Best Practices Validation
Saturno includes built-in SQL best practices validation to help maintain code quality and performance standards:
- Automatic Validation: Configure validation through the
saturno.validateGoodPractices setting to automatically check queries against best practices.
- Manual Validation: Use dedicated commands to validate individual queries or entire documents on demand.
Validation Rules
When enabled, Saturno validates queries against the following SQL best practices:
- SELECT * Restrictions: Prevents the use of
SELECT * on result zone or raw data tables (tables starting with resultados_ or s_ )
- Table Wildcard Prevention: Blocks table wildcard selections like
table.*
- Subquery Restrictions: Prohibits subqueries within
IN () clauses
- INSERT VALUES Prevention: Blocks
INSERT VALUES statements to maintain data integrity
- JOIN Limitations: Limits JOIN operations to a maximum of 5 per query
- UNION Limitations: Restricts UNION operations to a maximum of 5 per query
- WITH Clause Limits: Limits WITH clauses to a maximum of 5 per query
- CASE Statement Limits: Restricts CASE statements to a maximum of 50 per query
- WHEN Clause Limits: Limits WHEN clauses to a maximum of 20 per CASE statement
Keyboard Shortcuts
Saturno provides the following keyboard shortcuts for quick access to its commands:
Command |
Windows/Linux Shortcut |
macOS Shortcut |
Saturno: Conectar a Impala |
Alt + . |
Alt + . |
Saturno: Desconectar de Impala |
Alt + , |
Alt + , |
Saturno: Ejecutar archivo SQL |
Ctrl + Shift + Enter |
Cmd + Shift + Enter |
Saturno: Ejecutar query SQL |
Ctrl + Enter |
Cmd + Enter |
Saturno: Ejecutar query SQL Explain |
Ctrl + Alt + Enter |
Cmd + Alt + Enter |
Saturno: Exportar query SQL a CSV |
Alt + Enter |
Alt + Enter |
Saturno: Validar buenas prácticas SQL |
Alt + - |
Alt + - |
Saturno: Validar documento completo |
Alt + Shift + - |
Alt + Shift + - |
Snippets
Below is a summary table of the available SQL snippets included with Saturno:
Prefix |
Label |
Description |
comment-file-sql |
Comment block file SQL |
Genera el comentario base para un archivo de código SQL |
comment-query-sql |
Comment block query SQL |
Genera el comentario base para un segmento de código SQL |
deta-alter-add-cols |
DETA ALTER TABLE add columns |
Genera comando ALTER TABLE de IMPALA para adicionar columnas a una tabla en resultados |
deta-create |
DETA CREATE table |
Genera comando CREATE de IMPALA para tabla con particiones y no transaccional en la zona de resultados_riesgos |
deta-create-kudu |
DETA CREATE Kudu table |
Genera comando CREATE de IMPALA para tabla KUDU en la zona de resultados_riesgos |
icreate |
CREATE table basic |
Genera comando CREATE Impala básico para tabla sin particiones |
icreate-full |
CREATE TEMPORAL table |
Genera comandos DROP, CREATE y COMPUTE para tabla de procesamiento |
icreate-no-p |
CREATE table |
Genera comando CREATE Impala para tabla sin particiones |
icreate-p |
CREATE PARTITIONED table |
Genera comando CREATE Impala para tabla con particiones y no transaccional |
icompute |
COMPUTE STATS |
Genera comando COMPUTE Impala |
icompute-incr |
COMPUTE INCREMENTAL STATS |
Genera comando COMPUTE INCREMENTAL STATS Impala |
idescribe |
DESCRIBE TABLE |
Genera comando DESCRIBE Impala para mostrar la estructura de una tabla |
idrop |
DROP TABLE |
Genera comando DROP Impala |
idrop-p |
DROP PARTITION |
Genera comando ALTER TABLE DROP Impala |
iinsert |
INSERT |
Genera comandos INSERT y COMPUTE Impala |
iinsert-ow |
INSERT OVERWRITE |
Genera comandos INSERT OVERWRITE y COMPUTE Impala |
iinsert-ow-p |
INSERT OVERWRITE PARTITIONED |
Genera comandos INSERT OVERWRITE y COMPUTE Impala para tabla con particiones |
iinsert-p |
INSERT PARTITIONED |
Genera comandos INSERT y COMPUTE Impala para tabla con particiones |
iselect |
SELECT |
Genera comando SELECT Impala |
ishow-partitions |
SHOW PARTITIONS |
Genera comando SHOW PARTITIONS Impala |
itruncate |
TRUNCATE TABLE |
Genera comando TRUNCATE Impala |
iwith |
WITH SELECT |
Genera un comando WITH seguido de un SELECT en Impala |
legado-deta-insert-normal |
DETA INSERT normal |
Genera comandos INSERT IMPALA para tabla con particiones en formato DETA |
legado-deta-insert-sin-frag |
DETA INSERT sin fragmentación |
Genera comandos INSERT IMPALA para tabla con particiones en formato DETA sin fragmentación |
legado-deta-insert-sin-frag-ow |
DETA INSERT sin fragmentación (overwrite) |
Genera comandos INSERT IMPALA para tabla con particiones en formato DETA sin fragmentación (overwrite) |
Logs
Logs for Saturno can be found in the Output panel of Visual Studio Code. To view logs:
- Open the Command Palette (
Ctrl + Shift + P or Cmd + Shift + P on macOS).
- Type
Output: Focus on Output View and select it.
- In the Output panel, select
Saturno logs from the dropdown to view logs related to Saturno operations.
Known Issues
- Performance may degrade with extremely large datasets.
- Some advanced Impala features might not be fully supported via ODBC.
- The extension may not handle all edge cases in SQL syntax, particularly with complex queries.
Contributing
Contributions are welcome! If you find a bug or have a feature request.
Additional Resources
Enhance your Impala workflow with Saturno in Visual Studio Code.
| |