public void SetFilter(DataSchema dataSchema, PropertyDescriptor propertyDescriptor, RowFilter rowFilter) { RowFilter = rowFilter; SetPropertyDescriptor(dataSchema, propertyDescriptor); var columnFilters = rowFilter.GetColumnFilters(propertyDescriptor).ToArray(); if (columnFilters.Length >= 1) { SetFilterOperation(comboOperation1, tbxOperand1, columnFilters[0]); tbxOperand1.Text = columnFilters[0].Predicate.GetOperandDisplayText(dataSchema, propertyDescriptor.PropertyType); } if (columnFilters.Length >= 2) { SetFilterOperation(comboOperation2, tbxOperand2, columnFilters[1]); } }
/// <summary> /// Does rows = F1( F2( rows ) ) /// </summary> public static RowFilter Compose( this RowFilter f1, RowFilter f2 ) { return a => f1( f2( a ) ); }
private static void DoHelloWorld() { try { // [START connecting_to_bigtable] // BigtableTableAdminClient API lets us create, manage and delete tables. BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create(); // BigtableClient API lets us read and write to a table. BigtableClient bigtableClient = BigtableClient.Create(); // [END connecting_to_bigtable] // [START creating_a_table] // Create a table with a single column family. Console.WriteLine($"Create new table: {tableId} with column family: {columnFamily}, Instance: {instanceId}"); // Check whether a table with given TableName already exists. if (!TableExist(bigtableTableAdminClient)) { bigtableTableAdminClient.CreateTable( new InstanceName(projectId, instanceId), tableId, new Table { Granularity = Table.Types.TimestampGranularity.Millis, ColumnFamilies = { { columnFamily, new ColumnFamily { GcRule = new GcRule { MaxNumVersions = 1 } } } } }); // Confirm that table was created successfully. Console.WriteLine(TableExist(bigtableTableAdminClient) ? $"Table {tableId} created succsessfully\n" : $"There was a problem creating a table {tableId}"); } else { Console.WriteLine($"Table: {tableId} already exist"); } // [END creating_a_table] // [START writing_rows] // Initialise Google.Cloud.Bigtable.V2.TableName object. Google.Cloud.Bigtable.Common.V2.TableName tableName = new Google.Cloud.Bigtable.Common.V2.TableName(projectId, instanceId, tableId); // Write some rows /* Each row has a unique row key. * * Note: This example uses sequential numeric IDs for simplicity, but * this can result in poor performance in a production application. * Since rows are stored in sorted order by key, sequential keys can * result in poor distribution of operations across nodes. * * For more information about how to design a Bigtable schema for the * best performance, see the documentation: * * https://cloud.google.com/bigtable/docs/schema-design */ Console.WriteLine($"Write some greetings to the table {tableId}"); // Insert 1 row using MutateRow() s_greetingIndex = 0; try { bigtableClient.MutateRow(tableName, rowKeyPrefix + s_greetingIndex, MutationBuilder()); Console.WriteLine($"\tGreeting: -- {s_greetings[s_greetingIndex],-18}-- written successfully"); } catch (Exception ex) { Console.WriteLine($"\tFailed to write Greeting: --{s_greetings[s_greetingIndex]}"); Console.WriteLine(ex.Message); throw; } // Insert multiple rows using MutateRows() // Build a MutateRowsRequest (contains table name and a collection of entries). MutateRowsRequest request = new MutateRowsRequest { TableNameAsTableName = tableName }; s_mapToOriginalGreetingIndex = new List <int>(); while (++s_greetingIndex < s_greetings.Length) { s_mapToOriginalGreetingIndex.Add(s_greetingIndex); // Build an entry for every greeting (consists of rowkey and a collection of mutations). string rowKey = rowKeyPrefix + s_greetingIndex; request.Entries.Add(Mutations.CreateEntry(rowKey, MutationBuilder())); } // Make the request to write multiple rows. MutateRowsResponse response = bigtableClient.MutateRows(request); // Check the Status code of each entry to insure that it was written successfully foreach (MutateRowsResponse.Types.Entry entry in response.Entries) { s_greetingIndex = s_mapToOriginalGreetingIndex[(int)entry.Index]; if (entry.Status.Code == 0) { Console.WriteLine($"\tGreeting: -- {s_greetings[s_greetingIndex],-18}-- written successfully"); } else { Console.WriteLine($"\tFailed to write Greeting: --{s_greetings[s_greetingIndex]}"); Console.WriteLine(entry.Status.Message); } } Mutation MutationBuilder() => Mutations.SetCell(columnFamily, columnName, s_greetings[s_greetingIndex], new BigtableVersion(DateTime.UtcNow)); //[END writing_rows] // [START creating_a_filter] RowFilter filter = RowFilters.CellsPerRowLimit(1); // [END creating_a_filter] // [START getting_a_row] // Read from the table. Console.WriteLine("Read the first row"); int rowIndex = 0; // Read a specific row. Apply filter to return latest only cell value accross entire row. Row rowRead = bigtableClient.ReadRow( tableName, rowKey: rowKeyPrefix + rowIndex, filter: filter); Console.WriteLine( $"\tRow key: {rowRead.Key.ToStringUtf8()} " + $" -- Value: {rowRead.Families[0].Columns[0].Cells[0].Value.ToStringUtf8(),-16} " + $" -- Time Stamp: {rowRead.Families[0].Columns[0].Cells[0].TimestampMicros}"); // [END getting_a_row] // [START scanning_all_rows] Console.WriteLine("Read all rows using streaming"); // stream the content of the whole table. Apply filter to return latest only cell values accross all rows. ReadRowsStream responseRead = bigtableClient.ReadRows(tableName, filter: filter); Task printRead = PrintReadRowsAsync(); printRead.Wait(); async Task PrintReadRowsAsync() { await responseRead.ForEachAsync(row => { Console.WriteLine($"\tRow key: {row.Key.ToStringUtf8()} " + $" -- Value: {row.Families[0].Columns[0].Cells[0].Value.ToStringUtf8(),-16} " + $" -- Time Stamp: {row.Families[0].Columns[0].Cells[0].TimestampMicros}"); }); } // [END scanning_all_rows] // [START deleting_a_table] // Clean up. Delete the table. Console.WriteLine($"Delete table: {tableId}"); bigtableTableAdminClient.DeleteTable(name: tableName); if (!TableExist(bigtableTableAdminClient)) { Console.WriteLine($"Table: {tableId} deleted succsessfully"); } // [END deleting_a_table] } catch (Exception ex) { Console.WriteLine($"Exception while running HelloWorld {ex.Message}"); } }
private void btnClearAllFilters_Click(object sender, EventArgs e) { RowFilter = RowFilter.Empty; DialogResult = DialogResult.OK; }
public async Task <bool> WriteWhenAsync(BigTable table, byte[] key, RowFilter filter, IEnumerable <Mutation> whenFilterIsTrue, IEnumerable <Mutation> whenFilterIsFalse, CancellationToken cancellationToken = default(CancellationToken)) { return(await WriteWhenAsync(table.Name, key, filter, whenFilterIsTrue, whenFilterIsFalse, cancellationToken)); }
/// <summary> /// Returns the contents of the requested row, optionally applying the specified Reader filter. /// </summary> /// <remarks> /// <para> /// This method simply delegates to <see cref="ReadRowAsync(TableName, BigtableByteString, RowFilter, CallSettings)"/>. /// </para> /// </remarks> /// <param name="tableName"> /// The unique name of the table from which to read. Must not be null. /// </param> /// <param name="rowKey"> /// The key of the row to read. Must not be empty. /// </param> /// <param name="filter"> /// The filter to apply to the contents of the specified row. If null, /// reads the entirety of the row. /// </param> /// <param name="callSettings"> /// If not null, applies overrides to this RPC call. /// </param> /// <returns> /// The row from the server or null if it does not exist. /// </returns> public virtual Row ReadRow( TableName tableName, BigtableByteString rowKey, RowFilter filter = null, CallSettings callSettings = null) => Task.Run(() => ReadRowAsync(tableName, rowKey, filter, callSettings)).ResultWithUnwrappedExceptions();
public async Task <IEnumerable <BigRow> > GetUnsortedRowsAsync(string tableName, RowFilter filter, Encoding encoding = null, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken = cancellationToken == default(CancellationToken) ? CancellationToken.None : cancellationToken; encoding = encoding ?? BigModel.DefaultEncoding; var request = new ReadRowsRequest { TableName = tableName.ToTableId(ClusterId), AllowRowInterleaving = true, Filter = filter, }; return(await ConvertRows(tableName, encoding, request, cancellationToken)); }
public async Task <IEnumerable <BigRow> > GetUnsortedRowsAsync(BigTable table, RowFilter filter, CancellationToken cancellationToken = default(CancellationToken)) { return(await GetUnsortedRowsAsync(table.Name, filter, table.Encoding, cancellationToken)); }
public async Task <IEnumerable <BigRow> > GetRowsAsync(BigTable table, RowFilter filter, long rowLimit = 0, CancellationToken cancellationToken = default(CancellationToken)) { return(await GetRowsAsync(table.Name, filter, rowLimit, table.Encoding, cancellationToken)); }
// [END bigtable_filters_composing_condition] // [START bigtable_filters_print] public string readFilter(string projectId, string instanceId, string tableId, RowFilter filter) { BigtableClient bigtableClient = BigtableClient.Create(); TableName tableName = new TableName(projectId, instanceId, tableId); ReadRowsStream readRowsStream = bigtableClient.ReadRows(tableName, filter: filter); string result = ""; readRowsStream.ForEach(row => result += printRow(row)); if (result == "") { return("empty"); } return(result); }
/// <summary> /// Executes incoming tuples /// </summary> /// <param name="tuple">The first field is treated as rowkey and rest as column names</param> public void Execute(SCPTuple tuple) { //get the tuple info string sessionId = tuple.GetString(0); string sessionEvent = tuple.GetString(1); long sessionEventTime = tuple.GetLong(2); //If it's a start event, assume there's nothing to find so just re-emit //NOTE: If messages may arrive out of order, you would need to add logic to //query HBase to see if the end event has previously arrived, //calculate the duration, etc. if (sessionEvent == "START") { //Just re-emit the incoming data, plus 0 for duration, since we declare we send a 0 duration //since we don't know the END event yet. Values emitValues = new Values(tuple.GetValue(0), tuple.GetValue(1), tuple.GetValue(2), 0L); //Is ack enabled? if (enableAck) { //Emit the values, anchored to the incoming tuple this.context.Emit(Constants.DEFAULT_STREAM_ID, new List <SCPTuple>() { tuple }, emitValues); //Ack the incoming tuple this.context.Ack(tuple); } else { //No ack enabled? Fire and forget. this.context.Emit(Constants.DEFAULT_STREAM_ID, emitValues); } } if (sessionEvent == "END") { //Use filters FilterList filters = new FilterList(FilterList.Operator.MustPassAll); //Filter on the row by sessionID RowFilter rowFilter = new RowFilter(CompareFilter.CompareOp.Equal, new BinaryComparator(TypeHelper.ToBytes(sessionId))); filters.AddFilter(rowFilter); //Filter on the event column for the START event SingleColumnValueFilter valueFilter = new SingleColumnValueFilter( Encoding.UTF8.GetBytes("cf"), Encoding.UTF8.GetBytes("event"), CompareFilter.CompareOp.Equal, Encoding.UTF8.GetBytes("START")); filters.AddFilter(valueFilter); //Create scanner settings using the filters var scannerSettings = new Scanner() { filter = filters.ToEncodedString() }; //Get the scanner var scanner = HBaseClusterClient.CreateScanner(HBaseTableName, scannerSettings); CellSet readSet = null; while ((readSet = HBaseClusterClient.ScannerGetNext(scanner)) != null) { //In theory we should only find one row foreach (var row in readSet.rows) { //Pull back just the event column var rowState = row.values.Where(v => Encoding.UTF8.GetString(v.column) == "cf:event") .Select(v => Encoding.UTF8.GetString(v.data)).ToArray()[0]; //Is it a START event as expected? if (rowState == "START") { //Get the start time var startTime = TypeHelper.FromUnixTime( row.values.Where(v => Encoding.UTF8.GetString(v.column) == "cf:time") .Select(v => BitConverter.ToInt64(v.data, 0)).ToArray()[0]); //Get the difference between start and end DateTime endTime = TypeHelper.FromUnixTime(sessionEventTime); TimeSpan duration = endTime.Subtract(startTime); //Emit the tuple, with the duration between start/end. Values emitValues = new Values(sessionId, sessionEvent, sessionEventTime, duration.Ticks); //If ack is enabled if (enableAck) { //Emit the values, anchored to the incoming tuple this.context.Emit(Constants.DEFAULT_STREAM_ID, new List <SCPTuple>() { tuple }, emitValues); //Ack the incoming tuple this.context.Ack(tuple); } else { //No ack enabled? Fire and forget. this.context.Emit(Constants.DEFAULT_STREAM_ID, emitValues); } } else { //Since this is a simple example, do nothing. //In a real solution, you'd have to figure out what to do //when receiving an END before a START. } } } } }