protected override NodeInfo VisitJoinOp(JoinBaseOp op, Node n) { if (op.OpType != OpType.InnerJoin && op.OpType != OpType.LeftOuterJoin && op.OpType != OpType.FullOuterJoin) { return(this.Unimplemented(n)); } ExtendedNodeInfo extendedNodeInfo1 = this.InitExtendedNodeInfo(n); ExtendedNodeInfo extendedNodeInfo2 = this.GetExtendedNodeInfo(n.Child0); ExtendedNodeInfo extendedNodeInfo3 = this.GetExtendedNodeInfo(n.Child1); NodeInfo nodeInfo = this.GetNodeInfo(n.Child2); extendedNodeInfo1.Definitions.Or(extendedNodeInfo2.Definitions); extendedNodeInfo1.Definitions.Or(extendedNodeInfo3.Definitions); extendedNodeInfo1.ExternalReferences.Or(extendedNodeInfo2.ExternalReferences); extendedNodeInfo1.ExternalReferences.Or(extendedNodeInfo3.ExternalReferences); extendedNodeInfo1.ExternalReferences.Or(nodeInfo.ExternalReferences); extendedNodeInfo1.ExternalReferences.Minus(extendedNodeInfo1.Definitions); extendedNodeInfo1.Keys.InitFrom(extendedNodeInfo2.Keys, extendedNodeInfo3.Keys); if (op.OpType == OpType.InnerJoin || op.OpType == OpType.LeftOuterJoin) { extendedNodeInfo1.NonNullableDefinitions.InitFrom(extendedNodeInfo2.NonNullableDefinitions); } if (op.OpType == OpType.InnerJoin) { extendedNodeInfo1.NonNullableDefinitions.Or(extendedNodeInfo3.NonNullableDefinitions); } extendedNodeInfo1.NonNullableVisibleDefinitions.InitFrom(extendedNodeInfo2.NonNullableDefinitions); extendedNodeInfo1.NonNullableVisibleDefinitions.Or(extendedNodeInfo3.NonNullableDefinitions); RowCount minRows; RowCount maxRows; if (op.OpType == OpType.FullOuterJoin) { minRows = RowCount.Zero; maxRows = RowCount.Unbounded; } else { maxRows = extendedNodeInfo2.MaxRows > RowCount.One || extendedNodeInfo3.MaxRows > RowCount.One ? RowCount.Unbounded : RowCount.One; minRows = op.OpType != OpType.LeftOuterJoin ? RowCount.Zero : extendedNodeInfo2.MinRows; } extendedNodeInfo1.SetRowCount(minRows, maxRows); return((NodeInfo)extendedNodeInfo1); }
public override NodeInfo Visit(FilterOp op, Node n) { ExtendedNodeInfo extendedNodeInfo1 = this.InitExtendedNodeInfo(n); ExtendedNodeInfo extendedNodeInfo2 = this.GetExtendedNodeInfo(n.Child0); NodeInfo nodeInfo = this.GetNodeInfo(n.Child1); extendedNodeInfo1.Definitions.Or(extendedNodeInfo2.Definitions); extendedNodeInfo1.ExternalReferences.Or(extendedNodeInfo2.ExternalReferences); extendedNodeInfo1.ExternalReferences.Or(nodeInfo.ExternalReferences); extendedNodeInfo1.ExternalReferences.Minus(extendedNodeInfo2.Definitions); extendedNodeInfo1.Keys.InitFrom(extendedNodeInfo2.Keys); extendedNodeInfo1.NonNullableDefinitions.InitFrom(extendedNodeInfo2.NonNullableDefinitions); extendedNodeInfo1.NonNullableVisibleDefinitions.InitFrom(extendedNodeInfo2.NonNullableDefinitions); extendedNodeInfo1.MinRows = RowCount.Zero; ConstantPredicateOp op1 = n.Child1.Op as ConstantPredicateOp; extendedNodeInfo1.MaxRows = op1 == null || !op1.IsFalse ? extendedNodeInfo2.MaxRows : RowCount.Zero; return((NodeInfo)extendedNodeInfo1); }
protected override NodeInfo VisitSortOp(SortBaseOp op, Node n) { ExtendedNodeInfo extendedNodeInfo1 = this.InitExtendedNodeInfo(n); ExtendedNodeInfo extendedNodeInfo2 = this.GetExtendedNodeInfo(n.Child0); extendedNodeInfo1.Definitions.Or(extendedNodeInfo2.Definitions); extendedNodeInfo1.ExternalReferences.Or(extendedNodeInfo2.ExternalReferences); extendedNodeInfo1.ExternalReferences.Minus(extendedNodeInfo2.Definitions); extendedNodeInfo1.Keys.InitFrom(extendedNodeInfo2.Keys); extendedNodeInfo1.NonNullableDefinitions.InitFrom(extendedNodeInfo2.NonNullableDefinitions); extendedNodeInfo1.NonNullableVisibleDefinitions.InitFrom(extendedNodeInfo2.NonNullableDefinitions); extendedNodeInfo1.InitRowCountFrom(extendedNodeInfo2); if (OpType.ConstrainedSort == op.OpType && n.Child2.Op.OpType == OpType.Constant && !((ConstrainedSortOp)op).WithTies) { ConstantBaseOp op1 = (ConstantBaseOp)n.Child2.Op; if (TypeHelpers.IsIntegerConstant(op1.Type, op1.Value, 1L)) { extendedNodeInfo1.SetRowCount(RowCount.Zero, RowCount.One); } } return((NodeInfo)extendedNodeInfo1); }
public override NodeInfo Visit(DistinctOp op, Node n) { ExtendedNodeInfo extendedNodeInfo1 = this.InitExtendedNodeInfo(n); extendedNodeInfo1.Keys.InitFrom((IEnumerable <Var>)op.Keys, true); ExtendedNodeInfo extendedNodeInfo2 = this.GetExtendedNodeInfo(n.Child0); extendedNodeInfo1.ExternalReferences.InitFrom(extendedNodeInfo2.ExternalReferences); foreach (Var key in op.Keys) { if (extendedNodeInfo2.Definitions.IsSet(key)) { extendedNodeInfo1.Definitions.Set(key); } else { extendedNodeInfo1.ExternalReferences.Set(key); } } extendedNodeInfo1.NonNullableDefinitions.InitFrom(extendedNodeInfo2.NonNullableDefinitions); extendedNodeInfo1.NonNullableDefinitions.And(op.Keys); extendedNodeInfo1.InitRowCountFrom(extendedNodeInfo2); return((NodeInfo)extendedNodeInfo1); }
public override NodeInfo Visit(UnnestOp op, Node n) { ExtendedNodeInfo extendedNodeInfo = this.InitExtendedNodeInfo(n); foreach (Var column in (List <Var>)op.Table.Columns) { extendedNodeInfo.LocalDefinitions.Set(column); extendedNodeInfo.Definitions.Set(column); } if (n.Child0.Op.OpType == OpType.VarDef && n.Child0.Child0.Op.OpType == OpType.Function && (op.Table.Keys.Count > 0 && op.Table.ReferencedColumns.Subsumes(op.Table.Keys))) { extendedNodeInfo.Keys.InitFrom((IEnumerable <Var>)op.Table.Keys); } if (n.HasChild0) { NodeInfo nodeInfo = this.GetNodeInfo(n.Child0); extendedNodeInfo.ExternalReferences.Or(nodeInfo.ExternalReferences); } else { extendedNodeInfo.ExternalReferences.Set(op.Var); } return((NodeInfo)extendedNodeInfo); }
/// <summary> /// Initialize the rowcounts for this node from the source node /// </summary> /// <param name="source"> nodeinfo of source </param> internal void InitRowCountFrom(ExtendedNodeInfo source) { m_minRows = source.m_minRows; m_maxRows = source.m_maxRows; }
protected override NodeInfo VisitSetOp(SetOp op, Node n) { ExtendedNodeInfo extendedNodeInfo1 = this.InitExtendedNodeInfo(n); extendedNodeInfo1.Definitions.InitFrom(op.Outputs); extendedNodeInfo1.LocalDefinitions.InitFrom(op.Outputs); ExtendedNodeInfo extendedNodeInfo2 = this.GetExtendedNodeInfo(n.Child0); ExtendedNodeInfo extendedNodeInfo3 = this.GetExtendedNodeInfo(n.Child1); RowCount rowCount = RowCount.Zero; extendedNodeInfo1.ExternalReferences.Or(extendedNodeInfo2.ExternalReferences); extendedNodeInfo1.ExternalReferences.Or(extendedNodeInfo3.ExternalReferences); if (op.OpType == OpType.UnionAll) { rowCount = extendedNodeInfo2.MinRows > extendedNodeInfo3.MinRows ? extendedNodeInfo2.MinRows : extendedNodeInfo3.MinRows; } if (op.OpType == OpType.Intersect || op.OpType == OpType.Except) { extendedNodeInfo1.Keys.InitFrom((IEnumerable <Var>)op.Outputs); } else { UnionAllOp unionAllOp = (UnionAllOp)op; if (unionAllOp.BranchDiscriminator == null) { extendedNodeInfo1.Keys.NoKeys = true; } else { VarVec varVec = this.m_command.CreateVarVec(); for (int index = 0; index < n.Children.Count; ++index) { ExtendedNodeInfo extendedNodeInfo4 = n.Children[index].GetExtendedNodeInfo(this.m_command); if (!extendedNodeInfo4.Keys.NoKeys && !extendedNodeInfo4.Keys.KeyVars.IsEmpty) { VarVec other = extendedNodeInfo4.Keys.KeyVars.Remap((Dictionary <Var, Var>)unionAllOp.VarMap[index].GetReverseMap()); varVec.Or(other); } else { varVec.Clear(); break; } } if (varVec.IsEmpty) { extendedNodeInfo1.Keys.NoKeys = true; } else { extendedNodeInfo1.Keys.InitFrom((IEnumerable <Var>)varVec); } } } VarVec other1 = extendedNodeInfo2.NonNullableDefinitions.Remap((Dictionary <Var, Var>)op.VarMap[0].GetReverseMap()); extendedNodeInfo1.NonNullableDefinitions.InitFrom(other1); if (op.OpType != OpType.Except) { VarVec other2 = extendedNodeInfo3.NonNullableDefinitions.Remap((Dictionary <Var, Var>)op.VarMap[1].GetReverseMap()); if (op.OpType == OpType.Intersect) { extendedNodeInfo1.NonNullableDefinitions.Or(other2); } else { extendedNodeInfo1.NonNullableDefinitions.And(other2); } } extendedNodeInfo1.NonNullableDefinitions.And(op.Outputs); extendedNodeInfo1.MinRows = rowCount; return((NodeInfo)extendedNodeInfo1); }