Compartilhar via


REFERENCE ASSEMBLY (U-SQL)

Summary

In order to use a user-defined c# functions, user-defined aggregator or user-defined operator, the assemblies that contain their code need to be referenced in the U-SQL script and the assembly has to be registered in the catalog with CREATE ASSEMBLY command before you can reference it.

The system then loads these assemblies to resolve names and types during compile time and load the code for execution.

Note that all assemblies that are needed at compile time, as well as all assemblies that are needed during execution will need to be referenced. Otherwise an error will be raised.

These requirements however mean, that an assembly that is used by a function that is not directly nor indirectly being used in the script, may not need to be referenced, thus reducing the amount of data that a script has to load for execution.

When referencing multiple assemblies that contain additional files, their names across the entire collection of referenced assemblies in the script need to be unique. In case file names conflict, the error E_CSC_USER_CONFLICTINGASSEMBLYFILE is raised. The file name paths of additional assembly files also cannot conflict with file name paths of deployed resources. In case they conflict, the error E_CSC_USER_SAMERESOURCEWITHDIFFERENTPATH is raised.

Syntax

Reference_User_Assembly_Statement :=                                                                     
     'REFERENCE' 'ASSEMBLY' Global_Assembly_Identifier.
Global_Assembly_Identifier := Quoted_or_Unquoted_Identifier.

Remarks

  • Global_Assembly_Identifier
    Specifies the quoted or unquoted identifier of the assembly to be loaded. The assembly name is resolved against the current static database context.

Examples

  • The examples can be executed in Visual Studio with the Azure Data Lake Tools plug-in.
  • The scripts can be executed locally. An Azure subscription and Azure Data Lake Analytics account is not needed when executed locally.
USE DATABASE SQLSpatial;

REFERENCE SYSTEM ASSEMBLY [System.Xml];
REFERENCE ASSEMBLY SqlSpatial;

USING Geometry = Microsoft.SqlServer.Types.SqlGeometry;
USING Geography = Microsoft.SqlServer.Types.SqlGeography;
USING SqlChars = System.Data.SqlTypes.SqlChars;

@spatial =
    SELECT * FROM (VALUES 
                   // The following expression is not using the native DDL
                   ( Geometry.Point(1.0,1.0,0).ToString()),    
                   // The following expression is using the native DDL
                   ( Geometry.STGeomFromText(new SqlChars("LINESTRING (100 100, 20 180, 180 180)"), 0).ToString()) 
                  ) AS T(geom);

OUTPUT @spatial
TO "/Output/ReferenceGuide/DDL/Assemblies/spatial.csv"
USING Outputters.Csv();

See Also