Search code examples
azure-data-lakeu-sql

How to throw a error or raise exception in U-SQL?


What is the mechanism used to raise an error or exception in a U-Sql script? I have a scenario where am processing a CSV file, and if duplicates are found in it, then I need to abandon processing.

In SQL, I could do raiseerror, what it the equivalent way of doing it in U-Sql?


Solution

  • Create a c# function to raise custom errors (or output to a file):

    DECLARE @RaiseError Func<string, int> = (error) => 
        {
            throw new Exception(error);
            return 0;
        };
    
    @Query = 
        SELECT @RaiseError(value) AS ErrorCode
        FROM (VALUES ("my custom error description")) AS T(value);
    
    OUTPUT @Query TO "/Output/errors.txt" USING Outputters.Csv(quoting : true);