2

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?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
sppc42
  • 2,994
  • 2
  • 31
  • 49

1 Answers1

3

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);
Miguel Domingues
  • 440
  • 3
  • 11