public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { var sides = EvaluateSides(binaryEpression); var newLeft = sides[0]; var newRight = sides[1]; return EvaluateBinary(newLeft, binaryEpression.ExpressionType, newRight); }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { var sides = EvaluateSides(binaryEpression); var newLeft = sides[0]; var newRight = sides[1]; return(EvaluateBinary(newLeft, binaryEpression.ExpressionType, newRight)); }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { Visit(binaryEpression.Left); var binaryOpString = GetBinaryOperatorString(binaryEpression.ExpressionType); builder.AppendFormat(" {0} ", binaryOpString); Visit(binaryEpression.Right); return binaryEpression; }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { Visit(binaryEpression.Left); var binaryOpString = GetBinaryOperatorString(binaryEpression.ExpressionType); builder.AppendFormat(" {0} ", binaryOpString); Visit(binaryEpression.Right); return(binaryEpression); }
internal SqlQuantifyExpression(SqlExpressionType expressionType, SqlBinaryExpression expression) : base(expressionType) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } if (!expression.ExpressionType.IsRelational()) { throw new ArgumentException("Cannot quantify a non-relational expression"); } Expression = expression; }
public virtual SqlExpression VisitBinary(SqlBinaryExpression expression) { var left = expression.Left; var right = expression.Right; if (left != null) { left = Visit(left); } if (right != null) { right = Visit(right); } return(SqlExpression.Binary(expression.ExpressionType, left, right)); }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { switch (binaryEpression.ExpressionType) { case SqlExpressionType.Add: case SqlExpressionType.Subtract: case SqlExpressionType.Multiply: case SqlExpressionType.Modulo: case SqlExpressionType.Divide: dataType = PrimitiveTypes.Numeric(); break; default: // we assume the expression type is already been check to be binary. dataType = PrimitiveTypes.Boolean(); break; } return base.VisitBinary(binaryEpression); }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { var sides = EvaluateSides(binaryEpression); var newLeft = sides[0]; var newRight = sides[1]; bool isAll = false, isAny = false; if (newRight is SqlQuantifiedExpression) { var quantified = (SqlQuantifiedExpression)newRight; isAll = quantified.ExpressionType == SqlExpressionType.All; isAny = quantified.ExpressionType == SqlExpressionType.Any; newRight = quantified.ValueExpression; } return(EvaluateBinary(newLeft, binaryEpression.ExpressionType, newRight, isAll, isAny)); }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { switch (binaryEpression.ExpressionType) { case SqlExpressionType.Add: case SqlExpressionType.Subtract: case SqlExpressionType.Multiply: case SqlExpressionType.Modulo: case SqlExpressionType.Divide: SetType(PrimitiveTypes.Numeric()); break; default: // we assume the expression type is already been check to be binary. SetType(PrimitiveTypes.Boolean()); break; } return(base.VisitBinary(binaryEpression)); }
private SqlExpression[] EvaluateSides(SqlBinaryExpression binary) { var info = new List <BinaryEvaluateInfo> { new BinaryEvaluateInfo { Expression = binary.Left, Offset = 0 }, new BinaryEvaluateInfo { Expression = binary.Right, Offset = 1 } }.OrderByDescending(x => x.Precedence); foreach (var evaluateInfo in info) { evaluateInfo.Expression = Visit(evaluateInfo.Expression); } return(info.OrderBy(x => x.Offset) .Select(x => x.Expression) .ToArray()); }
/// <summary> /// /// </summary> /// <param name="binaryEpression"></param> /// <returns></returns> public virtual SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { var left = binaryEpression.Left; var right = binaryEpression.Right; if (left != null) left = Visit(left); if (right != null) right = Visit(right); return SqlExpression.Binary(left, binaryEpression.ExpressionType, right); }
public StandardJoinPlan(QueryTablePlanner planner, SqlBinaryExpression expression, float optimizeFactor) : base(optimizeFactor) { this.planner = planner; this.expression = expression; }
public SimpleSubQueryPlan(QueryTablePlanner planner, SqlBinaryExpression expression) : base(0.3f) { this.planner = planner; this.expression = expression; }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { var op = binaryEpression.ExpressionType; // Evaluate to an object var value = binaryEpression.Right.EvaluateToConstant(context, null); // If the evaluated object is not of a comparable type, then it becomes // null. var fieldType = field.ColumnType; if (!value.Type.IsComparable(fieldType)) value = DataObject.Null(fieldType); // Intersect this in the range set indexRangeSet = indexRangeSet.Intersect(op, value); return base.VisitBinary(binaryEpression); }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { if (binaryEpression.ExpressionType == SqlExpressionType.And) { rangeSet = UpdateRange(binaryEpression.Left); rangeSet = UpdateRange(binaryEpression.Right); } else if (binaryEpression.ExpressionType == SqlExpressionType.Or) { var left = CalcExpression(binaryEpression.Left); var right = CalcExpression(binaryEpression.Right); rangeSet = rangeSet.Union(left); rangeSet = rangeSet.Union(right); } else { rangeSet = UpdateRange(binaryEpression); } return base.VisitBinary(binaryEpression); }
public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) { var sides = EvaluateSides(binaryEpression); var newLeft = sides[0]; var newRight = sides[1]; bool isAll = false, isAny = false; if (newRight is SqlQuantifiedExpression) { var quantified = (SqlQuantifiedExpression) newRight; isAll = quantified.ExpressionType == SqlExpressionType.All; isAny = quantified.ExpressionType == SqlExpressionType.Any; newRight = quantified.ValueExpression; } return EvaluateBinary(newLeft, binaryEpression.ExpressionType, newRight, isAll, isAny); }
private SqlExpression[] EvaluateSides(SqlBinaryExpression binary) { var info = new List<BinaryEvaluateInfo> { new BinaryEvaluateInfo {Expression = binary.Left, Offset = 0}, new BinaryEvaluateInfo {Expression = binary.Right, Offset = 1} }.OrderByDescending(x => x.Precedence); foreach (var evaluateInfo in info) { evaluateInfo.Expression = Visit(evaluateInfo.Expression); } return info.OrderBy(x => x.Offset) .Select(x => x.Expression) .ToArray(); }
public static SqlQuantifyExpression All(SqlBinaryExpression expression) => Quantify(SqlExpressionType.All, expression);
public static SqlQuantifyExpression Quantify(SqlExpressionType expressionType, SqlBinaryExpression expression) { if (!expressionType.IsQuantify()) { throw new ArgumentException($"The expression type {expressionType} is not a quantification expression"); } return(new SqlQuantifyExpression(expressionType, expression)); }
public static ITable SimpleJoin(this ITable thisTable, IQueryContext context, ITable other, SqlBinaryExpression binary) { var objRef = binary.Left as SqlReferenceExpression; if (objRef == null) throw new ArgumentException(); // Find the row with the name given in the condition. int lhsColumn = thisTable.FindColumn(objRef.ReferenceName); if (lhsColumn == -1) throw new Exception("Unable to find the LHS column specified in the condition: " + objRef.ReferenceName); // Create a variable resolver that can resolve columns in the destination // table. var resolver = other.GetVariableResolver(); // The join algorithm. It steps through the RHS expression, selecting the // cells that match the relation from the LHS table (this table). var thisRowSet = new List<int>(); var tableRowSet = new List<int>(); var e = other.GetEnumerator(); while (e.MoveNext()) { int rowIndex = e.Current.RowId.RowNumber; // Select all the rows in this table that match the joining condition. var selectedSet = thisTable.SelectRows(resolver, context, binary); var selectList = selectedSet.ToList(); var size = selectList.Count; // Include in the set. for (int i = 0; i < size; i++) { tableRowSet.Add(rowIndex); } thisRowSet.AddRange(selectList); } // Create the new VirtualTable with the joined tables. var tabs = new[] {thisTable, other}; var rowSets = new IList<int>[] {thisRowSet, tableRowSet}; return new VirtualTable(tabs, rowSets); }
public static IEnumerable<int> SelectRows(this ITable table, IVariableResolver resolver, IQueryContext context, SqlBinaryExpression expression) { var objRef = expression.Left as SqlReferenceExpression; if (objRef == null) throw new NotSupportedException(); var columnName = objRef.ReferenceName; var column = table.FindColumn(columnName); if (column < 0) throw new InvalidOperationException(); var reduced = expression.Right.Evaluate(context, resolver); if (reduced.ExpressionType != SqlExpressionType.Constant) throw new InvalidOperationException(); var value = ((SqlConstantExpression) reduced).Value; var binOperator = expression.ExpressionType; return table.SelectRows(column, binOperator, value); }