Esempio n. 1
0
        public void TestGetRowWithFilterAndLogicOrAllNotHit()
        {
            CreateTestTableWith4PK();

            var pk = new PrimaryKey();

            pk.Add("PK0", new ColumnValue("a"));
            pk.Add("PK1", new ColumnValue("a"));
            pk.Add("PK2", new ColumnValue(10));
            pk.Add("PK3", new ColumnValue(20));

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(10));
            attribute.Add("Col1", new ColumnValue(2));
            attribute.Add("Col2", new ColumnValue(3));

            PutSingleRow(TestTableName, pk, attribute);

            var columnsToGet = new HashSet <string>();
            var filter1      = new RelationalCondition("Col0", RelationalCondition.CompareOperator.LESS_EQUAL, new ColumnValue(5));
            var filter2      = new RelationalCondition("Col1", RelationalCondition.CompareOperator.NOT_EQUAL, new ColumnValue(2));
            var filter       = new CompositeCondition(CompositeCondition.LogicOperator.OR);

            filter.AddCondition(filter1);
            filter.AddCondition(filter2);

            CheckSingleRow(TestTableName, pk, attribute, new CapacityUnit(1, 0), columnsToGet, isEmpty: true, condition: filter);
        }
Esempio n. 2
0
        public void TestGetRowWithFilterOneRowAndReturnCol1()
        {
            CreateTestTableWith4PK();

            var pk = new PrimaryKey();

            pk.Add("PK0", new ColumnValue("a"));
            pk.Add("PK1", new ColumnValue("aff"));
            pk.Add("PK2", new ColumnValue(10));
            pk.Add("PK3", new ColumnValue(20));

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(10));
            attribute.Add("Col1", new ColumnValue(2));
            attribute.Add("Col2", new ColumnValue(3));

            PutSingleRow(TestTableName, pk, attribute);

            var columnsToGet = new HashSet <string>();

            columnsToGet.Add("Col0");
            columnsToGet.Add("Col1");
            var filter = new RelationalCondition("Col0", RelationalCondition.CompareOperator.LESS_THAN, new ColumnValue(5));

            CheckSingleRow(TestTableName, pk, attribute, new CapacityUnit(1, 0), columnsToGet, isEmpty: true, condition: filter);
        }
Esempio n. 3
0
        public void PutRowTest()
        {
            CreateTable();
            var otsClient  = OTSClient;
            var primaryKey = new PrimaryKey();

            primaryKey.Add("PK0", new ColumnValue("ABC"));
            primaryKey.Add("PK1", new ColumnValue(123));

            var attribute = new AttributeColumns();

            attribute.Add("IntAttr0", new ColumnValue(12345));
            attribute.Add("StringAttr1", new ColumnValue("ABC"));
            attribute.Add("DoubleAttr2", new ColumnValue(3.14));
            attribute.Add("BooleanAttr3", new ColumnValue(true));

            var putRowRequest = new PutRowRequest(
                "SampleTable",
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                attribute
                );

            var putRowResponse = otsClient.PutRow(putRowRequest);

            System.Console.WriteLine("PutRow CU Consumed: Read {0} Write {0}",
                                     putRowResponse.ConsumedCapacityUnit.Read,
                                     putRowResponse.ConsumedCapacityUnit.Write);
            DeleteTable();
        }
        private void PutRow(OTSClient client, String tableName)
        {
            var primaryKey = new PrimaryKey();

            primaryKey.Add(COLUMN_GID_NAME, new ColumnValue(1));
            primaryKey.Add(COLUMN_UID_NAME, new ColumnValue(101));

            var attribute = new AttributeColumns();

            attribute.Add(COLUMN_NAME_NAME, new ColumnValue("张三"));
            attribute.Add(COLUMN_MOBILE_NAME, new ColumnValue(111111111));
            attribute.Add(COLUMN_ADDRESS_NAME, new ColumnValue("中国A地"));
            attribute.Add(COLUMN_AGE_NAME, new ColumnValue(20));

            Condition cond    = new Condition(RowExistenceExpectation.EXPECT_NOT_EXIST);
            var       request = new PutRowRequest(tableName, cond, primaryKey, attribute);

            try
            {
                client.PutRow(request);
                Console.WriteLine("PutRow success");
            }
            catch (OTSServerException e)
            {
                Console.WriteLine("PutRow fail: {0}", e.ErrorMessage);
            }
        }
Esempio n. 5
0
File: Route.cs Progetto: hyd309/BIDO
        public void TableStoreAddLocation(DataRowCollection drs)
        {
            int           batchCount = 0;
            int           i;
            List <string> list = new List <string>();//存储批量上传的主键字符串,用于判断批量上传数据中是否有重复

            try
            {
                RowChanges rowChanges = new RowChanges();
                for (i = 0; i < drs.Count; i++)
                {
                    DataRow dr = drs[i];
                    i++;
                    var primaryKey = new PrimaryKey();
                    primaryKey.Add("d", new ColumnValue(Convert.ToInt64(dr["device_code"])));
                    primaryKey.Add("s", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(dr["startTime"]))));

                    string primarykey = dr["device_code"].ToString() + ";" + dr["startTime"].ToString();
                    if (list.Contains(primarykey))
                    {
                        log.Info(i + "发现重复记录" + primarykey + "数据库记录:");
                        continue;
                    }
                    list.Add(primarykey);
                    var attribute = new AttributeColumns();
                    attribute.Add("e", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(dr["endTime"]))));
                    //行驶数据
                    attribute.Add("r", new ColumnValue(ByteIntHelper.GetRouteByte(dr["startLongitude"], dr["startLatitude"], dr["endLongitude"], dr["endLatitude"], dr["drivingTime"], dr["mileage"], dr["topSpeed"])));
                    //行驶时长统计
                    attribute.Add("ds", new ColumnValue(ByteIntHelper.GetDurationstatsByte(dr["speedingTime"], dr["highSpeedTime"], dr["mediumSpeedTime"], dr["lowSpeedTime"], dr["idleTime"])));
                    //事件次数统计
                    attribute.Add("es", new ColumnValue(ByteIntHelper.GetEventStatsByte(dr["rapidAccelerationTimes"], dr["rapidDecelerationTimes"], dr["sharpTurnTimes"])));

                    rowChanges.AddPut(new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute);
                    batchCount++;
                    if (batchCount == 200)//200行数据进行批量提交一次
                    {
                        batchRequest.Add(TableName, rowChanges);
                        BatchWriteRowResponse batchWriteRowResponse = oTSClient.BatchWriteRow(batchRequest);
                        BatchWriteResult(batchWriteRowResponse, i, rowChanges);
                        rowChanges   = new RowChanges();
                        batchRequest = new BatchWriteRowRequest();
                        batchCount   = 0;
                        list         = new List <string>();
                    }
                }
                if (rowChanges.PutOperations.Count > 0)
                {
                    batchRequest.Add(TableName, rowChanges);
                    BatchWriteRowResponse batchWriteRowResponse = oTSClient.BatchWriteRow(batchRequest);
                    BatchWriteResult(batchWriteRowResponse, i, rowChanges);
                }
                batchRequest = new BatchWriteRowRequest();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
        }
        public static void ConditionDeleteRow()
        {
            Console.WriteLine("Start delete row...");

            PrepareTable();
            OTSClient otsClient = Config.GetClient();

            // 定义行的主键,必须与创建表时的TableMeta中定义的一致
            PrimaryKey primaryKey = new PrimaryKey();

            primaryKey.Add("pk0", new ColumnValue(2));
            primaryKey.Add("pk1", new ColumnValue("abc"));

            // 定义要写入改行的属性列
            AttributeColumns attribute = new AttributeColumns();

            attribute.Add("col0", new ColumnValue(2));
            attribute.Add("col1", new ColumnValue("a"));
            attribute.Add("col2", new ColumnValue(true));

            PutRowRequest putRequest = new PutRowRequest(tableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute);

            // 新创建一行数据
            try
            {
                otsClient.PutRow(putRequest);

                Console.WriteLine("Put row succeeded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Put row failed. error:{0}", ex.Message);
            }

            // 当col2列的值等于true的时候,允许删除
            try
            {
                // 构造条件语句:col2列的值等于true
                var condition = new Condition(RowExistenceExpectation.EXPECT_EXIST);
                condition.ColumnCondition = new RelationalCondition("col2",
                                                                    CompareOperator.EQUAL,
                                                                    new ColumnValue(true));

                // 构造删除请求
                var deleteRequest = new DeleteRowRequest(tableName, condition, primaryKey);

                // 删除满足条件的特定行
                otsClient.DeleteRow(deleteRequest);

                Console.WriteLine("Delete row succeeded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Delete row failed. error:{0}", ex.Message);
            }

            Console.WriteLine("Delete row succeeded.");
        }
        public AttributeColumns GetPredefinedAttributeWith5PK(int index)
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue("ABC" + index));
            attribute.Add("Col1", new ColumnValue(123 + index));
            attribute.Add("Col2", new ColumnValue(3.14 + index));
            attribute.Add("Col3", new ColumnValue(index % 2 == 0));
            attribute.Add("Col4", new ColumnValue(new byte[] { 0x20, 0x20 }));
            return(attribute);
        }
Esempio n. 8
0
        public void TestFourColumnInAttribute()
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(3.14));
            attribute.Add("Col1", new ColumnValue(3.14));
            attribute.Add("Col2", new ColumnValue(3.14));
            attribute.Add("Col3", new ColumnValue(3.14));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
Esempio n. 9
0
        public void GetRowTest()
        {
            CreateTable();
            var otsClient = OTSClient;

            var primaryKey = new PrimaryKey();

            primaryKey.Add("PK0", new ColumnValue("ABC"));
            primaryKey.Add("PK1", new ColumnValue(123));

            var attribute = new AttributeColumns();

            attribute.Add("IntAttr0", new ColumnValue(12345));
            attribute.Add("StringAttr1", new ColumnValue("ABC"));
            attribute.Add("DoubleAttr2", new ColumnValue(3.14));
            attribute.Add("BooleanAttr3", new ColumnValue(true));
            var putRowRequest = new PutRowRequest(
                "SampleTable",
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                attribute
                );
            var putRowResponse = otsClient.PutRow(putRowRequest);

            var getRowRequest = new GetRowRequest(
                "SampleTable",
                primaryKey
                );
            var getRowResponse = otsClient.GetRow(getRowRequest);

            System.Console.WriteLine("GetRow CU Consumed: Read {0} Write {0}",
                                     getRowResponse.ConsumedCapacityUnit.Read,
                                     getRowResponse.ConsumedCapacityUnit.Write);

            var pk0 = getRowResponse.PrimaryKey["PK0"];

            System.Console.WriteLine("PrimaryKey PK0 Value {0}", pk0.StringValue);
            var pk1 = getRowResponse.PrimaryKey["PK1"];

            System.Console.WriteLine("PrimaryKey PK1 Value {0}", pk1.IntegerValue);
            var attr0 = getRowResponse.Attribute["IntAttr0"];

            System.Console.WriteLine("Attribute IntAttr0 Value {0}", attr0.IntegerValue);
            var attr1 = getRowResponse.Attribute["StringAttr1"];

            System.Console.WriteLine("Attribute StringAttr1 Value {0}", attr1.StringValue);
            var attr2 = getRowResponse.Attribute["DoubleAttr2"];

            System.Console.WriteLine("Attribute DoubleAttr2 Value {0}", attr2.DoubleValue);
            var attr3 = getRowResponse.Attribute["BooleanAttr3"];

            System.Console.WriteLine("Attribute BooleanAttr3 Value {0}", attr2.BooleanValue);
            DeleteTable();
        }
Esempio n. 10
0
        public void TestGetRowWithDefaultColumnsToGet()
        {
            CreateTestTableWith4PK();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(1));
            attribute.Add("Col1", new ColumnValue(2));
            attribute.Add("Col2", new ColumnValue(3));
            attribute.Add("Col3", new ColumnValue(4));

            PutSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute);
            CheckSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute, new CapacityUnit(1, 0));
        }
Esempio n. 11
0
        public void TestColumnsToGet()
        {
            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(123));
            attribute.Add("Col1", new ColumnValue("ABC"));
            attribute.Add("Col2", new ColumnValue(new byte[] { 0x20, 0x21, 0x23, 0x24 }));
            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,
                new HashSet <string>()
            {
                "Col0", "Col2"
            }
                );
            var response2 = OTSClient.GetRow(request2);

            Assert.AreEqual(1, response2.ConsumedCapacityUnit.Read);
            Assert.AreEqual(0, response2.ConsumedCapacityUnit.Write);
            AssertColumns(new PrimaryKey(), response2.PrimaryKey);


            var attributeToExpect = new AttributeColumns();

            attributeToExpect.Add("Col0", new ColumnValue(123));
            attributeToExpect.Add("Col2", new ColumnValue(new byte[] { 0x20, 0x21, 0x23, 0x24 }));

            AssertColumns(attributeToExpect, response2.Attribute);
        }
        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 TestIntegerValueInBoundary()
        {
            var primaryKey = new PrimaryKey();

            primaryKey.Add("PK0", new ColumnValue("ABC"));
            primaryKey.Add("PK1", new ColumnValue("DEF"));
            primaryKey.Add("PK2", new ColumnValue(Int64.MaxValue));
            primaryKey.Add("PK3", new ColumnValue(456));
            SetTestConext(primaryKey: primaryKey);
            TestAllDataAPI();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(Int64.MaxValue));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();

            primaryKey = new PrimaryKey();
            primaryKey.Add("PK0", new ColumnValue("ABC"));
            primaryKey.Add("PK1", new ColumnValue("DEF"));
            primaryKey.Add("PK2", new ColumnValue(Int64.MinValue));
            primaryKey.Add("PK3", new ColumnValue(456));
            SetTestConext(primaryKey: primaryKey);
            TestAllDataAPI();

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(Int64.MinValue));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        public void Test4PutAnd4DeleteInUpdateRow()
        {
            CreateTestTableWith2PK();

            var pk = new PrimaryKey();

            pk.Add("PK0", new ColumnValue("123"));
            pk.Add("PK1", new ColumnValue(123));

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue("0"));
            attribute.Add("Col1", new ColumnValue("1"));
            attribute.Add("Col2", new ColumnValue("2"));
            attribute.Add("Col3", new ColumnValue("3"));
            attribute.Add("Col4", new ColumnValue("4"));

            PutSingleRow(TestTableName, pk, attribute);

            var updateOfAttribute = new UpdateOfAttribute();

            updateOfAttribute.AddAttributeColumnToPut("Col3", new ColumnValue("5"));
            updateOfAttribute.AddAttributeColumnToPut("Col4", new ColumnValue("6"));
            updateOfAttribute.AddAttributeColumnToPut("Col5", new ColumnValue("7"));
            updateOfAttribute.AddAttributeColumnToPut("Col6", new ColumnValue("8"));

            updateOfAttribute.AddAttributeColumnToDelete("Col1");
            updateOfAttribute.AddAttributeColumnToDelete("Col2");
            updateOfAttribute.AddAttributeColumnToDelete("Col7");
            updateOfAttribute.AddAttributeColumnToDelete("Col8");

            var request = new UpdateRowRequest(
                TestTableName, new Condition(RowExistenceExpectation.IGNORE), pk, updateOfAttribute);
            var response = OTSClient.UpdateRow(request);

            AssertCapacityUnit(new CapacityUnit(0, 1), response.ConsumedCapacityUnit);

            var expectAttribute = new AttributeColumns();

            expectAttribute.Add("Col0", new ColumnValue("0"));
            expectAttribute.Add("Col3", new ColumnValue("5"));
            expectAttribute.Add("Col4", new ColumnValue("6"));
            expectAttribute.Add("Col5", new ColumnValue("7"));
            expectAttribute.Add("Col6", new ColumnValue("8"));

            CheckSingleRow(TestTableName, pk, expectAttribute);
        }
        public void TestForError()
        {
            var schema = new PrimaryKeySchema();

            schema.Add("pk1", ColumnValueType.String);

            CreateTestTable(TestTableName, schema, new CapacityUnit(0, 0));

            var attr1 = new AttributeColumns();

            attr1.Add("attr", new ColumnValue("attr_value1"));
            var attr2 = new AttributeColumns();

            attr2.Add("attr", new ColumnValue("attr_value2"));
            var attr3 = new AttributeColumns();

            attr3.Add("attr", new ColumnValue("attr_value3"));

            {
                var pk1 = new PrimaryKey();
                pk1.Add("pk1", new ColumnValue("1"));
                pk1.Add("pk2", new ColumnValue("1"));

                var pk2 = new PrimaryKey();
                pk2.Add("pk1", new ColumnValue("2"));
                pk2.Add("pk2", new ColumnValue("2"));

                var pk3 = new PrimaryKey();
                pk3.Add("pk1", new ColumnValue("3"));
                pk3.Add("pk2", new ColumnValue("3"));

                {
                    var request = new BatchWriteRowRequest();
                    var change  = new RowChanges();
                    change.AddPut(new Condition(RowExistenceExpectation.IGNORE), pk1, attr1);
                    change.AddPut(new Condition(RowExistenceExpectation.IGNORE), pk2, attr2);
                    change.AddPut(new Condition(RowExistenceExpectation.IGNORE), pk3, attr3);

                    request.Add(TestTableName, change);

                    var response = OTSClient.BatchWriteRow(request);
                    var tables   = response.TableRespones;

                    Assert.AreEqual(1, tables.Count);

                    var rows = tables[TestTableName];

                    Assert.AreEqual(3, rows.PutResponses.Count);

                    Assert.AreEqual("OTSInvalidPK", rows.PutResponses[0].ErrorCode);
                    Assert.AreEqual("OTSInvalidPK", rows.PutResponses[1].ErrorCode);
                    Assert.AreEqual("OTSInvalidPK", rows.PutResponses[2].ErrorCode);

                    Assert.AreEqual("Validate PK size fail. Input: 2, Meta: 1.", rows.PutResponses[0].ErrorMessage);
                    Assert.AreEqual("Validate PK size fail. Input: 2, Meta: 1.", rows.PutResponses[1].ErrorMessage);
                    Assert.AreEqual("Validate PK size fail. Input: 2, Meta: 1.", rows.PutResponses[2].ErrorMessage);
                }
            }
        }
        public void TestBooleanValueFalse()
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(false));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
        public void TestEmptyBinaryValue()
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(generateBinaryString(0)));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
Esempio n. 19
0
        public void TableStoreAddLocation(DataRowCollection drs)
        {
            if (drs.Count == 0)
            {
                return;
            }
            int           batchCount = 0;
            int           i          = 0;
            List <string> list       = new List <string>();//存储批量上传的主键字符串,用于判断批量上传数据中是否有重复

            try
            {
                RowChanges rowChanges = new RowChanges();
                foreach (DataRow dr in drs)
                {
                    i++;
                    var primaryKey = new PrimaryKey();
                    primaryKey.Add("d", new ColumnValue(Convert.ToInt64(dr["device_code"])));
                    primaryKey.Add("t", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(dr["gps_time"]))));

                    string primarykey = dr["device_code"].ToString() + ";" + dr["gps_time"].ToString();
                    if (list.Contains(primarykey))
                    {
                        log.Info(i + "发现重复记录" + primarykey + "数据库记录:id = " + dr["id"]);
                        continue;
                    }
                    list.Add(primarykey);

                    var attribute = new AttributeColumns();
                    //定位数据
                    attribute.Add("l", new ColumnValue(ByteIntHelper.GetLocationByte(dr["latitude"], dr["longitude"], Convert.ToInt32(dr["speed"]), Convert.ToInt32(dr["direct"]), 0)));

                    rowChanges.AddPut(new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute);
                    batchCount++;
                    if (batchCount == 200)//200行数据进行批量提交一次
                    {
                        batchRequest.Add(TableName, rowChanges);
                        BatchWriteRowResponse bwResponse = oTSClient.BatchWriteRow(batchRequest);
                        BatchWriteResult(bwResponse, i, rowChanges);
                        rowChanges   = new RowChanges();
                        batchRequest = new BatchWriteRowRequest();
                        batchCount   = 0;
                        list         = new List <string>();
                    }
                }
                if (rowChanges.PutOperations.Count > 0)
                {
                    batchRequest.Add(TableName, rowChanges);
                    BatchWriteRowResponse batchWriteRowResponse = oTSClient.BatchWriteRow(batchRequest);
                    BatchWriteResult(batchWriteRowResponse, i, rowChanges);
                }
                batchRequest = new BatchWriteRowRequest();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
        }
Esempio n. 20
0
        public void TestConditionExpectNotExist()
        {
            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(new byte[] { 0x20, 0x21, 0x23, 0x24 }));
            {
                var request1 = new PutRowRequest(
                    "SampleTableName",
                    new Condition(RowExistenceExpectation.EXPECT_NOT_EXIST),
                    primaryKey,
                    attribute
                    );

                var response1 = OTSClient.PutRow(request1);
                Assert.AreEqual(1, 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);
            }
            {
                var request1 = new PutRowRequest(
                    "SampleTableName",
                    new Condition(RowExistenceExpectation.EXPECT_NOT_EXIST),
                    primaryKey,
                    attribute
                    );

                try
                {
                    OTSClient.PutRow(request1);
                    Assert.Fail();
                }
                catch (OTSServerException e)
                {
                    Assert.AreEqual("/PutRow", e.APIName);
                    Assert.AreEqual(403, (int)e.HttpStatusCode);
                    Assert.AreEqual("OTSConditionCheckFail", e.ErrorCode);
                    Assert.AreEqual("Condition check failed.", e.ErrorMessage);
                    Assert.NotNull(e.RequestID);
                }
            }
        }
Esempio n. 21
0
        public static void PutRowAsync()
        {
            Console.WriteLine("Start put row async...");
            PrepareTable();
            OTSClient TabeStoreClient = Config.GetClient();

            try
            {
                var putRowTaskList = new List <Task <PutRowResponse> >();
                for (int i = 0; i < 100; i++)
                {
                    // 定义行的主键,必须与创建表时的TableMeta中定义的一致
                    var primaryKey = new PrimaryKey();
                    primaryKey.Add("pk0", new ColumnValue(i));
                    primaryKey.Add("pk1", new ColumnValue("abc"));

                    // 定义要写入改行的属性列
                    var attribute = new AttributeColumns();
                    attribute.Add("col0", new ColumnValue(i));
                    attribute.Add("col1", new ColumnValue("a"));
                    attribute.Add("col2", new ColumnValue(true));

                    var request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE),
                                                    primaryKey, attribute);

                    putRowTaskList.Add(TabeStoreClient.PutRowAsync(request));
                }

                foreach (var task in putRowTaskList)
                {
                    task.Wait();
                    Console.WriteLine("consumed read:{0}, write:{1}", task.Result.ConsumedCapacityUnit.Read,
                                      task.Result.ConsumedCapacityUnit.Write);
                }

                Console.WriteLine("Put row async succeeded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Put row async failed. exception:{0}", ex.Message);
            }
        }
Esempio n. 22
0
        public void TestGetRowWith4ColumnsToGet()
        {
            CreateTestTableWith4PK();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(1));
            attribute.Add("Col1", new ColumnValue(2));
            attribute.Add("Col2", new ColumnValue(3));
            attribute.Add("Col3", new ColumnValue(4));

            PutSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute);

            var columnsToGet = new HashSet <string>()
            {
                "PK0", "PK1", "Col0", "Col1"
            };

            CheckSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute, new CapacityUnit(1, 0), columnsToGet);
        }
        public void TestBinaryValueTooLong()
        {
            CreateTestTableWith4PK();
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(generateBinaryString(1024 * 1024)));

            SetTestConext(attribute: attribute,
                          allFailedMessage: "The length of attribute column: 'Col0' exceeded the MaxLength:65536 with CurrentLength:1048576.");
            TestAllDataAPIWithColumnValue(false);
        }
        private static void PrepareData()
        {
            OTSClient otsClient = Config.GetClient();

            // 插入100条数据
            for (int i = 0; i < 100; i++)
            {
                PrimaryKey primaryKey = new PrimaryKey();
                primaryKey.Add("pk0", new ColumnValue(i));
                primaryKey.Add("pk1", new ColumnValue("abc"));

                // 定义要写入改行的属性列
                AttributeColumns attribute = new AttributeColumns();
                attribute.Add("col0", new ColumnValue(0));
                attribute.Add("col1", new ColumnValue("a"));
                attribute.Add("col2", new ColumnValue(i % 3 != 0));
                PutRowRequest request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute);

                otsClient.PutRow(request);
            }
        }
        public void TestNormalDoubleValue()
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(3.1415926));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(3.1415926));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
        public void TestDoubleValueInBoundary()
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(double.MaxValue));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(double.MinValue));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
        public void CheckSingleRow(string tableName, PrimaryKey primaryKey,
                                   AttributeColumns attribute,
                                   CapacityUnit expectCapacityUnitConsumed = null,
                                   HashSet <string> columnsToGet           = null,
                                   bool isEmpty = false,
                                   ColumnCondition condition = null)
        {
            var request = new GetRowRequest(tableName, primaryKey, columnsToGet, condition);

            var response = OTSClient.GetRow(request);

            PrimaryKey       primaryKeyToExpect;
            AttributeColumns attributeToExpect;

            if (isEmpty)
            {
                primaryKeyToExpect = new PrimaryKey();
                attributeToExpect  = new AttributeColumns();
            }
            else if (columnsToGet == null || columnsToGet.Count == 0)
            {
                primaryKeyToExpect = primaryKey;
                attributeToExpect  = attribute;
            }
            else
            {
                primaryKeyToExpect = new PrimaryKey();
                attributeToExpect  = new AttributeColumns();
                foreach (var columnName in columnsToGet)
                {
                    if (primaryKey.ContainsKey(columnName))
                    {
                        primaryKeyToExpect.Add(columnName, primaryKey[columnName]);
                    }

                    if (attribute.ContainsKey(columnName))
                    {
                        attributeToExpect.Add(columnName, attribute[columnName]);
                    }
                }
            }

            AssertColumns(primaryKeyToExpect, response.PrimaryKey);
            AssertColumns(attributeToExpect, response.Attribute);

            if (expectCapacityUnitConsumed != null)
            {
                AssertCapacityUnit(expectCapacityUnitConsumed, response.ConsumedCapacityUnit);
            }
        }
Esempio n. 28
0
        public void TestDoubleValueOutOfBoundary()
        {
            CreateTestTableWith4PK();
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(double.MaxValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "Infinity can't be set to double value.");
            TestAllDataAPIWithColumnValue(createTable: false);

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(double.MinValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "Infinity can't be set to double value.");
            TestAllDataAPIWithColumnValue(createTable: false);
        }
        public void TestDoubleValueOutOfBoundary()
        {
            CreateTestTableWith4PK();
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(double.MaxValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "The input parameter is invalid.");
            TestAllDataAPIWithColumnValue(createTable: false);

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(double.MinValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "The input parameter is invalid.");
            TestAllDataAPIWithColumnValue(createTable: false);
        }
        public void TestInvalidValueType()
        {
            CreateTestTableWith4PK();
            var attribute = new AttributeColumns();

            attribute.Add("Col0", ColumnValue.INF_MAX);
            SetTestConext(attribute: attribute, allFailedMessage: "INF_MAX is an invalid type for the attribute column.");
            TestAllDataAPIWithColumnValue(createTable: false);

            attribute = new AttributeColumns();
            attribute.Add("Col0", ColumnValue.INF_MIN);
            SetTestConext(attribute: attribute, allFailedMessage: "INF_MIN is an invalid type for the attribute column.");
            TestAllDataAPIWithColumnValue(createTable: false);
        }