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 TestRetryWithOTSNotEnoughCapacityUnit()
        {
            var schema = new PrimaryKeySchema
            {
                { "PK0", ColumnValueType.String },
                { "PK1", ColumnValueType.Integer }
            };

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

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

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

            PutSingleRow(TestTableName, primaryKey, attribute);

            for (int i = 0; i < 20; i++)
            {
                CheckSingleRow(TestTableName, primaryKey, attribute, new CapacityUnit(1, 0));
            }

            DeleteTable(TestTableName);
        }
Пример #3
0
        public void TestInvalidPKInSchema()
        {
            // TODO Error Injection to test DescribeTable

            var primaryKeySchema = new PrimaryKeySchema();

            primaryKeySchema.Add("PK0", ColumnValueType.Double);
            primaryKeySchema.Add("PK1", ColumnValueType.Double);

            SetTestConext(pkSchema: primaryKeySchema, allFailedMessage: "DOUBLE is an invalid type for the primary key.");
            TestSingleAPI("CreateTable");

            primaryKeySchema = new PrimaryKeySchema();
            primaryKeySchema.Add("PK0", ColumnValueType.Boolean);
            primaryKeySchema.Add("PK1", ColumnValueType.Boolean);

            SetTestConext(pkSchema: primaryKeySchema, allFailedMessage: "BOOLEAN is an invalid type for the primary key.");
            TestSingleAPI("CreateTable");

            //primaryKeySchema = new PrimaryKeySchema();
            //primaryKeySchema.Add("PK0", ColumnValueType.Binary);
            //primaryKeySchema.Add("PK1", ColumnValueType.Binary);

            //SetTestConext(pkSchema:primaryKeySchema, allFailedMessage:"BINARY is an invalid type for the primary key.");
            //TestSingleAPI("CreateTable");

            // INF_MIN INF_MAX 类型的 ColumnValueType 在C# SDK里没有
        }
Пример #4
0
        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"));
            }
        }
        public void TestOneColumnInPK()
        {
            var primaryKeySchema = new PrimaryKeySchema();

            primaryKeySchema.Add("PK0", ColumnValueType.Integer);

            var primaryKey = new PrimaryKey();

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

            var startPrimaryKey = new PrimaryKey();

            startPrimaryKey.Add("PK0", ColumnValue.INF_MIN);

            var endPrimaryKey = new PrimaryKey();

            endPrimaryKey.Add("PK0", ColumnValue.INF_MAX);

            SetTestConext(pkSchema: primaryKeySchema, primaryKey: primaryKey,
                          startPrimaryKey: startPrimaryKey, endPrimaryKey: endPrimaryKey);

            TestSingleAPI("CreateTable");
            TestSingleAPI("DescribeTable");
            WaitForTableReady();
            TestAllDataAPI(createTable: false);
        }
        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);
                }
            }
        }
Пример #7
0
        public void TestBadColumnName(string badColumnName)
        {
            var badPrimaryKeySchema = new PrimaryKeySchema
            {
                { badColumnName, ColumnValueType.String }
            };

            var badPrimaryKey = new PrimaryKey
            {
                { badColumnName, new ColumnValue(3.14) }
            };

            var badColumnsToGet = new HashSet <string>
            {
                badColumnName
            };

            var expectFailureInfo = "Invalid column name: '" + badColumnName + "'.";

            var expectedFailure = new Dictionary <string, string>
            {
                { "CreateTable", expectFailureInfo }
            };

            var errorMessage = String.Format("Bug: unsupported primary key type: Double");
            var badAttribute = new AttributeColumns
            {
                { badColumnName, new ColumnValue(3.14) }
            };

            SetTestConext(
                pkSchema: badPrimaryKeySchema,
                primaryKey: badPrimaryKey,
                startPrimaryKey: badPrimaryKey,
                expectedFailure: expectedFailure,
                allFailedMessage: errorMessage);
            TestAllDataAPI(deleteTable: false);

            try
            {
                SetTestConext();
                TestSingleAPI("CreateTable");
            }
            catch (OTSServerException ex)
            {
                Console.WriteLine(ex.ErrorMessage);
            }

            SetTestConext(
                attribute: badAttribute,
                allFailedMessage: expectFailureInfo);
            TestAllDataAPIWithAttribute(false);

            SetTestConext(
                columnsToGet: badColumnsToGet,
                expectedFailure: expectedFailure,
                allFailedMessage: expectFailureInfo);
            TestAllDataAPIWithColumnsToGet();
        }
 public MemberColumnSchema GetPrimaryKeyColumn(PrimaryKeySchema primaryKey)
 {
     if (primaryKey.MemberColumns.Count != 1)
     {
         throw new System.ApplicationException("This method will only work on primary keys with exactly one member column.");
     }
     return(primaryKey.MemberColumns[0]);
 }
Пример #9
0
        private static void UpdateRow(DataRow dr)
        {
            string    setFields = string.Empty;
            string    condition = string.Empty;
            DataTable dt        = dr.Table;

            PrimaryKeySchema pks = DataBaseSchemaProvider.GetTablePrimaryKey(DatabaseSchema.Tables[dt.TableName]);

            if (pks == null || pks.MemberColumns.Count == 0)
            {
                throw new Exception(dt.TableName + "没有设置主键!");
            }
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                bool isPKColumn = false;
                foreach (MemberColumnSchema mcs in pks.MemberColumns)
                {
                    //Equals(dt.Columns[i].ColumnName, StringComparison.OrdinalIgnoreCase))
                    if (mcs.Name.Equals(dt.Columns[i].ColumnName, StringComparison.OrdinalIgnoreCase))
                    {
                        isPKColumn = true;
                        break;
                    }
                }
                if (!isPKColumn)
                {
                    setFields += (dt.Columns[i].ColumnName + "=@" + dt.Columns[i].ColumnName + ",");
                }
            }
            setFields = setFields.Remove(setFields.Length - 1);


            foreach (MemberColumnSchema mcs in pks.MemberColumns)
            {
                condition += string.Format(@" {0}='{1}' AND", mcs.Name, dr[mcs.Name].ToString());
            }
            condition = condition.Remove(condition.Length - 3);


            string sql = string.Format(@"UPDATE {0} SET {1} WHERE {2}", dr.Table.TableName, setFields, condition);

            DbCommand updateCommand = SysDataBase.CreateCommandByCommandType(CommandType.Text, sql);

            ColumnSchema[] css = DataBaseSchemaProvider.GetTableColumns(DatabaseSchema.Tables[dt.TableName]);
            foreach (DataColumn dc in dt.Columns)
            {
                foreach (ColumnSchema cs in css)
                {
                    if (cs.Name.Equals(dc.ColumnName, StringComparison.OrdinalIgnoreCase))
                    {
                        SysDataBase.AddInParameter(updateCommand, dc.ColumnName, cs.DataType, dr[dc.ColumnName]);
                        break;
                    }
                }
            }

            SysDataBase.ExecuteDataSet(updateCommand);
        }
        public void CreateTestTableWith2PK()
        {
            var schema = new PrimaryKeySchema();

            schema.Add("PK0", ColumnValueType.String);
            schema.Add("PK1", ColumnValueType.Integer);

            CreateTestTable(TestTableName, schema, new CapacityUnit(0, 0));
        }
    public bool IsMutliColumnPrimaryKey(PrimaryKeySchema primaryKey)
    {
        if (primaryKey.MemberColumns.Count == 0)
        {
            throw new System.ApplicationException("This template will only work on primary keys with exactly one member column.");
        }

        return(primaryKey.MemberColumns.Count > 1);
    }
Пример #12
0
            protected override string GetPkIdentifier(PrimaryKeySchema primaryKeySchema)
            {
                if (primaryKeySchema == null || !primaryKeySchema.AutoIncrement)
                {
                    return(string.Empty);
                }

                return(" AUTOINC");
            }
Пример #13
0
        public void TestForError()
        {
            var schema = new PrimaryKeySchema
            {
                { "pk1", ColumnValueType.String }
            };

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


            var request = new BatchGetRowRequest();
            List <PrimaryKey> primaryKeys = new List <PrimaryKey>();
            var pk1 = new PrimaryKey
            {
                { "pk1", new ColumnValue("1") },
                { "pk2", new ColumnValue("1") }
            };

            var pk2 = new PrimaryKey
            {
                { "pk1", new ColumnValue("2") },
                { "pk2", new ColumnValue("2") }
            };

            var pk3 = new PrimaryKey
            {
                { "pk1", new ColumnValue("3") },
                { "pk2", new ColumnValue("3") }
            };

            primaryKeys.Add(pk1);
            primaryKeys.Add(pk2);
            primaryKeys.Add(pk3);

            request.Add(TestTableName, primaryKeys);

            var response = OTSClient.BatchGetRow(request);

            var tables = response.RowDataGroupByTable;

            Assert.AreEqual(1, tables.Count);

            var rows = tables[TestTableName];

            Assert.AreEqual(3, rows.Count);

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

            Assert.AreEqual("Validate PK size fail. Input: 2, Meta: 1.", rows[0].ErrorMessage);
            Assert.AreEqual("Validate PK size fail. Input: 2, Meta: 1.", rows[1].ErrorMessage);
            Assert.AreEqual("Validate PK size fail. Input: 2, Meta: 1.", rows[2].ErrorMessage);

            DeleteTable(TestTableName);
        }
        public void AssertPrimaryKeySchema(PrimaryKeySchema expect, PrimaryKeySchema actual)
        {
            Assert.AreEqual(expect.Count, actual.Count);

            for (int i = 0; i < expect.Count; i++)
            {
                Assert.AreEqual(expect[i].Item1, actual[i].Item1);
                Assert.AreEqual(expect[i].Item2, actual[i].Item2);
            }
        }
Пример #15
0
        public static void TableOperations()
        {
            // 创建表
            OTSClient otsClient = Config.GetClient();

            {
                Console.WriteLine("Start create table...");
                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);

                Console.WriteLine("Table is created: " + TableName);
            }

            //// 更新表
            //{
            //    Thread.Sleep(60 * 1000); // 每次更新表需要至少间隔1分钟
            //    Console.WriteLine("Start update table...");
            //    CapacityUnit reservedThroughput = new CapacityUnit(0, 0); // 将预留CU调整为0,0
            //    UpdateTableRequest request = new UpdateTableRequest(TableName, reservedThroughput);
            //    UpdateTableResponse response = otsClient.UpdateTable(request);
            //    Console.WriteLine("LastIncreaseTime: " + response.ReservedThroughputDetails.LastIncreaseTime);
            //    Console.WriteLine("LastDecreaseTime: " + response.ReservedThroughputDetails.LastDecreaseTime);
            //    Console.WriteLine("NumberOfDecreaseToday: " + response.ReservedThroughputDetails.LastIncreaseTime);
            //    Console.WriteLine("ReadCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Read);
            //    Console.WriteLine("WriteCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Write);
            //}

            // 描述表
            {
                Console.WriteLine("Start describe table...");
                DescribeTableRequest  request  = new DescribeTableRequest(TableName);
                DescribeTableResponse response = otsClient.DescribeTable(request);
                Console.WriteLine("LastIncreaseTime: " + response.ReservedThroughputDetails.LastIncreaseTime);
                Console.WriteLine("LastDecreaseTime: " + response.ReservedThroughputDetails.LastDecreaseTime);
                Console.WriteLine("NumberOfDecreaseToday: " + response.ReservedThroughputDetails.LastIncreaseTime);
                Console.WriteLine("ReadCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Read);
                Console.WriteLine("WriteCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Write);
            }

            //// 删除表
            //{
            //    Console.WriteLine("Start delete table...");
            //    DeleteTableRequest request = new DeleteTableRequest(TableName);
            //    otsClient.DeleteTable(request);
            //    Console.WriteLine("Table is deleted.");
            //}
        }
Пример #16
0
        public void CreateAutoIncrementColumnTableTest()
        {
            var schema = new PrimaryKeySchema
            {
                { "PK0", ColumnValueType.String },
                { "PK1", ColumnValueType.Integer, PrimaryKeyOption.AUTO_INCREMENT }
            };

            CreateAutoIncrementColumnTable(schema);
            DeleteTable();
        }
Пример #17
0
        public void TestNoColumnInPK()
        {
            var primaryKeySchema = new PrimaryKeySchema();
            var primaryKey       = new PrimaryKey();

            SetTestConext(pkSchema: primaryKeySchema, primaryKey: primaryKey,
                          endPrimaryKey: primaryKey,
                          allFailedMessage: "The number of primary key columns must be in range: [1, 4].");

            TestSingleAPI("CreateTable");
        }
        public void CreateTestTable(string tableName, PrimaryKeySchema schema, CapacityUnit reservedThroughput, bool waitFlag = true)
        {
            var tableMeta = new TableMeta(tableName, schema);
            var request   = new CreateTableRequest(tableMeta, reservedThroughput);

            OTSClient.CreateTable(request);

            if (waitFlag)
            {
                WaitForTableReady();
            }
        }
Пример #19
0
        public void TestStringPKInSchema()
        {
            var primaryKeySchema = new PrimaryKeySchema();

            primaryKeySchema.Add("PK0", ColumnValueType.String);
            primaryKeySchema.Add("PK1", ColumnValueType.String);

            SetTestConext(pkSchema: primaryKeySchema);

            TestSingleAPI("CreateTable");
            TestSingleAPI("DescribeTable");
        }
        public void TestIntegerPKInSchema()
        {
            var primaryKeySchema = new PrimaryKeySchema
            {
                { "PK0", ColumnValueType.Integer },
                { "PK1", ColumnValueType.Integer }
            };

            SetTestConext(pkSchema: primaryKeySchema);

            TestSingleAPI("CreateTable");
            TestSingleAPI("DescribeTable");
        }
Пример #21
0
        public void PutRowWithAutoIncrementColumnTableTest()
        {
            var schema = new PrimaryKeySchema
            {
                { "PK0", ColumnValueType.String },
                { "PK1", ColumnValueType.Integer, PrimaryKeyOption.AUTO_INCREMENT }
            };

            CreateAutoIncrementColumnTable(schema);

            var otsClient     = OTSClient;
            var putRowRequest = new PutRowRequest(
                TestTableName,
                new Condition(RowExistenceExpectation.IGNORE)
                );

            // put first row
            var primaryKey = new PrimaryKey
            {
                { "PK0", new ColumnValue("ABC") },
                { "PK1", ColumnValue.AUTO_INCREMENT }
            };

            var attribute1 = new Column("Col0", new ColumnValue("Hangzhou"));

            putRowRequest.RowPutChange = new RowPutChange(TestTableName, primaryKey);
            putRowRequest.RowPutChange.AddColumn(attribute1);

            var putRowResponse = otsClient.PutRow(putRowRequest);

            Console.WriteLine("PutRow CU Consumed: Read {0} Write {1}",
                              putRowResponse.ConsumedCapacityUnit.Read,
                              putRowResponse.ConsumedCapacityUnit.Write);

            // put second row
            primaryKey = new PrimaryKey
            {
                { "PK0", new ColumnValue("CDE") },
                { "PK1", ColumnValue.AUTO_INCREMENT }
            };

            attribute1 = new Column("Col0", new ColumnValue("Beijing"));

            putRowRequest.RowPutChange = new RowPutChange(TestTableName, primaryKey);
            putRowRequest.RowPutChange.AddColumn(attribute1);

            putRowResponse = otsClient.PutRow(putRowRequest);
            Console.WriteLine("PutRow CU Consumed: Read {0} Write {1}",
                              putRowResponse.ConsumedCapacityUnit.Read,
                              putRowResponse.ConsumedCapacityUnit.Write);
        }
Пример #22
0
        public void CreateTestTable()
        {
            var primaryKeys = new PrimaryKeySchema();

            primaryKeys.Add("PK0", ColumnValueType.String);
            primaryKeys.Add("PK1", ColumnValueType.Integer);

            var tableMeta          = new TableMeta("SampleTableName", primaryKeys);
            var reservedThroughput = new CapacityUnit(0, 0);
            var request            = new CreateTableRequest(tableMeta, reservedThroughput);

            OTSClient.CreateTable(request);

            WaitForTableReady();
        }
        private void CreateTable(String tableName)
        {
            foreach (var tableItem in OTSClient.ListTable(new ListTableRequest()).TableNames)
            {
                OTSClient.DeleteTable(new DeleteTableRequest(tableItem));
            }
            var primaryKeySchema = new PrimaryKeySchema();

            primaryKeySchema.Add("PK0", ColumnValueType.Integer);
            var tableMeta          = new TableMeta(tableName, primaryKeySchema);
            var reservedThroughput = new CapacityUnit(0, 0);
            var request            = new CreateTableRequest(tableMeta, reservedThroughput);
            var response           = OTSClient.CreateTable(request);

            WaitForTableReady();
        }
Пример #24
0
        private void CreateTable()
        {
            var otsClient        = OTSClient;
            var primaryKeySchema = new PrimaryKeySchema();

            primaryKeySchema.Add("PK0", ColumnValueType.String);
            primaryKeySchema.Add("PK1", ColumnValueType.Integer);

            var tableMeta = new TableMeta("SampleTable", primaryKeySchema);

            var reservedThroughput = new CapacityUnit(0, 0);
            var request            = new CreateTableRequest(tableMeta, reservedThroughput);
            var response           = otsClient.CreateTable(request);

            WaitForTableReady();
        }
        public void TestForError()
        {
            var schema = new PrimaryKeySchema();

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

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

            {
                var request = new BatchGetRowRequest();
                List <PrimaryKey> primaryKeys = new List <PrimaryKey>();
                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"));

                primaryKeys.Add(pk1);
                primaryKeys.Add(pk2);
                primaryKeys.Add(pk3);

                request.Add(TestTableName, primaryKeys);

                var response = OTSClient.BatchGetRow(request);

                var tables = response.RowDataGroupByTable;
                Assert.AreEqual(1, tables.Count);

                var rows = tables[TestTableName];

                Assert.AreEqual(3, rows.Count);

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

                Assert.AreEqual("Primary key schema mismatch.", rows[0].ErrorMessage);
                Assert.AreEqual("Primary key schema mismatch.", rows[1].ErrorMessage);
                Assert.AreEqual("Primary key schema mismatch.", rows[2].ErrorMessage);
            }
        }
        public void CreateTableAndDelete()
        {
            string tableName = "SampleTableName";

            var primaryKeys = new PrimaryKeySchema
            {
                { "PK0", ColumnValueType.String },
                { "PK1", ColumnValueType.Integer }
            };

            var tableOption = new TableOptions
            {
                MaxVersions = 1,
                TimeToLive  = -1
            };

            var tableMeta          = new TableMeta(tableName, primaryKeys);
            var reservedThroughput = new CapacityUnit(0, 0);
            var request1           = new CreateTableRequest(tableMeta, reservedThroughput)
            {
                TableOptions = tableOption
            };

            var response1 = OTSClient.CreateTable(request1);

            var request2  = new ListTableRequest();
            var response2 = OTSClient.ListTable(request2);

            Assert.IsTrue(response2.TableNames.Contains(tableName));

            Thread.Sleep(1000);
            var request3  = new DescribeTableRequest(tableName);
            var response3 = OTSClient.DescribeTable(request3);

            Assert.AreEqual(tableName, response3.TableMeta.TableName);
            Assert.AreEqual(primaryKeys, response3.TableMeta.PrimaryKeySchema);
            Assert.AreEqual(reservedThroughput.Read, response3.ReservedThroughputDetails.CapacityUnit.Read);
            Assert.AreEqual(reservedThroughput.Write, response3.ReservedThroughputDetails.CapacityUnit.Write);


            OTSClient.DeleteTable(new DeleteTableRequest(tableName));

            var request4  = new ListTableRequest();
            var response4 = OTSClient.ListTable(request4);

            Assert.IsFalse(response4.TableNames.Contains(tableName));
        }
        //static void Main(string[] args)
        //{
        //    OTSClient otsClient = Config.GetClient();
        //    //DeleteSearchIndex(otsClient);
        //    //DeleteTable(otsClient);

        //    //创建一张TableStore表
        //    CreateTable(otsClient);
        //    //在TableStore表上创建一个索引表
        //    CreateSearchIndex(otsClient);

        //    //Wait searchIndex load success
        //    Console.WriteLine("wait searchIndex load success");
        //    Thread.Sleep(3 * 1000);

        //    ListSearchIndex(otsClient);
        //    CreateSearchIndexWithIndexSort(otsClient);
        //    DescribeSearchIndex(otsClient);
        //    PutRow(otsClient);

        //    //等待索引数据同步成功
        //    WaiteAllDataSyncSuccess(otsClient, 7);

        //    //MatchAll Query
        //    MatchAllQuery(otsClient);

        //    //MatchQuery
        //    MatchQuery(otsClient);

        //    //MatchPhraseQuery
        //    MatchPhraseQuery(otsClient);

        //    //RangeQuery
        //    RangeQuery(otsClient);

        //    //PrefixQuery
        //    PrefixQuery(otsClient);

        //    //TermQuery
        //    TermQuery(otsClient);

        //    //WildcardQuery
        //    WildcardQuery(otsClient);

        //    //BoolQuery
        //    BoolQuery(otsClient);

        //    Console.ReadLine();
        //}

        public static void CreateTable(OTSClient otsClient)
        {
            Console.WriteLine("\n Start create table...");
            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);

            Console.WriteLine("Table is created: " + TableName);
        }
Пример #28
0
        //static void Main(string[] args)
        //{
        //    Console.WriteLine("GlobalIndexSample");

        //    CreateTableWithGlobalIndex();

        //    CreateGlobalIndex();

        //    PutRow();

        //    GetRangeFromIndexTable();

        //    DeleteGlobalIndex();

        //    DeleteTable();

        //    Console.ReadLine();

        //}

        /// <summary>
        /// 创建一个带二级索引的表
        /// </summary>
        public static void CreateTableWithGlobalIndex()
        {
            //建主表,两列Pk:Pk1、Pk2。 预定义列:Col1、Col2。
            //建索引表,索引表中Col1放Pk0
            OTSClient otsClient = Config.GetClient();

            Console.WriteLine("Start create table with globalIndex...");
            PrimaryKeySchema primaryKeySchema = new PrimaryKeySchema
            {
                { Pk1, ColumnValueType.String },
                { Pk2, ColumnValueType.String }
            };
            TableMeta tableMeta = new TableMeta(TableName, primaryKeySchema);

            tableMeta.DefinedColumnSchema = new DefinedColumnSchema {
                { Col1, DefinedColumnType.STRING },
                { Col2, DefinedColumnType.STRING }
            };

            IndexMeta indexMeta = new IndexMeta(IndexName);

            indexMeta.PrimaryKey = new List <string>()
            {
                Col1
            };
            indexMeta.DefinedColumns = new List <string>()
            {
                Col2
            };
            //indexMeta.IndexType = IndexType.IT_GLOBAL_INDEX;
            //indexMeta.IndexUpdateModel = IndexUpdateMode.IUM_ASYNC_INDEX;

            List <IndexMeta> indexMetas = new List <IndexMeta>()
            {
            };

            indexMetas.Add(indexMeta);

            CapacityUnit       reservedThroughput = new CapacityUnit(0, 0);
            CreateTableRequest request            = new CreateTableRequest(tableMeta, reservedThroughput, indexMetas);

            otsClient.CreateTable(request);

            Console.WriteLine("Table is created: " + TableName);
        }
        private void CreateTable(OTSClient client, String tableName)
        {
            foreach (var tableItem in client.ListTable(new ListTableRequest()).TableNames)
            {
                client.DeleteTable(new DeleteTableRequest(tableItem));
            }
            var primaryKeySchema = new PrimaryKeySchema();

            primaryKeySchema.Add(COLUMN_GID_NAME, ColumnValueType.Integer);
            primaryKeySchema.Add(COLUMN_UID_NAME, ColumnValueType.Integer);
            var tableMeta          = new TableMeta(tableName, primaryKeySchema);
            var reservedThroughput = new CapacityUnit(0, 0);
            var request            = new CreateTableRequest(tableMeta, reservedThroughput);
            var response           = OTSClient.CreateTable(request);

            // 创建表只是提交请求,OTS创建表需要一段时间,这里是简单的sleep,请根据实际逻辑修改
            WaitForTableReady();
        }
        public void TestTooMuchColumnInPK()
        {
            var primaryKeySchema = new PrimaryKeySchema();
            var primaryKey       = new PrimaryKey();

            for (int i = 0; i < 1000; i++)
            {
                primaryKeySchema.Add("PK" + i, ColumnValueType.Integer);
                primaryKey.Add("PK" + i, new ColumnValue(123));
            }

            SetTestConext(pkSchema: primaryKeySchema, primaryKey: primaryKey,
                          endPrimaryKey: primaryKey,
                          allFailedMessage: "The number of primary key columns must be in range: [1, 4].");

            TestSingleAPI("CreateTable");
            CreateTestTableWith4PK();

            TestAllDataAPI(createTable: false);
        }