none
CASE / SWITCH Statement In U-SQL?

    Question

  • All,

    The language reference for Data Lake isnt comprehensive yet.  Does anyone know if it is possible to use a CASE/SWITCH/IF-THEN-ELSE statement in the select clause of a U-SQL statement?  If not is this planned?

    Thanks!

    Monday, May 9, 2016 3:33 PM

Answers

  • If/else

    We have plans to support If/Else in U-SQL for constant foldable expressions (https://feedback.azure.com/forums/327234-data-lake/suggestions/12376380-compilation-directive-or-environment-variables).

    Today, you can use inline C# for simple if statements that can be expressed as (condition == true)? statement1 : statement2

    Case/Switch

    We don't have plans to support switch statements in U-SQL, you can use codebehind to write more complicated conditional statements in C#.

    If you are looking for these capabilities in U-SQL, it would be great if you can file your feedback (along with the problem you are trying to solve and your scenario) in https://feedback.azure.com/forums/327234-data-lake.

    Monday, May 9, 2016 3:42 PM
  • The IF ELSE that Rukmani mentions is at the statement level (e.g., around @a = SELECT) and not in an expression. For that you use the ternary C# "if" expression mentioned also above:

    (condition)? true_statement1 : false_statement2

    The SQL CASE expression can be easily expressed by composing the ternary C# if expression:

    (cond1) ? statement1 :
    (cond2) ? statement2 :
    (cond3) ? statement3 : else_statement



    Michael Rys

    Wednesday, June 15, 2016 10:25 PM
    Moderator

All replies

  • If/else

    We have plans to support If/Else in U-SQL for constant foldable expressions (https://feedback.azure.com/forums/327234-data-lake/suggestions/12376380-compilation-directive-or-environment-variables).

    Today, you can use inline C# for simple if statements that can be expressed as (condition == true)? statement1 : statement2

    Case/Switch

    We don't have plans to support switch statements in U-SQL, you can use codebehind to write more complicated conditional statements in C#.

    If you are looking for these capabilities in U-SQL, it would be great if you can file your feedback (along with the problem you are trying to solve and your scenario) in https://feedback.azure.com/forums/327234-data-lake.

    Monday, May 9, 2016 3:42 PM
  • The IF ELSE that Rukmani mentions is at the statement level (e.g., around @a = SELECT) and not in an expression. For that you use the ternary C# "if" expression mentioned also above:

    (condition)? true_statement1 : false_statement2

    The SQL CASE expression can be easily expressed by composing the ternary C# if expression:

    (cond1) ? statement1 :
    (cond2) ? statement2 :
    (cond3) ? statement3 : else_statement



    Michael Rys

    Wednesday, June 15, 2016 10:25 PM
    Moderator

  • You can find usage examples at Common SQL Expressions in U-SQL, msdn.microsoft.com/en-us/library/azure/mt771654.aspx
    Monday, February 13, 2017 11:31 PM