public void TestDuplicateDeleteInUpdateRow() { var pk = new PrimaryKey(); pk.Add("PK0", new ColumnValue("123")); pk.Add("PK1", new ColumnValue(123)); var updateOfAttribute = new UpdateOfAttribute(); updateOfAttribute.AddAttributeColumnToDelete("Col0"); updateOfAttribute.AddAttributeColumnToDelete("Col0"); var request = new UpdateRowRequest( TestTableName, new Condition(RowExistenceExpectation.IGNORE), pk, updateOfAttribute); try { var response = OTSClient.UpdateRow(request); Assert.Fail(); } catch (OTSServerException e) { AssertOTSServerException(e, new OTSServerException( "/UpdateRow", HttpStatusCode.BadRequest, "OTSParameterInvalid", "Duplicated attribute column name: 'Col0' while updating row." )); } }
/// <summary> /// 查询表中geo_type_col这一列的值距离中心点不超过一定距离的数据。 /// </summary> /// <param name="client"></param> public static void GeoDistanceQuery(OTSClient client) { Console.WriteLine("\n Start GeoDistance query..."); SearchQuery searchQuery = new SearchQuery(); GeoDistanceQuery geoDistanceQuery = new GeoDistanceQuery(); // 设置查询类型为GeoDistanceQuery geoDistanceQuery.FieldName = Geo_type_col; geoDistanceQuery.CenterPoint = "10,11"; // 设置中心点 geoDistanceQuery.DistanceInMeter = 10000; // 设置到中心点的距离条件,不超过50米 searchQuery.Query = geoDistanceQuery; SearchRequest searchRequest = new SearchRequest(TableName, IndexName, searchQuery); ColumnsToGet columnsToGet = new ColumnsToGet(); columnsToGet.Columns = new List <string>() { Geo_type_col }; //设置返回Col_GeoPoint这一列 searchRequest.ColumnsToGet = columnsToGet; SearchResponse response = client.Search(searchRequest); Console.WriteLine(response.TotalCount); foreach (var row in response.Rows) { PrintRow(row); } }
/// <summary> /// 创建一个多元索引,包含Keyword_type_col、Long_type_col、Text_type_col三个属性列,类型分别设置为不分词字符串(KEYWORD),整型(LONG),分词字符串(TEXT) /// </summary> /// <param name="otsClient"></param> public static void CreateSearchIndex(OTSClient otsClient) { Console.WriteLine("\n Start Create searchindex..."); //指定表名和索引名 CreateSearchIndexRequest request = new CreateSearchIndexRequest(TableName, IndexName); List <FieldSchema> FieldSchemas = new List <FieldSchema>() { new FieldSchema(Keyword_type_col, FieldType.KEYWORD) //设置字段名和字段类型 { index = true, //开启索引 EnableSortAndAgg = true //开启排序和统计功能 }, new FieldSchema(Long_type_col, FieldType.LONG) { index = true, EnableSortAndAgg = true }, new FieldSchema(Text_type_col, FieldType.TEXT) { index = true } }; request.IndexSchame = new IndexSchema() { FieldSchemas = FieldSchemas }; CreateSearchIndexResponse response = otsClient.CreateSearchIndex(request); Console.WriteLine("Searchindex is created: " + IndexName); }
public static void PutRow(string pk1Value) { Console.WriteLine("Start put row..."); OTSClient otsClient = Config.GetClient(); // 定义行的主键,必须与创建表时的TableMeta中定义的一致 PrimaryKey primaryKey = new PrimaryKey { { Pk1, new ColumnValue(pk1Value) }, { Pk2, ColumnValue.AUTO_INCREMENT } }; // 定义要写入该行的属性列 AttributeColumns attribute = new AttributeColumns { { "Col1", new ColumnValue(0) } }; PutRowRequest request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute); request.RowPutChange.ReturnType = ReturnType.RT_PK; var response = otsClient.PutRow(request); Console.WriteLine("Put row succeed,autoIncrement Pk value:" + response.Row.GetPrimaryKey()[Pk2].IntegerValue); }
static void Main(string[] args) { OTSClient otsClient = Config.GetClient(); //DeleteSearchIndex(otsClient); //DeleteTable(otsClient); //CreateTable(otsClient); //CreateSearchIndex(otsClient); ////Wait searchIndex load success //Console.WriteLine("wait searchIndex load success"); //Thread.Sleep(3 * 1000); //ListSearchIndex(otsClient); //DescribeSearchIndex(otsClient); //PutRow(otsClient); //Wait searchIndex load success WaiteAllDataSyncSuccess(otsClient, 10); //GeoBoundingBoxQuery GeoBoundingBoxQuery(otsClient); //GeoDistanceQuery GeoDistanceQuery(otsClient); //GeoPolygonQuery GeoPolygonQuery(otsClient); Console.ReadLine(); }
/// <summary> /// 类似MatchQuery(MatchQuery 仅匹配某个词即可),但是 MatchPhraseQuery会匹配所有的短语。 /// </summary> /// <param name="otsClient"></param> public static void MatchPhraseQuery(OTSClient otsClient) { Console.WriteLine("\n Start MatchPhrase query..."); var searchQuery = new SearchQuery(); searchQuery.Query = new MatchPhraseQuery(Text_type_col, "TableStore SearchIndex"); searchQuery.GetTotalCount = true; var request = new SearchRequest(TableName, IndexName, searchQuery); request.ColumnsToGet = new ColumnsToGet() { Columns = new List <string>() { Long_type_col, Text_type_col, Keyword_type_col } }; var response = otsClient.Search(request); Console.WriteLine("Total Count:" + response.TotalCount); foreach (var row in response.Rows) { PrintRow(row); } }
/// <summary> ///联合查询(复杂查询条件下用的最多的一个查询)。Bool查询由一个或者多个子句组成,每个子句都有特定的类型。 ///must: 文档必须完全匹配条件 ///should: should下面会带一个以上的条件,至少满足一个条件,这个文档就符合should ///must_not: 文档必须不匹配条件 ///MinimumShouldMatch: should查询的条件至少满足几个 /// </summary> /// <param name="otsClient"></param> public static void BoolQuery(OTSClient otsClient) { Console.WriteLine("\n Start bool query..."); var searchQuery = new SearchQuery(); searchQuery.GetTotalCount = true; var boolQuery = new BoolQuery(); var shouldQuerys = new List <IQuery>(); shouldQuerys.Add(new TermQuery(Keyword_type_col, new ColumnValue("SearchIndex"))); shouldQuerys.Add(new TermQuery(Keyword_type_col, new ColumnValue("TableStore"))); boolQuery.ShouldQueries = shouldQuerys; boolQuery.MinimumShouldMatch = 1; searchQuery.Query = boolQuery; var request = new SearchRequest(TableName, IndexName, searchQuery); request.ColumnsToGet = new ColumnsToGet() { ReturnAll = true }; var response = otsClient.Search(request); Console.WriteLine("Total Count:" + response.TotalCount); foreach (var row in response.Rows) { PrintRow(row); } }
public void CreateMultiAutoIncrementColumnTableTest_ShouldFailed() { var schema = new PrimaryKeySchema { { "PK0", ColumnValueType.String }, { "PK1", ColumnValueType.Integer, PrimaryKeyOption.AUTO_INCREMENT }, { "PK2", ColumnValueType.Integer, PrimaryKeyOption.AUTO_INCREMENT } }; var tableMeta = new TableMeta(TestTableName, schema); var tableOptions = new TableOptions { MaxVersions = 10, TimeToLive = -1 }; var reservedThroughput = new CapacityUnit(0, 0); var request = new CreateTableRequest(tableMeta, reservedThroughput) { TableOptions = tableOptions }; try{ OTSClient.CreateTable(request); WaitForTableReady(); }catch (Exception e) { Assert.IsTrue(e.Message.Contains("AUTO_INCREMENT primary key count must <= 1")); } }
private static void PrepareTable() { // 创建表 OTSClient otsClient = Config.GetClient(); IList <string> tables = otsClient.ListTable(new ListTableRequest()).TableNames; if (tables.Contains(TableName)) { return; } PrimaryKeySchema primaryKeySchema = new PrimaryKeySchema { { "pk0", ColumnValueType.Integer }, { "pk1", ColumnValueType.String } }; TableMeta tableMeta = new TableMeta(TableName, primaryKeySchema); CapacityUnit reservedThroughput = new CapacityUnit(0, 0); CreateTableRequest request = new CreateTableRequest(tableMeta, reservedThroughput); otsClient.CreateTable(request); }
public void TestForNormal() { var result = PutRows(); var primaryKeys = result.Item1; var columns = result.Item2; var batchGetRequest = new BatchGetRowRequest(); batchGetRequest.Add(TestTableName, primaryKeys); var response = OTSClient.BatchGetRow(batchGetRequest); var tables = response.RowDataGroupByTable; Assert.AreEqual(1, tables.Count); var rows = tables[TestTableName]; Assert.AreEqual(batchCount, rows.Count); for (int i = 0; i < batchCount; i++) { AssertPrimaryKey(primaryKeys[i], rows[i].Row.GetPrimaryKey()); AssertAttribute(columns[i], (rows[i].Row as Row).GetColumns()); } DeleteTable(TestTableName); }
public void GetRangeTest() { CreateTable(); var otsClient = OTSClient; // 指定范围读取数据 var startPrimaryKey = new PrimaryKey(); startPrimaryKey.Add("PK0", new ColumnValue("TestData")); startPrimaryKey.Add("PK1", ColumnValue.INF_MIN); var endPrimaryKey = new PrimaryKey(); endPrimaryKey.Add("PK0", new ColumnValue("TestData")); endPrimaryKey.Add("PK1", ColumnValue.INF_MAX); var consumed = new CapacityUnit(0, 0); var request = new GetIteratorRequest("SampleTable", GetRangeDirection.Forward, startPrimaryKey, endPrimaryKey, consumed); var iterator = OTSClient.GetRangeIterator(request); foreach (var rowData in iterator) { // 处理每一行数据 } DeleteTable(); }
public static void GetRow() { Console.WriteLine("Start get row..."); // PrepareTable(); OTSClient otsClient = Config.GetClient(); // 定义行的主键,必须与创建表时的TableMeta中定义的一致 PrimaryKey primaryKey = new PrimaryKey(); primaryKey.Add("key", new ColumnValue("the key")); Stopwatch stopwatch = Stopwatch.StartNew(); GetRowRequest request = new GetRowRequest("tableName", primaryKey); // 未指定读哪列,默认读整行 GetRowResponse response = otsClient.GetRow(request); stopwatch.Stop(); PrimaryKey primaryKeyRead = response.PrimaryKey; AttributeColumns attributesRead = response.Attribute; Console.WriteLine("Primary key read: "); foreach (KeyValuePair <string, ColumnValue> entry in primaryKeyRead) { Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value)); } Console.WriteLine("Attributes read: "); foreach (KeyValuePair <string, ColumnValue> entry in attributesRead) { Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value)); } Console.WriteLine("Get row succeed."); Console.WriteLine(stopwatch.Elapsed); }
public bool UpdateRow(String tableName, Int64 pk, String colName, ColumnValue colValue, ColumnCondition cond) { bool success = true; var primaryKey = new PrimaryKey(); primaryKey.Add("PK0", new ColumnValue(pk)); Condition rowCond = new Condition(RowExistenceExpectation.IGNORE); rowCond.ColumnCondition = cond; UpdateOfAttribute updateOfAttributeForPut = new UpdateOfAttribute(); updateOfAttributeForPut.AddAttributeColumnToPut(colName, colValue); var request = new UpdateRowRequest(tableName, rowCond, primaryKey, updateOfAttributeForPut); try { OTSClient.UpdateRow(request); } catch (OTSServerException e) { Console.WriteLine("UpdateRow fail: {0}", e.ErrorMessage); success = false; } return(success); }
private bool PutRow(string tableName, Int64 pk, string colName, ColumnValue colValue, ColumnCondition cc) { var primaryKey = new PrimaryKey(); primaryKey.Add("PK0", new ColumnValue(pk)); var attribute = new AttributeColumns(); attribute.Add(colName, colValue); Condition cond = new Condition(RowExistenceExpectation.IGNORE); cond.ColumnCondition = cc; var request = new PutRowRequest(tableName, cond, primaryKey, attribute); bool success = true; try { OTSClient.PutRow(request); } catch (OTSServerException e) { Console.WriteLine("PutRow fail: {0}", e.ErrorMessage); success = false; } return(success); }
public void TestInvalidPBInError() { OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest); OTSClientTestHelper.SetHTTPResponseBody(new byte[] {}); var request = new ListTableRequest(); try { var response = OTSClient.ListTable(request); Assert.Fail(); } catch (OTSServerException e) { AssertOTSServerException(new OTSServerException("/ListTable", HttpStatusCode.BadRequest), e); } var body = new byte[20]; OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest); OTSClientTestHelper.SetHTTPResponseBody(body); var headers = MakeResponseHeaders("/ListTable", body); OTSClientTestHelper.SetHttpRequestHeaders(headers); request = new ListTableRequest(); try { var response = OTSClient.ListTable(request); Assert.Fail(); } catch (OTSServerException e) { AssertOTSServerException(new OTSServerException("/ListTable", HttpStatusCode.BadRequest), e); } }
public static void PutRow() { Console.WriteLine("Start put row..."); PrepareTable(); OTSClient otsClient = Config.GetClient(); // 定义行的主键,必须与创建表时的TableMeta中定义的一致 PrimaryKey primaryKey = new PrimaryKey { { "pk0", new ColumnValue(0) }, { "pk1", new ColumnValue("abc") } }; // 定义要写入该行的属性列 AttributeColumns attribute = new AttributeColumns { { "col0", new ColumnValue(0) }, { "col1", new ColumnValue("a") }, { "col2", new ColumnValue(true) } }; PutRowRequest request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute); otsClient.PutRow(request); Console.WriteLine("Put row succeed."); }
/// <summary> /// 等待数据同步到索引表完成 /// </summary> /// <param name="otsClient"></param> /// <param name="expectTotalCount"></param> public static void WaiteAllDataSyncSuccess(OTSClient otsClient, int expectTotalCount) { Console.WriteLine("wait all rows sync success"); int timeoutSeconds = 3 * 60; var beginTime = DateTime.Now; while (true) { var searchQuery = new SearchQuery(); searchQuery.GetTotalCount = true; searchQuery.Query = new MatchAllQuery(); var request = new SearchRequest(TableName, IndexName, searchQuery); var response = otsClient.Search(request); if (response.TotalCount == expectTotalCount) { break; } else if ((DateTime.Now - beginTime).Seconds > timeoutSeconds) { throw new Exception("searchIndex sync data timeout"); } Thread.Sleep(1000); } }
private void TestRetryWithException(OTSServerException[] exceptions) { foreach (var e in exceptions) { OTSClientTestHelper.RetryExceptions.Add(e); } var lastException = exceptions[exceptions.Count() - 1]; var request = new ListTableRequest(); try { OTSClient.ListTable(request); Assert.Fail(); } catch (OTSServerException e) { AssertOTSServerException(lastException, e); } Assert.AreEqual(3, OTSClientTestHelper.RetryTimes); for (int i = 0; i < OTSClientTestHelper.RetryTimes; i++) { AssertOTSServerException(exceptions[i], OTSClientTestHelper.RetryExceptions[i]); } }
/// <summary> /// 精确的terms查询,查询Keyword_type_col这一列精确匹配"TableStore"或者"SearchIndex"的数据 /// TermsQuery可以使用多个Term同时查询 /// </summary> /// <param name="otsClient"></param> public static void TermsQuery(OTSClient otsClient) { Console.WriteLine("\n Start terms query..."); var searchQuery = new SearchQuery(); searchQuery.GetTotalCount = true; var query = new TermsQuery(); query.FieldName = Keyword_type_col; query.Terms = new List <ColumnValue>() { new ColumnValue("TableStore"), new ColumnValue("SearchIndex") }; var request = new SearchRequest(TableName, IndexName, searchQuery); request.ColumnsToGet = new ColumnsToGet() { ReturnAll = true }; var response = otsClient.Search(request); Console.WriteLine("Total Count:" + response.TotalCount); foreach (var row in response.Rows) { PrintRow(row); } }
public void TestEmptyUpdateRow() { var primaryKey = new PrimaryKey { { "PK0", new ColumnValue(0) } }; var updateOfAttribute = new UpdateOfAttribute(); var request = new UpdateRowRequest(TestTableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, updateOfAttribute); try { OTSClient.UpdateRow(request); Assert.Fail(); } catch (OTSServerException e) { AssertOTSServerException(e, new OTSServerException( "/UpdateRow", HttpStatusCode.BadRequest, "OTSParameterInvalid", "Attribute column is missing." )); } }
/// <summary> /// 有一个类型为NESTED的列,子文档包含nested_1和nested_2两列,现在查询col1_nested.nested_1为"tablestore"的数据 /// </summary> /// <param name="otsClient"></param> public static void NestedQuery(OTSClient otsClient) { Console.WriteLine("\n Start bool query..."); var searchQuery = new SearchQuery(); searchQuery.GetTotalCount = true; var nestedQuery = new NestedQuery(); nestedQuery.Path = "col1_nested"; //设置nested字段路径 TermQuery termQuery = new TermQuery("col1_nested.nested_1", new ColumnValue("tablestore")); //构造NestedQuery的子查询 nestedQuery.Query = termQuery; nestedQuery.ScoreMode = ScoreMode.None; var request = new SearchRequest(TableName, IndexName, searchQuery); request.ColumnsToGet = new ColumnsToGet() { ReturnAll = true }; var response = otsClient.Search(request); Console.WriteLine("Total Count:" + response.TotalCount); foreach (var row in response.Rows) { PrintRow(row); } }
public void Test1000PutAnd1000DeleteInUpdateRow() { var pk = new PrimaryKey { { "PK0", new ColumnValue("123") }, { "PK1", new ColumnValue(123) } }; var updateOfAttribute = new UpdateOfAttribute(); for (int i = 0; i < 1000; i++) { updateOfAttribute.AddAttributeColumnToPut("Put" + i, new ColumnValue("blah")); updateOfAttribute.AddAttributeColumnToDelete("Delete" + i); } var request = new UpdateRowRequest( TestTableName, new Condition(RowExistenceExpectation.IGNORE), pk, updateOfAttribute); try { var response = OTSClient.UpdateRow(request); } catch (OTSServerException e) { AssertOTSServerException(e, new OTSServerException( "/UpdateRow", HttpStatusCode.BadRequest, "OTSParameterInvalid", "The number of attribute columns exceeds the limit, limit count: 1024, column count: 2000." )); } }
public static void PutRow(OTSClient otsClient) { Console.WriteLine("\n Start put row..."); List <string> colList = new List <string>() { "0,0", "7,3", "2,8", "5,9", "10,10", "20,20", "14,18", "12,16", "15,4", "8,13" }; for (int i = 0; i < 10; i++) { PrimaryKey primaryKey = new PrimaryKey { { Pk0, new ColumnValue(i) }, { Pk1, new ColumnValue("pk1value") } }; AttributeColumns attribute = new AttributeColumns { { Geo_type_col, new ColumnValue(colList[i]) } }; PutRowRequest request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute); otsClient.PutRow(request); } Console.WriteLine("Put row succeed."); }
public void TestGetRowWith1000ColumnsToGet() { CreateTestTableWith4PK(new CapacityUnit(0, 0)); var columnsToGet = new HashSet <string>(); for (int i = 0; i < 1025; i++) { columnsToGet.Add("Col" + i); } var request = new GetRowRequest(TestTableName, PrimaryKeyWith4Columns, columnsToGet); try { OTSClient.GetRow(request); Assert.Fail(); } catch (OTSServerException exception) { AssertOTSServerException(new OTSServerException( "/GetRow", HttpStatusCode.BadRequest, "OTSParameterInvalid", "The number of columns from the request exceeds the limit, limit count: 1024, column count: 1025." ), exception); } }
/// <summary> /// geo_type_col是GeoPoint类型,查询表中geo_type_col这一列的值在左上角为"10,0", 右下角为"0,10"的矩形范围内的数据 /// </summary> /// <param name="client"></param> public static void GeoBoundingBoxQuery(OTSClient client) { Console.WriteLine("\n Start GeoBoundingBox query..."); SearchQuery searchQuery = new SearchQuery(); GeoBoundingBoxQuery geoBoundingBoxQuery = new GeoBoundingBoxQuery(); // 设置查询类型为GeoBoundingBoxQuery geoBoundingBoxQuery.FieldName = Geo_type_col; // 设置比较哪个字段的值 geoBoundingBoxQuery.TopLeft = "10,0"; // 设置矩形左上角 geoBoundingBoxQuery.BottomRight = "0,10"; // 设置矩形右下角 searchQuery.Query = geoBoundingBoxQuery; SearchRequest searchRequest = new SearchRequest(TableName, IndexName, searchQuery); var columnsToGet = new ColumnsToGet(); columnsToGet.Columns = new List <string> { Geo_type_col }; //设置返回Col_GeoPoint这一列 searchRequest.ColumnsToGet = columnsToGet; SearchResponse response = client.Search(searchRequest); Console.WriteLine(response.TotalCount); foreach (var row in response.Rows) { PrintRow(row); } }
public static void GetRow() { Console.WriteLine("Start get row..."); PrepareTable(); OTSClient otsClient = Config.GetClient(); // 定义行的主键,必须与创建表时的TableMeta中定义的一致 PrimaryKey primaryKey = new PrimaryKey { { Pk1, new ColumnValue(0) }, { Pk2, new ColumnValue("abc") } }; GetRowRequest request = new GetRowRequest(TableName, primaryKey); // 未指定读哪列,默认读整行 GetRowResponse response = otsClient.GetRow(request); PrimaryKey primaryKeyRead = response.PrimaryKey; AttributeColumns attributesRead = response.Attribute; Console.WriteLine("Primary key read: "); foreach (KeyValuePair <string, ColumnValue> entry in primaryKeyRead) { Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value)); } Console.WriteLine("Attributes read: "); foreach (KeyValuePair <string, ColumnValue> entry in attributesRead) { Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value)); } Console.WriteLine("Get row succeed."); }
/// <summary> /// 查询表中geo_type_col这一列的值在一个给定多边形范围内的数据。 /// </summary> /// <param name="client"></param> public static void GeoPolygonQuery(OTSClient client) { Console.WriteLine("\n Start GeoPolygon query..."); SearchQuery searchQuery = new SearchQuery(); GeoPolygonQuery geoPolygonQuery = new GeoPolygonQuery(); // 设置查询类型为GeoPolygonQuery geoPolygonQuery.FieldName = Geo_type_col; geoPolygonQuery.Points = new List <string>() { "0,0", "10,0", "10,10" }; // 设置多边形的顶点 searchQuery.Query = geoPolygonQuery; SearchRequest searchRequest = new SearchRequest(TableName, IndexName, searchQuery); ColumnsToGet columnsToGet = new ColumnsToGet(); columnsToGet.Columns = new List <string>() { Geo_type_col }; //设置返回Col_GeoPoint这一列 searchRequest.ColumnsToGet = columnsToGet; SearchResponse response = client.Search(searchRequest); Console.WriteLine(response.TotalCount); foreach (var row in response.Rows) { PrintRow(row); } }
/// <summary> /// 更新行的时候,指定某一列为原子自增列,并对这一列进行原子自增 /// </summary> public static void Increment(int incrementValue) { Console.WriteLine("Start set increment column..."); OTSClient otsClient = Config.GetClient(); // 定义行的主键,必须与创建表时的TableMeta中定义的一致 PrimaryKey primaryKey = new PrimaryKey { { Pk1, new ColumnValue(0) }, { Pk2, new ColumnValue("abc") } }; RowUpdateChange rowUpdateChange = new RowUpdateChange(TableName, primaryKey); rowUpdateChange.ReturnType = ReturnType.RT_AFTER_MODIFY; rowUpdateChange.ReturnColumnNames = new List <string>() { IncrementCol }; //设置一个原子自增列,这一列从0开始自增,每次增增加1。 rowUpdateChange.Increment(new Column(IncrementCol, new ColumnValue(incrementValue))); UpdateRowRequest updateRowRequest = new UpdateRowRequest(rowUpdateChange); var response = otsClient.UpdateRow(updateRowRequest); Console.WriteLine("set Increment column succeed,Increment result:" + response.Row.GetColumns()[0].Value); }
/// <summary> /// 通过PutRow 接口写入一些数据到TableStore,数据将自动同步到索引表 /// </summary> /// <param name="otsClient"></param> public static void PutRow(OTSClient otsClient) { Console.WriteLine("\n Start put row..."); List <string> colList = new List <string>() { "TableStore SearchIndex Sample", "TableStore", "SearchIndex", "Sample", "SearchIndex Sample", "TableStore Sample", "TableStore SearchIndex" }; for (int i = 0; i < 7; i++) { PrimaryKey primaryKey = new PrimaryKey { { Pk0, new ColumnValue(i) }, { Pk1, new ColumnValue("pk1value") } }; AttributeColumns attribute = new AttributeColumns { { Long_type_col, new ColumnValue(i) }, { Text_type_col, new ColumnValue(colList[i]) }, { Keyword_type_col, new ColumnValue(colList[i]) } }; PutRowRequest request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute); otsClient.PutRow(request); } Console.WriteLine("Put row succeed."); }
public void TestString() { CreateTestTable(); var primaryKey = new PrimaryKey(); primaryKey.Add("PK0", new ColumnValue("ABC")); primaryKey.Add("PK1", new ColumnValue(123)); var attribute = new AttributeColumns(); attribute.Add("Col0", new ColumnValue("abcdefghijklnm")); var request1 = new PutRowRequest( "SampleTableName", new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute ); var response1 = OTSClient.PutRow(request1); Assert.AreEqual(0, response1.ConsumedCapacityUnit.Read); Assert.AreEqual(1, response1.ConsumedCapacityUnit.Write); var request2 = new GetRowRequest( "SampleTableName", primaryKey ); var response2 = OTSClient.GetRow(request2); Assert.AreEqual(1, response2.ConsumedCapacityUnit.Read); Assert.AreEqual(0, response2.ConsumedCapacityUnit.Write); AssertColumns(primaryKey, response2.PrimaryKey); AssertColumns(attribute, response2.Attribute); }