This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Azure Data Lake provides theU-SQL language. U-SQL combines declarative SQL with imperative C# to process data at any scale. In this document, you learn how to create test cases for U-SQL and extended C# user-defined operator (UDO) code.
Important
Azure Data Lake Analytics retired on 29 February 2024. Learn morewith this announcement.
For data analytics, your organization can useAzure Synapse Analytics orMicrosoft Fabric.
The U-SQL script is compiled and optimized for executable code to run in Azure or on your local computer. The compilation and optimization process treats the entire U-SQL script as a whole. You can't do a traditional unit test for every statement. However, by using the U-SQL test SDK and the local run SDK, you can do script-level tests.
Azure Data Lake Tools for Visual Studio enables you to create U-SQL script test cases.
Right-click a U-SQL script in Solution Explorer, and then selectCreate Unit Test.
Create a new test project or insert the test case into an existing test project.

When you test U-SQL scripts, you need test input files. To manage the test data, inSolution Explorer, right-click the U-SQL project, and selectProperties. You can enter a source inTest Data Source.

When you call theInitialize() interface in the U-SQL test SDK, a temporary local data root folder is created under the working directory of the test project. All files and folders in the test data source folder are copied to the temporary local data root folder before you run the U-SQL script test cases. You can add more test data source folders by splitting the test data folder path with a semicolon.
If your U-SQL scripts use or query with U-SQL database objects, you need to initialize the database environment before you run U-SQL test cases. This approach can be necessary when calling stored procedures. TheInitialize() interface in the U-SQL test SDK helps you deploy all databases that are referenced by the U-SQL project to the temporary local data root folder in the working directory of the test project.
For more information about how to manage U-SQL database project references for a U-SQL project, seeReference a U-SQL database project.
TheRun() interface returns a job execution result.0 means success, and1 means failure. You can also use C# assert functions to verify the outputs.
A U-SQL script test project is built on top of a C# unit test framework. After you build the project, selectTest >Windows >Test Explorer. You can run test cases fromTest Explorer. Alternatively, right-click the .cs file in your unit test and selectRun Tests.
You can use a C# unit test framework to test your C# user-defined operators (UDOs). When testing UDOs, you need to prepare correspondingIRowset objects as inputs.
There are two ways to create anIRowset object:
Load data from a file to createIRowset:
//Schema: "a:int, b:int"USqlColumn<int> col1 = new USqlColumn<int>("a");USqlColumn<int> col2 = new USqlColumn<int>("b");List<IColumn> columns = new List<IColumn> { col1, col2 };USqlSchema schema = new USqlSchema(columns);//Generate one row with default valuesIUpdatableRow output = new USqlRow(schema, null).AsUpdatable();//Get data from fileIRowset rowset = UnitTestHelper.GetRowsetFromFile(@"processor.txt", schema, output.AsReadOnly(), discardAdditionalColumns: true, rowDelimiter: null, columnSeparator: '\t');Use data from a data collection to createIRowset:
//Schema: "a:int, b:int"USqlSchema schema = new USqlSchema( new USqlColumn<int>("a"), new USqlColumn<int>("b"));IUpdatableRow output = new USqlRow(schema, null).AsUpdatable();//Generate Rowset with specified valuesList<object[]> values = new List<object[]>{ new object[2] { 2, 3 }, new object[2] { 10, 20 }};IEnumerable<IRow> rows = UnitTestHelper.CreateRowsFromValues(schema, values);IRowset rowset = UnitTestHelper.GetRowsetFromCollection(rows, output.AsReadOnly());After you call UDO functions, you can verify the results through the schema and Rowset value verification by using C# assert functions. You can add aU-SQL C# UDO Unit Test Project to your solution. To do so, selectFile > New > Project in Visual Studio.
After you build the project, selectTest >Windows >Test Explorer. You can run test cases fromTest Explorer. Alternatively, right-click the .cs file in your unit test and selectRun Tests.
BothU-SQL script test projects andC# UDO test projects inherit C# unit test projects. TheVisual Studio test task in Azure Pipelines can run these test cases.
For a U-SQL test, make sure you loadCPPSDK on your build computer, and then pass theCPPSDK path toUSqlScriptTestRunner(cppSdkFolderFullPath: @"").
CPPSDK is a package that includes Microsoft Visual C++ 14 and Windows SDK 10.0.10240.0. This package includes the environment that's needed by the U-SQL runtime. You can get this package under the Azure Data Lake Tools for Visual Studio installation folder:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Microsoft Azure Data Lake Tools for Visual Studio 2015\X.X.XXXX.X\CppSDKC:\Program Files (x86)\Microsoft Visual Studio\2017\<Visual Studio Edition>\SDK\ScopeCppSDKC:\Program Files (x86)\Microsoft Visual Studio\2019\<Visual Studio Edition>\SDK\ScopeCppSDKThe most common way to prepare the CPPSDK dependency in Azure Pipelines is as follows:
Zip the folder that includes the CPPSDK libraries.
Check in the .zip file to your source control system. The .zip file ensures that you check in all libraries under the CPPSDK folder so that files aren't ignored because of a.gitignore file.
Unzip the .zip file in the build pipeline.
PointUSqlScriptTestRunner to this unzipped folder on the build computer.
For a C# UDO test, make sure to reference the following assemblies, which are needed for UDOs.
If you reference them throughthe NuGet package Microsoft.Azure.DataLake.USQL.Interfaces, make sure you add a NuGet Restore task in your build pipeline.