Muokkaa

Jaa


Test Stream Analytics queries locally with sample data using Visual Studio Code

You can use Azure Stream Analytics tools for Visual Studio Code to test your Stream Analytics jobs locally with sample data. The output results can be found as JSON files in the LocalRunOutputs folder of your project.

For more information, see Overview of local Stream Analytics runs in Visual Studio Code with ASA Tools.

Prerequisites

  • Install .NET core SDK and restart Visual Studio Code.

  • Use this quickstart to learn how to create a Stream Analytics job using Visual Studio Code.

Prepare sample data

You need to prepare sample input data files first. If you already have some sample data files on your machine, you can skip this step and move on to the next one.

  1. Click Preview data in your input configuration file from the top line. Some input data will be fetched from IoT Hub and shown in the preview window.

  2. Once the data is shown, select Save as to save the data to a local file.

Preview live input

Define a local input

  1. Select input.json under Inputs folder in your Stream Analytics project. Then select Add local input from the top line.

    Add local input from project

    You can also use Ctrl+Shift+P to open the command palette and enter ASA: Add Input.

    Add Stream Analytics input in VS Code

  2. Select Local Input.

    Add ASA local input in Visual Studio Code

  3. Select + New Local Input.

    Add a new ASA local input in Visual Studio Code

  4. Enter the same input alias that you used in your query.

    Add a new ASA local input alias

  5. In the newly generated LocalInput_Input.json file, enter the file path where your local data file is located.

    Enter local file path in Visual Studio

  6. Select Preview Data to preview the input data. The serialization type (JSON or CSV) for your data is automatically detected. Use the selector to view your data in Table or Raw format. The following table is an example of data in the Table format:

    Preview local data in table format

    The following table is an example of data in the Raw format:

    Preview local data in raw format

Run queries locally

Return to your query editor, and select Run locally. Then select Use local input from the dropdown list.

Select run locally in the query editor

Use local input

The result is shown in the right window. You can select Run to test again. You can also select Open in folder to see the result files in file explorer and further open them with other tools. The result files are only available in JSON format.

View local run result

Next steps