本文整理汇总了C#中HBaseClient.ScannerGetNext方法的典型用法代码示例。如果您正苦于以下问题:C# HBaseClient.ScannerGetNext方法的具体用法?C# HBaseClient.ScannerGetNext怎么用?C# HBaseClient.ScannerGetNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HBaseClient
的用法示例。
在下文中一共展示了HBaseClient.ScannerGetNext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: TestFullScan
public void TestFullScan()
{
var client = new HBaseClient(_credentials);
StoreTestData(client);
// full range scan
var scanSettings = new Scanner { batch = 10 };
ScannerInformation scannerInfo = client.CreateScanner(_testTableName, scanSettings);
CellSet next;
var expectedSet = new HashSet<int>(Enumerable.Range(0, 100));
while ((next = client.ScannerGetNext(scannerInfo)) != null)
{
Assert.AreEqual(10, next.rows.Count);
foreach (CellSet.Row row in next.rows)
{
int k = BitConverter.ToInt32(row.key, 0);
expectedSet.Remove(k);
}
}
Assert.AreEqual(0, expectedSet.Count, "The expected set wasn't empty! Items left {0}!", string.Join(",", expectedSet));
}
示例3: TestSubsetScan
public void TestSubsetScan()
{
var client = new HBaseClient(_credentials);
const int startRow = 15;
const int endRow = 15 + 13;
StoreTestData(client);
// subset range scan
var scanSettings = new Scanner { batch = 10, startRow = BitConverter.GetBytes(startRow), endRow = BitConverter.GetBytes(endRow) };
ScannerInformation scannerInfo = client.CreateScanner(_testTableName, scanSettings);
CellSet next;
var expectedSet = new HashSet<int>(Enumerable.Range(startRow, endRow - startRow));
while ((next = client.ScannerGetNext(scannerInfo)) != null)
{
foreach (CellSet.Row row in next.rows)
{
int k = BitConverter.ToInt32(row.key, 0);
expectedSet.Remove(k);
}
}
Assert.AreEqual(0, expectedSet.Count, "The expected set wasn't empty! Items left {0}!", string.Join(",", expectedSet));
}
示例4: StartListening
public bool StartListening()
{
Background = Task.Run(async () =>
{
while (true)
{
var clusterURL = ConfigurationManager.AppSettings["ClusterUrl"];
var hadoopUsername = ConfigurationManager.AppSettings["Username"];
var hadoopUserPassword = ConfigurationManager.AppSettings["Password"];
var hbaseTableName =ConfigurationManager.AppSettings["TableName"];
// Create a new instance of an HBase client.
var creds = new ClusterCredentials(new Uri(clusterURL), hadoopUsername, hadoopUserPassword);
var hbaseClient = new HBaseClient(creds);
//Scan over rows in a table. Assume the table has integer keys and you want data between keys 25 and 35.
var scanSettings = new Scanner()
{
batch = 10
};
var scannerInfo = await hbaseClient.CreateScannerAsync(hbaseTableName, scanSettings);
CellSet next = null;
var res = new List<HBaseEntry>();
var rowNum = 0;
while ((next = hbaseClient.ScannerGetNext(scannerInfo)) != null)
{
res.AddRange(from row in next.rows
let key = Encoding.UTF8.GetString(row.key)
let value = Encoding.UTF8.GetString(row.values[0].data)
let parts = key.Split(',')
where parts.Length == 3
select new HBaseEntry()
{
Type = parts[0], Date = parts[1].Replace("0000000", "000"), RoomNumber = parts[2], Reading = value
});
}
var dateRangedList =
res.Where(a => DateTime.Parse(a.Date) >= DateTime.UtcNow.AddDays(-5)).Select(a => a).ToList();
var map = new Dictionary<String, Dictionary<String, Dictionary<String, String>>> ();
var tempList = dateRangedList.Where(a => a.Type == "Temperature").ToList();
var engyList = dateRangedList.Where(a => a.Type == "Energy").ToList();
var humList = dateRangedList.Where(a => a.Type == "Humidity").ToList();
var lghtList = dateRangedList.Where(a => a.Type == "Light").ToList();
map.Add("Temperature", GetDataAsMap(tempList));
map.Add("Energy", GetDataAsMap(engyList));
map.Add("Humidity", GetDataAsMap(humList));
map.Add("Light", GetDataAsMap(lghtList));
//get data
var ctx = GlobalHost.ConnectionManager.GetHubContext<DashHub>();
ctx.Clients.All.acceptData(JsonConvert.SerializeObject(map));
Thread.Sleep(15000);
}
});
Background.Wait();
return true;
}
示例5: GetSessionsByTime
/// <summary>
/// Retrieve sessions within the given time range
/// </summary>
/// <param name="hbaseClient">The hbase client</param>
/// <param name="eventType">The type of event to look for</param>
/// <param name="start">Lower bound of the time range</param>
/// <param name="end">Upper bound of the time range</param>
static void GetSessionsByTime(HBaseClient hbaseClient, string eventType, DateTime start, DateTime end)
{
//Create filters list
FilterList filters = new FilterList(FilterList.Operator.MustPassAll);
//Filter to search for the event type value
SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(
Encoding.UTF8.GetBytes("cf"),
Encoding.UTF8.GetBytes("event"),
CompareFilter.CompareOp.Equal,
Encoding.UTF8.GetBytes(eventType));
filters.AddFilter(valueFilter);
//Create scanner, set maxVersions so we can get previous versions of rows
//Since START events may not be the currently returned value
var scannerSettings = new Scanner()
{
filter = filters.ToEncodedString(),
maxVersions = 5,
startTime = ToUnixTime(start),
endTime = ToUnixTime(end)
};
var scanner = hbaseClient.CreateScanner(Properties.Settings.Default.HBaseTableName, scannerSettings);
//Read data from scanner
CellSet readSet = null;
//While reading cell sets
while ((readSet = hbaseClient.ScannerGetNext(scanner)) != null)
{
//Iterate over the rows returned
foreach (var row in readSet.rows)
{
//Get the time stored for the START event
var endTime = row.values.Where(v => Encoding.UTF8.GetString(v.column) == "cf:time")
.Select(v => BitConverter.ToInt64(v.data, 0)).ToArray()[0];
//Get the hbase timestamp of the row
var timestamp = row.values.Select(v => v.timestamp).ToArray()[0];
//If it's an end event type
if (eventType == "END")
{
//Get the duration stored between END and START events
var duration = new TimeSpan(
row.values.Where(v => Encoding.UTF8.GetString(v.column) == "cf:duration")
.Select(v => BitConverter.ToInt64(v.data, 0)).ToArray()[0]);
//Write out the session info, including duration
Console.WriteLine("Session {0} lasted {1} minutes, and ended at {2}",
Encoding.UTF8.GetString(row.key),
duration.Minutes,
FromUnixTime(endTime));
}
else
{
//If start event type, just write out when it started and the hbase timestamp for the row
Console.WriteLine("Session {0} started at {1}. Timestamp = {2}",
Encoding.UTF8.GetString(row.key),
FromUnixTime(endTime),
timestamp);
}
}
}
}
示例6: RetrieveResults
private IEnumerable<FilterTestRecord> RetrieveResults(ScannerInformation scanInfo)
{
var rv = new List<FilterTestRecord>();
var client = new HBaseClient(_credentials);
CellSet next;
while ((next = client.ScannerGetNext(scanInfo)) != null)
{
foreach (CellSet.Row row in next.rows)
{
string rowKey = _encoding.GetString(row.key);
List<Cell> cells = row.values;
string a = null;
string b = null;
int lineNumber = 0;
foreach (Cell c in cells)
{
string columnName = ExtractColumnName(c.column);
switch (columnName)
{
case LineNumberColumnName:
lineNumber = c.data.Length > 0 ? BitConverter.ToInt32(c.data, 0) : 0;
break;
case ColumnNameA:
a = _encoding.GetString(c.data);
break;
case ColumnNameB:
b = _encoding.GetString(c.data);
break;
default:
throw new InvalidOperationException("Don't know what to do with column: " + columnName);
}
}
var rec = new FilterTestRecord(rowKey, lineNumber, a, b);
rv.Add(rec);
}
}
return rv;
}
示例7: RetrieveTimestamps
private IEnumerable<long> RetrieveTimestamps(ScannerInformation scanInfo)
{
var rv = new HashSet<long>();
var client = new HBaseClient(_credentials);
CellSet next;
while ((next = client.ScannerGetNext(scanInfo)) != null)
{
foreach (CellSet.Row row in next.rows)
{
List<Cell> cells = row.values;
foreach (Cell c in cells)
{
rv.Add(c.timestamp);
}
}
}
return rv;
}