Skip to content

Instantly share code, notes, and snippets.

@TheTribe
Last active December 26, 2015 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheTribe/7190398 to your computer and use it in GitHub Desktop.
Save TheTribe/7190398 to your computer and use it in GitHub Desktop.
a quick and dirty HBase.Stargate.Client usage sample

Here's how to get the Stargate client registered with Autofac... once you have an IContainer, you'll be able to resolve instances of IStargate wherever you need...

private static IContainer CreateContainer(string serverUrl)
{
var builder = new ContainerBuilder();
builder.RegisterModule(new StargateModule(new StargateOptions
{
ServerUrl = serverUrl
}));
return builder.Build();
}

Now, all you have to do is create the container and ask for an IStargate instance.

var container = CreateContainer("http://hbase.server.com:9999");
var stargate = container.Resolve<IStargate>();

And then you can create tables, write to them, scan them, destroy them... and more. Have fun!

string table = "test";
stargate.CreateTable(new TableSchema
{
Name = table,
Columns = new List<ColumnSchema>
{
new ColumnSchema{ Name = "alpha" },
new ColumnSchema{ Name = "beta" },
new ColumnSchema{ Name = "gamma" },
new ColumnSchema{ Name = "zeta" }
}
});
string row = Guid.NewGuid().ToString("N").Substring(0, 7);
stargate.WriteValue("foo", table, row, "alpha");
stargate.WriteValue("bar", table, row, "beta");
stargate.WriteValue("rab", table, row, "gamma");
stargate.WriteValue("oof", table, row, "zeta");
// only get the alpha / beta columns
var scannerOptions = new ScannerOptions
{
TableName = table,
Filter = new MultipleColumnPrefixFilter{ "a", "b" }
};
using(IScanner scanner = stargate.CreateScanner(scannerOptions))
{
foreach(CellSet result in scanner)
{
/** process results **/
}
} // scanner auto-deletes when disposed
stargate.DeleteTable(table);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment