<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Big Data Support</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/bigdatasupport/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/feed.xml</link>
    <description>This is the team blog for the Big Data Analytics &amp;amp; NoSQL Support team at Microsoft. We support HDInsight which is Hadoop running on Azure in the cloud, as well as other big data analytics features.</description>
    <lastBuildDate>Mon, 03 Oct 2016 17:43:23 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Rerunning many slices and activities in Azure Data Factory</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/rerunning-many-slices-and-activities-in-azure-data-factory</link>
      <pubDate>Wed, 31 Aug 2016 20:09:20 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/?p=1635</guid>
      <description><![CDATA[Today someone asked me how to run all the data slices in their data factory on-demand in an ad-hoc...]]></description>
      <content:encoded><![CDATA[<p>Today someone asked me how to run all the data slices in their data factory on-demand in an ad-hoc fashion, to say run the whole pipeline again from scratch. 
</p><p>For example, if you have a one-time copy data factory that is used to load a data warehouse or a development environment in its entirety, you might want to run it only on-demand, and not have it run on a schedule.
</p><h1>A. Click on each Dataset and click Run on the data slice blade
</h1><p>Then can click on one data set at a time and run it or rerun it. That is still a piecemeal and a bit tedious if you have many datasets and slice times.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2016/08/090116_0013_Rerunningma1.png" alt="" />
	</p><p>1. Select the data set in question. 2. Find the time slice in question. 3. Click the Run button to rerun it.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2016/08/090116_0013_Rerunningma2.png" alt="" />
	</p><h1>B. Multiselect from the ADF Monitor and Manage web app.
</h1><p>You can filter the list and rerun the slices from the Monitoring web app. Multiselect (hold shift key and arrow down through the list) will work there in the Activity Windows grid, then you can run many with a single click.
</p><p>If you have 100 tables being copied for example, you might have a bunch of different data sets and nested slice times as shown.
</p><p>However, if you have a one-time copy that you did from the Copy Data tool in the browser, you won't see any data sets most likely, so this option is universal for all copy activities I worry.
</p><p><img src="https://msdnshared.blob.core.windows.net/media/2016/08/090116_0013_Rerunningma3.png" alt="" />
	</p><p>
 </p><h1>C. Script it with PowerShell
</h1><p>Another way to rerun many slices is to use a PowerShell script to loop over all datasets in a given data factory or pipeline and reset the status to run them again.
</p><p>Below is a code sample to do that. <span style="font-family:Arial">This script will rerun all slices on all datasets. If you only want to run some of them (not all slices), you can change the * filter in the where like query.
</span></p><h2>1. Launch Windows PowerShell ISE from the Windows start menu. 
</h2><p><span style="font-family:Arial">Open the code, or paste it in the <strong>script</strong> window at the top. <br />You can press the play button to run the whole script, or highlight lines piecemeal and run selection as needed.
</span></p><p><span style="font-family:Arial">Example of how to highlight the code and run one line at a time:
</span></p><p><img src="https://msdnshared.blob.core.windows.net/media/2016/08/090116_0013_Rerunningma4.png" alt="" /><span style="font-family:Arial">
		</span></p><h2>2. First time Installations
</h2><p><span style="font-family:Arial">The first time you want to use Azure PowerShell on a given computer, you could either Download the whole Azure PowerShell SDK  or launch powershell <strong>as administrator</strong> and run PowerShell commands to install the needed modules:
</span></p><blockquote><p>Install-Module <span style="color:blueviolet">AzureRM  
</span></p></blockquote><blockquote><p>Install-Module <span style="color:blueviolet">AzureRM.DataFactories 
</span></p></blockquote><p style="background: white"> 
 </p><h2>3. Set your active subscription once per session.
</h2><p>The first time you need to get connected to Azure and authenticate, and pick which subscription to work on. <br />If you use the same PowerShell window on the second time, you can skip these lines, to save time and save typing your password again. Use # pound sign as a comment to comment out the code as needed.
</p><blockquote><p># To login to Azure Resource Manager<br /><span style="color:blue">Login-AzureRmAccount
</span></p></blockquote><blockquote><p># To view all subscriptions for your account<br /><span style="color:blue">Get-AzureRmSubscription
</span></p></blockquote><blockquote><p><span style="color:darkgreen"># To select a default subscription for your current session<br />Get-AzureRmSubscription -SubscriptionName "your sub" | Select-AzureRmSubscription
</span></p></blockquote><p>
 </p><h2>4. Example PowerShell code to run. 
</h2><p>
 </p><p>There are #Comments inline to help you understand the intent. 
</p><p>This sample finds your data factory by name and resource group, then lists all slices, and loops to set the slice status to waiting. That will reset them so that the slices run again. 
</p><p>In case you want to filter just to Output slices, or a certain naming pattern, you can edit the <em>like</em> * clause.  
</p><p>You should adjust the <span style="background-color:yellow">two time stamps</span> highlighted to a reasonable range so that it finds only recent slices, else it may be a bit slow if you have days or years of slices in the history to repeat.
</p><p>
		<span style="color:navy">-StartDateTime</span>
		<span style="color:blueviolet">2016-01-01T00:00:00.0000000   <span style="color:navy">-EndDateTime</span> 2017-01-01T00:00:00.0000000</span>
	</p><p>
 </p><blockquote><p><span style="color:darkgreen">#Put your Data Factory name and Resource group here<br /><span style="color:orangered">$RG <span style="color:darkgray">= "YourResourceGroup"<br /><span style="color:orangered">$DFname <span style="color:darkgray">= "YourFactory"
</span></span></span></span></span></p></blockquote><blockquote><p><span style="color:darkgreen">#Once per session - comment out to save time<br /># Login-AzureRmAccount
</span></p></blockquote><blockquote><p><span style="color:darkgreen"># Once, select a default subscription for your current session<br /># Get-AzureRmSubscription -SubscriptionName "your sub" | Select-AzureRmSubscription
</span></p></blockquote><blockquote><p><span style="color:darkgreen"># One time per computer - comment out to save time<br /># Register-AzureRmResourceProvider -ProviderNamespace Microsoft.DataFactory
</span></p></blockquote><blockquote><p><span style="color:darkgreen"># Debug option: List all DF in a resource group for debugging if needed<br /># Get-AzureRmDataFactory -ResourceGroupName  $RG 
</span></p></blockquote><blockquote><p><span style="color:darkgreen"># Find the Data Factory<br /><span style="color:orangered">$df<span style="color:darkgray">= <span style="color:blue">Get-AzureRmDataFactory <span style="color:navy">-ResourceGroupName  <span style="color:orangered">$RG <span style="color:navy">-Name <span style="color:orangered">$DFname<br /><span style="color:darkblue">if (<span style="color:orangered">$df <span style="color:darkgray">-eq <span style="color:orangered">$null) { <span style="color:blue">Write-Host "Data Factory " <span style="color:orangered">$DFname " cannot be found. Check spelling and resource group name. Error: " $_ <span style="color:navy">-BackgroundColor:<span style="color:blueviolet">Red }
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p></blockquote><blockquote><p><span style="color:darkgreen"># List all DataSets in the data factory - Add the LIKE filter by name instead of * if needed such as *output*<br /><span style="color:orangered">$DataSets <span style="color:darkgray">= <span style="color:blue">Get-AzureRmDataFactoryDataset <span style="color:navy">-DataFactory <span style="color:orangered">$df <span style="color:darkgray">| <span style="color:blue">Where {<span style="color:orangered">$_<span style="color:darkgray">.DatasetName -like "*"} | <span style="color:blue">Sort-Object <span style="color:blueviolet">DatasetName
</span></span></span></span></span></span></span></span></span></span></span></span></p></blockquote><blockquote><p><span style="color:darkgreen"># Loop over matching named DataSets<br /><span style="color:orangered">$i <span style="color:darkgray">= <span style="color:purple">1<br /><span style="color:darkblue">ForEach(<span style="color:orangered">$DS <span style="color:darkblue">in <span style="color:orangered">$DataSets)<br />{<br />
											<span style="color:blue">Write-Host <span style="color:orangered">$DS<span style="color:darkgray">.DataFactoryName "--&gt; " <span style="color:orangered">$DS<span style="color:darkgray">.DatasetName <span style="color:navy">-ForegroundColor:<span style="color:blueviolet">Yellow  <br />
																		<span style="color:darkgreen"># List slices<br />
																			<span style="color:orangered">$Slices <span style="color:darkgray">= <span style="color:blue">Get-AzureRmDataFactorySlice <span style="color:navy">-DataFactory <span style="color:orangered">$df <span style="color:navy">-DatasetName <span style="color:orangered">$DS<span style="color:darkgray">.DatasetName <span style="color:navy"><span style="background-color:yellow">-StartDateTime <span style="color:blueviolet">2016-01-01T00:00:00.0000000 <span style="color:navy">-EndDateTime <span style="color:blueviolet">2017-01-01T00:00:00.0000000</span></span></span></span>
																											</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p></blockquote><blockquote><p><span style="color:darkgreen"># Reset all slices to status Waiting for the given dataset, in case there are multiple<br />
				<span style="color:darkblue">ForEach(<span style="color:orangered">$S <span style="color:darkblue">in <span style="color:orangered">$Slices) <br />    {<br />        $outcome<span style="color:darkgray">=<span style="color:orangered">$false<br />
										<span style="color:blue">Write-Host <span style="color:orangered">$i ":" $DS<span style="color:darkgray">.DataFactoryName "--&gt; " <span style="color:orangered">$DS<span style="color:darkgray">.DatasetName "--&gt; Slice Start:["<span style="color:orangered">$S<span style="color:darkgray">.Start"] End:["<span style="color:orangered">$S<span style="color:darkgray">.End"] State:"<span style="color:orangered">$S<span style="color:darkgray">.State <span style="color:orangered">$S<span style="color:darkgray">.SubState <span style="color:navy">-ForegroundColor:<span style="color:blueviolet">Cyan
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p></blockquote><blockquote><p>
			<span style="color:darkblue">Try {<br />
				<span style="color:orangered">$outcome<span style="color:darkgray">=<span style="color:blue">Set-AzureRmDataFactorySliceStatus <span style="color:navy">-DataFactory <span style="color:orangered">$df <span style="color:navy">-DatasetName <span style="color:orangered">$DS<span style="color:darkgray">.DatasetName <span style="color:navy">-Status <span style="color:blueviolet">Waiting <span style="color:navy">-UpdateType <span style="color:blueviolet">UpstreamInPipeline <span style="color:navy">-StartDateTime <span style="color:orangered">$S<span style="color:darkgray">.Start <span style="color:navy">-EndDateTime <span style="color:orangered">$S<span style="color:darkgray">.End<br />
																						<span style="color:blue">Write-Host "                          Slice status reset to Waiting so it will run again:" <span style="color:orangered">$outcome <span style="color:navy">-ForegroundColor:<span style="color:blueviolet">Green
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p></blockquote><blockquote><p>        }<br />
			<span style="color:darkblue">Catch<br />        {<br />
				<span style="color:blue">Write-Host "                          Slice status reset has failed. Error: " <span style="color:orangered">$_ <span style="color:navy">-ForegroundColor:<span style="color:blueviolet">Red<br />        }<br />
								<span style="color:orangered">$i<span style="color:darkgray">++<br />    }<br />}
</span></span></span></span></span></span></span></p></blockquote><p style="background: white"> 
 </p><p>
 </p><p>
 </p><blockquote><p>
 </p></blockquote><p>
 </p>]]></content:encoded>
    </item>
    <item>
      <title>Capture Microsoft Azure Stream Analytics logs</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/capture-microsoft-azure-stream-analytics-logs</link>
      <pubDate>Wed, 24 Aug 2016 07:50:18 GMT</pubDate>
      <dc:creator><![CDATA[sudhirblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/?p=1585</guid>
      <description><![CDATA[Microsoft Azure Stream Analytics makes building real time solution very easy. Developers can build...]]></description>
      <content:encoded><![CDATA[<h1></h1>
<p align="justify"><a href="https://azure.microsoft.com/en-in/documentation/articles/stream-analytics-introduction/">Microsoft Azure Stream Analytics</a> makes building real time solution very easy. Developers can build Stream Analytics job with few clicks.</p>
<p align="justify">While running Stream Analytics jobs, you may encounter an error which may cause Stream Analytics job to go in degrade/stop state. So it requires to figure out the error in job to troubleshoot it. There could be various error you might get into like improper data, issue at source/destination side, query computation fail etc. Before you start fixing the issue, it’s required to figure out the cause of the failing job.</p>
<p align="justify">There is a way to figure out the issue from audit logs in azure portal. During our work we figured out another way to capture logs for a Stream Analytics job. In this blog I am showcasing about various technique’s to capture Stream Analytics log including the one we came up using <a href="https://azure.microsoft.com/en-in/documentation/articles/powershell-install-configure/">PowerShell</a>.</p>

<h2 align="justify"><strong>Microsoft Azure Ibiza Portal (<a href="https://portal.azure.com">https://portal.azure.com</a>)</strong></h2>
<ul>
 	<li>
<div align="justify">Click Audit log and click Filter. Change parameter to show only Stream analytic logs (as shown in picture below). Click Update.</div></li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image609.png"><img width="729" height="418" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb493.png" border="0" /></a></blockquote>
<ul>
 	<li>Now we’ll see logs for Azure Stream Analytics. if logs are more, we’ll have <strong>Load More </strong>option at the end to load more logs information.</li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image612.png"><img width="480" height="369" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb494.png" border="0" /></a></blockquote>
<h2><span style="font-weight: bold">Microsoft Azure Classic Portal (<a href="https://manage.windowsazure.com">https://manage.windowsazure.com</a>) </span></h2>
<ul>
 	<li>Either you can go directly to <strong>management services (from left side pane) or click Operation Logs from Stream Analytics dashboard. </strong></li>
</ul>
<p align="center"><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image613.png"><img width="196" height="101" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb495.png" border="0" /></a></p>

<ul>
 	<li>Change parameters and click run to get all logs.</li>
</ul>
<a href="https://msdnshared.blob.core.windows.net/media/2016/08/image614.png"><img width="499" height="350" title="image" style="float: none;padding-top: 0px;padding-left: 0px;margin-left: auto;padding-right: 0px;margin-right: auto;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb496.png" border="0" /></a>
<ul>
 	<li>If there are too many logs then you have to move from one page to another.</li>
</ul>
<p align="justify"></p>

<h2 align="justify"><span style="font-weight: bold">Capture Stream Analytics logs through PowerShell</span></h2>
<p align="justify">There is another way to download Stream Analytics log which is from PowerShell. The PowerShell script not only capture the logs but also zip it in local system.</p>

<ul>
 	<li>
<div align="justify">Download PowerShell script from <a href="https://github.com/rawatsudhir/CaptureASALogScript"><u>here</u></a></div></li>
 	<li>
<div align="justify">Open Windows PowerShell ISE and copy script</div></li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image615.png"><img width="862" height="403" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb497.png" border="0" /></a></blockquote>
<ul>
 	<li>Run Script</li>
 	<li>At first step, it will prompt for login information with which Azure subscription is linked. Stream Analytics job should be part of the subscription.</li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image616.png"><img width="362" height="386" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb498.png" border="0" /></a></blockquote>
<ul>
 	<li>Once authenticated successfully, it will showcase all the Stream Analytics jobs with in the subscription.</li>
 	<li>Choose one or all jobs for which logs need to be extracted. Press <strong>Enter</strong></li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image5110.png"><img width="719" height="194" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image51_thumb.png" border="0" /></a></blockquote>
<ul>
 	<li>Provide number of days log need to be extracted. Press <strong>Enter</strong></li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image617.png"><img width="729" height="212" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb499.png" border="0" /></a>
<ul>
 	<li>After writing log files it will zip all content.</li>
</ul>
</blockquote>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image618.png"><img width="756" height="258" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb500.png" border="0" /></a></blockquote>
<ul>
 	<li>Open <strong>windows explorer</strong> and look onto <strong>C:\Temp</strong> folder. There will be 1) StreamAnalytics folder 2) StreamAnalytics.zip file</li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image619.png"><img width="433" height="147" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb501.png" border="0" /></a></blockquote>
<ul>
 	<li>Open <strong>StreamAnalytics</strong> folder. Below are the files available in it.</li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image620.png"><img width="606" height="144" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb502.png" border="0" /></a></blockquote>
Description of files.
<ul>
 	<li><strong>StreamAnalytics_JobXXXXXXXXXXXXXXXXXXX.txt</strong> and <strong>StreamAnalytics_JobXXXXXXXXXXXXXXXXXXX.json</strong> :- Both contains same information. Later file (with extension JSON) contains information in JSON format. The size of the file depends on number of jobs selected and number of days log required (max 14 days). It contains information like Subscription, Resource Name, Job name, date range, input, output and log.</li>
 	<li><strong>StreamAnalytics_JobsListing.txt</strong> :- This file contains information (mentioned below) about selected job.</li>
</ul>
<blockquote><a href="https://msdnshared.blob.core.windows.net/media/2016/08/image621.png"><img width="1052" height="281" title="image" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/08/image_thumb503.png" border="0" /></a></blockquote>
I would like to thanks my colleagues (Jason Howell and Dan Shaver) for their contribution.

&nbsp;

Hope it help in debugging Stream Analytics job.]]></content:encoded>
    </item>
    <item>
      <title>HDFS gets full in Azure HDInsight with many Hive temporary files</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/hdfs-gets-full-in-azure-hdinsight-with-many-hive-temporary-files</link>
      <pubDate>Mon, 15 Aug 2016 17:24:27 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/?p=1245</guid>
      <description><![CDATA[Sometimes when Hive is using temporary files, and a VM is restarted in an HDInsight cluster in...]]></description>
      <content:encoded><![CDATA[Sometimes when Hive is using temporary files, and a VM is restarted in an HDInsight cluster in Microsoft Azure, then those files can become orphaned and consume space.

In Azure HDInsight, those temp files live in the HDFS file system, which is distributed across the local disks in the worker nodes. This is a different location than where user data is stored in HDInsight, since user data will be kept in Azure Blob Storage or Azure Data Lake Store when using HDInsight. The local disk and HDFS is not used for user data files by default and only the temporary files for Hive are kept there.

In the <strong>Hive-site.xml</strong>, this is the property that controls the location of the temporary files:
<blockquote>&lt;property&gt;
&lt;name&gt;hive.exec.scratchdir&lt;/name&gt;
&lt;value&gt;hdfs://mycluster/tmp/hive&lt;/value&gt;
&lt;/property&gt;</blockquote>
<h2>Step 1. Checking Disk space</h2>
<h3>A&gt; Ambari dashboard shows an HDFS usage percentage in the dashboard.</h3>
This is the HDFS file system spread across a number of worker nodes on local disk.

From the Azure portal, it should direct you to the URL such as https://yourhdinsightname.azurehdinsight.net/

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2016/08/081516_2124_HDFSgetsful1.png" />

Ambari should log this kind of text in its metrics collector "/var/log/ambari-metrics-collector/ambari-metrics-collector.log"
<ul>
 	<li><span style="font-family: Courier New;font-size: 9pt">2016-08-15 20:01:44,739 [WARNING] [HDFS] [namenode_hdfs_capacity_utilization] (HDFS Capacity Utilization) <span style="background-color: yellow">Capacity Used:[82%,</span> 301787316224], Capacity Remaining:[68437065728]
</span></li>
 	<li><span style="font-family: Courier New;font-size: 9pt">2016-08-15 20:01:47,317 [WARNING] [HDFS] [datanode_storage] (DataNode Storage) Remaining Capacity:[29831340032], Total Capacity:[<span style="background-color: yellow">86% Used</span>, 210168897536]
</span></li>
</ul>
<h3>B&gt; To see how much local disk space on each worker node and headnode, you could run these kind of commands.</h3>
You may ssh into each worker node to run it manually.
<h3>&gt; Get free disk space to see if any disk is nearly full.</h3>
<strong>df -h
</strong>
<p style="margin-left: 36pt"><span style="font-family: Courier New;font-size: 7pt">Filesystem Size Used Avail Use% Mounted on
udev 3.4G 12K 3.4G 1% /dev
tmpfs 697M 744K 697M 1% /run
/dev/sda1 985G 15G 931G 2% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 3.5G 12K 3.5G 1% /run/shm
none 100M 0 100M 0% /run/user
none 64K 0 64K 0% /etc/network/interfaces.dynamic.d
/dev/sdb1 281G 7.3G 259G 3% /mnt
</span></p>

<h3>&gt; List all detailed file sizes starting from the root directory</h3>
<strong>sudo du / -ch
</strong>
<h3>&gt; See only the total file size from the root directory</h3>
<p style="margin-left: 36pt"><strong>sudo du / -ch |grep total
</strong><span style="font-family: Courier New;font-size: 9pt">22G total</span><strong>
</strong></p>

<h3>&gt; Find files that are larger than 1000 MB</h3>
<strong>sudo find / -size +1000M -print0 | xargs -0 ls -l
</strong>
<p style="margin-left: 36pt">These are system files in Linux we can ignore
<span style="font-family: Courier New;font-size: 8pt">-rw------- 1 root root 7516192768 Aug 15 18:08 /mnt/resource/swap
-r-------- 1 root root 140737477881856 Aug 15 19:17 /proc/kcore</span></p>

<h3>&gt; Find files that are larger than 500 MB</h3>
<strong>sudo find / -size +500M -print0 | xargs -0 ls -l
</strong>

Usually the larger files on the local disks are log files from one of the various Hadoop services can use local significant space. You could delete old log files if you don't need them, or edit the log4j.properties for the service to lower the logging level, such as lowering DEBUG to WARN level or something along those lines. <a href="https://logging.apache.org/log4j/1.2/manual.html">https://logging.apache.org/log4j/1.2/manual.html</a>
<h2>Step 2: To see if there are many hive temporary files, you can check HDFS to list the temp folder like this:</h2>
<h3>&gt; List HDFS files under the hive temp scratch directory</h3>
<blockquote><span style="font-family: Courier New"><strong>hadoop fs -ls -R hdfs://mycluster/tmp/hive/hive
</strong></span></blockquote>
Notice when the temp files are in use there is a inuse.lck file that Hive maintains to show the folder is in use.

<img alt="" src="https://msdnshared.blob.core.windows.net/media/2016/08/081516_2124_HDFSgetsful2.png" />

Normally once the temp folder is done, Hive will automatically clean it up. In the case Hive crashes, or the server is taken offline abruptly, the files may become dangling / orphaned.
<h2>Step 3. Cleaning Up dangling orphaned hive directories in HDFS as needed</h2>
<h2>A. There is a hive command <em>cleardanglingscratchdir</em> to automate this cleanup safely.</h2>
<a href="https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-ClearDanglingScratchDirTool">https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-ClearDanglingScratchDirTool</a>

Quoting the docs:
<blockquote>The tool cleardanglingscratchdir can be run to clean up any dangling scratch directories that might be left over from improper shutdowns of Hive, such as when a virtual machine restarts and leaves no chance for Hive to run the shutdown hook.</blockquote>
<blockquote>hive --service cleardanglingscratchdir [-r] [-v] [-s scratchdir]</blockquote>
<blockquote>-r dry-run mode, which produces a list on console</blockquote>
<blockquote>-v verbose mode, which prints extra debugging information</blockquote>
<blockquote>-s if you are using non-standard scratch directory</blockquote>
<blockquote>The tool tests if a scratch directory is in use, and if not, will remove it. This relies on HDFS write locks to detect if a scratch directory is in use. An HDFS client opens an HDFS file ($scratchdir/inuse.lck) for writing and only closes it at the time that the session is closed. cleardanglingscratchdir will try to open $scratchdir/inuse.lck for writing to test if the corresponding HiveCli/HiveServer2 is still running. If the lock is in use, the scratch directory will not be cleared. If the lock is available, the scratch directory will be cleared. Note that it might take NameNode up to 10 minutes to reclaim the lease on scratch file locks from a dead HiveCli/HiveServer2, at which point cleardanglingscratchdir will be able to remove it if run again.</blockquote>
<blockquote></blockquote>
<h3>1. Dry Run</h3>
So you can run this command from the head node to get a dry run list of any files that need to be cleaned up:
<blockquote><span style="font-family: Courier New;font-size: 10pt">hive --service cleardanglingscratchdir <span style="background-color: yellow">-r</span>
</span></blockquote>
-or-
<blockquote><span style="font-family: Courier New;font-size: 10pt">hive --service cleardanglingscratchdir -r -s hdfs://mycluster/tmp/hive/hive
</span></blockquote>
<h3>2. Real Run</h3>
If that list looks reasonable, and the dates look old and orphaned, then run it for real without the -r dry run.
<blockquote><span style="font-family: Courier New;font-size: 10pt">hive --service cleardanglingscratchdir
</span></blockquote>
-or-
<blockquote><span style="font-family: Courier New;font-size: 10pt">hive --service cleardanglingscratchdir -s hdfs://mycluster/tmp/hive/hive
</span></blockquote>
Note, if you get the error "Cannot find any scratch directory to clear" then it is likely that there is no dangling orphan folder to clean up.
<h2>B. If the tool doesn't work, or you are on an older build that doesn't have the cleanup, then you could manually remove the old files</h2>
To be very sure none of the files are in use, you should stop Hive services (using Ambari) before running any command, or selectively run the command only on old directories that are not currently in use.
<h3>Manual Step 1. Stop Hive – I'm using Ambari to do that</h3>
<img alt="" src="https://msdnshared.blob.core.windows.net/media/2016/08/081516_2124_HDFSgetsful3.png" /><span style="color: black;font-family: Arial;font-size: 10pt">
</span>
<h3>Manual Step 2. Remove the temporary files in HDFS</h3>
<h3>Option A: All folders at once:</h3>
<blockquote><span style="font-family: Courier New">hadoop fs -rm -r -skipTrash hdfs://mycluster/tmp/hive/hive/
</span></blockquote>
<h3>Option B: Remove only the folders you are worried about. The date of the hive job is typically listed in the directory name:</h3>
<blockquote><span style="font-family: Courier New">hadoop fs -rm -r -skipTrash hdfs://mycluster/tmp/hive/hive/7178b22b-186d-4284-a5a5-6092f165db37/hive_<span style="background-color: yellow">2016-04-14</span>_22-35-31_149_2691354643150374266-1/
hadoop fs -rm -r -skipTrash hdfs://mycluster/tmp/hive/hive/7178b22b-186d-4284-a5a5-6092f165db37/hive_2016-04-14_22-36-56_659_7340036377865464119-4/
hadoop fs -rm -r -skipTrash hdfs://mycluster/tmp/hive/hive/7178b22b-186d-4284-a5a5-6092f165db37/hive_2016-04-14_22-47-26_179_2802662959127515918-4/
</span></blockquote>
<h3>Manual Step 3. Now Start Hive again in Ambari using the same menu, then check that it made a fresh scratch file directory.</h3>
<blockquote><span style="font-family: Courier New">hadoop fs -ls -R hdfs://mycluster/tmp/hive/hive
</span></blockquote>
That's it for now. Let us know if you run into this problem, how you solve it, and any quirks you faced along the way.

Thanks! Jason Howell]]></content:encoded>
    </item>
    <item>
      <title>How to Find and Kill a running Yarn Application Master in HDInsight with and without SSH access</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/how-to-find-and-kill-a-running-yarn-application-master-in-hdinsight-with-and-without-ssh-access</link>
      <pubDate>Sat, 11 Jun 2016 19:54:28 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/?p=1205</guid>
      <description><![CDATA[Today we faced a challenge in HDInsight not knowing the SSH user password to terminal into the...]]></description>
      <content:encoded><![CDATA[Today we faced a challenge in HDInsight not knowing the SSH user password to terminal into the server, and we needed to kill some running Hive jobs that were too far gone and taking too many resources.

The user knows the user name and password for Hadoop and Ambari, but does not know the SSH user name and password. HDInsight uses separate accounts and passwords for these two purposes.
<h2>Without SSH use cURL to talk REST to kill it</h2>
You can use the REST endpoints for Resource manager in HDInsight to kill an application using the Hadoop/Ambari password.

<span style="color: black;font-family: Segoe UI;font-size: 10pt">1. Download or build your own cURL <a href="https://curl.haxx.se/download.html">https://curl.haxx.se/download.html</a> for Windows, I found it here <a href="https://www.paehl.com/open_source/?CURL_7.49.1">https://www.paehl.com/open_source/?CURL_7.49.1</a>
</span>

<span style="color: black;font-family: Segoe UI;font-size: 10pt">Make sure to get one WITH SUPPORT SSL (Since HDInsight only works in HTTPS)
</span>

&nbsp;

<span style="color: black;font-family: Segoe UI;font-size: 10pt">2. To check the application status, you can get a long list of all the applications
</span>
<blockquote>
<pre>curl -u admin:SomePassword -H "Content-Type: application/json" -d "https://servername.azurehdinsight.net/ws/v1/cluster/apps/"</pre>
</blockquote>
<span style="color: black;font-family: Segoe UI;font-size: 10pt">Or focus in on your one application-id
</span>
<blockquote>
<pre>curl -u admin:SomePassword -H "Content-Type: application/json" -d "https://servername.azurehdinsight.net/ws/v1/cluster/apps/application_0000000000_0000/"</pre>
</blockquote>
&nbsp;

<span style="color: black;font-family: Segoe UI;font-size: 10pt">3. To Kill a job,on the commandline, run cURL to point to your HDInsight server and the application id, and PUT to change the state to KILLED, effectively killing the Yarn job.
</span>
<blockquote>
<pre>curl -u admin:SomePassword -v -X PUT -H "Content-Type: application/json" -d '{"state": "KILLED"}' "https://servername.azurehdinsight.net/ws/v1/cluster/apps/application_0000000000_0000/state"</pre>
</blockquote>
&nbsp;

&nbsp;

Note: for special characters I found I could use an escape character \ before the special character in the password.

If you get an error about https, try "" double-quotes around the URL instead of '' single-quotes.

More Resource Manager REST options <a href="https://hadoop.apache.org/docs/r2.4.1/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html">https://hadoop.apache.org/docs/r2.4.1/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html</a>

&nbsp;
<h2>With SSH use Yarn commands to list and kill applications</h2>
I am used to killing Yarn applications like this, over a BASH session connected with the ssh account credentials. <span style="color: black;font-family: Arial;font-size: 10pt">From SSH paste in the application name and this command should attempt the kill
</span>
<pre><span style="font-family: Courier New;font-size: 10pt"><strong>yarn application -kill application_000000000000000_0001
 </strong></span></pre>
<a href="https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/YarnCommands.html"><span style="font-family: Arial;font-size: 10pt">https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/YarnCommands.html</span></a><span style="color: black;font-family: Arial;font-size: 10pt">
</span>

To find the application ID , you can do <strong>yarn application -list</strong> or use the resource manager UI from the active head node.

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/061116_2354_HowtoFindan1.png" alt="" />

From Ambari <a href="https://servername.azurehdinsight.net/#/main/dashboard/metrics">https://servername.azurehdinsight.net/#/main/dashboard/metrics</a> click Dashbaord, then YARN links tile, click More… &gt; and pick the Active head node, then click the menu for ResourceManagerUI

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/061116_2354_HowtoFindan2.png" alt="" />

&nbsp;

&nbsp;

It will jump to the website like this URL <a href="https://servername.azurehdinsight.net/yarnui/hn/cluster">https://servername.azurehdinsight.net/yarnui/hn/cluster</a>

The first column lists the application ID, which is what Yarn needs to know to kill something.

<img src="https://msdnshared.blob.core.windows.net/media/2016/06/061116_2354_HowtoFindan3.png" alt="" />]]></content:encoded>
    </item>
    <item>
      <title>How to Lock a Resource Group to prevent accidental deletion of resources like HDInsight</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/how-to-lock-a-resource-group-to-prevent-accidental-deletion-of-resources-like-hdinsight</link>
      <pubDate>Mon, 16 May 2016 13:43:47 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/?p=1165</guid>
      <description><![CDATA[Did you know it is possible to prevent accidental deletion of resources in Azure? This could apply...]]></description>
      <content:encoded><![CDATA[<span style="font-family: Arial">Did you know it is possible to prevent accidental deletion of resources in Azure? This could apply to any number of resource, HDInsight, Stream Analytics jobs, Data Factories, DocumentDB accounts, etc.
</span>

<span style="font-family: Arial">We can add a lock to the resource group to prevent resources from being removed inadvertantly.
</span>

<span style="font-family: Arial">I found out the hard way when someone here tried to delete their HDInsight and it failed. The delete request fails with HTTP status code <strong>409</strong> CONFLICT which indicates the Resource Group is locked.
</span>
<p style="margin-left: 36pt"><span style="font-family: Arial">DELETE/SUBSCRIPTIONS/RESOURCEGROUPS/PROVIDERS/MICROSOFT.HDINSIGHT/CLUSTERS/ Http request failed with ErrorResponseMessageException. HttpStatus: 'Conflict', ErrorCode: 'ScopeLocked' and ErrorMessage: 'The scope '/subscriptions/subscriptionid/resourceGroups/HDInsightRG/providers/Microsoft.HDInsight/clusters/hdinsightclustername' cannot perform delete operation because following scope(s) are locked: '/subscriptions/subscriptionid/resourceGroups/HDInsightRG'. Please remove the lock and try again.'.
</span></p>
&nbsp;
<h1>References</h1>
<ul>
	<li><span style="font-family: Arial">New-AzureRmResourceLock <a href="https://msdn.microsoft.com/en-us/library/mt652515.aspx" target="_blank">https://msdn.microsoft.com/en-us/library/mt652515.aspx</a>
</span></li>
	<li><span style="font-family: Arial">Get-AzureRmResourceLock <a href="https://msdn.microsoft.com/en-us/library/mt652497.aspx" target="_blank">https://msdn.microsoft.com/en-us/library/mt652497.aspx</a>
</span></li>
	<li><span style="font-family: Arial">Remove-AzureRmResourceLock <a href="https://msdn.microsoft.com/en-us/library/mt652493.aspx" target="_blank">https://msdn.microsoft.com/en-us/library/mt652493.aspx</a>
</span></li>
</ul>
&nbsp;
<h1>Here's how to make a lock in PowerShell and prevent resources from being delete.</h1>
&nbsp;

Perequisite: Download the PowerShell SDK for Azure from here <a href="https://azure.microsoft.com/en-us/downloads/" target="_blank">https://azure.microsoft.com/en-us/downloads/</a>

<span style="font-family: Arial"><strong>Start &gt; Run &gt; PowerShell ISE
</strong></span>

I like PowerShell ISE because you can highlight one line at a time, and run it one by one.
<p style="background: white"><img src="https://msdnshared.blob.core.windows.net/media/2016/05/051616_1743_HowtoLockaR1.png" alt="" /><span style="color: darkgreen;font-family: Lucida Console;font-size: 14pt">
</span></p>

<h1>Example Code</h1>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: darkgreen"># 1. Login</span>
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: blue">Login-AzureRmAccount</span>
</span></p>
<p style="background: white"></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: darkgreen"># 2. Make a new lock</span>
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: blue">New-AzureRmResourceLock </span><span style="color: navy">-LockLevel </span><span style="color: blueviolet">CanNotDelete </span><span style="color: navy">-LockName </span><span style="color: blueviolet">LockHDInsightRG </span><span style="color: navy">-ResourceGroup </span><span style="color: blueviolet">HDInsightRG</span>
</span></p>
<p style="background: white"></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: darkgreen"># 3. List existing locks and their names – it will prompt Yes/No unless you add -Force switch.</span>
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: blue">Get-AzureRmResourceLock</span>
</span></p>
<p style="background: #012456"><span style="color: whitesmoke;font-family: Lucida Console">Name : LockHDInsightRG
</span><span style="color: whitesmoke;font-family: Lucida Console">ResourceId : /subscriptions/subscriptionid/resourceGroups/HDInsightRG/providers/Microsoft
</span><span style="color: whitesmoke;font-family: Lucida Console"> .Authorization/locks/LockHDInsightRG
</span><span style="color: whitesmoke;font-family: Lucida Console">ResourceName : LockHDInsightRG
</span><span style="color: whitesmoke;font-family: Lucida Console">ResourceType : Microsoft.Authorization/locks
</span><span style="color: whitesmoke;font-family: Lucida Console">ResourceGroupName : HDInsightRG
</span><span style="color: whitesmoke;font-family: Lucida Console">SubscriptionId : subscriptionid
</span><span style="color: whitesmoke;font-family: Lucida Console">Properties : @{Level=CanNotDelete}
</span><span style="color: whitesmoke;font-family: Lucida Console">LockId : /subscriptions/subscriptionid/resourceGroups/HDInsightRG/providers/Microsoft</span><span style="color: whitesmoke;font-family: Lucida Console">.Authorization/locks/LockHDInsightRG
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: darkgreen"># 4. Try to delete an HDInsight cluster – it will Error out</span>
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: blue">Remove-AzureRmHDInsightCluster </span><span style="color: navy">-ClusterName </span><span style="color: blueviolet">MyCluster</span></span></p>
<p style="background: #012456"><span style="color: whitesmoke;font-family: Lucida Console">Remove-AzureRmHDInsightCluster -ClusterName MyCluster -ResourceGroupName HDInsightRG
</span><span style="color: red;font-family: Lucida Console">Remove-AzureRmHDInsightCluster : ScopeLocked: The scope '/subscriptions/subscriptionid/resourceG</span><span style="color: red;font-family: Lucida Console">roups/HDInsightRG/providers/Microsoft.HDInsight/clusters/MyCluster' cannot perform delete operation because </span><span style="color: red;font-family: Lucida Console">following scope(s) are locked: '/subscriptions/subscriptionid/resourceGroups/HDInsightRG'.
</span><span style="color: red;font-family: Lucida Console">Please remove the lock and try again.
</span><span style="color: red;font-family: Lucida Console">At line:1 char:1
</span><span style="color: red;font-family: Lucida Console">+ Remove-AzureRmHDInsightCluster -ClusterName MyCluster -ResourceGroup ...
</span><span style="color: red;font-family: Lucida Console">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</span><span style="color: red;font-family: Lucida Console"> + CategoryInfo : CloseError: (:) [Remove-AzureRmHDInsightCluster], CloudException
</span><span style="color: red;font-family: Lucida Console"> + FullyQualifiedErrorId : Microsoft.Azure.Commands.HDInsight.RemoveAzureHDInsightCommand
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: darkgreen"># 5. Remove the lock by name - it will prompt Yes/No unless you add -Force switch.</span>
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: blue">Remove-AzureRmResourceLock </span><span style="color: navy">-LockName </span><span style="color: blueviolet">LockHDInsightRG <span style="color: navy">-ResourceGroup</span> HDInsightRG</span>
</span></p>
<p style="background: #012456"><span style="color: whitesmoke;font-family: Lucida Console;font-size: 12pt">Remove-AzureRmResourceLock -LockName LockHDInsightRG -ResourceGroup HDInsightRG
</span><span style="color: whitesmoke;font-family: Lucida Console;font-size: 12pt">True
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt"><span style="color: darkgreen"># 6. List existing locks and their names – no results</span>
</span></p>
<p style="background: white"><span style="color: blue;font-family: Lucida Console;font-size: 14pt">Get-AzureRmResourceLock
</span></p>
<p style="background: white"><span style="font-family: Lucida Console;font-size: 14pt">
</span></p>]]></content:encoded>
    </item>
    <item>
      <title>HDInsight Name Node can stay in Safe mode after a Scale Down</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/hdinsight-hdfs-can-stay-in-safe-mode-after-a-scale-down</link>
      <pubDate>Wed, 16 Mar 2016 21:37:23 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/?p=1134</guid>
      <description><![CDATA[This week we worked on an HDInsight cluster where the Name Node has gone into Safe mode and didn't...]]></description>
      <content:encoded><![CDATA[<span style="font-family: Arial">This week we worked on an HDInsight cluster where the Name Node has gone into Safe mode and didn't leave that mode on its own. It's not very common, but I wanted to share why it happened, and how to get out of the situation, in case it prevents a headache for someone else.
</span>
<h1>HDInsight Scaling up &amp; down is so useful</h1>
<span style="font-family: Arial">HDInsight offers elasticity by giving administrators the option to scale up and scale down the number of Worker Nodes in the clusters. This allows a cluster to be shrunk during after hours or on weekends, and grown during peak business demands.
</span>

<span style="font-family: Arial">Let's say there is some batch processing that happens one day a week or once a month, the HDInsight cluster can be scaled up a few minutes prior to that scheduled event so that there is plenty of Memory and CPU compute power. You can automate that with PowerShell cmdlet <strong><a href="https://azure.microsoft.com/en-us/documentation/articles/hdinsight-administer-use-powershell/#scale-clusters" target="_blank"><span class="typ">Set</span><span class="pun">-</span></a><span class="typ"><a href="https://azure.microsoft.com/en-us/documentation/articles/hdinsight-administer-use-powershell/#scale-clusters" target="_blank">AzureRmHDInsightClusterSize</a>. </span> </strong>Later, after the processing is done, and usage is expected to go down again, the administrator can scale down the HDInsight cluster to fewer worker nodes.
</span>

<span style="font-family: Arial">From the Azure Portal, find your HDInsight, click the Scale Cluster setting, then on the Scale blade, you just type in the number of worker nodes, and click save, and in a few minutes your HDInsight cluster will have been resized. You can go up or down.
</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/03/031716_0137_HDInsightHD1.png" alt="" width="785" height="324" /><span style="font-family: Arial">
</span>

&nbsp;

<span style="font-family: Arial">In a few occurrences, we have had HDInsight customers shrink their cluster down to the bare minimum 1 worker node as shown above. That works most of the time for them if you start at 1 worker node. But once in a while, scaling from a bunch of nodes all the way down to 1 worker node caused HDFS to get stuck in safe mode during maintenance when they are not expecting it.
</span>

<span style="font-family: Arial">Maybe when worker nodes are rebooted due to patching, or right after the scale, safe mode can occur during that maintenance timeframe.
</span>

&nbsp;

<hr />

&nbsp;
<h1>The Short Story – If you get in Safe mode, you can manually Leave Safe Mode to ignore the issue (most of the time)</h1>
<span style="font-family: Arial">The gist is that Hive uses some scratchdir files, and by default expects 3 replicas of each block, but there is only 1 replica possible if you scale down to the minimum 1 worker node, so the files in the scratchdir are under replicated. HDFS stays in Safe mode because of that at the time when the services are restarted after the scale maintenance.
</span>

<span style="color: black;font-family: Arial">One way to get HDFS out of safe mode is to just leave safe mode (ignoring the cause assuming its benign). For example, if you know that the only reason safe mode is on is that the temporary files are under replicated (discussed in detail below) then you really don't need those files anyway because they are hive temporary scratch files, so it's reasonable to leave Safe Mode "safely" without a worry.
</span>

HDInsight on Linux:

<strong><span style="color: black;font-family: Courier New;font-size: 10pt"><span style="color: #339966">hdfs dfsadmin -D 'fs.default.name=hdfs://mycluster/' -safemode leave</span></span><span style="color: black;font-family: Courier New;font-size: 10pt">
</span></strong>

** note that the tick marks/apostrophes are slanted due to blog formatting. Please use plain quote/tick mark.

HDInsight on Windows:

<strong><span style="color: black;font-family: Courier New;font-size: 10pt"><span style="color: #339966">hdfs dfsadmin -fs hdfs://headnodehost:9000 -safemode leave</span></span></strong>

<span style="font-family: Arial">After leaving safe mode, that you can remove the problematic temp files or wait for Hive to clean them up if you are optimistic.
</span>

&nbsp;

&nbsp;

<hr />

&nbsp;
<h2>The Details</h2>
<span style="font-family: Arial">Even in HDInsight, the default HDFS configuration is set to require least 3 worker nodes to a copy of each file's blocks to be considered healthy. That is to say HDFS is configured with the <strong>dfs.replication</strong> setting of 3, so the blocks of those files are under replicated whenever there are less than 3 worker nodes online, because there are not 3 copies of each file block available.
</span>

<span style="font-family: Arial">We know from working with HortonWorks Support from time to time, that in an Hadoop in a on-premise environment where disks can get full, disks can fail, and networking errors between worker nodes can happen, it is common to see Safe mode from time to time during a catastrophie. But in the Azure cloud, most of those things are not going to happen, so unexpected Safe mode is probably not a hardware problem going on. <a href="https://hadooptutorial.info/safe-mode-in-hadoop/">Other folks have blogged about it</a>
</span>

<span style="font-family: Arial">Examples of errors we saw when running Hive queries after the safe mode was turned on:
</span>
<p style="margin-left: 36pt"><span style="font-family: Arial">ERROR 1
</span></p>
<p style="margin-left: 36pt"><span style="font-family: Arial">H070 Unable to open Hive session. org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.ipc.RetriableException): org.apache.hadoop.hdfs.server.namenode.<span style="color: red">SafeModeException: Cannot create directory /tmp/hive/hive/819c215c-6d87-4311-97c8-4f0b9d2adcf0. Name node is in safe mode. </span>The reported blocks 75 needs additional 12 blocks to reach the threshold 0.9900 of total blocks 87. The number of live datanodes 10 has reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been reached.
</span></p>
<p style="margin-left: 36pt"><span style="font-family: Arial">ERROR 2
</span></p>
<p style="margin-left: 36pt"><span style="font-family: Arial"><span style="color: #ff0000">H100</span> Unable to submit statement show databases': org.apache.thrift.transport.TTransportException: org.apache.http.conn.HttpHostConnectException: Connect to hn0-clustername.servername.internal.cloudapp.net:10001 [hn0-clustername.servername. internal.cloudapp.net/1.1.1.1] failed: <span style="color: #ff0000">Connection refused</span>
</span></p>
<p style="margin-left: 36pt"><span style="font-family: Arial">ERROR 3
</span></p>
<p style="margin-left: 36pt"><span style="font-family: Arial"><span style="color: #ff0000">H020</span> Could not establish connecton to hn0-hdisrv.servername.bx.internal.cloudapp.net:10001:
org.apache.thrift.transport.TTransportException: <span style="color: #ff0000">Could not create http connection to https://hn0-hdisrv.servername.bx.internal.cloudapp.net:10001/.</span> org.apache.http.conn.HttpHostConnectException: Connect to hn0-hdisrv.servername.bx.internal.cloudapp.net:10001
[hn0-hdisrv.servername.bx.internal.cloudapp.net/10.0.0.28] failed: Connection refused: org.apache.thrift.transport.TTransportException: Could not create http connection to https://hn0-hdisrv.servername.bx.internal.cloudapp.net:10001/. org.apache.http.conn.HttpHostConnectException: Connect to hn0-hdisrv.servername.bx.internal.cloudapp.net:10001 [hn0-hdisrv.servername.bx.internal.cloudapp.net/10.0.0.28] failed: Connection refused</span></p>
<p style="margin-left: 36pt"><span style="font-family: Arial">ERROR 4 - from the Hive logs
</span></p>
<p style="margin-left: 36pt"><span style="font-family: Arial">WARN [main]: server.HiveServer2 (HiveServer2.java:startHiveServer2(442)) - <span style="color: #ff0000">Error starting HiveServer2 on attempt 21, will retry in 60 seconds</span>
java.lang.RuntimeException: Error applying authorization policy on hive configuration: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.ipc.RetriableException): org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /tmp/hive/hive/70a42b8a-9437-466e-acbe-da90b1614374. <span style="color: #ff0000">Name node is in safe mode.</span>
The reported blocks 0 needs additional 9 blocks to reach the threshold 0.9900 of total blocks 9.
The number of live datanodes 10 has reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been reached.
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkNameNodeSafeMode(FSNamesystem.java:1324)</span></p>
<span style="font-family: Arial">You can review the Name Node logs from folder /var/log/hadoop/hdfs/ near the time when the cluster was scaled to see when it got stuck in safe mode. Log files like Hadoop-hdfs-namenode-hn0-clustername.*
</span>

<span style="font-family: Arial">The gist of these errors and this this problems is that even in HDInsight where HDFS is rarely used, Hive does depend on temporary files in HDFS while running queries, and HDFS has gone into "Safe mode". Hive cannot run queries if it cannot write to HDFS. Those temp files in HDFS are kept in the local C: drive mounted to the individual worker node VMs and replicated amongst the worker nodes 3 replicas minumum.
</span>

<span style="font-family: Arial">Check out how the hive.exec.scratchdir in Hive is configured in HDInsight (on Linux) "/etc/hive/conf/hive-site.xml"
</span>
<p style="margin-left: 36pt"><img src="https://msdnshared.blob.core.windows.net/media/2016/03/031716_0137_HDInsightHD2.png" alt="" /><span style="font-family: Arial">
</span></p>
&nbsp;

&nbsp;

<hr />

&nbsp;
<h2><span style="font-family: Arial">How is this Safe mode issue related to Scale down?
</span></h2>
<span style="font-family: Arial">When a scale down attempt happens, HDInsight relies upon the Ambari management interfaces to decommission the extra unwanted worker nodes, which replicates the HDFS blocks to other online worker nodes, and safely scale the cluster down. HDFS goes into a safe mode during the maintenance window, and is supposed to come out once the scaling is finished, normally.
</span>

<span style="font-family: Arial">However, when you scale to 1 node, there is no longer 3 worker nodes available to host 3 replicas of the HDFS blocks, so the file blocks that were replicated amongst 3 worker nodes or more are now only in 1 worker node, and HDFS considers those blocks "under replicated".
</span>

<span style="font-family: Arial">Recall that in Azure HDInsight, we tell you not to keep user data in the HDFS file system, and instead put your user data in Azure Blob Storage using wasb:// URI or in Azure Data Lake Store using adl:// URI paths. That azure stored data is accessible to the various Hadoop components much like HDFS without any noticeable difference, maybe even faster than HDFS, and it lives in Azure Storage within the data center, and not on the locally attached disks in the compute VMs. This model of storage in the cloud gives you flexibility to remove HDInsight clusters, and recreate them on demand later, while safely keep your data in tact and stored at a low cost.
</span>

<span style="font-family: Arial">Its typically only the Hive Scratchdir files that are remaining in HDFS, unless one of the users accidentally saved user data into hdfs:// instead of the normal Azure stores: wasb:// or adl://
</span>

<span style="font-family: Arial">You can inventory your HDFS file system by do a list from the console to see if it is the system temporary files, or some user data:
</span>

<span style="font-family: Courier New"><strong>hadoop fs -ls -R hdfs://mycluster/
</strong></span>

&nbsp;

<hr />

<h2><span style="font-family: Arial">How to see the health and state of your HDFS file system?</span></h2>
<span style="color: black;font-family: Arial;font-size: 10pt">You can get a report of status from each name node to show that the name nodes are in Safe Mode or not. SSH into each head node to run this kind of command.
</span>
<p style="padding-left: 30px"><span style="color: #339966"><strong>hdfs dfsadmin -D 'fs.default.name=hdfs://mycluster/' -safemode get</strong></span></p>
<img src="https://msdnshared.blob.core.windows.net/media/2016/03/031716_0137_HDInsightHD3.png" alt="" /><span style="color: black;font-family: Arial;font-size: 10pt">
</span>

Next you can get a report that shows the details of HDFS state when all is healthy and all blocks are replicated to the expected degree.
<p style="padding-left: 30px"><span style="color: black;font-family: Arial;font-size: 10pt"><strong><span style="color: #339966">hdfs dfsadmin -D 'fs.default.name=hdfs://mycluster/' -report</span></strong>
</span></p>
<img src="https://msdnshared.blob.core.windows.net/media/2016/03/031716_0137_HDInsightHD4.png" alt="" />

&nbsp;

<span style="font-family: Arial">Side bar: The reason we have to give -D switch, is that on HDInsight the default file system is Azure Blob Storage, so you have to specify the local HDFS file system in the commands like this
</span>
<p style="margin-left: 36pt"><span style="color: black;font-family: Courier New;font-size: 10pt"><strong>
</strong></span></p>

<h3>Let's compare a couple of example output from of a healthy hdfs file system when in and not in safe mode.</h3>
<h3 style="padding-left: 30px"><span style="color: #339966">hdfs fsck -D 'fs.default.name=hdfs://mycluster/' /tmp/hive/hive</span></h3>
<h3>1. Healthy HDFS and no under replicated blocks:</h3>
<div>
<table style="border-collapse: collapse" border="0"><colgroup> <col style="width: 779px" /></colgroup>
<tbody valign="top">
<tr>
<td style="padding-left: 9px;padding-right: 9px;border: solid 0.5pt"><span style="font-family: Courier New;font-size: 8pt">Connecting to namenode via https://hn0-clustername.servername.bx.internal.cloudapp.net:30070
</span><span style="font-family: Courier New;font-size: 8pt">FSCK started by sshuser (auth:SIMPLE) from /10.0.0.14 for path /tmp/hive/hive at Wed Mar 16 23:49:30 UTC 2016
</span><span style="font-family: Courier New;font-size: 8pt"><span style="background-color: lime">Status: HEALTHY</span>
</span><span style="font-family: Courier New;font-size: 8pt"> Total size: 0 B
</span><span style="font-family: Courier New;font-size: 8pt"> Total dirs: 13
</span><span style="font-family: Courier New;font-size: 8pt"> Total files: 0
</span><span style="font-family: Courier New;font-size: 8pt"> Total symlinks: 0
</span><span style="font-family: Courier New;font-size: 8pt"> Total blocks (validated): 0
</span><span style="font-family: Courier New;font-size: 8pt"> Minimally replicated blocks: 0
</span><span style="font-family: Courier New;font-size: 8pt">
<span style="background-color: lime">Over-replicated blocks: 0
</span></span></td>
</tr>
</tbody>
</table>
</div>
<span style="font-family: Courier New;font-size: 8pt"><span style="background-color: lime"> Under-replicated blocks: 0</span>
</span>

<span style="font-family: Courier New;font-size: 8pt"> Mis-replicated blocks: 0
</span>

<span style="font-family: Courier New;font-size: 8pt"> Default replication factor: 3
</span>

<span style="font-family: Courier New;font-size: 8pt"> Average block replication: 0.0
</span>

<span style="font-family: Courier New;font-size: 8pt"> Corrupt blocks: 0
</span>

<span style="font-family: Courier New;font-size: 8pt"> Missing replicas: 0
</span>

<span style="font-family: Courier New;font-size: 8pt"> Number of data-nodes: 1
</span>

<span style="font-family: Courier New;font-size: 8pt"> Number of racks: 1
</span>

<span style="font-family: Courier New;font-size: 8pt">FSCK ended at Wed Mar 16 23:49:30 UTC 2016 in 5 milliseconds
</span>

&nbsp;
<h3>2. Healthy HDFS and some under replicated blocks:</h3>
<span style="font-family: Arial">There is only one block on this file in this output, but it is under replicated, only exists on 1 worker node, and not 3 as expected by HDFS.
</span>
<div>
<table style="border-collapse: collapse" border="0"><colgroup> <col style="width: 779px" /></colgroup>
<tbody valign="top">
<tr>
<td style="padding-left: 9px;padding-right: 9px;border: solid 0.5pt"><span style="color: black;font-family: Courier New;font-size: 8pt">Connecting to namenode via https://hn0-servername. internal.cloudapp.net:30070
</span><span style="color: black;font-family: Courier New;font-size: 8pt">FSCK started by sshuser (auth:SIMPLE) from /10.0.0.14 for path /tmp/hive/hive at Thu Dec 31 19:28:03 UTC 2015
</span><span style="color: black;font-family: Courier New;font-size: 8pt">.
</span><span style="color: black;font-family: Courier New;font-size: 8pt">/tmp/hive/hive/_tez_session_dir/62b64823-4d61-48b0-9f36-82bc60ba368f/hive-hcatalog-core.jar:  Under replicated BP-2018565019-10.0.0.15-1450760688291:blk_1073741828_1004. <span style="background-color: yellow">Target Replicas is 3 but found 1 replica(s).</span>
</span><span style="color: black;font-family: Courier New;font-size: 8pt"><span style="background-color: lime">Status: HEALTHY</span>
</span><span style="color: black;font-family: Courier New;font-size: 8pt">Total size:    253448 B
</span><span style="color: black;font-family: Courier New;font-size: 8pt">Total dirs:    31
</span><span style="color: black;font-family: Courier New;font-size: 8pt">Total files:   1
</span><span style="color: black;font-family: Courier New;font-size: 8pt">Total symlinks:                0
</span><span style="color: black;font-family: Courier New;font-size: 8pt">Total blocks (validated):      1 (avg. block size 253448 B)
</span></td>
</tr>
</tbody>
</table>
</div>
<span style="color: black;font-family: Courier New;font-size: 8pt">Minimally replicated blocks:   1 (100.0 %)
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt">Over-replicated blocks:        0 (0.0 %)
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt"><span style="background-color: yellow">Under-replicated blocks:       1 (100.0 %)</span>
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt">Mis-replicated blocks:         0 (0.0 %)
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt"><span style="background-color: yellow">Default replication factor:    3</span>
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt">Average block replication:     1.0
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt">Corrupt blocks:                0
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt"><span style="background-color: yellow">Missing replicas:              2 (66.666664 %)</span>
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt">Number of data-nodes:          1
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt">Number of racks:               1
</span>

<span style="color: black;font-family: Courier New;font-size: 8pt">FSCK ended at Thu Dec 31 19:28:03 UTC 2015 in 8 milliseconds
</span>

&nbsp;
<h3>3. Ambari shows this as well.</h3>
<span style="font-family: Arial">Click the HDInsight Dashboard link from the Azure portal, and it will launch the Ambari web site. Ambari will report the block health as well, but is not as detailed as the above commands.
</span>

<span style="font-family: Courier New">https://<strong><em>clustername</em></strong>.azurehdinsight.net/#/main/services/HDFS/summary
</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/03/031716_0137_HDInsightHD5.png" alt="" /><span style="font-family: Arial">
</span>

&nbsp;

&nbsp;

<hr />

&nbsp;
<h2>How to Prevent HDInsight from getting stuck in Safe mode due to under-replicated blocks</h2>
<span style="font-family: Arial">A little foresight can prevent HDInsight being left in Safe mode. A few options are:</span>

<a href="https://msdnshared.blob.core.windows.net/media/2016/03/SafeModeOptions.png"><img class="alignnone  wp-image-1143" src="https://msdnshared.blob.core.windows.net/media/2016/03/SafeModeOptions.png" alt="SafeModeOptions" width="617" height="363" /></a>
<h2>Let's go through these possibilities in more detail:</h2>

<hr />

<h2><span style="color: #ed7d31;font-family: Arial">A&gt; Queisce Hive – Stop all jobs
</span></h2>
<span style="font-family: Arial">Stop all Hive jobs before scaling down to 1 worker node. If you know your workload is scheduled, then do your Scale Down after Hive work is done.
</span>

<span style="font-family: Arial">That will help minimize the number of scratch files in the tmp folder (if any).
</span>

<hr />

&nbsp;
<h2><span style="color: #ffc000;font-family: Arial"><strong><span style="color: #808080">B&gt; Manually clean up behind Hive by removing scratch files</span>
</strong></span></h2>
<span style="font-family: Arial">If Hive has left behind temporary files, before you scale down, then you can manually cleanup the tmp files before scaling down to avoid safe mode.
</span>

<span style="font-family: Arial">You should stop Hive services to be safe, and at a minimum make sure all queries and jobs are done.
</span>

<span style="font-family: Arial">You can list the directory hdfs://mycluster/tmp/hive/ to see if it has any files left or not.
</span>

<span style="font-family: Courier New"><strong>hadoop fs -ls -R hdfs://mycluster/tmp/hive/hive
</strong></span>
<div>
<table style="border-collapse: collapse" border="0"><colgroup> <col style="width: 1147px" /></colgroup>
<tbody valign="top">
<tr>
<td style="padding-left: 9px;padding-right: 9px;border: solid 0.5pt"><span style="font-family: Courier New;font-size: 8pt">sshuser@hn0-servername:~$ hadoop fs -ls -R hdfs://mycluster/tmp/hive/hive
</span><span style="font-family: Courier New;font-size: 8pt">drwx------ - hive hdfs 0 2016-03-14 00:36 hdfs://mycluster/tmp/hive/hive/37ebc52b-d87f-4c3d-bb42-94ddf7c349dc
</span><span style="font-family: Courier New;font-size: 8pt">drwx------ - hive hdfs 0 2016-03-14 00:36 hdfs://mycluster/tmp/hive/hive/37ebc52b-d87f-4c3d-bb42-94ddf7c349dc/_tmp_space.db
</span><span style="font-family: Courier New;font-size: 8pt">drwx------ - hive hdfs 0 2016-03-14 00:05 hdfs://mycluster/tmp/hive/hive/85122ce9-bc22-4ad2-9c34-d497492523bd
</span><span style="font-family: Courier New;font-size: 8pt">drwx------ - hive hdfs 0 2016-03-14 00:05 hdfs://mycluster/tmp/hive/hive/85122ce9-bc22-4ad2-9c34-d497492523bd/_tmp_space.db
</span></td>
</tr>
</tbody>
</table>
</div>
&nbsp;

<span style="font-family: Arial">If you know Hive is done with these files, you can remove them. You can stop Hive services to be extra safe.
</span>

<span style="font-family: Arial"><span style="color: red">Note - </span>this can break Hive if some jobs are still running, so don't do this unless all Hive jobs are done. Be sure that Hive doesn't have any queries running by looking in the Yarn Resource Manager page before doing so.
</span>

<span style="font-family: Arial">Example command line to remove files from HDFS:
</span>

<span style="font-family: Courier New"><strong>hadoop fs -rm -r -skipTrash hdfs://mycluster/tmp/hive/
</strong></span>

&nbsp;

<hr />

&nbsp;
<h2><span style="color: #0070c0;font-family: Arial"><span style="color: #ff9900">C&gt; Avoid going too low – Three's company, One's a lonely number</span>
</span></h2>
<span style="font-family: Arial">If you can't do any of the prior approaches, then you may want to avoid the problem by only scaling down to 3 worker nodes minimum. Don't go lower than that. It will cost some compute hours / money, so its nontrivial I know.
</span>

<span style="font-family: Arial">With 1 worker node, HDFS can't guarantee 3 replicas of the data will be available.
</span>

<span style="font-family: Arial">Having 3 workers node is the safest minimum for HDFS with the default replication factor.
</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/03/031716_0137_HDInsightHD7.png" alt="" /><span style="font-family: Arial">
</span>

<hr />

&nbsp;
<h2><span style="color: #70ad47;font-family: Arial"><span style="color: #0000ff">D&gt; Fiddle with dfs.replication settings – advanced topic</span>
</span></h2>
<span style="font-family: Arial">You could reduce the dfs.replication factor to 1 to prevent the under replicated scenario when using 1 worker node. This is overkill in my opinion, and an advanced option, and has consequences when other regular maintenance is done, so you need to test more thoroughly. If you keep real data (not just the Hive temporary files) in HDFS, you likely do not want to do this!! You could change this in Ambari on the HDFS configuration if you only use HDFS for temp files as recommended in HDInsight.
</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/03/031716_0137_HDInsightHD8.png" alt="" /><span style="font-family: Arial">
</span>

<hr />

&nbsp;
<h2><span style="color: #ed7d31;font-family: Arial"><span style="color: #339966">E&gt; Else plan to leave Safe Mode regularly if it happens from time to time</span>
</span></h2>
<span style="font-family: Arial">If you can't prevent it, then if it gets in Safe mode, then tell it to leave safe mode. Once you prove the reason is just Hive temporary files are under replicated, then leave Safe mode without worry.
</span>

Linux:

<span style="color: black;font-family: Courier New;font-size: 10pt">hdfs dfsadmin -D 'fs.default.name=hdfs://mycluster/' -safemode leave
</span>

Windows:

<span style="color: black;font-family: Courier New;font-size: 10pt">hdfs dfsadmin -fs hdfs://headnodehost:9000 -safemode leave</span>

&nbsp;

<hr />

&nbsp;

&nbsp;

That's all folks. Let us know if this post helps you one day. I'm all ears.

Regards, Jason Howell (Microsoft Azure Big Data Analytics Support team)]]></content:encoded>
    </item>
    <item>
      <title>HDInsight Hive Metastore fails when the database name has dashes or hyphens</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/hdinsight-hive-metastore-fails-when-the-database-name-has-dashes-or-hyphens</link>
      <pubDate>Wed, 24 Feb 2016 13:36:00 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/2016/02/24/hdinsight-hive-metastore-fails-when-the-database-name-has-dashes-or-hyphens/</guid>
      <description><![CDATA[Working in Azure HDInsight support today, we see a failure when trying to run a Hive query on a...]]></description>
      <content:encoded><![CDATA[Working in Azure HDInsight support today, we see a failure when trying to run a Hive query on a freshly created HDInsight cluster. Its brand new and fails on the first try, so what could be wrong?

Our Hive client app fails with this kind of error.
<table border="0">
<tbody>
<tr>
<td>Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:445)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:619)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
at org.apache.hadoop.hive.metastore.MetaStoreUtils.newInstance(MetaStoreUtils.java:1483)
at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.&lt;init&gt;(RetryingMetaStoreClient.java:63)
at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:73)
at org.apache.hadoop.hive.ql.metadata.Hive.createMetaStoreClient(Hive.java:2743)
at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:2762)
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:426)
... 8 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.hive.metastore.MetaStoreUtils.newInstance(MetaStoreUtils.java:1481)
... 13 more
<span style="background-color: #ffff00">Caused by: javax.jdo.JDOUserException: Could not create "increment"/"table" value-generation container meta-store-database.dbo.SEQUENCE_TABLE since autoCreate flags do not allow it.</span>
NestedThrowables:
org.datanucleus.exceptions.NucleusUserException: Could not create "increment"/"table" value-generation container meta-store-database.dbo.SEQUENCE_TABLE since autoCreate flags do not allow it.
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:549)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:732)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:752)
at org.apache.hadoop.hive.metastore.ObjectStore.createDatabase(ObjectStore.java:499)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:98)
at com.sun.proxy.$Proxy9.createDatabase(Unknown Source)
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB_core(HiveMetaStore.java:578)
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:598)
at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:436)
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.&lt;init&gt;(RetryingHMSHandler.java:66)
at org.apache.hadoop.hive.metastore.RetryingHMSHandler.getProxy(RetryingHMSHandler.java:72)
at org.apache.hadoop.hive.metastore.HiveMetaStore.newRetryingHMSHandler(HiveMetaStore.java:5509)
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.&lt;init&gt;(HiveMetaStoreClient.java:178)
at org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient.&lt;init&gt;(SessionHiveMetaStoreClient.java:74)
... 18 more
<span style="background-color: #ffff00">Caused by: org.datanucleus.exceptions.NucleusUserException: Could not create "increment"/"table" value-generation container meta-store-database.dbo.SEQUENCE_TABLE since autoCreate flags do not allow it.</span>
at org.datanucleus.store.rdbms.valuegenerator.TableGenerator.createRepository(TableGenerator.java:261)
at org.datanucleus.store.rdbms.valuegenerator.AbstractRDBMSGenerator.obtainGenerationBlock(AbstractRDBMSGenerator.java:162)
at org.datanucleus.store.valuegenerator.AbstractGenerator.obtainGenerationBlock(AbstractGenerator.java:197)
at org.datanucleus.store.valuegenerator.AbstractGenerator.next(AbstractGenerator.java:105)
at org.datanucleus.store.rdbms.RDBMSStoreManager.getStrategyValueForGenerator(RDBMSStoreManager.java:2005)
at org.datanucleus.store.AbstractStoreManager.getStrategyValue(AbstractStoreManager.java:1386)
at org.datanucleus.ExecutionContextImpl.newObjectId(ExecutionContextImpl.java:3827)
at org.datanucleus.state.JDOStateManager.setIdentity(JDOStateManager.java:2571)
at org.datanucleus.state.JDOStateManager.initialiseForPersistentNew(JDOStateManager.java:513)
at org.datanucleus.state.ObjectProviderFactoryImpl.newForPersistentNew(ObjectProviderFactoryImpl.java:232)
at org.datanucleus.ExecutionContextImpl.newObjectProviderForPersistentNew(ExecutionContextImpl.java:1414)
at org.datanucleus.ExecutionContextImpl.persistObjectInternal(ExecutionContextImpl.java:2218)
at org.datanucleus.ExecutionContextImpl.persistObjectWork(ExecutionContextImpl.java:2065)
at org.datanucleus.ExecutionContextImpl.persistObject(ExecutionContextImpl.java:1913)
at org.datanucleus.ExecutionContextThreadedImpl.persistObject(ExecutionContextThreadedImpl.java:217)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:727)
... 34 more</td>
</tr>
</tbody>
</table>
We found out the problem is very simple. The Hive metastore database in HDInsight usually lives in an Azure SQL Database, and the name of that database can be customized. In this case it was a name "hive-meta-store" database name.

The error gives us a hint, but the error isn't clear about what caused the failure.

Caused by: org.datanucleus.exceptions.NucleusUserException: Could not create "increment"/"table" value-generation container meta<span style="background-color: #ffff00">-</span>store<span style="background-color: #ffff00">-</span>database.dbo.SEQUENCE_TABLE since autoCreate flags do not allow it.

Apparently in HiveServer2  there is a bug where if the metastore database name is not always are escaped by tick marks 'hive-meta-store' or brackets [hive-meta-store] so instead, Hive gets an incorrect syntax error. On such clusters, the Hiveserver2 wouldn’t start. HiveServer2 wouldn’t start because of table “meta-store-database.dbo.SEQUENCE_TABLE” table
<table border="0">
<tbody>
<tr>
<td>2016-01-16 02:14:10,228 DEBUG [main]: Datastore.Native (Log4JLogger.java:debug(58)) - SELECT NEXT_VAL FROM <span style="background-color: #ffff00">meta-store-database</span>.SEQUENCE_TABLE WHERE SEQUENCE_NAME=&lt;'org.apache.hadoop.hive.metastore.model.MDatabase'&gt;

2016-01-16 02:14:10,233 INFO  [main]: DataNucleus.ValueGeneration (Log4JLogger.java:info(77)) - Error encountered allocating block of IDs : Couldnt obtain a new sequence (unique id) : <span style="background-color: #ff0000">Incorrect syntax near '-'.</span></td>
</tr>
</tbody>
</table>
<h2></h2>
<h2>The known issue</h2>
The issue is being tracked here <a href="https://issues.apache.org/jira/browse/HIVE-6113" target="_blank">https://issues.apache.org/jira/browse/HIVE-6113</a> and in Hortonworks' internal Jira item HIVE-433.

Hortonworks is aware of the issue, and it already fixed in a later build as per reading HIVE-6113 has already upgraded the datanucleus version to 4.x. This upgrade will be available as part of Hive 2.0, which is not out yet in Azure HDInsight.

Until that is done, avoid dashes or hyphens in your custom metastore, else HiveServer2 will not start.]]></content:encoded>
    </item>
    <item>
      <title>How to call a Azure Machine Learning Web Service from NodeJS</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/how-to-call-a-azure-machine-learning-web-service-from-nodejs</link>
      <pubDate>Thu, 18 Feb 2016 08:32:00 GMT</pubDate>
      <dc:creator><![CDATA[carrollwp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/2016/02/18/how-to-call-a-azure-machine-learning-web-service-from-nodejs/</guid>
      <description><![CDATA[Azure machine learning allows data scientists and developers to embed predictive analytics into...]]></description>
      <content:encoded><![CDATA[Azure machine learning allows data scientists and developers to embed predictive analytics into applications. To learn more about Azure machine learning visit <a href="https://azure.microsoft.com/en-us/documentation/services/machine-learning/">Azure machine learning documentation</a> . A simplified process flow for Azure machine learning is:
<ul>
	<li>Create an Azure machine learning workspace that has an associated Azure storage account.</li>
	<li>Login to your Azure machine learning workspace and then login into ML Studio. ML Studio is where you can create your machine learning experiments and publish them as a web services. You need to create an experiment which produces the machine learning model, and then publish it as a web service.</li>
	<li>Once you publish your web service, the portal has a page with information on how to call the web service and example code in C#, Python, and R.</li>
	<li>
<div>Calling the web service allows you to embed your predictive analytics into applications. You will pass new input feature data to the web service. The new feature data will be run through the machine learning model and the web service will send back the prediction.</div>
&nbsp;</li>
</ul>
Recently I had a request on how to call an Azure machine learning web service from NodeJS. The portal did not have an example. In this post I will show the basic code in NodeJS to call an Azure machine learning web service.

Below is a simple experiment I created that tries to predict the percent gain ten days from now for the SP 500 Index. At the bottom is a button to set up your web service once you are comfortable with the model.

<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/metablogapi/3542.021816_1632_HowtocallaA1.png" alt="" />

&nbsp;

Below is the web service predictive experiment page after you have published it.

<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/metablogapi/0246.021816_1632_HowtocallaA2.png" alt="" />

&nbsp;

Below is the information for the published web service. You will need information from this page to call the web service from NodeJS. One piece of information that you will need is the API key. You can also test out your web service here. Under the REQUEST/RESPONSE link is more information that you will need like the POST Request URI.

<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/metablogapi/0310.021816_1632_HowtocallaA3.png" alt="" />

&nbsp;

Below you will see the post request URI. You will need this. Also on this page are code examples in C#, Python and R. Now that we have created an experiment published it as a web service and have the Post Request URI and API Key we can start to write the code in NodeJS to call the web service and get a prediction.

<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/metablogapi/6014.021816_1632_HowtocallaA4.png" alt="" />

&nbsp;

I am assuming you are somewhat familiar with NodeJS and have downloaded it and installed it. Here is the download link <a href="https://nodejs.org/en/download/">Download NodeJS</a> and web site. You can create the maml-server.js file in notepad or your favorite IDE.

From the POST Request URI you can get the information for the host and path variables. The headers will need the API key. The options variable has this information and is created in the getPred function. In the buildFeatureInput function, I just hard coded the new feature data, but you could easily get this information from a web form or a RDMS call. I wanted to keep the example simple.

&nbsp;

//maml-server.js

var http = require("http");

var https = require("https");

var querystring = require("querystring");

var fs = require('fs');

&nbsp;

function getPred(data) {

console.log('===getPred()===');

var dataString = JSON.stringify(data)

var host = 'ussouthcentral.services.azureml.net'

var path = '/workspaces/fda91d2e52b74ee2ae68b1aac4dba8b9/services/1b2f5e6f99574756a8fde751def19a0a/execute?api-version=2.0&amp;details=true'

var method = 'POST'

var api_key = 'vKKR78dSdQeSc9qdMaDmu2Z5bcFqb4TfkZdNgSxzcIjGV9p5OP2uy4k1HfJes1T4Ws3St+EBgQTX/N8vqCs4zg=='

var headers = {'Content-Type':'application/json', 'Authorization':'Bearer ' + api_key};

&nbsp;

var options = {

host: host,

port: 443,

path: path,

method: 'POST',

headers: headers

};

&nbsp;

console.log('data: ' + data);

console.log('method: ' + method);

console.log('api_key: ' + api_key);

console.log('headers: ' + headers);

console.log('options: ' + options);

&nbsp;

var reqPost = https.request(options, function (res) {

console.log('===reqPost()===');

console.log('StatusCode: ', res.statusCode);

console.log('headers: ', res.headers);

&nbsp;

res.on('data', function(d) {

process.stdout.write(d);

});

});

&nbsp;

// Would need more parsing out of prediction from the result

reqPost.write(dataString);

reqPost.end();

reqPost.on('error', function(e){

console.error(e);

});

&nbsp;

}

&nbsp;

//Could build feature inputs from web form or RDMS. This is the new data that needs to be passed to the web service.

function buildFeatureInput(){

console.log('===performRequest()===');

var data = {

"Inputs": {

"input1": {

"ColumnNames": ["gl10", "roc20", "uo", "ppo", "ppos", "macd", "macds", "sstok", "sstod", "pmo", "pmos", "wmpr"],

"Values": [ [ "0", "-1.3351", "50.2268", "-0.2693", "-0.2831", "-5.5310", "-5.8120", "61.9220", "45.3998", "-0.0653", "-0.0659", "-30.3005" ], ]

},

},

"GlobalParameters": {}

}

getPred(data);

}

&nbsp;

&nbsp;

function send404Reponse(response) {

response.writeHead(404, {"Context-Type": "text/plain"});

response.write("Error 404: Page not Found!");

response.end();

}

&nbsp;

function onRequest(request, response) {

if(request.method == 'GET' &amp;&amp; request.url == '/' ){

response.writeHead(200, {"Context-Type": "text/plain"});

fs.createReadStream("./index.html").pipe(response);

}else {

send404Reponse(response);

}

}

&nbsp;

http.createServer(onRequest).listen(8050);

console.log("Server is now running on port 8050");

buildFeatureInput();

&nbsp;

&nbsp;

Once you have saved the code to disk you can run it in NodeJS by issuing, "Node &lt;path to maml-server.js&gt;". I am also displaying the status code from the POST and the results from calling the web service. You would need to parse out the JSON to get the "Scored Labels" column that has the prediction. The model is predicting that the SP 500 will be down 4.71% ten days from now. The SP 500 closed yesterday (2016-02-17) at 1926.82. We can check back on 2016-03-04 and see how well the model did! Machine learning is a big topic but Azure machine learning makes it easy to embed analytics in your applications.

&nbsp;

<img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/metablogapi/1145.021816_1632_HowtocallaA5.png" alt="" />

&nbsp;

I hope this helps some one. I will have changed my API key, so if you try to run the example you might get an authorization error.

Bill]]></content:encoded>
    </item>
    <item>
      <title>Encoding 101 - Exporting from SQL Server into flat files, to create a Hive external table</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/encoding-101-exporting-from-sql-server-into-flat-files-to-create-a-hive-external-table</link>
      <pubDate>Fri, 05 Feb 2016 16:33:00 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/2016/02/05/encoding-101-exporting-from-sql-server-into-flat-files-to-create-a-hive-external-table/</guid>
      <description><![CDATA[Today in Microsoft Big Data Support we faced the issue of how to correctly move Unicode data from...]]></description>
      <content:encoded><![CDATA[<span style="color: black;font-family: Arial;font-size: 10pt">Today in Microsoft Big Data Support we faced the issue of how to correctly move Unicode data from SQL Server into Hive via flat text files. The main issue faced was encoding special Unicode characters from the source database, such as the degree sign (Unicode 00B0) and other complex Unicode characters outside of A-Z 0-9. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">The goal was to get Hive to read those same strings SQL Server had saved out to text files and represent them equally to the Hive consumer. We could have used Sqoop if there was a connection between Hadoop and the SQL Server, but that was not possible, as this was across company boundaries and shipping files was the easier approach. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">It was tricky to do, but we found a couple of solutions. When the Unicode string value is exported from Microsoft SQL Server via SSIS or the Import Export wizard, they look fine to the naked eye, but SELECT * FROM HiveTable; and the data looks different. </span>

<span style="color: black;font-size: 10pt"><span style="font-family: Tahoma">Microsoft SQL Server: </span><span style="font-family: Arial"><strong>zyx°°° </strong>Looks good </span></span>

<span style="color: black;font-size: 10pt"><span style="font-family: Arial">Hive: <strong>zyx</strong></span><span style="font-family: Tahoma"><strong>���</strong> Uh-oh! We've got trouble. </span></span>

&nbsp;

<span style="color: black;font-size: 10pt"><span style="font-family: Arial">That Unicode string (NVARCHAR) value in SQL appears as <strong>zyx°°° </strong>We Export that data to a flat file using SSIS or the Import Export Wizard, then copy the files into Azure Blob Storage. Next using Azure HDInsight, when a Hive table is created atop those files, then the same characters look garbled black question marked - zyx</span><span style="font-family: Tahoma">��� as if the characters are unknown to Hive's interpretation. </span></span>

<span style="color: black;font-family: Tahoma;font-size: 10pt">Linux and Hive default to text files encoded to UTF-8 format. That differs from the SSIS Flat File Destination's Unicode output. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">I found two ways we found to make them compatible. </span>
<ol>
	<li><span style="color: black;font-family: Arial;font-size: 10pt">Change the export options in SQL Server SSIS Flat File Destination to uncheck the "Unicode" checkmark and select <strong>code page 65001 (UTF-8)</strong> instead. </span></li>
	<li><span style="color: black;font-family: Arial;font-size: 10pt">Keep the Unicode encoding as is in SSIS, but tell Hive to interpret the data differently using <strong>serdeproperties ('serialization.encoding'='ISO-8859-1');</strong> </span></li>
</ol>
&nbsp;
<h1>Time for a little trial and error</h1>
<h2>1. Setup an example Database</h2>
<span style="color: black;font-family: Arial;font-size: 10pt">These are the steps I used to see the issue. You can use SQL Server (any version from 2005-2016). </span>

<span style="color: black;font-family: Arial;font-size: 10pt">Using SQL Management Studio, I create a database TestHive and table T1 in SQL Server. Insert some data into the NVarchar column, including some special characters. NChar and NVarChar and NVarChar(max) are the double-byte Unicode data type in SQL Server columns, that are used for global language support. </span>
<div>
<table style="border-collapse: collapse" border="0"><colgroup> <col style="width: 779px" /></colgroup>
<tbody valign="top">
<tr>
<td style="padding-left: 9px;padding-right: 9px;border: solid 0.5pt"><span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">CREATE</span> <span style="color: blue">DATABASE</span> TestHive </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">GO</span> </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">USE</span> TestHive </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">GO</span> </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">CREATE</span> <span style="color: blue">TABLE</span> T1<span style="color: gray">(</span>Col1 <span style="color: blue">Int<span style="color: gray">,</span> Col2 NVarchar<span style="color: gray">(</span>255<span style="color: gray">));</span> </span></span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">GO</span> </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">INSERT</span> <span style="color: blue">INTO</span> T1 <span style="color: blue">VALUES</span> </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: gray">(</span>1<span style="color: gray">,N<span style="color: red">'abcdef'<span style="color: gray">),</span> </span></span></span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: gray">(</span>2<span style="color: gray">,N<span style="color: red">'zyx°°°'<span style="color: gray">),</span> </span></span></span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: gray">(</span>3<span style="color: gray">,N<span style="color: red">'123456'</span> )</span> </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">GO</span> </span>

<span style="font-family: Consolas;font-size: 9pt"><span style="color: blue">SELECT</span> <span style="color: gray">*</span> <span style="color: blue">FROM</span> T1 </span></td>
</tr>
</tbody>
</table>
</div>
&nbsp;
<h2>2. Run the SQL Server Import Export Wizard from the Start menu to copy the rows into a text file.</h2>
&nbsp;

<span style="color: black;font-family: Arial;font-size: 10pt">On the Source – point to your SQL Server instance, and select the database and table you want to pull from. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">On the Destination – choose Flat File Destination, point to a file path on the local disk, and Select the <strong><em>Unicode</em></strong> checkbox on the locale. </span>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/2273.image001.jpg"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/2273.image001.jpg" alt="" border="0" /></a>

You could use the same Flat File Destination from within an Integration Services (SSIS) package design and run that if you prefer more control on how the data is transformed in the Data Flow Task, but the Import Export Wizard does the simple copy that we need here.

This is the output – so far looks good.

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5340.image002.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5340.image002.png" alt="" width="358" height="398" border="0" /></a>
<h2>3. Connect to my Azure HDInsight cluster in the cloud to upload the file.</h2>
&nbsp;

<span style="color: black;font-family: Arial;font-size: 10pt">I used a Linux based HDInsight Hadoop cluster, so I will use SSH to connect to the head node. </span>

<span style="font-family: Arial;font-size: 10pt">Then I create a directory, and upload the first file into that location in blob store. This is much like saving the file from the local disk into HDFS for the purposes of Hadoop outside of Azure. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">hadoop fs -mkdir -p /tutorials/usehive/import1/ </span>

<span style="color: black;font-family: Arial;font-size: 10pt">hadoop fs -copyFromLocal tableexport_ssisunicode.txt wasb:///tutorials/usehive/import1/tableexport_ssisunicode.txt </span>

<span style="font-family: Arial;font-size: 10pt">You could also upload the files directly to Azure Blob Storage from tools such as Visual Studio Azure <a href="https://go.microsoft.com/fwlink/?linkid=518003&amp;clcid=0x409">VS 2015</a> / <a href="https://go.microsoft.com/fwlink/?linkid=323510&amp;clcid=0x409">VS 2013</a> or <a href="https://storageexplorer.com/" target="_blank">Microsoft Azure Storage Explorer</a> / <a href="https://azurestorageexplorer.codeplex.com/" target="_blank">Azure Storage Explorer</a> or <a href="https://visualstudiogallery.msdn.microsoft.com/d3896fc2-109b-4420-9c38-b6ab1cfa9fe5" target="_blank">Cloud Explorer for Visual Studio 2013</a> </span>

&nbsp;
<h2>4. Run Hive to read that first folder</h2>
<span style="color: black;font-family: Arial;font-size: 10pt">Now that the text file is ready in Blob storage, I can run Hive and create a table, and query from that file saved into the <strong>import1</strong> folder. From my SSH session I simply run hive. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">cd /bin </span>

<span style="color: black;font-family: Arial;font-size: 10pt">hive </span>

<span style="color: black;font-family: Arial;font-size: 10pt">{ </span>
<p style="margin-left: 36pt"><span style="color: black;font-family: Arial;font-size: 10pt">DROP TABLE Import1; </span></p>
<p style="margin-left: 36pt"><span style="color: black;font-family: Arial;font-size: 10pt">CREATE EXTERNAL TABLE Import1(col1 string, col2 string) ROW FORMAT DELIMITED </span></p>
<p style="margin-left: 36pt"><span style="color: black;font-family: Arial;font-size: 10pt">FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION '/tutorials/usehive/import1/' tblproperties ("skip.header.line.count"="1"); </span></p>
<p style="margin-left: 36pt"><span style="color: black;font-family: Arial;font-size: 10pt">SELECT * FROM Import1; </span></p>
<span style="color: black;font-family: Arial;font-size: 10pt">} </span>

&nbsp;

<span style="color: black;font-size: 10pt"><span style="font-family: Arial">Notice the strange characters </span><span style="font-family: Tahoma"><strong>��� </strong></span><span style="font-family: Arial">where I expected my degree signs. </span></span>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/8233.image004.jpg"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/8233.image004.jpg" alt="" border="0" /></a>

<span style="color: black;font-family: Arial;font-size: 10pt"><strong>Just to be sure it's not something special with my SSH client (MobaXTerm here) I am trying from the Ambari web dashboard for my Azure HDInsight Cluster, and using the Hive View from the menu icon in the upper right. </strong></span>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/8461.image005.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/8461.image005.png" alt="" border="0" /></a>

&nbsp;
<h2>5. OK let's try exporting again – this time changing the flat file encoding setting.</h2>
<span style="color: black;font-family: Arial;font-size: 10pt">In the SSIS Import Export Wizard (SSIS Flat File Destination) choose code page UTF-8. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">- Uncheck the "Unicode" checkmark. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">- Choose code page 65001 (UTF-8) </span>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5344.image007.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5344.image007.png" alt="" border="0" /></a>

&nbsp;
<h2><span style="color: black">6. Upload that second file to Linux (SFTP) and then copy into HDFS or Azure Blob Storage. </span></h2>
I made a new folder, so I could compare my trials side-by-side.

<span style="color: black;font-family: Arial;font-size: 10pt">hadoop fs -mkdir -p /tutorials/usehive/import2/ </span>

<span style="color: black;font-family: Arial;font-size: 10pt">hadoop fs -copyFromLocal tableexport_ssisunicode2.txt wasb:///tutorials/usehive/import2/tableexport_ssisunicode2.txt </span>

&nbsp;
<h2>7. Now test the Hive table again with the UTF-8 encoded file in the second folder</h2>
<span style="color: black;font-family: Arial;font-size: 10pt"><strong>Run Hive </strong></span>

<span style="color: black;font-family: Arial;font-size: 10pt">cd /bin </span>

<span style="color: black;font-family: Arial;font-size: 10pt">hive </span>

<span style="color: black;font-family: Arial;font-size: 10pt">{ </span>

<span style="color: black;font-family: Arial;font-size: 10pt">DROP TABLE Import2; </span>

<span style="color: black;font-family: Arial;font-size: 10pt">CREATE EXTERNAL TABLE Import2(col1 string, col2 string) ROW FORMAT DELIMITED </span>

<span style="color: black;font-family: Arial;font-size: 10pt">FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION '/tutorials/usehive/import2/' tblproperties ("skip.header.line.count"="1"); </span>

<span style="color: black;font-family: Arial;font-size: 10pt">SELECT * FROM Import2; </span>

<span style="color: black;font-family: Arial;font-size: 10pt">QUIT; </span>

<span style="color: black;font-family: Arial;font-size: 10pt">} </span>

<span style="color: black;font-family: Arial;font-size: 10pt">My zyx°°° looks normal now! Success! </span>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/0652.image009.jpg"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/0652.image009.jpg" alt="" border="0" /></a>

&nbsp;

<span style="color: black;font-family: Arial;font-size: 10pt">The Hive View in Ambari likes this data too. </span>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/1452.image010.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/1452.image010.png" alt="" width="597" height="454" border="0" /></a>
<h1>8. An alternative- Tell hive to encode / decode the external files differently</h1>
<span style="color: black;font-family: Arial;font-size: 10pt">Perhaps you don't want to change the file format to UTF-8 (most universal in Linux and Hadoop), or maybe you cannot change the format at all, because the files come from an outsider. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">Starting in <strong>Hive 0.14</strong> version and above, Hive has a simple way to change the encoding of serialization (for interpreting the bytes encoding in text files for example). </span>

<span style="color: black;font-family: Arial;font-size: 10pt">The change was explained here <a href="https://issues.apache.org/jira/browse/HIVE-7142" target="_blank">https://issues.apache.org/jira/browse/HIVE-7142</a> </span>

&nbsp;

<span style="color: black;font-family: Arial;font-size: 10pt">1. You can Create from scratch with this code page serializer and override the <strong>serialization.encoding</strong> property to a code page that best matches your source data encoding. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">CREATE TABLE person(id INT, name STRING, desc STRING)
<span style="background-color: yellow">ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' WITH SERDEPROPERTIES("serialization.encoding"='ISO-8859-1');</span> </span>

&nbsp;

<span style="color: black;font-family: Arial;font-size: 10pt">2. Or if you have an existing table, this can be adjusted after the fact. You need to carefully match your encoding to whatever kind of files will be presented in the storage underneath this Hive table. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">Choose one, or make your own… </span>

<span style="color: black;font-family: Arial;font-size: 10pt">ALTER TABLE Import1 SET serdeproperties ('serialization.encoding'='US-ASCII');
ALTER TABLE Import1 SET serdeproperties ('serialization.encoding'='ISO-8859-1');
ALTER TABLE Import1 SET serdeproperties ('serialization.encoding'='UTF-8'); </span>

&nbsp;

<span style="color: black;font-family: Arial;font-size: 10pt">To find out which tokens to list next to the equal sign, refer to the Charset code ID is listed in Java documentation
<a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html" target="_blank">https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html</a> </span>

<span style="color: black;font-family: Arial;font-size: 10pt">I am guessing the right one is this one to match SQL's "Unicode" but it needs to be tested further to be totally sure that ALL characters are interpreted as expected. </span>
<div>
<table style="border-collapse: collapse" border="0"><colgroup> <col style="width: 231px" /> <col style="width: 550px" /></colgroup>
<tbody valign="top">
<tr>
<td style="padding: 4px 4px 4px 9px"><span style="color: #353833;font-family: Courier New;font-size: 10pt"><span style="background-color: yellow">ISO-8859-1</span>  </span></td>
<td style="padding: 4px 4px 4px 9px" valign="middle"><span style="color: #353833"><span style="font-family: Arial;font-size: 9pt">ISO Latin Alphabet No. 1, a.k.a. </span><span style="font-family: Courier New;font-size: 10pt">ISO-LATIN-1</span></span></td>
</tr>
</tbody>
</table>
</div>
&nbsp;
<h1>Other tips we didn't have time to try yet:</h1>
<span style="color: black;font-family: Arial;font-size: 10pt">Someone made a tool to help convert files if it is not possible for them to change the format in SSIS or BCP exports to text files. <a href="https://code.msdn.microsoft.com/windowsdesktop/UTF8WithoutBOM-Converter-7a8218af" target="_blank">https://code.msdn.microsoft.com/windowsdesktop/UTF8WithoutBOM-Converter-7a8218af</a> </span>

&nbsp;
<h1><span style="font-family: arial, helvetica, sans-serif">Hope this helps someone out there. Let us know if it does, or if you still get stuck, post a comment below, or try the <a href="https://social.msdn.microsoft.com/forums/azure/en-us/home?forum=hdinsight" target="_blank">Azure forums</a> for help.</span></h1>
&nbsp;
<h1>Happy Hadooping! Jason</h1>]]></content:encoded>
    </item>
    <item>
      <title>Encoding the Hive query file in Azure HDInsight</title>
      <link>https://docs.microsoft.com/archive/blogs/bigdatasupport/encoding-the-hive-query-file-in-azure-hdinsight</link>
      <pubDate>Fri, 05 Feb 2016 14:33:00 GMT</pubDate>
      <dc:creator><![CDATA[JasonHowell]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bigdatasupport/2016/02/05/encoding-the-hive-query-file-in-azure-hdinsight/</guid>
      <description><![CDATA[Today at Microsoft we were using Azure Data Factory to run Hive Activities in Azure HDInsight on a...]]></description>
      <content:encoded><![CDATA[Today at Microsoft we were using <a href="https://azure.microsoft.com/en-us/documentation/articles/data-factory-hive-activity/" target="_blank">Azure Data Factory to run Hive Activities</a> in Azure HDInsight on a schedule. Things were working fine for a while, but then we got an error that was hard to understand. I've simplified the scenario to illustrate the key points. The key is that Hive did not like the Byte Order Mark (first 3 bytes) in the hive .hql file, and failed with an error. Be careful which text editor and text encoding you choose when saving your Hive Query Language (HQL) command into a text file.

We are using Azure Data Factory (Feb 2016) with a linked service to Microsoft Azure HDInsight Hadoop on Linux (version 3.2.1000.0) which is the distribution from Hortonworks Data Platform version 2.2.7.1-36 and includes Hive 0.14.0.

<strong>Error message: </strong>
<p style="margin-left: 36pt">Hive script failed with exit code '64'. See 'wasb://adfjobs@mycontainer.blob.core.windows.net/HiveQueryJobs/92994500-5dc2-4ba3-adb8-4fac51c4d959/05_02_2016_05_49_34_516/Status/stderr' for more details.</p>
To drill into that stderror logging, In the Data Factory activity blade, we see the error text, and see the log files below. We click on the stderr file and read it in the log blade.

<strong>Stderr says: </strong>
<p style="margin-left: 36pt">WARNING: Use "yarn jar" to launch YARN applications.</p>
<p style="margin-left: 36pt">Logging initialized using configuration in jar:file:/mnt/resource/hadoop/yarn/local/filecache/11/hive.tar.gz/hive/lib/hive-common-1.2.1.2.3.3.1-1.jar!/hive-log4j.properties</p>
<p style="margin-left: 36pt"><span style="background-color: yellow">FAILED: ParseException line 1:0 character '' not supported here</span></p>
That's strange, because the Hive query file looks fine to the naked eye.

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/2605.image001.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/2605.image001.png" alt="" border="0" /></a>

&nbsp;

<strong>If you use a binary editor though you can see these two text files are not the same. </strong>

I have Visual Studio handy, and it can show the hex representation of these files.

File &gt; Open &gt; File…

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4331.image003.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4331.image003.png" alt="" border="0" /></a>

&nbsp;

Next to the open button there is a drop down – choose "Open with…"

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/7142.image005.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/7142.image005.png" alt="" border="0" /></a>

Choose <strong>Binary Editor. </strong>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4670.image007.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4670.image007.png" alt="" border="0" /></a>

&nbsp;

Notice that <strong>file2.hql</strong> shown below has 3 extra bytes in the beginning. This is called a byte-order mark (BOM).

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5226.image009.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5226.image009.png" alt="" border="0" /></a>
<h2>The Standards Controversy</h2>
<span style="color: black;font-family: Arial;font-size: 10pt">There is some controversy about whether UTF-8 text files should have a byte order mark or not. </span>

<span style="color: black;font-family: Arial;font-size: 10pt">The standards folks say don't use it in most cases, but also don't remove it if you already have a BOM. We software developers sometimes forget that and are inconsistent -Microsoft Windows vs. Linux vs. Apache Hive </span>

<span style="color: black;font-family: Arial;font-size: 10pt">Citing the crowdsourced Wikipedia information here for neutrality: </span>

<span style="color: black;font-family: Arial;font-size: 10pt">            <a href="https://en.wikipedia.org/wiki/Byte_order_mark" target="_blank">https://en.wikipedia.org/wiki/Byte_order_mark</a> </span>
<p style="padding-left: 30px">UTF-8 byte order mark is EF BB BF in hex.</p>
<p style="margin-left: 36pt">The Unicode Standard permits the BOM in UTF-8,<a href="https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fen.wikipedia.org%2fwiki%2fByte_order_mark%23cite_note-2&amp;data=01%7c01%7cjasonh%40exchange.microsoft.com%7c05e68c801df8438fc02608d32e717362%7c72f988bf86f141af91ab2d7cd011db47%7c1&amp;sdata=Bo9bzmYbViYWAbOP7YQTBLtiLfKlp%2bvFrJ2dGd3ghHo%3d"><span style="color: blue;font-size: 9pt"><sup>[2]</sup></span></a> but does not require or recommend its use.</p>
<p style="margin-left: 36pt">The standard also <span style="background-color: aqua">does not recommend removing</span> a BOM when it is there, so that round-tripping between encodings does not lose information, and so that code that relies on it continues to work.</p>
<p style="margin-left: 36pt"><span style="color: black;font-family: Arial;font-size: 10pt">In Linux distributions since around 2004 the convention is to generate UTF-8 files <span style="background-color: aqua">without a BOM.</span> </span></p>
<p style="margin-left: 36pt">Microsoft compilers<a href="https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fen.wikipedia.org%2fwiki%2fByte_order_mark%23cite_note-10&amp;data=01%7c01%7cjasonh%40exchange.microsoft.com%7c05e68c801df8438fc02608d32e717362%7c72f988bf86f141af91ab2d7cd011db47%7c1&amp;sdata=YysDbVoupSVucCdN6gNKUKRKcjyp0jHZl3HzKVBZC0A%3d"><span style="color: blue;font-size: 9pt"><sup>[10]</sup></span></a> and interpreters, and many pieces of software on Microsoft Windows such as <a title="Notepad (Windows)" href="https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fen.wikipedia.org%2fwiki%2fNotepad_(Windows)&amp;data=01%7c01%7cjasonh%40exchange.microsoft.com%7c05e68c801df8438fc02608d32e717362%7c72f988bf86f141af91ab2d7cd011db47%7c1&amp;sdata=%2b7gYavq59jPLAH1uyiV5MqtRZ7OXAl%2bt5wi4jsxw2OQ%3d"><span style="background-color: aqua">Notepad</span></a><span style="background-color: aqua"> treat the BOM as a required <a title="Magic number (programming)" href="https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fen.wikipedia.org%2fwiki%2fMagic_number_(programming)%23Magic_numbers_in_files&amp;data=01%7c01%7cjasonh%40exchange.microsoft.com%7c05e68c801df8438fc02608d32e717362%7c72f988bf86f141af91ab2d7cd011db47%7c1&amp;sdata=ECgiXmY0vRL3MWkRCmiqpfpbwkhUTyLgK36CjTSO2Vo%3d">magic number</a></span> rather than use heuristics. These tools add a BOM when saving text as UTF-8, and interpret as UTF-8 on reading only when the BOM is present.</p>
&nbsp;
<h1>The Litmus Test</h1>
So let's try the two .hql text files in Hive console directly outside of Azure Data Factory to see if they work in Hive alone. I am using SSH to connect to my Linux head node in HDInsight. I have uploaded the two files using SFTP (easy to do in MobaXTerm if you like that 3<sup>rd</sup> party tool – I can't endorse any specific tool, but seems nice). The source command here is running the query file from within the hive app.

1. First I launch Hive on my SSH session.
<pre><code><strong>Cd /bin </strong></code></pre>
<pre><code><strong>Hive </strong></code></pre>
&nbsp;

2. Then I run the script from the first file. It works well and returns a list of my Hive tables from my metastore.
<pre><code><strong>source /home/sshuser/file1.hql; </strong></code></pre>
<p style="margin-left: 36pt"></p>

<pre><code>OK </code></pre>
&nbsp;

3. Then I run the script from the second file. It fails with a parsing error
<pre><code><strong>source /home/sshuser/file2.hql; </strong></code></pre>
<pre><code><span style="color: red">FAILED: ParseException line 1:0 character '' not supported here </span></code></pre>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5228.image011.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5228.image011.png" alt="" border="0" /></a>

&nbsp;

&nbsp;
<h1>The lesson learned</h1>
So the lesson learned is that Hive doesn't like the .hql text files when they are encoded in UTF-8 with a Byte-order mark up front in the hex/binary.

UTF-8 is the encoding of choice, but the byte-order mark is not desired.
<h1>Action Required!</h1>
Check your favorite text editor to see if it is marking the BOM or not.
<h3>1. Windows Notepad seems to encode UTF-8 files to include a Byte Order Mark, so avoid that one.</h3>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/3223.image013.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/3223.image013.png" alt="" border="0" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5265.image015.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5265.image015.png" alt="" border="0" /></a>

&nbsp;
<h3>2. Visual Studio 2013 / 2015 gives you the option to save "With Encoding" on the drop down beside the Save button, then you can pick which Encoding you want.</h3>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5047.image017.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5047.image017.png" alt="" width="200" /></a>

&nbsp;

First trial - I picked <strong>Unicode (UTF-8 with signature) – Codepage 65001</strong>. That "signature" means it adds a BOM, which is undesirable for Hive to interpret.

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/6886.image019.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/6886.image019.png" alt="" width="600" /></a>

&nbsp;

Second trial – I picked <strong>Unicode (UTF-8 without signature) - Codepage 65001. </strong>Looks better now. That's the one without the BOM in the first three bytes, so Hive should be OK to read this one.

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/1425.image023.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/1425.image023.png" alt="" border="0" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/7752.image025.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/7752.image025.png" alt="" border="0" /></a>
<h3>3. Linux's common Vi text editor</h3>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/3124.image027.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/3124.image027.png" alt="" border="0" /></a>

The hex representation does not have a BOM, so we are good to use this with Hive.

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5280.image029.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/5280.image029.png" alt="" border="0" /></a>

&nbsp;

Hive can run this one OK

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/8508.image031.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/8508.image031.png" alt="" border="0" /></a>
<h3>4. Nano – another easy text editor on Linux</h3>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/7658.image033.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/7658.image033.png" alt="" border="0" /></a>

Looks good as well, no BOM

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4454.image035.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4454.image035.png" alt="" border="0" /></a>

Hive can run this one OK too.

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4010.image037.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/78/4010.image037.png" alt="" border="0" /></a>

&nbsp;

To be continued... There are many more text editors, so please let me know if you have trouble with encoding using another text editor when saving Hive queries to text.
<h1></h1>
<h1><span style="font-size: medium">Hope this helps someone out there. Let us know if it does, or if you still get stuck, post a comment below, or try the <a href="https://social.msdn.microsoft.com/forums/azure/en-us/home?forum=hdinsight" target="_blank">Azure forums</a> for help.</span></h1>
<h1><span style="font-size: medium">Happy Hadooping! Jason </span></h1>]]></content:encoded>
    </item>
  </channel>
</rss>