问题
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?
回答1:
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);
来源:https://stackoverflow.com/questions/51963804/how-to-throw-a-error-or-raise-exception-in-u-sql