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);
            }
        }
Example #2
0
        public ActionResult SearchLocation()
        {
            OTSClient  _oTSClient = OTSHelper.GetOTSClientLocation(_tableStoreModel);
            PrimaryKey pk         = new PrimaryKey();

            pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"])));
            pk.Add("t", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["t"]))));
            GetRowRequest  getRowRequest      = new GetRowRequest("L_100000000", pk);
            GetRowResponse response           = _oTSClient.GetRow(getRowRequest);
            StringBuilder  sbAttributeColumns = new StringBuilder();

            foreach (var item in response.Attribute)
            {
                if (item.Key == "l")
                {
                    byte[] lbyte = item.Value.BinaryValue;
                    Dictionary <string, int> dictionary = ByteIntHelper.GetLocationByByte(lbyte);
                    foreach (var dic in dictionary)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                }
            }
            ViewData["pk"]  = "设备:" + Request.Form["d"] + " 时间:" + Request.Form["t"];
            ViewData["att"] = sbAttributeColumns.ToString();
            return(View("Search", ViewBag));
        }
        private void Run()
        {
            for (int i = 0; i < round; ++i)
            {
                var primaryKey = new PrimaryKey();
                primaryKey.Add("PK0", new ColumnValue(pk));
                var                 request     = new GetRowRequest(tableName, primaryKey);
                var                 response    = OTSClient.GetRow(request);
                var                 attr        = response.Attribute["Col1"];
                long                oldIntValue = attr.IntegerValue;
                ColumnValue         oldValue    = new ColumnValue(oldIntValue);
                ColumnValue         newValue    = new ColumnValue(oldIntValue + 1);
                RelationalCondition cc          = new RelationalCondition("Col1", RelationalCondition.CompareOperator.EQUAL, oldValue);
                Condition           cond        = new Condition(RowExistenceExpectation.IGNORE);

                cond.ColumnCondition = cc;
                UpdateOfAttribute updateOfAttributeForPut = new UpdateOfAttribute();
                updateOfAttributeForPut.AddAttributeColumnToPut("Col1", newValue);
                UpdateRowRequest updateReq = new UpdateRowRequest(tableName, cond, primaryKey, updateOfAttributeForPut);
                bool             success   = true;
                try
                {
                    OTSClient.UpdateRow(updateReq);
                }
                catch (OTSServerException)
                {
                    success = false;
                }
                if (success)
                {
                    ++count;
                }
            }
        }
Example #4
0
        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.");
        }
Example #5
0
        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);
        }
Example #6
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);
        }
Example #7
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);
                }
            }
        }
        public void TestColumnsToGet()
        {
            CreateTable();

            var primaryKey = new PrimaryKey
            {
                { "PK0", new ColumnValue("ABC") },
                { "PK1", new ColumnValue(123) }
            };

            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue(123) },
                { "Col1", new ColumnValue("ABC") },
                { "Col2", new ColumnValue(new byte[] { 0x20, 0x21, 0x23, 0x24 }) }
            };

            var request1 = new PutRowRequest(
                TestTableName,
                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(
                TestTableName,
                primaryKey,
                new HashSet <string>()
            {
                "Col0", "Col2"
            }
                );

            var response2 = OTSClient.GetRow(request2);

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


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

            AssertColumns(attributeToExpect, response2.Attribute);

            DeleteTable();
        }
Example #9
0
        public static void GetRowWithFilter()
        {
            Console.WriteLine("Start get row with filter ...");
            PrepareTable();
            OTSClient otsClient = Config.GetClient();

            // 定义行的主键,必须与创建表时的TableMeta中定义的一致
            PrimaryKey primaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(0) },
                { "pk1", new ColumnValue("abc") }
            };

            var rowQueryCriteria = new SingleRowQueryCriteria(TableName)
            {
                RowPrimaryKey = primaryKey
            };

            // 只返回col0的值等于5的行或者col1不等于ff的行
            var filter1 = new RelationalCondition("col0",
                                                  CompareOperator.EQUAL,
                                                  new ColumnValue(5));

            var filter2 = new RelationalCondition("col1", CompareOperator.NOT_EQUAL, new ColumnValue("ff"));

            var filter = new CompositeCondition(LogicOperator.OR);

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

            rowQueryCriteria.Filter = filter.ToFilter();
            rowQueryCriteria.AddColumnsToGet("col0");
            rowQueryCriteria.AddColumnsToGet("col1");

            GetRowRequest request = new GetRowRequest(rowQueryCriteria);

            // 查询
            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 with filter succeed.");
        }
        public long ReadRow(String tableName, Int64 pk)
        {
            var primaryKey = new PrimaryKey();

            primaryKey.Add("PK0", new ColumnValue(pk));
            var  request  = new GetRowRequest(tableName, primaryKey);
            var  response = OTSClient.GetRow(request);
            var  attr     = response.Attribute["Col1"];
            long value    = attr.IntegerValue;

            return(value);
        }
        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);
            }
        }
        public void TestEmptyPrimaryKey()
        {
            CreateTable();
            var primaryKey = new PrimaryKey();

            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue(true) }
            };

            var request1 = new PutRowRequest(
                TestTableName,
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                attribute
                );

            try
            {
                OTSClient.PutRow(request1);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                Assert.AreEqual("/PutRow", e.APIName);
                Assert.AreEqual(400, (int)e.HttpStatusCode);
                Assert.AreEqual("OTSParameterInvalid", e.ErrorCode);
                Assert.AreEqual("Cell data broken, empty PK.", e.ErrorMessage);
                Assert.NotNull(e.RequestID);
            }

            var request2 = new GetRowRequest(
                TestTableName,
                primaryKey
                );

            try
            {
                OTSClient.GetRow(request2);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                Assert.AreEqual("/GetRow", e.APIName);
                Assert.AreEqual(400, (int)e.HttpStatusCode);
                Assert.AreEqual("OTSParameterInvalid", e.ErrorCode);
                Assert.AreEqual("Cell data broken, empty PK.", e.ErrorMessage);
                Assert.NotNull(e.RequestID);
            }

            DeleteTable();
        }
Example #13
0
        public ActionResult SearchRoute()
        {
            OTSClient  _oTSClient = OTSHelper.GetOTSClientRoute(_tableStoreModel);
            PrimaryKey pk         = new PrimaryKey();

            pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"])));
            pk.Add("s", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["s"]))));
            GetRowRequest  getRowRequest      = new GetRowRequest("Route", pk);
            GetRowResponse response           = _oTSClient.GetRow(getRowRequest);
            StringBuilder  sbAttributeColumns = new StringBuilder();

            foreach (var item in response.Attribute)
            {
                switch (item.Key)
                {
                case "e":
                    sbAttributeColumns.Append(item.Key + ":" + item.Value.IntegerValue + "【" + TimeHelper.ConvertStringToDateTime(item.Value.IntegerValue.ToString()).ToString("yyyy-MM-dd HH:mm:ss fff") + "】;");
                    break;

                case "r":
                    byte[] lbyte = item.Value.BinaryValue;
                    Dictionary <string, int> dictionary = ByteIntHelper.GetRouteByByte(lbyte);
                    foreach (var dic in dictionary)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;

                case "ds":
                    byte[] ds = item.Value.BinaryValue;
                    Dictionary <string, int> dsDic = ByteIntHelper.GetDurationstatsByByte(ds);
                    foreach (var dic in dsDic)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;

                case "es":
                    byte[] es = item.Value.BinaryValue;
                    Dictionary <string, int> esDic = ByteIntHelper.GetEventStatsByByte(es);
                    foreach (var dic in esDic)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;
                }
            }
            ViewData["pk"]  = "设备:" + Request.Form["d"] + " 开始时间:" + Request.Form["s"];
            ViewData["att"] = sbAttributeColumns.ToString();
            return(View("Search", ViewBag));
        }
        private void GetRow(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    request  = new GetRowRequest(tableName, primaryKey);
            var    response = OTSClient.GetRow(request);
            String name     = response.Attribute[COLUMN_NAME_NAME].StringValue;
            String addr     = response.Attribute[COLUMN_ADDRESS_NAME].StringValue;
            long   age      = response.Attribute[COLUMN_AGE_NAME].IntegerValue;

            Console.WriteLine("本次读取name信息:{0}", name);
            Console.WriteLine("本次读取addr信息:{0}", addr);
            Console.WriteLine("本次读取age信息: {0}", age);
        }
Example #15
0
        public void TestEmptyPrimaryKey()
        {
            var primaryKey = new PrimaryKey();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(true));
            var request1 = new PutRowRequest(
                "SampleTableName",
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                attribute
                );

            try
            {
                OTSClient.PutRow(request1);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                Assert.AreEqual("/PutRow", e.APIName);
                Assert.AreEqual(400, (int)e.HttpStatusCode);
                Assert.AreEqual("OTSParameterInvalid", e.ErrorCode);
                Assert.AreEqual("The number of primary key columns must be in range: [1, 4].", e.ErrorMessage);
                Assert.NotNull(e.RequestID);
            }

            var request2 = new GetRowRequest(
                "SampleTableName",
                primaryKey
                );

            try
            {
                OTSClient.GetRow(request2);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                Assert.AreEqual("/GetRow", e.APIName);
                Assert.AreEqual(400, (int)e.HttpStatusCode);
                Assert.AreEqual("OTSParameterInvalid", e.ErrorCode);
                Assert.AreEqual("The number of primary key columns must be in range: [1, 4].", e.ErrorMessage);
                Assert.NotNull(e.RequestID);
            }
        }
        public void TestDouble()
        {
            CreateTable();

            var primaryKey = new PrimaryKey
            {
                { "PK0", new ColumnValue("ABC") },
                { "PK1", new ColumnValue(123) }
            };

            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue(123.321) }
            };

            var request1 = new PutRowRequest(
                TestTableName,
                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(
                TestTableName,
                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);

            DeleteTable();
        }
Example #17
0
        public ActionResult SearchEvent()
        {
            OTSClient  _oTSClient = OTSHelper.GetOTSClientEvent(_tableStoreModel);
            PrimaryKey pk         = new PrimaryKey();

            pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"])));
            pk.Add("et", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["et"]))));
            pk.Add("ei", new ColumnValue(ByteIntHelper.intToBytes2(Convert.ToInt64(Request.Form["ei"]), 1)));
            GetRowRequest  getRowRequest      = new GetRowRequest("E_100000000", pk);
            GetRowResponse response           = _oTSClient.GetRow(getRowRequest);
            StringBuilder  sbAttributeColumns = new StringBuilder();

            foreach (var item in response.Attribute)
            {
                switch (item.Key)
                {
                case "ep":
                    //事件参数字段暂不做处理
                    //byte[] ep = item.Value.BinaryValue;
                    break;

                case "t":
                    sbAttributeColumns.Append(item.Key + ":" + item.Value.IntegerValue + "【" + TimeHelper.ConvertStringToDateTime(item.Value.IntegerValue.ToString()).ToString("yyyy-MM-dd HH:mm:ss fff") + "】;");
                    break;

                case "l":
                    byte[] lbyte = item.Value.BinaryValue;
                    Dictionary <string, int> dictionary = ByteIntHelper.GetLocationByByte(lbyte);
                    foreach (var dic in dictionary)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;
                }
            }

            ViewData["pk"]  = "设备:" + Request.Form["d"] + " 事件时间:" + Request.Form["et"] + " 事件ID:" + Request.Form["ei"];
            ViewData["att"] = sbAttributeColumns.ToString();
            return(View("Search", ViewBag));
        }
Example #18
0
        public static Dictionary <string, string> GetAppKey(string keyname)
        {
            GetClient();
            Dictionary <string, string> keyValues = new Dictionary <string, string>();
            PrimaryKey primaryKey = new PrimaryKey();

            primaryKey.Add("KeyName", new ColumnValue(keyname));
            try
            {
                var request  = new GetRowRequest("Appkey", primaryKey);
                var response = OtsClient.GetRow(request);
                var columns  = response.Columns;
                foreach (var q in columns)
                {
                    keyValues[q.Name] = PrintColumnValue(q.Value);
                }
                return(keyValues);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                return(null);
            }
        }