IMPORT PACKAGE (U-SQL)

Summary

The IMPORT PACKAGE statement will import all the assembly references, variable declarations and resource deployments exported by the specified package. The package identifier will be resolved in the static context of its invocation and can refer to a package in the current account or a different Azure Data Lake Analytics account. The optional arguments can be used inside the package.

If conflicting assemblies or references are being referenced, imported or deployed, errors are raised once a package gets imported in the main U-SQL script.

Syntax

Import_Package_Statement :=                                                                              
    'IMPORT' 'PACKAGE' Global_Identifier ['(' [Argument_List] ')'] [Package_Alias].
Package_Alias := 'AS' Package_Name_Alias.
Package_Name_Alias := Quoted_or_Unquoted_Identifier.

The optional package alias must be used when referring to variables imported from the given package.

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.
  • The examples utilize the packages created from CREATE PACKAGE (U-SQL).

The following script uses the now the previously defined package XMLorJSON from database TestReferenceDB with the parameter xml and parses the XML file that was provided in the package's @xmlfile variable. Please note that the file deployment will occur as well, but is not really required for this script to work.

IMPORT PACKAGE TestReferenceDB.dbo.XMLorJSON("xml") AS xmlpackage;

USING xml = Microsoft.Analytics.Samples.Formats.Xml;

// Currently the EXTRACT FROM and OUTPUT TO clauses do not support package variables.
// Therefore we need to rename them.
DECLARE @input = xmlpackage.@xmlfile;

@configdata =
EXTRACT option1 string,
        option2 string,
        option3 string
FROM @input
USING new xml.XmlDomExtractor("/config", 
                                new SqlMap<string,string>{
                                    {"option1", "option1"},
                                    {"option2", "option2"}, 
                                    {"option3", "option3"}});

@res =
SELECT xmlpackage.@format AS format,
        *
FROM @configdata;

OUTPUT @res
TO "/output/packexample.csv"
USING Outputters.Csv();

See Also