In this article we are trying to discuss about Using C# Code behind in U-SQL script. As we look that every U-SQL script has a C# code behind.
Now the question is why we are going to use this C# code behind as we can create function, stored procedure and other thing successfully in U-SQL. The answer is quite simple. If we want to use the power of C# and the entire library related to it, we can use the C# code behind.
For an example, we need to create a complex scalar value function and using C# it is quite easy by using it’s math library inbuilt functionality.
To understand the C# code behind, we are not taking any complex example. Here we have a CSV file, that have “StudentID”, “StidentName” ,“Marks1”, “Marks2” and “Marks3”.
We are going to retrieve information from CSV file and try to put the information to another output CSV file.
We are doing little transformation work by adding “Marks1”, “Marks2” and “Marks3” and give it a “Total Marks”.
We are going to use C# code behind by creating a function name “GetTotalMarks”. It takes three input marks and returns the total of three input marks.
C# Code Behind
public static class StudentRecor
public static Double GetTotalMarks(int marks_1, int marks_2, int marks_3)
return marks_1 + marks_2 + marks_3;
EXTRACT StudentID int,
TestApplication.StudentRecor.GetTotalMarks(Marks1, Marks2, Marks3) AS TotalMarks