public void Project() { TableDefinition productsTable = new TableDefinition() { Name = "Product" }; productsTable.Add(new AttributeDefinition() { Name = "Maker", Type = ValueType.String }); productsTable.Add(new AttributeDefinition() { Name = "Model", Type = ValueType.String }); productsTable.Add(new AttributeDefinition() { Name = "Type", Type = ValueType.String }); Set products = new Set(productsTable); products.Add(new object[] { "A", "10001", "PC" }); products.Add(new object[] { "B", "10001", "PC" }); Set projection = products.Projection(new List <string> { "Maker" }); Assert.AreEqual(2, projection.Count()); Assert.AreEqual(1, projection.First().Entries.Count); Assert.IsTrue(projection.First().Entries[0].AttributeDefinition.Name == "Maker"); }
public void Union() { TableDefinition productsTable = new TableDefinition() { Name = "Product" }; productsTable.Add(new AttributeDefinition() { Name = "Maker", Type = ValueType.String }); productsTable.Add(new AttributeDefinition() { Name = "Model", Type = ValueType.String }); productsTable.Add(new AttributeDefinition() { Name = "Type", Type = ValueType.String }); Set products1 = new Set(productsTable); products1.Add(new object[] { "A", "10001", "PC" }); products1.Add(new object[] { "B", "10001", "PC" }); Set products2 = new Set(productsTable); products2.Add(new object[] { "C", "10003", "Laptop" }); Set union = products1.Union(products2); Assert.AreEqual(3, union.Count()); }
public void Intersect() { new LexicalAnalyzer(LexicalLanguage.GetLanguage(), "\"AMD\"").GetNextToken(); TableDefinition productsTable = new TableDefinition() { Name = "Product" }; productsTable.Add(new AttributeDefinition() { Name = "Maker", Type = ValueType.String }); productsTable.Add(new AttributeDefinition() { Name = "Model", Type = ValueType.String }); productsTable.Add(new AttributeDefinition() { Name = "Type", Type = ValueType.String }); Set products1 = new Set(productsTable); products1.Add(new object[] { "A", "10001", "PC" }); products1.Add(new object[] { "B", "10001", "PC" }); products1.Add(new object[] { "B", "10002", "PC" }); products1.Add(new object[] { "B", "10002", "Laptop" }); Set products2 = new Set(productsTable); products2.Add(new object[] { "A", "10001", "PC" }); products2.Add(new object[] { "B", "10002", "Laptop" }); products2.Add(new object[] { "C", "10003", "Laptop" }); Set intersection = products1.Intersect(products2); Assert.AreEqual(2, intersection.Count()); }
private void LoadRelationsFromStorage() { foreach (CustomTuple tableTuple in Program.ExecuteQuery("SELECT * FROM Tables")) { TableDefinition tableDefinition = tableTuple.ToModel <TableDefinition>(); foreach (CustomTuple columnTuple in Program.ExecuteQuery("SELECT * FROM Columns WHERE RelationId = " + tableDefinition.Id)) { tableDefinition.Add(columnTuple.ToModel <AttributeDefinition>()); } foreach (CustomTuple indexTuple in Program.ExecuteQuery("SELECT * FROM Indexes WHERE RelationId = " + tableDefinition.Id)) { Index index = indexTuple.ToModel <Index>(); tableDefinition.AddIndex(index); } tableDefinition.SyncRelation(); Relations.Add(tableDefinition); Tables.Add(new Table(this, _memoryManager, tableDefinition, new Pointer(tableDefinition.RootBlockId))); } }
private void LoadDefaultRelations() { foreach (int valueId in Enum.GetValues(typeof(ValueType))) { CreateIndexRelation((ValueType)valueId); } TableDefinition TablesTable = new TableDefinition() { Name = "Tables", Id = 4 }; TablesTable.Add(new AttributeDefinition() { Name = "Id", Type = ValueType.Integer }); TablesTable.Add(new AttributeDefinition() { Name = "Name", Type = ValueType.String }); TablesTable.Add(new AttributeDefinition() { Name = "RootBlockId", Type = ValueType.UnsignedInteger }); TablesTable.SyncRelation(); Relations.Add(TablesTable); TableDefinition ColumnsTable = new TableDefinition() { Name = "Columns", Id = 5 }; ColumnsTable.Add(new AttributeDefinition() { Name = "RelationId", Type = ValueType.Integer }); ColumnsTable.Add(new AttributeDefinition() { Name = "Type", Type = ValueType.Integer }); ColumnsTable.Add(new AttributeDefinition() { Name = "Name", Type = ValueType.String }); ColumnsTable.SyncRelation(); Relations.Add(ColumnsTable); TableDefinition IndexesTable = new TableDefinition() { Name = "Indexes", Id = 6 }; IndexesTable.Add(new AttributeDefinition() { Name = "RelationId", Type = ValueType.Integer }); IndexesTable.Add(new AttributeDefinition() { Name = "IsClustered", Type = ValueType.Boolean }); IndexesTable.Add(new AttributeDefinition() { Name = "Column", Type = ValueType.String }); IndexesTable.Add(new AttributeDefinition() { Name = "RootBlockId", Type = ValueType.UnsignedInteger }); IndexesTable.SyncRelation(); Relations.Add(IndexesTable); //TableDefinition StatisticsTable = new TableDefinition() //{ // Name = "Indexes", // Id = 7 //}; //StatisticsTable.Add(new AttributeDefinition() { Name = "RelationId", Type = ValueType.Integer }); //StatisticsTable.Add(new AttributeDefinition() { Name = "TotalSize", Type = ValueType.Integer }); //StatisticsTable.Add(new AttributeDefinition() { Name = "Column", Type = ValueType.String }); //StatisticsTable.Add(new AttributeDefinition() { Name = "RootBlockId", Type = ValueType.UnsignedInteger }); //Relations.Add(StatisticsTable); Table tablesTable = new Table(this, _memoryManager, TablesTable, new Pointer(1, 0)); Tables.Add(tablesTable); Table columnsTable = new Table(this, _memoryManager, ColumnsTable, new Pointer(2, 0)); Tables.Add(columnsTable); Table indexesTable = new Table(this, _memoryManager, IndexesTable, new Pointer(3, 0)); Tables.Add(indexesTable); //Table statisticsTable = new Table(this, _memoryManager, StatisticsTable, new Pointer(4, 0)); //Tables.Add(statisticsTable); }