Databricks Driver for SQLTools for Visual Studio Code
Preview
This feature is in Public Preview.
The Databricks Driver for SQLTools enables you to use the SQLTools extension for Visual Studio Code to browse SQL objects and to run SQL queries in remote Databricks workspaces.
Before you begin
Before you can use the Databricks Driver for SQLTools, your Databricks workspace and your local development machine must meet the following requirements.
Workspace requirements
You must have at least one Databricks workspace available, and the workspace must meet the following requirements:
The workspace must contain at least one Databricks SQL warehouse.
Note
Databricks clusters are not supported by the Databricks Driver for SQLTools.
For workspaces that are enabled for Unity Catalog, the workspace must contain at least one catalog, with at least one schema (formally called a database) within that catalog.
For workspaces that are not enabled for Unity Catalog, the workspace must contain at least one schema (formerly called a database).
Local development machine requirements
You must have the following on your local development machine:
Visual Studio Code version 1.70 or higher. To view your installed version, click Code > About Visual Studio Code from the manin menu on Linux or macOS and Help > About on Windows. To download, install, and configure Visual Studio Code, see Setting up Visual Studio Code.
The SQLTools extension for Visual Studio Code.
The Databricks Driver for SQLTools extension for Visual Studio Code.
To install the SQLTools extension, go to SQLTools and then click Install, or:
In Visual Studio Code, click View > Extensions on the main menu.
In the Search Extensions in Marketplace box, enter
SQLTools
.Click the SQLTools entry from Matheus Teixeira.
Note
There might be multiple SQLTools entries listed. Be sure to click the entry from Matheus Teixeira.
Click Install.
To install the Databricks Driver for SQLTools extension, go to Databricks Driver for SQLTools and then click Install, or:
In Visual Studio Code, click View > Extensions on the main menu.
In the Search Extensions in Marketplace box, enter
Databricks Driver for SQLTools
.Click the Databricks Driver for SQLTools entry.
Click Install.
Authentication
You must set up authentication for the Databricks Driver for SQLTools as follows.
The Databricks Driver for SQLTools supports the following Databricks authentication types:
Databricks personal access token authentication
To use the Databricks Driver for SQLTools with Databricks personal access token authentication, you must have a Databricks personal access token. To create a personal access token, follow the steps in Databricks personal access tokens for workspace users.
Databricks OAuth machine-to-machine (M2M) authentication
You can use Databricks OAuth machine-to-machine (M2M) authentication to authenticate with the Databricks Driver for SQLTools, as follows:
Note
Databricks OAuth M2M authentication is available in Databricks Driver for SQLTools versions 0.4.2 and above.
Complete the configuration steps for OAuth M2M authentication. See OAuth machine-to-machine (M2M) authentication.
Create a Databricks configuration profile with your OAuth M2M authentication configuration settings. See the “Config” section of OAuth machine-to-machine (M2M) authentication.
Install and open the Databricks extension for Visual Studio Code on your local development machine.
In the Databricks extension for Visual Studio Code, click the Configure button in the Configuration pane. If the Configure button is not displayed, click the gear (Configure workspace) icon instead.
In the Command Palette, for Databricks Host, enter your Databricks workspace instance URL, for example
https://1234567890123456.7.gcp.databricks.com
, and then press Enter.Select the configuration profile entry that matches the one that you created in step 2.
Complete the on-screen instructions in your web browser to finish authenticating with your Databricks account.
Databricks OAuth user-to-machine (U2M) authentication
You can use Databricks OAuth user-to-machine (U2M) authentication to authenticate with the Databricks Driver for SQLTools, as follows:
Note
Databricks OAuth U2M authentication is available in Databricks Driver for SQLTools versions 0.4.2 and above.
Install and open the Databricks extension for Visual Studio Code on your local development machine.
In the Databricks extension for Visual Studio Code, click the Configure button in the Configuration pane. If the Configure button is not displayed, click the gear (Configure workspace) icon instead.
In the Command Palette, for Databricks Host, enter your Databricks workspace instance URL, for example
https://1234567890123456.7.gcp.databricks.com
. Then press Enter.Select OAuth (user to machine).
Complete the on-screen instructions in your web browser to finish authenticating with your Databricks account. If prompted, allow
all-apis
access.
Connect to a schema
In Visual Studio Code, on the sidebar, click the SQLTools icon.
In the SQLTools view, if this is your first time using the SQLTools extension, click Add New Connection within the Connections pane. Otherwise, click the Add New Connection icon in the pane’s title bar.
On the SQLTools Settings tab, for the Select a database driver step, click the Databricks icon.
For the Connection Settings step, enter the following information about your warehouse, catalog, and schema:
For Connection name, enter some unique name for this connection.
(Optional) For Connection group enter the name of an existing connection group to add the new connection to that group. Or, enter a unique name to create a new connection group with the new connection. Connection groups make it easier to find connections in the extension.
For Connect using, select one of the following:
To use a Databricks personal access token for authentication, select Hostname and Token.
For Databricks Driver for SQLTools versions 0.4.2 and above, to use OAuth U2M or M2M authentication, select VS Code extension (beta).
If you selected Hostname and Token for Connect using, then for Host, enter the warehouse’s Server hostname setting. To get a warehouse’s Server hostname setting, see Get connection details for a Databricks compute resource.
For Path, enter the warehouse’s or cluster’s HTTP path setting. To get a warehouse’s HTTP path setting, see Get connection details for a Databricks compute resource.
If you selected Hostname and Token for Connect using, enter your Databricks personal access token value in Token.
For Catalog, enter the name of your catalog.
Note
For workspaces that are not enabled for Unity Catalog, you can leave Catalog blank to use the default value of
hive_metastore
.For Schema, enter the name of your schema.
(Optional) For Show records default limit, leave the default of
50
to show only up to the first 50 rows for each query, or enter a different limit.
Click Test Connection.
If the connection test succeeds, click Save Connection.
Change a connection’s settings
This procedure assumes that you have successfully connected to at least one warehouse.
If the SQLTools view is not visible, then in Visual Studio Code, on the sidebar, click the SQLTools icon.
In the Connections pane, expand the connection group, if one exists for your target connection.
Right-click the connection, and click Edit Connection.
Change the target settings.
Click Test Connection.
If the connection test succeeds, click Save Connection.
Browse a schema’s objects
In the Connections pane, expand the connection group, if one exists for your target connection.
Double-click or expand the target connection for your warehouse.
Expand the target database (schema), if one exists for your connection.
Expand Tables or Views, if one or more tables or views exist for your database (schema).
Expand any target table or view to view the table’s or view’s columns.
View the rows or schema for a table or view
With Tables or Views expanded in the Connections pane, do one of the following:
To show the table’s or view’s rows, right-click the table or view, and click Show Table Records or Show View Records.
To show the table’s or view’s schema, right-click the table or view, and click Describe Table or Describe View.
Generate an insert query for a table
Place your cursor in an existing editor at the location where you want the insert query to be added.
With Tables expanded in the Connections pane, right-click the table, and click Generate Insert Query. The insert query’s definition is added at the cursor’s insertion point.
Create and run a query
This procedure assumes that you have successfully connected to at least one warehouse.
In the Connections pane, expand the connection group, if one exists for your target connection.
Double-click or expand the target connection for your warehouse.
With the connection selected, click New SQL File in the Connections pane’s title bar. A new editor tab appears.
Enter your SQL query in the new editor.
To run the SQL query, click Run on active connection in the editor. The query’s results display in a new editor tab.
Run an existing query
This procedure assumes that you have successfully connected to at least one warehouse.
In the Connections pane, expand the connection group, if one exists for your target connection.
Double-click or expand the target connection for your warehouse.
With the connection selected, open any file with the file extension of
.sql
, or select any group of continuous SQL statements in any editor that was previously opened.To run the SQL query from an open
.sql
file, with your.sql
file’s contents displayed in the editor, click Run on active connection in the editor. The query’s results display in a new editor tab.To run a selected group of continuous SQL statements in an editor that was previously opened, right-click your selection, and then click Run Selected Query. The query’s results display in a new editor tab.
Send usage logs to Databricks
If you encounter issues while using the Databricks Driver for SQLTools, you can send usage logs and related information to Databricks Support by doing the following:
Install the Databricks extension for Visual Studio Code on your local development machine.
Turn on logging by checking the Logs: Enabled setting, or setting
databricks.logs.enabled
totrue
, as described in Settings for the Databricks extension for Visual Studio Code Be sure to restart Visual Studio Code after you turn on logging.Attempt to reproduce your issue.
From the Command Palette (View > Command Palette from the main menu), run the Databricks: Open full logs command.
Send the
Databricks Logs.log
,databricks-cli-logs.json
, andsdk-and-extension-logs.json
files that appear to Databricks Support.Also copy the contents of the Terminal (View > Terminal) in the context of the issue, and send this content to Databricks Support.
The Output view (View > Output, Databricks Logs) shows truncated information if Logs: Enabled is checked or databricks.logs.enabled
is set to true
. To show more information, change the following settings, as described in Settings for the Databricks extension for Visual Studio Code:
Logs: Max Array Length or
databricks.logs.maxArrayLength
Logs: Max Field Length or
databricks.logs.maxFieldLength
Logs: Truncation Depth or
databricks.logs.truncationDepth