static IEnumerable <TupBase> While(CommonHeading heading, IEnumerable <TupBase> body, Func <RelNode, RelNode> func) { var stack = new Stack <TupBase>(body); var hash = new HashSet <TupBase>(); while (stack.Count > 0) { var top = stack.Pop(); if (!hash.Contains(top)) { hash.Add(top); var result = func(new WrapperNode(heading, Enumerable.Repeat(top, 1))); var eq = result.Heading.IsEqual(heading); var map = heading.CreateMap(result.Heading); if (result.Heading.Degree != heading.Degree || map.Any(x => x < 0)) { throw Error.Fatal("While", $"heading mismatch: {result.Heading} {heading}"); } // convert compatible if needed foreach (var t in result) { stack.Push(eq ? t : RelStatic.CreateByMap <Tup>(t, map)); } } } return(hash); }
public RenameNode(RelNode source, CommonHeading nodeheading) { _source = source; _nodeheading = nodeheading; _map = _nodeheading.CreateMap(_source.Heading); if (!(_map.Length == 2 && _map[0] >= 0 && _map[1] < 0)) { throw Error.Fatal("Rename", "heading is invalid"); } Heading = _source.Heading.Rename(_nodeheading[0], _nodeheading[1]); }
public RestrictNode(RelNode source, CommonHeading nodeheading, RelFuncBase func) { _source = source; _restheading = nodeheading; _restfunc = func; Heading = _source.Heading; _restmap = _restheading.CreateMap(Heading); if (_restmap.Any(x => x < 0)) { throw Error.Fatal("Restrict", "heading has unknown attribute"); } }
public AggregateNode(RelNode source, CommonHeading nodeheading, RelFuncBase func, object initial = null) { _source = source; _heading = nodeheading; _func = func; _initial = initial; Heading = _source.Heading.Rename(_heading[0], _heading[1]); _vmap = _heading.CreateMap(_source.Heading); _jhead = _source.Heading.Minus(_heading); _jmap1 = _jhead.CreateMap(_source.Heading); _jmap2 = Heading.CreateMap(_jhead); if (!(_heading.Degree == 2 && _jmap2.Length == Heading.Degree)) { throw Error.Fatal("Aggregate", "heading is not valid"); } }
public UngroupNode(RelNode source, UngroupingOp op, CommonHeading nodeheading) { _source = source; _op = op; _nodeheading = nodeheading; _nodemap = _nodeheading.CreateMap(_source.Heading); if (!(_nodemap.Length == 1 && _nodemap[0] >= 0)) { throw Error.Fatal("Ungroup", "heading is not valid"); } // on output replace one field by the TVA/RVA Heading = _source.Heading.Remove(_nodeheading[0]).Append(_nodeheading[0].Fields); // var tupheading = CommonHeading.Create(_nodeheading[0].Fields); _map1 = Heading.CreateMap(_source.Heading); _map2 = Heading.CreateMap(tupheading); }
public ExtendNode(RelNode source, CommonHeading nodeheading, RelFuncBase func) { _source = source; _nodeheading = nodeheading; _func = func; Heading = CommonHeading.Create(_source.Heading.Fields.Union(_nodeheading.Fields)); // get the argument fields _argheading = CommonHeading.Create(_nodeheading.Fields.Take(_nodeheading.Fields.Length - 1)); _argmap = _argheading.CreateMap(_source.Heading); // last field can extend or replace, remove name but retain place var outh = Heading.Rename(_nodeheading.Fields.Last(), CommonField.Empty); _outmap = Heading.CreateMap(outh); if (_argmap.Any(x => x < 0)) { throw Error.Fatal("Extend", "heading has unknown attribute"); } if (_outmap.Count(x => x < 0) != 1) { throw Error.Fatal("Extend", "invalid heading, invalid new attribute"); // any use? } }