Skip to main content

A Quick introduction to Hadoop Hive on Azure and Querying Hive using LINQ in C#

imageEarlier, in a couple of posts related to Hadoop on Azure - Analyzing some ‘Big Data’ using C# and Extracting Top 500 MSDN Links from Stack Overflow – I showed how to use C# Map Reduce Jobs with Hadoop Streaming to do some meaningful analytics.

Now, a preview version of the .NET SDK for Hadoop is available, making it easier to work with Hadoop from .NET – with more types for supporting Map Reduce Jobs, For creating LINQ to Hive queries etc.  You can experiment with Hadoop and C# either by creating a cluster in or you can obtain Hadoop in your machine by installing Microsoft HDInsight using WebPI.

In case you are new to Hadoop on Azure, I suggest you read the introductory concepts here before you start. This post is just a quick example that shows how to use LINQ to Hive.

Hive is a data warehouse system for Hadoop that facilitates easy data summarization, ad-hoc queries, and the analysis of large datasets stored in Hadoop compatible file systems

Installing the libraries

To start with, you can fire up Visual Studio, Create a console project, and install Microsoft.Hadoop.Hive libraries via Nuget.

install-package Microsoft.Hadoop.Hive -pre 

Also, head over to and create a new cluster. And you are now set.

Creating the typed wrappers

To access Hive, you need to create a strongly typed wrapper – as of now, you need to roll this out your own, as there is no automated generation support. When you provision a Hadoop cluster, the Hive will be pre populated with a sample table (hivesampletable), and I’m using the same for the below example for brevity.  You can connect to the Hive via ODBC and see the hive tables in Excel.

So, let us go ahead and create a hive connection (much like an EF data context) and a typed representation for a row in the table. HiveConnection and HiveTable types are in the Microsoft.Hadoop.Hive namespace.

    //Our concrete hive connection
    public class SampleHiveConnection : HiveConnection
        public SampleHiveConnection(string hostName, int port) 
            : base(hostName, port, null, null) { }

        public SampleHiveConnection(string hostName, int port, 
                            string username, string password) 
            : base(hostName, port, username, password) { }

        public HiveTable<DeviceInfo> DeviceInfoTable
                return this.GetTable<DeviceInfo>("hivesampletable");

    //A typed row. Property names based on field names hivesampletable
    public class DeviceInfo : HiveRow
        public string DevicePlatform { get; set; }
        public string DeviceMake { get; set; }
        public int ClientId { get; set; }

Querying the Hive using LINQ

Now,  you may perform LINQ queries against your Hive context, thanks to the Hadoop SDK we installed via Nuget. Just make sure to substitute the connection string, username and password with your own.

class Program
        static void Main(string[] args)

            //Create a hive connection
            //I've my cluster in
            var hive = new SampleHiveConnection(
                    "", //your connection string
                    10000,                       //port                    
                    "user",                      //your username
                    "yourpass");                 //your password

            //Get the results
            //Make sure you goto the dashboard and turn on the ODBC port
            var res = from d in hive.DeviceInfoTable
                      where d.ClientId < 100
                      select d;

            //Dump it to the console if you like
            var list = res.ToList();     

That is cool. Your LINQ query will be submitted to the Azure cluster via the ODBC driver, and will be compiled and executed in the Hive.

Popular posts from this blog

MVVM - Binding Multiple Radio Buttons To a single Enum Property in WPF

I had a property in my View Model, of an Enum type, and wanted to bind multiple radio buttons to this.

Firstly, I wrote a simple Enum to Bool converter, like this.

public class EnumToBoolConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (parameter.Equals(value)) return true; else return false; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return parameter; } #endregion }

And my enumeration is like

public enum CompanyTypes { Type1Comp, Type2Comp, Type3Comp } Now, in my XAML, I provided the enumeration as the ConverterParameter, of the Converter we wrote earlier, like

Creating a quick Todo listing app on Windows using IIS7, Node.js and Mongodb

As I mentioned in my last post, more and more organizations are leaning towards Web Oriented Architecture (WOA) which are highly scalable. If you were exploring cool, scalable options to build highly performing web applications, you know what Node.js is for.After following the recent post from Scott Hanselman, I was up and running quickly with Node.js. In this post, I’ll explain step by step how I’ve setup Node.js and Mongodb to create a simple Todo listing application.Setting up Node.jsThis is what I’ve done.1 – Goto, scroll down and download node.exe for Windows, and place it in your c:\node folder2 – Goto IIS Node project in Git at, download the correct ‘retail’ link of IIS Node zip file (I downloaded the already built retail package, otherwise you can download and build from the source).3 – Extract the zip file some where, and run the install.bat or install_iisexpress.bat depending on your IIS Version. If you don’t have IIS in…

Top 7 Coding Standards & Guideline Documents For C#/.NET Developers

Some time back, I collated a list of 7 Must Read, Free EBooks for .NET Developers, and a lot of people found it useful. So, I thought about putting together a list of Coding Standard guidelines/checklists for .NET /C# developers as well.As you may already know, it is easy to come up with a document - the key is in implementing these standards in your organization, through methods like internal trainings, Peer Reviews, Check in policies, Automated code review tools etc. You can have a look at FxCop and/or StyleCop for automating the review process to some extent, and can customize the rules based on your requirements.Anyway, here is a list of some good Coding Standard Documents. They are useful not just from a review perspective - going through these documents can definitely help you and me to iron out few hidden glitches we might have in the programming portion of our brain. So, here we go, the listing is not in any specific order.1 – IDesign C# Coding StandardsIDesign C# coding stand…