sppc42
sppc42

Reputation: 3292

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?

Upvotes: 2

Views: 539

Answers (1)

Miguel Domingues
Miguel Domingues

Reputation: 440

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);

Upvotes: 3

Related Questions