本文整理汇总了C#中HBaseClient类的典型用法代码示例。如果您正苦于以下问题:C# HBaseClient类的具体用法?C# HBaseClient怎么用?C# HBaseClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HBaseClient类属于命名空间,在下文中一共展示了HBaseClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_I_Scan_with_a_ColumnCountGetFilter_I_get_the_expected_results
public void When_I_Scan_with_a_ColumnCountGetFilter_I_get_the_expected_results()
{
// B column should not be returned, so set the value to null.
List<FilterTestRecord> expectedRecords = (from r in _allExpectedRecords select r.WithBValue(null)).ToList();
var client = new HBaseClient(_credentials);
var scanner = new Scanner();
var filter = new ColumnCountGetFilter(2);
scanner.filter = filter.ToEncodedString();
RequestOptions scanOptions = RequestOptions.GetDefaultOptions();
scanOptions.AlternativeEndpoint = Constants.RestEndpointBaseZero;
ScannerInformation scanInfo = null;
try
{
scanInfo = client.CreateScannerAsync(_tableName, scanner, scanOptions).Result;
List<FilterTestRecord> actualRecords = RetrieveResults(scanInfo, scanOptions).ToList();
actualRecords.ShouldContainOnly(expectedRecords);
}
finally
{
if (scanInfo != null)
{
client.DeleteScannerAsync(_tableName, scanInfo, scanOptions).Wait();
}
}
}
示例2: HBaseWriter
public HBaseWriter()
{
//Get the Hadoop Cluster info and create connection
this.ClusterName = ConfigurationManager.AppSettings["ClusterName"];
this.HadoopUserName = ConfigurationManager.AppSettings["HadoopUserName"];
string HadoopUserPassword = ConfigurationManager.AppSettings["HadoopUserPassword"];
this.HBaseTableName = ConfigurationManager.AppSettings["HBaseTableName"];
SecureString pw = new SecureString();
for(int i = 0; i < HadoopUserPassword.Length; i++){
pw.InsertAt(i, HadoopUserPassword[i]);
}
Uri clusterUri = new Uri(this.ClusterName);
ClusterCredentials creds = new ClusterCredentials(clusterUri, this.HadoopUserName, pw);
this.client = new HBaseClient(creds);
//create table and enable the hbase writer
if (!client.ListTables().name.Contains(this.HBaseTableName))
{
// Create the table
var tableSchema = new TableSchema();
tableSchema.name = this.HBaseTableName;
tableSchema.columns.Add(new ColumnSchema { name = "d" });
client.CreateTable(tableSchema);
Console.WriteLine("Table \"{0}\" created.", this.HBaseTableName);
}
WriterThread = new Thread(new ThreadStart(WriterThreadFunction));
WriterThread.Start();
}
示例3: TestLoadBalancerRetriesExhausted
public void TestLoadBalancerRetriesExhausted()
{
int numServers = 4;
int numFailures = 5;
var client = new HBaseClient(numServers);
int count = 0;
Func<string, Task<int>> f = (endpoint) =>
{
count++;
if (count < numFailures)
{
throw new TimeoutException(count.ToString());
}
return EmitIntAsync(count);
};
try
{
var output = client.ExecuteAndGetWithVirtualNetworkLoadBalancing(f);
}
catch (TimeoutException ex)
{
Assert.AreEqual(ex.Message, numServers.ToString());
return;
}
Assert.Fail();
}
示例4: Context
protected override void Context()
{
if (!_arrangementCompleted)
{
// at present, no tables are modified so only arrange the tables once per test pass
// and putting the arrangement into a static context.
// (this knocked test runs down to ~30 seconds from ~5 minutes).
_credentials = ClusterCredentialsFactory.CreateFromFile(@".\credentials.txt");
var client = new HBaseClient(_credentials);
// ensure tables from previous tests are cleaned up
TableList tables = client.ListTables();
foreach (string name in tables.name)
{
string pinnedName = name;
if (name.StartsWith(TableNamePrefix, StringComparison.Ordinal))
{
client.DeleteTable(pinnedName);
}
}
AddTable();
PopulateTable();
_arrangementCompleted = true;
}
}
示例5: HBaseReader
// The constructor
public HBaseReader()
{
ClusterCredentials creds = new ClusterCredentials(
new Uri(CLUSTERNAME),
HADOOPUSERNAME,
HADOOPUSERPASSWORD);
client = new HBaseClient(creds);
}
示例6: HBaseReader
public HBaseReader()
{
var creds = new ClusterCredentials(
new Uri(ConfigurationManager.AppSettings["Cluster"]),
ConfigurationManager.AppSettings["User"],
ConfigurationManager.AppSettings["Pwd"]);
client = new HBaseClient(creds);
}
示例7: When_I_Scan_all_I_get_the_expected_results
public void When_I_Scan_all_I_get_the_expected_results()
{
var client = new HBaseClient(_credentials);
var scan = new Scanner();
ScannerInformation scanInfo = client.CreateScanner(_tableName, scan);
List<FilterTestRecord> actualRecords = RetrieveResults(scanInfo).ToList();
actualRecords.ShouldContainOnly(_allExpectedRecords);
}
示例8: HBaseReaderClient
public HBaseReaderClient(string hbaseclusterurl, string hbaseclusterusername, string hbaseclusteruserpassword)
{
this.HBaseClusterUrl = hbaseclusterurl;
this.HBaseClusterUserName = hbaseclusterusername;
this.HBaseClusterUserPassword = hbaseclusteruserpassword;
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
this.HBaseClusterCredentials = new ClusterCredentials(new Uri(HBaseClusterUrl), HBaseClusterUserName, HBaseClusterUserPassword);
this.HBaseClusterClient = new HBaseClient(HBaseClusterCredentials);
}
示例9: EventHBaseWriter
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="tablename"></param>
public EventHBaseWriter(Context context, Dictionary<string, Object> parms = null)
{
this.context = context;
this.appConfig = new AppConfig();
Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>();
inputSchema.Add(Constants.DEFAULT_STREAM_ID, AggregatedTupleFields);
this.context.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, null));
//Setup the credentials for HBase cluster
HBaseClusterCredentials =
new ClusterCredentials(
new Uri(this.appConfig.HBaseClusterUrl),
this.appConfig.HBaseClusterUserName,
this.appConfig.HBaseClusterUserPassword);
HBaseClusterClient = new HBaseClient(HBaseClusterCredentials);
//Query HBase for existing tables
var tabs = HBaseClusterClient.ListTables();
Context.Logger.Info("HBase Tables (" + tabs.name.Count + "): " + String.Join(", ", tabs.name));
this.PrimaryKey = this.appConfig.PrimaryKey;
this.SecondaryKey = this.appConfig.SecondaryKey;
this.HBaseTableName =
this.appConfig.HBaseTableNamePrefix +
this.appConfig.PrimaryKey + this.appConfig.SecondaryKey +
this.appConfig.HBaseTableNameSuffix;
Context.Logger.Info("HBaseTableName = " + this.HBaseTableName);
//Create a HBase table if it not exists
if (!tabs.name.Contains(this.HBaseTableName))
{
var tableSchema = new TableSchema();
tableSchema.name = this.HBaseTableName;
tableSchema.columns.Add(new ColumnSchema() { name = "v" });
HBaseClusterClient.CreateTable(tableSchema);
Context.Logger.Info("Created HBase Table: " + this.HBaseTableName);
}
Context.Logger.Info("HBaseOverwrite: " + this.appConfig.HBaseOverwrite);
globalstopwatch = new Stopwatch();
globalstopwatch.Start();
emitstopwatch = new Stopwatch();
emitstopwatch.Start();
}
示例10: Main
static void Main(string[] args)
{
while (true)
{
Random rnd = new Random();
Console.Clear();
string clusterURL = "https://hb12345.azurehdinsight.net";
string userName = "HDUser";
string password = "HDPa$$w0rd";
// Connect to HBase cluster
ClusterCredentials creds = new ClusterCredentials(new Uri(clusterURL),
userName, password);
HBaseClient hbaseClient = new HBaseClient(creds);
// Get all stocks
Scanner scanSettings = new Scanner()
{
batch = 10,
startRow = Encoding.UTF8.GetBytes("AAA"),
endRow = Encoding.UTF8.GetBytes("ZZZ")
};
ScannerInformation stockScanner = hbaseClient.CreateScanner("Stocks", scanSettings);
CellSet stockCells = null;
while ((stockCells = hbaseClient.ScannerGetNext(stockScanner)) != null)
{
foreach (var row in stockCells.rows)
{
string stock = Encoding.UTF8.GetString(row.key);
Double currentPrice = Double.Parse(Encoding.UTF8.GetString(row.values[1].data));
Double newPrice = currentPrice + (rnd.NextDouble() * (1 - -1) + -1);
Cell c = new Cell
{
column = Encoding.UTF8.GetBytes("Current:Price"),
data =
Encoding.UTF8.GetBytes(newPrice.ToString())
};
row.values.Insert(2, c);
Console.WriteLine(stock + ": " + currentPrice.ToString() + " := "
+ newPrice.ToString());
}
hbaseClient.StoreCells("Stocks", stockCells);
}
}
}
示例11: HBaseReader
public HBaseReader()
{
//Get the Hadoop Cluster info and create connection
this.ClusterName = ConfigurationManager.AppSettings["ClusterName"];
this.HadoopUserName = ConfigurationManager.AppSettings["HadoopUserName"];
string HadoopUserPassword = ConfigurationManager.AppSettings["HadoopUserPassword"];
SecureString pw = new SecureString();
for (int i = 0; i < HadoopUserPassword.Length; i++)
{
pw.InsertAt(i, HadoopUserPassword[i]);
}
Uri clusterUri = new Uri(this.ClusterName);
ClusterCredentials creds = new ClusterCredentials(clusterUri, this.HadoopUserName, pw);
this.client = new HBaseClient(creds);
}
示例12: HBaseStore
public HBaseStore()
{
// Initialize HBase connection
var credentials = CreateFromFile(@"credentials.txt");
client = new HBaseClient(credentials);
if (!client.ListTables().name.Contains(TABLE_BY_WORDS_NAME))
{
// Create the table
var tableSchema = new TableSchema();
tableSchema.name = TABLE_BY_WORDS_NAME;
tableSchema.columns.Add(new ColumnSchema { name = "d" });
client.CreateTable(tableSchema);
}
}
示例13: CreateHBaseTable
/// <summary>
/// Create a new HBase table
/// </summary>
/// <param name="hbaseClient">client used to connect to HBase</param>
public static void CreateHBaseTable(HBaseClient hbaseClient)
{
//Define the 'cf family
//Set versions to retain to 5
ColumnSchema cf = new ColumnSchema() {
name = Properties.Settings.Default.HBaseTableColumnFamily,
maxVersions = 5
};
//Define the table
TableSchema tableSchema = new TableSchema();
tableSchema.name = Properties.Settings.Default.HBaseTableName;
tableSchema.columns.Add(cf);
//Create the table
hbaseClient.CreateTable(tableSchema);
Console.WriteLine("Table created.");
}
示例14: CreateTable
/// <summary>
/// Create a new HBase table
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public static bool CreateTable(string tableName, string[] columnFamilysKeys)
{
TableSchema tableSchema = new TableSchema();
tableSchema.name = tableName;
foreach (var columnFamilySKey in columnFamilysKeys)
{
tableSchema.columns.Add(new ColumnSchema() { name = columnFamilySKey });
}
if (hbaseClient == null)
hbaseClient = CreateHBaseClient(clusterURL, httpName, httpUserPassword);
int millisecondsTimeout = 3000;
return hbaseClient.CreateTableAsync(tableSchema).Wait(millisecondsTimeout);
}
示例15: InitHBase
private static void InitHBase()
{
try
{
clusterURL = System.Configuration.ConfigurationManager.AppSettings["HBaseClusterURL"].ToString();
httpName = System.Configuration.ConfigurationManager.AppSettings["HBaseHttpName"].ToString();
httpUserPassword = System.Configuration.ConfigurationManager.AppSettings["HBaseHttpUserPassword"].ToString();
hbaseClient = CreateHBaseClient(clusterURL, httpName, httpUserPassword);
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message + "\r\n" + e.StackTrace);
Console.ReadKey();
}
}