Skip to content

Latest commit

 

History

History
113 lines (72 loc) · 4.71 KB

apache-hadoop-use-mapreduce-powershell.md

File metadata and controls

113 lines (72 loc) · 4.71 KB
title description services author ms.reviewer ms.service ms.custom ms.topic ms.date ms.author
Use MapReduce and PowerShell with Apache Hadoop - Azure HDInsight
Learn how to use PowerShell to remotely run MapReduce jobs with Apache Hadoop on HDInsight.
hdinsight
hrasheed-msft
jasonh
hdinsight
hdinsightactive
conceptual
05/09/2018
hrasheed

Run MapReduce jobs with Apache Hadoop on HDInsight using PowerShell

[!INCLUDE mapreduce-selector]

This document provides an example of using Azure PowerShell to run a MapReduce job in a Hadoop on HDInsight cluster.

Prerequisites

  • An Azure HDInsight (Hadoop on HDInsight) cluster

    [!IMPORTANT] Linux is the only operating system used on HDInsight version 3.4 or greater. For more information, see HDInsight retirement on Windows.

  • A workstation with Azure PowerShell.

Run a MapReduce job

Azure PowerShell provides cmdlets that allow you to remotely run MapReduce jobs on HDInsight. Internally, PowerShell makes REST calls to WebHCat (formerly called Templeton) running on the HDInsight cluster.

The following cmdlets are used when running MapReduce jobs in a remote HDInsight cluster.

  • Connect-AzureRmAccount: Authenticates Azure PowerShell to your Azure subscription.

  • New-AzureRmHDInsightMapReduceJobDefinition: Creates a new job definition by using the specified MapReduce information.

  • Start-AzureRmHDInsightJob: Sends the job definition to HDInsight and starts the job. A job object is returned.

  • Wait-AzureRmHDInsightJob: Uses the job object to check the status of the job. It waits until the job completes or the wait time is exceeded.

  • Get-AzureRmHDInsightJobOutput: Used to retrieve the output of the job.

The following steps demonstrate how to use these cmdlets to run a job in your HDInsight cluster.

  1. Using an editor, save the following code as mapreducejob.ps1.

    [!code-powershellmain]

  2. Open a new Azure PowerShell command prompt. Change directories to the location of the mapreducejob.ps1 file, then use the following command to run the script:

     .\mapreducejob.ps1
    

    When you run the script, you are prompted for the name of the HDInsight cluster and the cluster login. You may also be prompted to authenticate to your Azure subscription.

  3. When the job completes, you receive output similar to the following text:

     Cluster         : CLUSTERNAME
     ExitCode        : 0
     Name            : wordcount
     PercentComplete : map 100% reduce 100%
     Query           :
     State           : Completed
     StatusDirectory : f1ed2028-afe8-402f-a24b-13cc17858097
     SubmissionTime  : 12/5/2014 8:34:09 PM
     JobId           : job_1415949758166_0071
    

    This output indicates that the job completed successfully.

    [!NOTE] If the ExitCode is a value other than 0, see Troubleshooting.

    This example also stores the downloaded files to an output.txt file in the directory that you run the script from.

View output

To see the words and counts produced by the job, open the output.txt file in a text editor.

Note

The output files of a MapReduce job are immutable. So if you rerun this sample, you need to change the name of the output file.

Troubleshooting

If no information is returned when the job completes, view errors for the job. To view error information for this job, add the following command to the end of the mapreducejob.ps1 file, save it, and then run it again.

# Print the output of the WordCount job.
Write-Host "Display the standard output ..." -ForegroundColor Green
Get-AzureRmHDInsightJobOutput `
        -Clustername $clusterName `
        -JobId $wordCountJob.JobId `
        -HttpCredential $creds `
        -DisplayOutputType StandardError

This cmdlet returns the information that was written to STDERR as the job runs.

Summary

As you can see, Azure PowerShell provides an easy way to run MapReduce jobs on an HDInsight cluster, monitor the job status, and retrieve the output.

Next steps

For general information about MapReduce jobs in HDInsight:

For information about other ways you can work with Hadoop on HDInsight: