/// <summary> /// Does this predicate preserve nulls on the specified columns of the table? /// If any of the columns participates in a comparison predicate, or in a /// not-null predicate, then, nulls are not preserved /// </summary> /// <param name="simplePredNode">the "simple" predicate node</param> /// <param name="tableColumns">list of table columns</param> /// <returns>true, if nulls are preserved</returns> private static bool PreservesNulls(Node simplePredNode, VarVec tableColumns) { VarRefOp varRefOp; switch (simplePredNode.Op.OpType) { case OpType.EQ: case OpType.NE: case OpType.GT: case OpType.GE: case OpType.LT: case OpType.LE: varRefOp = simplePredNode.Child0.Op as VarRefOp; if (varRefOp != null && tableColumns.IsSet(varRefOp.Var)) { return(false); } varRefOp = simplePredNode.Child1.Op as VarRefOp; if (varRefOp != null && tableColumns.IsSet(varRefOp.Var)) { return(false); } return(true); case OpType.Not: if (simplePredNode.Child0.Op.OpType != OpType.IsNull) { return(true); } varRefOp = simplePredNode.Child0.Child0.Op as VarRefOp; return(varRefOp == null || !tableColumns.IsSet(varRefOp.Var)); case OpType.Like: // If the predicate is "column LIKE constant ...", then the // predicate does not preserve nulls ConstantBaseOp constantOp = simplePredNode.Child1.Op as ConstantBaseOp; if (constantOp == null || (constantOp.OpType == OpType.Null)) { return(true); } varRefOp = simplePredNode.Child0.Op as VarRefOp; if (varRefOp != null && tableColumns.IsSet(varRefOp.Var)) { return(false); } return(true); default: return(true); } }
protected override void VisitConstantOp(ConstantBaseOp op, Node n) { using (new AutoString(this, op)) { if (null == op.Value) { WriteString("null"); } else { WriteString("("); WriteString(op.Type.EdmType.FullName); WriteString(")"); WriteString(String.Format(CultureInfo.InvariantCulture, "{0}", op.Value)); } VisitChildren(n); } }
private static bool PreservesNulls(System.Data.Entity.Core.Query.InternalTrees.Node simplePredNode, VarVec tableColumns) { switch (simplePredNode.Op.OpType) { case OpType.GT: case OpType.GE: case OpType.LE: case OpType.LT: case OpType.EQ: case OpType.NE: VarRefOp op1 = simplePredNode.Child0.Op as VarRefOp; if (op1 != null && tableColumns.IsSet(op1.Var)) { return(false); } VarRefOp op2 = simplePredNode.Child1.Op as VarRefOp; return(op2 == null || !tableColumns.IsSet(op2.Var)); case OpType.Like: ConstantBaseOp op3 = simplePredNode.Child1.Op as ConstantBaseOp; if (op3 == null || op3.OpType == OpType.Null) { return(true); } VarRefOp op4 = simplePredNode.Child0.Op as VarRefOp; return(op4 == null || !tableColumns.IsSet(op4.Var)); case OpType.Not: if (simplePredNode.Child0.Op.OpType != OpType.IsNull) { return(true); } VarRefOp op5 = simplePredNode.Child0.Child0.Op as VarRefOp; if (op5 != null) { return(!tableColumns.IsSet(op5.Var)); } return(true); default: return(true); } }
/// <summary> /// Copies a ConstantOp /// </summary> /// <param name="op">The Op to Copy</param> /// <param name="n">The Node that references the Op</param> /// <returns>A copy of the original Node that references a copy of the original Op</returns> public override Node Visit(ConstantOp op, Node n) { ConstantBaseOp newOp = m_destCmd.CreateConstantOp(op.Type, op.Value); return(m_destCmd.CreateNode(newOp)); }