您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在本地计算机上运行 U-SQL 脚本Run U-SQL scripts on your local machine

开发 U-SQL 脚本时,我们通常会在本地运行 U-SQL 脚本,因为这可以节省时间和开支。When you develop U-SQL scripts, you can save time and expense by running the scripts locally. 针对 Visual Studio 的 Azure Data Lake 工具支持在本地计算机上运行 U-SQL 脚本。Azure Data Lake Tools for Visual Studio supports running U-SQL scripts on your local machine.

本地运行的基本概念Basic concepts for local runs

以下图表显示用于本地运行的组件以及这些组件如何映射到云运行。The following chart shows the components for local run and how these components map to cloud run.

组件Component 本地运行Local run 云运行Cloud run
存储Storage 本地数据根文件夹Local data root folder 默认 Azure Data Lake Store 帐户Default Azure Data Lake Store account
计算Compute U-SQL 本地运行引擎U-SQL local run engine Azure Data Lake Analytics 服务Azure Data Lake Analytics service
运行环境Run environment 本地计算机上的工作目录Working directory on local machine Azure Data Lake Analytics 群集Azure Data Lake Analytics cluster

以下部分提供有关本地运行组件的详细信息。The sections that follow provide more information about local run components.

本地数据根文件夹Local data root folders

本地数据根文件夹是本地计算帐户的 本地存储A local data root folder is a local store for the local compute account. 本地计算机上的本地文件系统中的任何文件夹都可以是本地数据根文件夹。Any folder in the local file system on your local machine can be a local data root folder. 它等同于 Data Lake Analytics 帐户的默认 Azure Data Lake Store 帐户。It's the same as the default Azure Data Lake Store account of a Data Lake Analytics account. 切换到不同数据根文件夹与切换到不同默认存储帐户的操作相同。Switching to a different data root folder is just like switching to a different default store account.

数据根文件夹的用途如下:The data root folder is used as follows:

  • 存储元数据。Store metadata. 示例包括数据库、表、表值函数和程序集。Examples are databases, tables, table-valued functions, and assemblies.
  • 查找在 U-SQL 脚本中定义为相对路径的输入和输出路径。Look up the input and output paths that are defined as relative paths in U-SQL scripts. 使用相对路径可更轻松地将 U-SQL 脚本部署到 Azure。By using relative paths, it's easier to deploy your U-SQL scripts to Azure.

U-SQL 本地运行引擎U-SQL local run engines

U-SQL 本地运行引擎是 U-SQL 作业的 本地计算帐户A U-SQL local run engine is a local compute account for U-SQL jobs. 用户可以通过针对 Visual Studio 的 Azure Data Lake 工具在本地运行 U-SQL 作业。Users can run U-SQL jobs locally through Azure Data Lake Tools for Visual Studio. 也支持通过 Azure Data Lake U-SQL SDK 命令行和编程接口在本地运行。Local runs are also supported through the Azure Data Lake U-SQL SDK command-line and programming interfaces. 详细了解 Azure Data Lake U-SQL SDKLearn more about the Azure Data Lake U-SQL SDK.

工作目录Working directories

运行 U-SQL 脚本时,需要使用工作目录文件夹来缓存编译结果、运行日志和执行其他函数。When you run a U-SQL script, a working directory folder is needed to cache compilation results, run logs, and perform other functions. 在针对 Visual Studio 的 Azure Data Lake 工具中,工作目录是 U-SQL 项目的工作目录。In Azure Data Lake Tools for Visual Studio, the working directory is the U-SQL project’s working directory. 该目录位于 <U-SQL project root path>/bin/debug> 下。It's located under <U-SQL project root path>/bin/debug>. 工作目录将在每次触发新运行时清理。The working directory is cleaned every time a new run is triggered.

Microsoft Visual Studio 中的本地运行Local runs in Microsoft Visual Studio

针对 Visual Studio 的 Azure Data Lake 工具具有内置的本地运行引擎。Azure Data Lake Tools for Visual Studio have a built-in local run engine. 这些工具将引擎展现为本地计算帐户。The tools surface the engine as a local compute account. 若要在本地运行 U-SQL 脚本,请在脚本的编辑器边缘下拉菜单中选择“本地计算机”或“本地项目”帐户。To run a U-SQL script locally, select the Local-machine or Local-project account in the script’s editor margin drop-down menu. 然后选择 “提交”Then select Submit.

将 U-SQL 脚本提交到本地帐户

使用本地计算机帐户的本地运行Local runs with a Local-machine account

本地计算机 帐户是一个共享的本地计算帐户,它含有单个本地数据根文件夹,作为本地存储帐户。A Local-machine account is a shared local compute account with a single local data root folder as the local store account. 默认情况下,数据根文件夹位于 C:\Users <username> \AppData\Local\USQLDataRootBy default, the data root folder is located at C:\Users<username>\AppData\Local\USQLDataRoot. 它还可通过 工具 > Data Lake > 选项和设置 进行配置。It's also configurable through Tools > Data Lake > Options and Settings.

配置本地数据根文件夹

本地运行需要一个 U-SQL 项目。A U-SQL project is required for a local run. U-SQL 项目的工作目录用于 U-SQL 本地运行工作目录。The U-SQL project’s working directory is used for the U-SQL local run working directory. 在本地运行期间生成编译结果、运行日志和其他与作业运行相关的文件,并存储在工作目录文件夹下。Compilation results, run logs, and other job run-related files are generated and stored under the working directory folder during the local run. 每次重新运行脚本时,工作目录中的所有这些文件都将被清理和重新生成。Every time you rerun the script, all the files in the working directory are cleaned and regenerated.

使用本地项目帐户的本地运行Local runs with a Local-project account

本地项目 帐户是针对每个项目独立于项目的本地计算帐户,具有独立的本地数据根文件夹。A Local-project account is a project-isolated local compute account for each project with an isolated local data root folder. 在解决方案资源管理器中打开的每个活动 U-SQL 项目都具有相应的 (Local-project: <project name>) 帐户。Every active U-SQL project that opens in Solution Explorer in Visual Studio has a corresponding (Local-project: <project name>) account. 该帐户在服务器资源管理器和 U-SQL 脚本编辑器的边缘列出。The accounts are listed in both Server Explorer in Visual Studio and the U-SQL script editor margin.

本地项目 帐户提供整洁和独立的开发环境。The Local-project account provides a clean and isolated development environment. 本地计算机 帐户具有一个共享的本地数据根文件夹,该文件夹为所有本地作业存储元数据和输入/输出数据。A Local-machine account has a shared local data root folder that stores metadata and input and output data for all local jobs. 但是,本地项目 帐户在 U-SQL 脚本每次运行时,在 U-SQL 项目工作目录下创建一个临时的本地数据根文件夹。But a Local-project account creates a temporary local data root folder under a U-SQL project working directory every time a U-SQL script is run. 此临时数据根文件夹将在重新生成或重新运行时被清理。This temporary data root folder is cleaned when a rebuild or rerun happens.

U-SQL 项目通过项目引用和属性来管理独立的本地运行环境。A U-SQL project manages the isolated local run environment through a project reference and property. 可以在项目和引用的数据库环境中配置 U-SQL 脚本的输入数据源。You can configure the input data sources for U-SQL scripts in both the project and the referenced database environments.

管理本地项目帐户的输入数据源Manage the input data source for a Local-project account

U-SQL 项目为 本地项目 帐户创建本地数据根文件夹和设置数据。A U-SQL project creates a local data root folder and sets up data for a Local-project account. 每次重新生成和在本地运行时,将在 U-SQL 项目工作目录下清理并重新创建临时数据根文件夹。A temporary data root folder is cleaned and recreated under the U-SQL project working directory every time a rebuild and local run happens. 由 U-SQL 项目配置的所有数据源将在本地作业运行之前复制到此临时本地数据根文件夹。All data sources that are configured by the U-SQL project are copied to this temporary local data root folder before the local job runs.

可以配置数据源的根文件夹。You can configure the root folder of your data sources. 右键单击 " U-SQL 项目 > 属性" " > 测试数据源"。Right-click U-SQL project > Property > Test Data Source. 本地项目 帐户中运行 U-SQL 脚本时,“测试数据源”文件夹中的所有文件和子文件夹将复制到临时本地数据根文件夹。When you run a U-SQL script on a Local-project account, all files and subfolders in the Test Data Source folder are copied to the temporary local data root folder. 包括子文件夹下的文件。Files under subfolders are included. 运行本地作业后,还可以在项目工作目录中的临时本地数据根文件夹下找到输出结果。After a local job runs, output results can also be found under the temporary local data root folder in the project working directory. 重新生成和清理项目时,将删除并清理所有这些输出。All this output is deleted and cleaned when the project gets rebuilt and cleaned.

配置项目的测试数据源

管理 本地项目 帐户的引用数据库环境Manage a referenced database environment for a Local-project account

如果 U-SQL 使用 U-SQL 数据库对象或使用它来进行查询,则在本地运行此 U-SQL 脚本前,必须在本地准备好数据库环境。If a U-SQL query uses or queries with U-SQL database objects, you must make the database environments ready locally before you run the U-SQL script locally. 对于 本地项目 帐户,U-SQL 数据库依赖关系可通过 U-SQL 项目引用进行管理。For a Local-project account, U-SQL database dependencies can be managed by U-SQL project references. 可将 U-SQL 数据库项目引用添加到 U-SQL 项目。You can add U-SQL database project references to your U-SQL project. 本地项目 帐户中运行 U-SQL 脚本之前,所有引用的数据库将部署到临时本地数据根文件夹。Before running U-SQL scripts on a Local-project account, all referenced databases are deployed to the temporary local data root folder. 每次运行时,临时数据根文件夹将清理为全新的隔离环境。And for each run, the temporary data root folder is cleaned as a fresh isolated environment.

请参阅以下相关文章:See this related article:

本地计算机本地项目 帐户之间的差异The difference between Local-machine and Local-project accounts

本地计算机 帐户在用户的本地计算机上模拟 Azure Data Lake Analytics 帐户。A Local-machine account simulates an Azure Data Lake Analytics account on users’ local machines. 它与 Azure Data Lake Analytics 帐户具有相同的体验。It shares the same experience with an Azure Data Lake Analytics account. 本地项目 帐户提供用户友好的本地开发环境。A Local-project account provides a user-friendly local development environment. 此环境可帮助用户在本地运行脚本之前部署数据库引用和输入数据。This environment helps users deploy database references and input data before they run scripts locally. 本地计算机 帐户提供共享的永久环境,可通过所有项目来访问。A Local-machine account provides a shared permanent environment that can be accessed through all projects. 本地项目 帐户为每个项目提供独立开发环境。A Local-project account provides an isolated development environment for each project. 每次运行时都会刷新该环境。It's refreshed for each run. 本地项目 帐户通过快速应用新更改来提供更快的开发体验。A Local-project account offers a faster development experience by quickly applying new changes.

下表描述了 本地计算机本地项目 帐户之间的其他差别:More differences between Local-machine and Local-project accounts are shown in the following table:

差异角度Difference angle 本地计算机Local-machine 本地项目Local-project
本地访问Local access 可由所有项目访问。Can be accessed by all projects. 只有相应的项目能够访问此帐户。Only the corresponding project can access this account.
本地数据根文件夹Local data root folder 永久本地文件夹。A permanent local folder. 通过 工具 > Data Lake > 选项和设置进行 配置。Configured through Tools > Data Lake > Options and Settings. 为在 U-SQL 项目工作目录下的每个本地运行创建的临时文件夹。A temporary folder created for each local run under the U-SQL project working directory. 重新生成或重新运行时会清理该文件夹。The folder gets cleaned when a rebuild or rerun happens.
U-SQL 脚本的输入数据Input data for a U-SQL script 永久本地数据根文件夹下的相对路径。The relative path under the permanent local data root folder. 通过 U-SQL 项目属性 > 测试数据源 设置。Set through U-SQL project property > Test Data Source. 在本地运行之前,会将所有文件和子文件夹复制到临时数据根文件夹。All files and subfolders are copied to the temporary data root folder before a local run.
U-SQL 脚本的输出数据Output data for a U-SQL script 永久本地数据根文件夹下的相对路径。Relative path under the permanent local data root folder. 输出到临时数据根文件夹。Output to the temporary data root folder. 在重新生成或重新运行时清理结果。The results are cleaned when a rebuild or rerun happens.
引用的数据库部署Referenced database deployment 针对 本地计算机 帐户运行时,不会自动部署引用的数据库。Referenced databases aren't deployed automatically when running against a Local-machine account. 在提交到 Azure Data Lake Analytics 帐户时也是如此。It's the same for submitting to an Azure Data Lake Analytics account. 引用的数据库在本地运行之前自动部署到 本地项目 帐户。Referenced databases are deployed to the Local-project account automatically before a local run. 重新生成或重新运行时,会清理和重新部署所有数据库环境。All database environments are cleaned and redeployed when a rebuild or rerun happens.

使用 U-SQL SDK 的本地运行A local run with the U-SQL SDK

可以在 Visual Studio 中本地运行 U-SQL 脚本,此外,还可以使用 Azure Data Lake U-SQL SDK 通过命令行及编程接口在本地运行 U-SQL 脚本。You can run U-SQL scripts locally in Visual Studio and also use the Azure Data Lake U-SQL SDK to run U-SQL scripts locally with command-line and programming interfaces. 通过这些接口,可以自动执行 U-SQL 本地运行和测试。Through these interfaces, you can automate U-SQL local runs and tests.

详细了解 Azure Data Lake U-SQL SDKLearn more about the Azure Data Lake U-SQL SDK.

后续步骤Next steps