var db = new MyHiveDatabase(
            webHCatUri: new Uri("http://localhost:50111"),
            userName: "hadoop", password: null,
            storageAccount: “ASV storage account name”, storageKey: “ASV storage account key”);

var q = from x in
            (from a in db.Actors
                select new { a.ActorId, foo = a.AwardsCount })
        group x by x.ActorId into g
        select new { ActorId = g.Key, bar = g.Average(z => z.foo) };

q.ExecuteQuery().Wait();
var results1 = q.ToList();


var projectionQuery = from aw in db.Awards
                        join t in db.Titles
                            on aw.MovieId equals t.MovieId
                        where t.Year == 1994 && aw.Won == "True"
                        select new { MovieId = t.MovieId, Name = t.Name, Type = aw.Type, Category = aw.Category, Year = t.Year };


var newTable = projectionQuery.CreateTable("AwardsIn1994");



Currently, we do not automatically generate types (eg the Actors and Awards tables above). You’ll need to code these by hand,

public class MyHiveDatabase : HiveConnection
{
    public MyHiveDatabase(Uri webHcatUri, string username, string password, string azureStorageAccount, string azureStorageKey) : base(webHcatUri, username, password, azureStorageAccount, azureStorageKey) { }

    public HiveTable<AwardsRow> Awards
    {
        get
        {
            return this.GetTable<AwardsRow>("Awards");
        }
    }

    public HiveTable<TitlesRow> Titles
    {
        get
        {
            return this.GetTable<TitlesRow>("Titles");
        }
    }

    public HiveTable<ActorsRow> Actors
    {
        get
        {
            return this.GetTable<ActorsRow>("Actors");
        }
    }
}

public class TitlesRow : HiveRow
{
    public string MovieId { get; set; }
    public string Name { get; set; }
    public int Year { get; set; }
    public string Rating { get; set; }
}

public class AwardsRow : HiveRow
{
    public string MovieId { get; set; }
    public string AwardId { get; set; }
    public int Year { get; set; }
    public string Won { get; set; }
    public string Type { get; set; }
    public string Category { get; set; }
}

public class ActorsRow : HiveRow
{
    public string MovieId { get; set; }
    public string ActorId { get; set; }
    public int AwardsCount { get; set; }
    public string Name { get; set; }
}

Last edited Jul 19, 2013 at 11:31 PM by maxluk, version 3

Comments

No comments yet.