/// <summary> /// 通过多个参数构造一个新的<see cref="GetRangeRequest"/> /// </summary> /// <param name="tableName">表名称</param> /// <param name="direction">前向还是后向</param> /// <param name="inclusiveStartPrimaryKey">区间开始位置,包含</param> /// <param name="exclusiveEndPrimaryKey">区间结束位置,不包含</param> /// <param name="columnsToGet">返回的列名称的列表</param> /// <param name="limit">最大返回数</param> public GetRangeRequest(string tableName, GetRangeDirection direction, PrimaryKey inclusiveStartPrimaryKey, PrimaryKey exclusiveEndPrimaryKey, HashSet <string> columnsToGet = null, int?limit = null, IColumnCondition condition = null) { QueryCriteria = new RangeRowQueryCriteria(tableName) { Direction = direction, Limit = limit, InclusiveStartPrimaryKey = inclusiveStartPrimaryKey, ExclusiveEndPrimaryKey = exclusiveEndPrimaryKey }; if (columnsToGet != null) { QueryCriteria.SetColumnsToGet(columnsToGet); } if (condition != null) { QueryCriteria.Filter = condition.ToFilter(); } }
public static void GetRangeWithFilter() { Console.WriteLine("Start get range with filter ..."); PrepareTable(); PrepareData(); OTSClient otsClient = Config.GetClient(); // 读取 (0, INF_MIN)到(100, INF_MAX)这个范围内的所有行,且col2等于false的行 PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey { { "pk0", new ColumnValue(0) }, { "pk1", ColumnValue.INF_MIN } }; PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey { { "pk0", new ColumnValue(100) }, { "pk1", ColumnValue.INF_MAX } }; // 构造列过滤条件 var condition = new RelationalCondition("col2", CompareOperator.EQUAL, new ColumnValue(false)); var queryCriteria = new RangeRowQueryCriteria(TableName) { Direction = GetRangeDirection.Forward, InclusiveStartPrimaryKey = inclusiveStartPrimaryKey, ExclusiveEndPrimaryKey = exclusiveEndPrimaryKey, Filter = condition.ToFilter() }; GetRangeResponse response = otsClient.GetRange(new GetRangeRequest(queryCriteria)); IList <Row> rows = response.RowDataList; PrimaryKey nextStartPrimaryKey = response.NextPrimaryKey; while (nextStartPrimaryKey != null) { queryCriteria = new RangeRowQueryCriteria(TableName) { Direction = GetRangeDirection.Forward, InclusiveStartPrimaryKey = nextStartPrimaryKey, ExclusiveEndPrimaryKey = exclusiveEndPrimaryKey, Filter = condition.ToFilter() }; response = otsClient.GetRange(new GetRangeRequest(queryCriteria)); nextStartPrimaryKey = response.NextPrimaryKey; foreach (var row in response.RowDataList) { rows.Add(row); } } foreach (var row in rows) { PrintRow(row); } Console.WriteLine("TotalRowsRead with filter: " + rows.Count); }
/// <summary> /// 通过<see cref="RangeRowQueryCriteria"/>构造一个新的<see cref="GetIteratorRequest"/> /// </summary> /// <param name="queryCriteria"></param> public GetIteratorRequest(RangeRowQueryCriteria queryCriteria, CapacityUnit consumedCapacityUnitCounter) : base(queryCriteria) { ConsumedCapacityUnitCounter = consumedCapacityUnitCounter; }
/// <summary> /// 通过<see cref="RangeRowQueryCriteria"/>构造一个新的<see cref="GetRangeRequest"/> /// </summary> /// <param name="queryCriteria"></param> public GetRangeRequest(RangeRowQueryCriteria queryCriteria) { QueryCriteria = queryCriteria; }