/// <summary> /// 单独在表上再创建一个索引表2 /// </summary> public static void CreateGlobalIndex() { OTSClient otsClient = Config.GetClient(); Console.WriteLine("Start create globalIndex..."); IndexMeta indexMeta = new IndexMeta(IndexName2); indexMeta.PrimaryKey = new List <string>() { Col2 }; indexMeta.DefinedColumns = new List <string>() { Pk1 }; CapacityUnit reservedThroughput = new CapacityUnit(0, 0); CreateGlobalIndexRequest request = new CreateGlobalIndexRequest(TableName, indexMeta); otsClient.CreateGlobalIndex(request); Console.WriteLine("Global Index is created,tableName: " + TableName + ",IndexName:" + IndexName2); }
protected ActionResult <IndexDto <TIndexDto> > Index(int page = 1, int limit = 100) { int offset = (page - 1) * limit; IEnumerable <TModel> projectsCollection = Repository.Index(offset, limit); int count = Repository.Count(); IndexMeta meta = new IndexMeta { Page = page, Limit = limit, Count = count, Resource = Resource }; IEnumerable <TIndexDto> data = Mapper.Map <IEnumerable <TIndexDto> >(projectsCollection); IndexDto <TIndexDto> dto = new IndexDto <TIndexDto>(data, meta); return(Ok(dto)); }
protected string BuildIndexName(IExprTableFullName tableIn, IndexMeta index) { if (index.Name != null && !string.IsNullOrEmpty(index.Name)) { return(index.Name); } var table = tableIn.AsExprTableFullName(); var schemaName = table.DbSchema != null?this.Options.MapSchema(table.DbSchema.Schema.Name) + "_" : null; var columns = string.Join("_", index.Columns.Select(c => c.Column.ColumnName.Name + (c.Descending ? "_DESC" : null))); return($"IX_{schemaName}{table.TableName.Name}_{columns}"); }
//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); }
protected void AppendIndexColumnList(IndexMeta tableIndex) { tableIndex.Columns.AssertNotEmpty("Table index has to contain at least one column"); this.Builder.Append('('); for (var index = 0; index < tableIndex.Columns.Count; index++) { var column = tableIndex.Columns[index]; if (index != 0) { this.Builder.Append(','); } column.Column.ColumnName.Accept(this.ExprBuilder, null); if (column.Descending) { this.Builder.Append(" DESC"); } } this.Builder.Append(')'); }
public CreateGlobalIndexRequest(string mainTableName, IndexMeta indexMeta) { this.MainTableName = mainTableName; this.IndexMeta = indexMeta; }
public IndexDto(IEnumerable <TDto> data, IndexMeta meta) { Data = data; Meta = meta; }
protected void BuildIndexAndConstraints(TableDef tableDefTmp, TableMeta tableMetaTmp, ref ArrayList indexList, ref ArrayList primaryKeyList, ref ArrayList uniqkeyList, ref ArrayList foreignKeyList) { // indexes, primaryKeyList, uniqkeyList; IndexDefCollection indexes = tableDefTmp.Indexes; foreach (IndexDef indxMixed in indexes) { if (ValidateVersion(indxMixed) == DDLActionEnum.NONE) // not in range! { continue; } if (indxMixed.Category == IndexCategoryEnum.NORMAL) { IndexMeta indexMetaTmp = new IndexMeta(indxMixed.IndexName, tableDefTmp.Name, _context); foreach (IndexColumn indCol in indxMixed.ColumnNames) { indexMetaTmp.GetColumnList().Add(indCol.ColumnName); } indexList.Add(indexMetaTmp); } else if (indxMixed.Category == IndexCategoryEnum.PRIMARYKEY) { PK_ConstraintAlter pkTmp = new PK_ConstraintAlter(tableMetaTmp, indxMixed.IndexName); foreach (IndexColumn indCol in indxMixed.ColumnNames) { pkTmp.GetColumnList().Add(indCol.ColumnName); } pkTmp.AlterAction = (int)DDLActionEnum.CREATE; primaryKeyList.Add(pkTmp); } else if (indxMixed.Category == IndexCategoryEnum.UNIQUEKEY) { UK_ConstraintAlter ukTmp = new UK_ConstraintAlter(tableMetaTmp, indxMixed.IndexName); foreach (IndexColumn indCol in indxMixed.ColumnNames) { ukTmp.GetColumnList().Add(indCol.ColumnName); } ukTmp.AlterAction = (int)DDLActionEnum.CREATE; uniqkeyList.Add(ukTmp); } } GlobalForeignKeyCollection gFrnKeys = tableDefTmp.GlobalTableForeignKeys; foreach (GlobalForeignKey fk in gFrnKeys) { if (ValidateVersion(fk) == DDLActionEnum.NONE) // not in range! { continue; } TableMeta refTable = new TableMeta(fk.ForeignTable, _context); FK_ConstraintAlter foreignKeyTmp = new FK_ConstraintAlter(tableMetaTmp, refTable, fk.Name); foreach (ForeignKeyColumn fkCol in fk.Columns) { foreignKeyTmp.GetColumnList().Add(fkCol.LocalColumn); foreignKeyTmp.GetRefColumnList().Add(fkCol.ForeignColumn); } foreignKeyTmp.AlterAction = (int)DDLActionEnum.CREATE; foreignKeyList.Add(foreignKeyTmp); } }