public AlgebraNodeTree(Table t, string[] projections, string[] selections) { head = new AlgebraNode(t, "pure"); if (selections.Length > 0) { foreach (string selection in selections) { var algebraNode = head; AlgebraNode n = new AlgebraNode(RelationalAlgebraModule.Selection, new [] { selection }, algebraNode); head = n; } } if (projections.Length > 0) { var algebraNode = head; AlgebraNode p = new AlgebraNode(RelationalAlgebraModule.Projection, projections, algebraNode); head = p; } PrintTree(); successfulParse = true; }
public AlgebraNodeTree(Database db, string[] projections, string[] selections, string tableInfo) { successfulParse = false; Parser joinParser = new Parser(tableInfo, Parser.ReadOptions.STRING); ParseTree joinInfoTree = new ParseTree(joinParser.ParseJoinInfoFull); Dictionary <string, AlgebraNode> nameToAlgebraNode = new Dictionary <string, AlgebraNode>(); if (joinInfoTree.successfulParse) // creates join tree, unless there are no joins //joinInfoTree.PrintTree(); { List <ParseNode> tableNames = joinInfoTree.GetAllOfType("<table_name>"); Table[] tables = new Table[tableNames.Count]; int index = 0; foreach (ParseNode tableName in tableNames) { string name = tableName[0][0].Data; Table tb; if (CommandInterpreter.variables.ContainsKey(name)) { tb = CommandInterpreter.variables[name].Data as Table; } else { tb = db[name]; } tables[index] = tb; if (tables[index] == null) { return; } index++; } foreach (Table table in tables) { nameToAlgebraNode.Add(table.Name, new AlgebraNode(table)); } AlgebraNode fixedJoins = ConvertJoinInfoFullIntoMultiplesJoinInfoString(joinInfoTree.Head, nameToAlgebraNode); if (fixedJoins == null) { return; } head = fixedJoins; } else { Table tb; if (CommandInterpreter.variables.ContainsKey(tableInfo)) { tb = CommandInterpreter.variables[tableInfo].Data as Table; } else { tb = db[tableInfo]; } if (tb == null) { return; } head = new AlgebraNode(tb, "pure"); } head.PrintTree(); head.EnforceParenthood(); if (selections.Length > 0) { foreach (string selection in selections) { var algebraNode = head; Regex namedSelectionStyle = new Regex("\\w*\\.\\w*=\"?\\w*\"?"); if (namedSelectionStyle.IsMatch(selection)) { string tableName = selection.Split('.')[0]; var originalNode = nameToAlgebraNode[tableName]; var originalParent = originalNode.Parent; AlgebraNode n = new AlgebraNode(RelationalAlgebraModule.Selection, new [] { selection }, originalNode); originalParent.ReplaceChild(originalNode, n); //originalNode.Options = new []{"pure"}; originalParent.PrintTree(); } else { AlgebraNode n = new AlgebraNode(RelationalAlgebraModule.Selection, new [] { selection }, algebraNode); head = n; } head.PrintTree(); } } if (projections.Length > 0) { var algebraNode = head; AlgebraNode p = new AlgebraNode(RelationalAlgebraModule.Projection, projections, algebraNode); head = p; } PrintTree(); successfulParse = true; }