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...
Last active
December 26, 2015 17:58
-
-
Save TheTribe/7190398 to your computer and use it in GitHub Desktop.
a quick and dirty HBase.Stargate.Client usage sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IContainer CreateContainer(string serverUrl) | |
{ | |
var builder = new ContainerBuilder(); | |
builder.RegisterModule(new StargateModule(new StargateOptions | |
{ | |
ServerUrl = serverUrl | |
})); | |
return builder.Build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var container = CreateContainer("http://hbase.server.com:9999"); | |
var stargate = container.Resolve<IStargate>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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