Visual Studio Code Tools



-->

Learn how to use Apache Spark & Hive Tools for Visual Studio Code. Use the tools to create and submit Apache Hive batch jobs, interactive Hive queries, and PySpark scripts for Apache Spark. First we'll describe how to install Spark & Hive Tools in Visual Studio Code. Then we'll walk through how to submit jobs to Spark & Hive Tools.

Visual studio code build tools

Spark & Hive Tools can be installed on platforms that are supported by Visual Studio Code. Note the following prerequisites for different platforms.

Prerequisites

The following items are required for completing the steps in this article:

  • An Azure HDInsight cluster. To create a cluster, see Get started with HDInsight. Or use a Spark and Hive cluster that supports an Apache Livy endpoint.
  • Visual Studio Code.
  • Mono. Mono is required only for Linux and macOS.
  • A PySpark interactive environment for Visual Studio Code.
  • A local directory. This article uses C:HDHDexample.

Oracle Developer Tools for VS Code. This extension enables editing and execution of SQL and PL/SQL for Oracle Database and Oracle Autonomous Database. View the Quickstart: Get Started with Oracle and VSCode for details on how to configure, connect and use Oracle Developer Tools for VS Code. Questions or feedback about this. Oracle Developer Tools for VS Code. This extension enables editing and execution of SQL and PL/SQL for Oracle Database and Oracle Autonomous Database. View the Quickstart: Get Started with Oracle and VSCode for details on how to configure, connect and use Oracle Developer Tools for VS Code. Questions or feedback about this. A Visual Studio Code extension that allows you to use the browser's Elements and Network tool from within the editor. The DevTools will connect to an instance of Microsoft Edge giving you the ability to see the runtime HTML structure, alter layout, fix styling issues, read console messages and view network requests. Visual Studio Code Tools for AI is an extension to build, test, and deploy Deep Learning / AI solutions. It seamlessly integrates with Azure Machine Learning for robust experimentation capabilities, including but not limited to submitting data preparation and model training jobs. No 'Tools' Option for Visual Studio Code The menu bar is missing it. Ask Question Asked 2 years, 3 months ago. Active 1 month ago. Viewed 10k times 6. Across the top I see: File Edit Selection View Go Debug Terminal Help No Tools options. And some of the things I was trying to do, like reset to default settings, I can only do through that.

Install Spark & Hive Tools

After you meet the prerequisites, you can install Spark & Hive Tools for Visual Studio Code by following these steps:

  1. Open Visual Studio Code.

  2. From the menu bar, navigate to View > Extensions.

  3. In the search box, enter Spark & Hive.

  4. Select Spark & Hive Tools from the search results, and then select Install:

  5. Select Reload when necessary.

Open a work folder

To open a work folder and to create a file in Visual Studio Code, follow these steps:

  1. From the menu bar, navigate to File > Open Folder.. > C:HDHDexample, and then select the Select Folder button. The folder appears in the Explorer view on the left.

  2. In Explorer view, select the HDexample folder, and then select the New File icon next to the work folder:

  3. Name the new file by using either the .hql (Hive queries) or the .py (Spark script) file extension. This example uses HelloWorld.hql.

Set the Azure environment

For a national cloud user, follow these steps to set the Azure environment first, and then use the Azure: Sign In command to sign in to Azure:

  1. Navigate to File > Preferences > Settings.

  2. Search on the following string: Azure: Cloud.

  3. Select the national cloud from the list:

Connect to an Azure account

Before you can submit scripts to your clusters from Visual Studio Code, user can either sign in to Azure subscription, or link a HDInsight cluster. Use the Ambari username/password or domain joined credential for ESP cluster to connect to your HDInsight cluster. Follow these steps to connect to Azure:

  1. From the menu bar, navigate to View > Command Palette.., and enter Azure: Sign In:

  2. Follow the sign-in instructions to sign in to Azure. After you're connected, your Azure account name shows on the status bar at the bottom of the Visual Studio Code window.

Link a cluster

Link: Azure HDInsight

Visual

You can link a normal cluster by using an Apache Ambari-managed username, or you can link an Enterprise Security Pack secure Hadoop cluster by using a domain username (such as: user1@contoso.com).

  1. From the menu bar, navigate to View > Command Palette.., and enter Spark / Hive: Link a Cluster.

  2. Select linked cluster type Azure HDInsight.

  3. Enter the HDInsight cluster URL.

  4. Enter your Ambari username; the default is admin.

  5. Enter your Ambari password.

  6. Select the cluster type.

  7. Set the display name of the cluster (optional).

  8. Review OUTPUT view for verification.

    Note

    The linked username and password are used if the cluster both logged in to the Azure subscription and linked a cluster.

Link: Generic Livy endpoint

  1. Download itune for mac. From the menu bar, navigate to View > Command Palette.., and enter Spark / Hive: Link a Cluster.

  2. Select linked cluster type Generic Livy Endpoint.

  3. Enter the generic Livy endpoint. For example: http://10.172.41.42:18080.

  4. Select authorization type Basic or None. If you select Basic:

    1. Enter your Ambari username; the default is admin.

    2. Enter your Ambari password.

  5. Review OUTPUT view for verification.

List clusters

  1. From the menu bar, navigate to View > Command Palette.., and enter Spark / Hive: List Cluster.

  2. Select the subscription that you want.

  3. Review the OUTPUT view. This view shows your linked cluster (or clusters) and all the clusters under your Azure subscription:

Set the default cluster

  1. Reopen the HDexample folder that was discussed earlier, if closed.

  2. Select the HelloWorld.hql file that was created earlier. It opens in the script editor.

  3. Right-click the script editor, and then select Spark / Hive: Set Default Cluster.

  4. Connect to your Azure account, or link a cluster if you haven't yet done so.

  5. Select a cluster as the default cluster for the current script file. The tools automatically update the .VSCodesettings.json configuration file:

Submit interactive Hive queries and Hive batch scripts

With Spark & Hive Tools for Visual Studio Code, you can submit interactive Hive queries and Hive batch scripts to your clusters.

  1. Reopen the HDexample folder that was discussed earlier, if closed.

  2. Select the HelloWorld.hql file that was created earlier. It opens in the script editor.

  3. Copy and paste the following code into your Hive file, and then save it:

  4. Connect to your Azure account, or link a cluster if you haven't yet done so.

  5. Right-click the script editor and select Hive: Interactive to submit the query, or use the Ctrl+Alt+I keyboard shortcut. Select Hive: Batch to submit the script, or use the Ctrl+Alt+H keyboard shortcut.

  6. If you haven't specified a default cluster, select a cluster. The tools also let you submit a block of code instead of the whole script file by using the context menu. After a few moments, the query results appear in a new tab:

    • RESULTS panel: You can save the whole result as a CSV, JSON, or Excel file to a local path or just select multiple lines.

    • MESSAGES panel: When you select a Line number, it jumps to the first line of the running script.

Submit interactive PySpark queries

Users can perform PySpark interactive in the following ways:

Using the PySpark interactive command in PY file

Using the PySpark interactive command to submit the queries, follow these steps:

  1. Reopen the HDexample folder that was discussed earlier, if closed.

  2. Create a new HelloWorld.py file, following the earlier steps.

  3. Copy and paste the following code into the script file:

  4. The prompt to install PySpark/Synapse Pyspark kernel is displayed in the lower right corner of the window. You can click on Install button to proceed for the PySpark/Synapse Pyspark installations; or click on Skip button to skip this step.

  5. If you need to install it later, you can navigate to File > Preference > Settings, then uncheck HDInsight: Enable Skip Pyspark Installation in the settings.

  6. If the installation is successful in step 4, the 'PySpark installed successfully' message box is displayed in the lower right corner of the window. Click on Reload button to reload the window.

  7. From the menu bar, navigate to View > Command Palette.. or use the Shift + Ctrl + P keyboard shortcut, and enter Python: Select Interpreter to start Jupyter Server.

  8. Select the python option below.

  9. From the menu bar, navigate to View > Command Palette.. or use the Shift + Ctrl + P keyboard shortcut, and enter Developer: Reload Window.

  10. Connect to your Azure account, or link a cluster if you haven't yet done so.

  11. Select all the code, right-click the script editor, and select Spark: PySpark Interactive / Synapse: Pyspark Interactive to submit the query.

  12. Select the cluster, if you haven't specified a default cluster. After a few moments, the Python Interactive results appear in a new tab. Click on PySpark to switch the kernel to PySpark / Synapse Pyspark, and the code will run successfully. If you want to switch to Synapse Pyspark kernel, disabling auto-settings in Azure portal is encouraged. Otherwise it may take a long while to wake up the cluster and set synapse kernel for the first time use. If The tools also let you submit a block of code instead of the whole script file by using the context menu:

  13. Enter %%info, and then press Shift+Enter to view the job information (optional):

The tool also supports the Spark SQL query:

Perform interactive query in PY file using a #%% comment

  1. Add #%% before the Py code to get notebook experience.

  2. Click on Run Cell. After a few moments, the Python Interactive results appear in a new tab. Click on PySpark to switch the kernel to PySpark/Synapse PySpark, then, click on Run Cell again, and the code will run successfully.

Leverage IPYNB support from Python extension

  1. You can create a Jupyter Notebook by command from the Command Palette or by creating a new .ipynb file in your workspace. For more information, see Working with Jupyter Notebooks in Visual Studio Code

  2. Click on Run cell button, follow the prompts to Set the default spark pool (strongly encourage to set default cluster/pool every time before opening a notebook) and then, Reload window.

  3. Click on PySpark to switch kernel to PySpark / Synapse Pyspark, and then click on Run Cell, after a while, the result will be displayed.

Note

ms-toolsai.jupyter >2021.3.684299474 version is not supported on this extension is a known issue. Please using Synapse kernel by sticking to Microsoft Jupyter 2021.3.684299474.

Submit PySpark batch job

  1. Reopen the HDexample folder that you discussed earlier, if closed.

  2. Create a new BatchFile.py file by following the earlier steps.

  3. Copy and paste the following code into the script file:

  4. Connect to your Azure account, or link a cluster if you haven't yet done so.

  5. Right-click the script editor, and then select Spark: PySpark Batch, or Synapse: PySpark Batch*.

  6. Select a cluster/spark pool to submit your PySpark job to:

After you submit a Python job, submission logs appear in the OUTPUT window in Visual Studio Code. The Spark UI URL and Yarn UI URL are also shown. If you submit the batch job to an Apache Spark pool, the Spark history UI URL and the Spark Job Application UI URL are also shown. You can open the URL in a web browser to track the job status.

Integrate with HDInsight Identity Broker (HIB)

Connect to your HDInsight ESP cluster with ID Broker (HIB)

You can follow the normal steps to sign in to Azure subscription to connect to your HDInsight ESP cluster with ID Broker (HIB). After sign-in, you'll see the cluster list in Azure Explorer. For more instructions, see Connect to your HDInsight cluster.

Run a Hive/PySpark job on an HDInsight ESP cluster with ID Broker (HIB)

For run a hive job, you can follow the normal steps to submit job to HDInsight ESP cluster with ID Broker (HIB). Refer to Submit interactive Hive queries and Hive batch scripts for more instructions.

For run a interactive PySpark job, you can follow the normal steps to submit job to HDInsight ESP cluster with ID Broker (HIB). Refer to Submit interactive PySpark queries for more instructions.

For run a PySpark batch job, you can follow the normal steps to submit job to HDInsight ESP cluster with ID Broker (HIB). Refer to Submit PySpark batch job for more instructions.

Apache Livy configuration

Apache Livy configuration is supported. You can configure it in the .VSCodesettings.json file in the workspace folder. Currently, Livy configuration only supports Python script. For more information, see Livy README.

How to trigger Livy configuration

Method 1

  1. From the menu bar, navigate to File > Preferences > Settings.
  2. In the Search settings box, enter HDInsight Job Submission: Livy Conf.
  3. Select Edit in settings.json for the relevant search result.

Method 2

Submit a file, and notice that the .vscode folder is automatically added to the work folder. You can see the Livy configuration by selecting .vscodesettings.json.

  • The project settings:

    Note

    For the driverMemory and executorMemory settings, set the value and unit. For example: 1g or 1024m.

  • Supported Livy configurations:

    POST /batches

    Request body

    namedescriptiontype
    fileFile containing the application to executePath (required)
    proxyUserUser to impersonate when running the jobString
    classNameApplication Java/Spark main classString
    argsCommand-line arguments for the applicationList of strings
    jarsJars to be used in this sessionList of strings
    pyFilesPython files to be used in this sessionList of strings
    filesFiles to be used in this sessionList of strings
    driverMemoryAmount of memory to use for the driver processString
    driverCoresNumber of cores to use for the driver processInt
    executorMemoryAmount of memory to use per executor processString
    executorCoresNumber of cores to use for each executorInt
    numExecutorsNumber of executors to launch for this sessionInt
    archivesArchives to be used in this sessionList of strings
    queueName of the YARN queue to be submitted toString
    nameName of this sessionString
    confSpark configuration propertiesMap of key=val

    Response bodyThe created Batch object.

    namedescriptiontype
    IDSession IDInt
    appIdApplication ID of this sessionString
    appInfoDetailed application infoMap of key=val
    logLog linesList of strings
    stateBatch stateString

    Note

    The assigned Livy config is displayed in the output pane when you submit the script.

Integrate with Azure HDInsight from Explorer

You can preview Hive Table in your clusters directly through the Azure HDInsight explorer:

  1. Connect to your Azure account if you haven't yet done so.

  2. Select the Azure icon from leftmost column.

  3. From the left pane, expand AZURE: HDINSIGHT. The available subscriptions and clusters are listed.

  4. Expand the cluster to view the Hive metadata database and table schema.

  5. Right-click the Hive table. For example: hivesampletable. Select Preview.

  6. The Preview Results window opens:

  • RESULTS panel

    You can save the whole result as a CSV, JSON, or Excel file to a local path, or just select multiple lines.

  • MESSAGES panel

    1. When the number of rows in the table is greater than 100, you see the following message: 'The first 100 rows are displayed for Hive table.'

    2. When the number of rows in the table is less than or equal to 100, you see the following message: '60 rows are displayed for Hive table.'

    3. When there's no content in the table, you see the following message: '0 rows are displayed for Hive table.'

      Note

      In Linux, install xclip to enable copy-table data.

Additional features

Spark & Hive for Visual Studio Code also supports the following features:

  • IntelliSense autocomplete. Suggestions pop up for keywords, methods, variables, and other programming elements. Different icons represent different types of objects:

  • IntelliSense error marker. The language service underlines editing errors in the Hive script.

  • Syntax highlights. The language service uses different colors to differentiate variables, keywords, data type, functions, and other programming elements:

Reader-only role

Users who are assigned the reader-only role for the cluster can't submit jobs to the HDInsight cluster, nor view the Hive database. Contact the cluster administrator to upgrade your role to HDInsight Cluster Operator in the Azure portal. If you have valid Ambari credentials, you can manually link the cluster by using the following guidance.

Browse the HDInsight cluster

Visual studio code install

When you select the Azure HDInsight explorer to expand an HDInsight cluster, you're prompted to link the cluster if you have the reader-only role for the cluster. Use the following method to link to the cluster by using your Ambari credentials.

Submit the job to the HDInsight cluster

When submitting job to an HDInsight cluster, you're prompted to link the cluster if you're in the reader-only role for the cluster. Use the following steps to link to the cluster by using Ambari credentials.

Visual Studio Code Tools For Ai

Link to the cluster

  1. Enter a valid Ambari username.

  2. Enter a valid password.

    Note

    You can use Spark / Hive: List Cluster to check the linked cluster:

Azure Data Lake Storage Gen2

Browse a Data Lake Storage Gen2 account

Select the Azure HDInsight explorer to expand a Data Lake Storage Gen2 account. Solitaire for mac spider. You're prompted to enter the storage access key if your Azure account has no access to Gen2 storage. After the access key is validated, the Data Lake Storage Gen2 account is auto-expanded.

Submit jobs to an HDInsight cluster with Data Lake Storage Gen2

Submit a job to an HDInsight cluster using Data Lake Storage Gen2. You're prompted to enter the storage access key if your Azure account has no write access to Gen2 storage. After the access key is validated, the job will be successfully submitted.

Note

You can get the access key for the storage account from the Azure portal. For more information, see Manage storage account access keys.

Unlink cluster

  1. From the menu bar, go to View > Command Palette, and then enter Spark / Hive: Unlink a Cluster.

  2. Select a cluster to unlink.

  3. See the OUTPUT view for verification.

Sign out

From the menu bar, go to View > Command Palette, and then enter Azure: Sign Out.

Known Issues

ms-toolsai.jupyter >2021.3.684299474 version is not supported on this extension, please using Synapse kernel by sticking to Microsoft Jupyter 2021.3.684299474.

  1. Disable auto updating extension.

  2. Install a selected version of Microsoft Jupyter.

  3. Install Microsoft Jupyter version 2021.3.684299474

Next steps

For a video that demonstrates using Spark & Hive for Visual Studio Code, see Spark & Hive for Visual Studio Code.

-->

Applies to: SQL Server (all supported versions) - Linux

This article shows how to use the mssql extension for Visual Studio Code to develop SQL Server databases. Because Visual Studio Code is cross-platform, you can use mssql extension on Linux, macOS, and Windows.

Install and start Visual Studio Code

Visual Studio Code is a cross-platform, graphical code editor that supports extensions.

  1. Download and install Visual Studio Code on your machine.

  2. Start Visual Studio Code.

    Note

    If Visual Studio Code does not start when you are connected through an xrdp remote desktop session, see VS Code not working on Ubuntu when connected using XRDP.

Visual studio code tools

Install the mssql extension

The mssql extension for Visual Studio Code lets you connect to a SQL Server, query with Transact-SQL (T-SQL), and view the results.

  1. In Visual Studio Code, select View > Command Palette, or press Ctrl+Shift+P, or press F1 to open the Command Palette.

  2. In the Command Palette, select Extensions: Install Extensions from the dropdown.

  3. In the Extensions pane, type mssql.

  4. Select the SQL Server (mssql) extension, and then select Install.

  5. After the installation completes, select Reload to enable the extension.

Create or open a SQL file

The mssql extension enables mssql commands and T-SQL IntelliSense in the code editor when the language mode is set to SQL.

Visual studio code build tools

Visual Studio Code Tools Menu

  1. Select File > New File or press Ctrl+N. Visual Studio Code opens a new Plain Text file by default.

  2. Select Plain Text on the lower status bar, or press Ctrl+K > M, and select SQL from the languages dropdown.

    Note

    If this is the first time you have used the extension, the extension installs supporting SQL Server tools.

If you open an existing file that has a .sql file extension, the language mode is automatically set to SQL.

Connect to SQL Server

Visual Studio Tools Download

Follow these steps to create a connection profile and connect to a SQL Server.

  1. Press Ctrl+Shift+P or F1 to open the Command Palette.

  2. Type sql to display the mssql commands, or type sqlcon, and then select MS SQL: Connect from the dropdown.

    Note

    A SQL file, such as the empty SQL file you created, must have focus in the code editor before you can execute the mssql commands.

  3. Select the MS SQL: Manage Connection Profiles command.

  4. Then select Create to create a new connection profile for your SQL Server.

  5. Follow the prompts to specify the properties for the new connection profile. After specifying each value, press Enter to continue.

    Connection propertyDescription
    Server name or ADO connection stringSpecify the SQL Server instance name. Use localhost to connect to a SQL Server instance on your local machine. To connect to a remote SQL Server, enter the name of the target SQL Server, or its IP address. To connect to a SQL Server container, specify the IP address of the container's host machine. If you need to specify a port, use a comma to separate it from the name. For example, for a server listening on port 1401, enter <servername or IP>,1401.
    As an alternative, you can enter the ADO connection string for your database here.
    Database name (optional)The database that you want to use. To connect to the default database, don't specify a database name here.
    Authentication TypeChoose either Integrated or SQL Login.
    User nameIf you selected SQL Login, enter the name of a user with access to a database on the server.
    PasswordEnter the password for the specified user.
    Save PasswordPress Enter to select Yes and save the password. Select No to be prompted for the password each time the connection profile is used.
    Profile Name (optional)Type a name for the connection profile, such as localhost profile.

    After you enter all values and select Enter, Visual Studio Code creates the connection profile and connects to the SQL Server.

    Tip

    If the connection fails, try to diagnose the problem from the error message in the Output panel in Visual Studio Code. To open the Output panel, select View > Output. Also review the connection troubleshooting recommendations.

  6. Verify your connection in the lower status bar.

As an alternative to the previous steps, you can also create and edit connection profiles in the User Settings file (settings.json). To open the settings file, select File > Preferences > Settings. For more information, see Manage connection profiles.

Visual Studio Toolbox Download

Create a SQL database

Visual Studio

  1. In the new SQL file that you started earlier, type sql to display a list of editable code snippets.

  2. Select sqlCreateDatabase.

  3. In the snippet, type TutorialDB to replace 'DatabaseName':

  4. Press Ctrl+Shift+E to execute the Transact-SQL commands. View the results in the query window.

    Tip

    You can customize the shortcut keys for the mssql commands. See Customize shortcuts.

Visual Studio Code Tools Menu

Create a table

  1. Delete the contents of the code editor window.

  2. Press Ctrl+Shift+P or F1 to open the Command Palette.

  3. Type sql to display the mssql commands, or type sqluse, and then select the MS SQL: Use Database command.

  4. Select the new TutorialDB database.

  5. In the code editor, type sql to display the snippets, select sqlCreateTable, and then press Enter.

  6. In the snippet, type Employees for the table name.

  7. Press Tab to get to the next field, and then type dbo for the schema name.

  8. Replace the column definitions with the following columns:

  9. Press Ctrl+Shift+E to create the table.

Insert and query

  1. Add the following statements to insert four rows into the Employees table.

    While you type, T-SQL IntelliSense helps you to complete the statements:

    Tip

    The mssql extension also has commands to help create INSERT and SELECT statements. These were not used in the previous example.

  2. Press Ctrl+Shift+E to execute the commands. The two result sets display in the Results window.

View and save the result

  1. Select View > Editor Layout > Flip Layout to switch to a vertical or horizontal split layout.

  2. Select the Results and Messages panel headers to collapse and expand the panels.

    Tip

    You can customize the default behavior of the mssql extension. See Customize extension options.

  3. Select the maximize grid icon on the second result grid to zoom in to those results.

    Note

    The maximize icon displays when your T-SQL script produces two or more result grids.

  4. Open the grid context menu by right-clicking on the grid.

  5. Select Select All.

  6. Open the grid context menu again and select Save as JSON to save the result to a .json file.

  7. Specify a file name for the JSON file.

  8. Verify that the JSON file saves and opens in Visual Studio Code.

If you need to save and run SQL scripts later, for administration or a larger development project, save the scripts with a .sql extension.

Next steps

If you're new to T-SQL, see Tutorial: Write Transact-SQL statements and the Transact-SQL Reference (Database Engine).

For more information on using or contributing to the mssql extension, see the mssql extension project wiki.

For more information on using Visual Studio Code, see the Visual Studio Code documentation.