使用適用於 Visual Studio 的 Data Lake 工具來開發 U-SQL 指令碼Develop U-SQL scripts by using Data Lake Tools for Visual Studio

Azure Data Lake 和串流分析工具包含兩項 Azure 服務、Azure Data Lake Analytics 和 Azure 串流分析相關的功能。Azure Data Lake and Stream Analytics Tools include functionality related to two Azure services, Azure Data Lake Analytics and Azure Stream Analytics. 如需 Azure 串流分析案例的詳細資訊,請參閱適用於 Visual Studio 的 Azure 串流分析工具For more information on the Azure Stream Analytics scenarios, see Azure Stream Analytics tools for Visual Studio.

本文說明如何使用 Visual Studio 建立 Azure Data Lake Analytics 帳戶、在 U-SQL 中定義作業,以及將作業提交至 Data Lake Analytics 服務。This article describes how to use Visual Studio to create Azure Data Lake Analytics accounts, define jobs in U-SQL, and submit jobs to the Data Lake Analytics service. 如需有關 Data Lake Analytics 的詳細資訊,請參閱 Azure Data Lake Analytics 概觀For more information about Data Lake Analytics, see Azure Data Lake Analytics overview.

重要

Microsoft 建議您升級至 Azure Data Lake Tools for Visual Studio 2.3.3000.4 版或更新版本。Microsoft recommends you upgrade to Azure Data Lake Tools for Visual Studio version 2.3.3000.4 or later. 舊版目前已淘汰,不再提供下載。The previous versions are no longer available for download and are now deprecated.

我需要做什麼事嗎?What do I need to do?

  1. 請檢查您是否使用比 2.3.3000.4 版 Azure Data Lake Tools for Visual Studio 還要舊的版本。Check if you are using an earlier version than 2.3.3000.4 of Azure Data Lake Tools for Visual Studio.

    檢查工具版本

  2. 如果您的版本比 2.3.3000.4 版還要舊,請藉由造訪下載中心來更新您的 Azure Data Lake Tools for Visual Studio:If your version is an earlier version of 2.3.3000.4, update your Azure Data Lake Tools for Visual Studio by visiting the download center:

先決條件Prerequisites

安裝 Azure Data Lake Tools for Visual StudioInstall Azure Data Lake Tools for Visual Studio

要進行本教學課程,就必須安裝 Data Lake Tools for Visual Studio。This tutorial requires that Data Lake Tools for Visual Studio is installed. 請依照安裝指示進行。Follow the installation instructions.

連線至 Azure Data Lake Analytics 帳戶Connect to an Azure Data Lake Analytics account

  1. 開啟 Visual Studio。Open Visual Studio.

  2. 選取 [檢視] > [伺服器總管] 可開啟伺服器總管。Open Server Explorer by selecting View > Server Explorer.

  3. 以滑鼠右鍵按一下 [Azure] 。Right-click Azure. 然後選取 [連線到 Microsoft Azure 訂用帳戶] 並遵循指示進行。Then select Connect to Microsoft Azure Subscription and follow the instructions.

  4. 在 [伺服器總管] 中,選取 Azure > Data Lake AnalyticsIn Server Explorer, select Azure > Data Lake Analytics. 您會看到 Data Lake Analytics 帳戶的清單。You see a list of your Data Lake Analytics accounts.

撰寫第一個 U-SQL 指令碼Write your first U-SQL script

下列文字是簡單的 U-SQL 指令碼。The following text is a simple U-SQL script. 它會定義小型資料集,並將該資料集寫入預設 Data Lake Store 中,作為名為 /data.csv 的檔案。It defines a small dataset and writes that dataset to the default Data Lake Store as a file called /data.csv.

USE DATABASE master;
USE SCHEMA dbo;
@a  = 
    SELECT * FROM 
        (VALUES
            ("Contoso", 1500.0),
            ("Woodgrove", 2700.0)
        ) AS 
              D( customer, amount );
OUTPUT @a
    TO "/data.csv"
    USING Outputters.Csv();

提交 Data Lake Analytics 作業Submit a Data Lake Analytics job

  1. 選取 [檔案] > [新增] > [專案] 。Select File > New > Project.

  2. 選取 [U-SQL 專案] 類型,然後按一下 [確定] 。Select the U-SQL Project type, and then click OK. Visual Studio 會建立具有 Script.usql 檔案的解決方案。Visual Studio creates a solution with a Script.usql file.

  3. 將先前的指令碼貼上 Script.usql 視窗。Paste the previous script into the Script.usql window.

  4. Script.usql 視窗的左上角中,指定 Data Lake Analytics 帳戶。In the upper-left corner of the Script.usql window, specify the Data Lake Analytics account.

    提交 U-SQL Visual Studio 專案

  5. Script.usql 視窗的左上角中,選取 [提交] 。In the upper-left corner of the Script.usql window, select Submit.

  6. 提交作業之後,[作業檢視] 索引標籤隨即開啟,並顯示作業進度。After the job submission, the Job view tab opens to show the job progress. 按一下 [重新整理] ,可查看最新的作業狀態並重新整理畫面。To see the latest job status and refresh the screen, click Refresh.

    U SQL Visual Studio Data Lake Analytics 工作效能圖表

    • 作業摘要會顯示作業的摘要。Job Summary shows the summary of the job.
    • 作業圖形會以視覺化方式檢視作業的進度。Job Graph visualizes the progress of the job.
    • 中繼資料作業會顯示 U-SQL 目錄上所執行的所有動作。MetaData Operations shows all the actions that were taken on the U-SQL catalog.
    • 資料會顯示所有的輸入和輸出。Data shows all the inputs and outputs.
    • [狀態歷程記錄] 會顯示時間軸和狀態的詳細資料。State History shows the timeline and state details.
    • [AU 分析] 會顯示作業中使用了多少個 AU,並探索不同 AU 配置策略的模擬。AU Analysis shows how many AUs were used in the job and explore simulations of different AUs allocation strategies.
    • 診斷會提供作業執行和效能最佳化的進階分析。Diagnostics provides an advanced analysis for job execution and performance optimization.

檢查作業狀態Check job status

  1. 在 [伺服器總管] 中,選取 Azure > Data Lake AnalyticsIn Server Explorer, select Azure > Data Lake Analytics.

  2. 展開 Data Lake Analytics 帳戶名稱。Expand the Data Lake Analytics account name.

  3. 按兩下 [作業] 。Double-click Jobs.

  4. 選取您先前提交的作業。Select the job that you previously submitted.

查看作業輸出See the job output

  1. 在伺服器總管中,瀏覽至您所提交的作業。In Server Explorer, browse to the job you submitted.

  2. 按一下 [資料] 索引標籤。Click the Data tab.

  3. 在 [作業輸出] 索引標籤中,選取 "/data.csv" 檔案。In the Job Outputs tab, select the "/data.csv" file.

後續步驟Next steps