SELECT Expression (U-SQL)
Updated: March 10, 2017
The SELECT expression is the transformation and query workhorse. It basically follows the standard SQL SELECT expression.
The logical processing flow of a SELECT expression is as follows: First the rowsets specified in the SELECT’s FROM clause will be combined into the SELECT expression’s rowset. Then the optional WHERE clause’s filter conditions are applied onto the rowset. The GROUP BY clause is then producing groups of rows, optionally filtered with the HAVING clause. The SELECT clause then projects the specified columns and allows aggregating the grouped data as well as transforming the selected data. Finally the ORDER BY clause with FETCH allows the selection of a limited number of rows based on the specified order.
Note that unlike in other systems, where a SELECT clause can output results to the user at any time, U-SQL’s current batch-mode centric execution model never outputs a SELECT result directly. Instead, a SELECT expression is always assigned to a rowset expression variable and in the end the script results needs to either be output into files or inserted into tables.
| Syntax |
|---|
Select_Expression :=
Select_Clause |
Semantics of Syntax Elements
Select_Clause
TheSELECTclause specifies the resulting structure and values of the rowset of theSELECTexpression.Select_From_Clause
TheFROMclause specifies the input rowsets to theSELECTexpression and how the rowsets are being combined into theSELECTexpression’s rowset.Where_Clause
The optionalWHEREclause specifies the filter conditions of theSELECTexpression which will reduces the rows that are being produced as a result.Group_By_Clause
The optionalGROUP BYclause groups the rows based on the provided expression list into groups that then can be aggregated over with the built-in and user-defined aggregator functions.Order_By_Fetch_Clause
The optionalORDER BYclause allows to order the rowset in order to select a number of rows based on their order using theFETCHsubclause.Since all rowsets flow unordered through the query processor to provide better optimization, having an ORDER BY clause without a FETCH clause is meaningless. Thus, the ORDER BY clause on a U-SQL SELECT expression has to contain a FETCH clause. In order to get ordered output, use the ORDER BY clause on the OUTPUT statement.