Ejemplo n.º 1
0
        public override IQueryState Visit(DistinctExpression exp)
        {
            IQueryState prevState = exp.PrevExpression.Accept(this);
            IQueryState state     = prevState.Accept(exp);

            return(state);
        }
        public override SqlFragment Visit(DistinctExpression expression)
        {
            SelectStatement select = VisitInputExpressionEnsureSelect(expression.Argument, null, null);

            select.IsDistinct = true;
            return(select);
        }
Ejemplo n.º 3
0
        private string Base(Expression exp)
        {
            var cached = (CachedExpression)exp;

            if (cached.Sql != null)
            {
                return(cached.Sql);
            }
            cached.Sql = exp switch
            {
                UnionExpression e => Union(e),
                SelectExpression e => Select(e),
                WhereExpression e => Where(e),
                MaxExpression e => Max(e),
                MinExpression e => Min(e),
                SumExpression e => Sum(e),
                CountExpression e => Count(e),
                TakeExpression e => Take(e),
                SkipExpression e => Skip(e),
                FirstExpression e => First(e),
                DistinctExpression e => Distinct(e),
                OrderByExpression e => OrderBy(e),
                OrderByDescendingExpression e => OrderByDescending(e),
                _ => throw new InvalidEnumArgumentException()
            };
            return(cached.Sql);
        }
        private void VisitDistinct(DistinctExpression node)
        {
            Visit(node.Source);

            var id = new BsonDocument("_id", AggregateLanguageTranslator.Translate(node.Selector));

            _stages.Add(new BsonDocument("$group", id));
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        protected override Expression VisitDistinct(DistinctExpression distinctExpression)
        {
            Check.NotNull(distinctExpression, nameof(distinctExpression));

            _relationalCommandBuilder.Append("DISTINCT (");
            Visit(distinctExpression.Operand);
            _relationalCommandBuilder.Append(")");

            return(distinctExpression);
        }
Ejemplo n.º 6
0
        public Expression Bind(ProjectionExpression projection, ProjectionBindingContext context, MethodCallExpression node, IEnumerable <Expression> arguments)
        {
            var distinct = new DistinctExpression(projection.Source, projection.Projector);

            var serializer = SerializerBuilder.Build(projection.Projector, context.SerializerRegistry);
            var info       = new BsonSerializationInfo("_id", serializer, serializer.ValueType);
            var projector  = new SerializationExpression(projection.Projector, info);

            return(new ProjectionExpression(
                       distinct,
                       projector));
        }
Ejemplo n.º 7
0
        protected override Expression VisitDistinct(DistinctExpression distinctExpression)
        {
            Check.NotNull(distinctExpression, nameof(distinctExpression));

            var parentOptimize = _optimize;

            _optimize = false;
            var operand = (SqlExpression)Visit(distinctExpression.Operand);

            _optimize = parentOptimize;

            return(ApplyConversion(distinctExpression.Update(operand), condition: false));
        }
Ejemplo n.º 8
0
        public virtual SqlExpression?ApplyTypeMapping(SqlExpression?sqlExpression, RelationalTypeMapping?typeMapping)
        {
#pragma warning disable IDE0046 // Convert to conditional expression
            if (sqlExpression == null
#pragma warning restore IDE0046 // Convert to conditional expression
                || sqlExpression.TypeMapping != null)
            {
                return(sqlExpression);
            }

            return(sqlExpression switch
            {
                CaseExpression e => ApplyTypeMappingOnCase(e, typeMapping),
                CollateExpression e => ApplyTypeMappingOnCollate(e, typeMapping),
                DistinctExpression e => ApplyTypeMappingOnDistinct(e, typeMapping),
                LikeExpression e => ApplyTypeMappingOnLike(e),
                SqlBinaryExpression e => ApplyTypeMappingOnSqlBinary(e, typeMapping),
                SqlUnaryExpression e => ApplyTypeMappingOnSqlUnary(e, typeMapping),
                SqlConstantExpression e => e.ApplyTypeMapping(typeMapping),
                SqlFragmentExpression e => e,
                SqlFunctionExpression e => e.ApplyTypeMapping(typeMapping),
                SqlParameterExpression e => e.ApplyTypeMapping(typeMapping),
                _ => sqlExpression
            });
Ejemplo n.º 9
0
        public IQuery <T> Distinct()
        {
            DistinctExpression e = new DistinctExpression(typeof(T), this._expression);

            return(new Query <T>(this._dbContext, e, this._trackEntity));
        }
Ejemplo n.º 10
0
        public virtual IQueryState Accept(DistinctExpression exp)
        {
            DistinctQueryState state = new DistinctQueryState(this.Result);

            return(state);
        }
Ejemplo n.º 11
0
        private bool ParseRelationalOperatorIfExists(Lexer lexer, Token token, Attributes attributes)
        {
            var successfullyParsed = true;

            successfullyParsed &= ParseAdditionOrSubstractionIfExists(lexer, token, attributes);

            if (lexer.GetCurrentToken().Is(TokenType.EqualOperator) ||
                lexer.GetCurrentToken().Is(TokenType.GreaterThanOperator) ||
                lexer.GetCurrentToken().Is(TokenType.GreaterThanOrEqualOperator) ||
                lexer.GetCurrentToken().Is(TokenType.LessThanOperator) ||
                lexer.GetCurrentToken().Is(TokenType.LessThanOrEqualOperator) ||
                lexer.GetCurrentToken().Is(TokenType.DistinctOperator))
            {
                BinaryExpression tree;

                if (lexer.GetCurrentToken().Is(TokenType.EqualOperator))
                {
                    tree = new EqualExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.GreaterThanOperator))
                {
                    tree = new GreaterThanExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.GreaterThanOrEqualOperator))
                {
                    tree = new GreaterThanOrEqualExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.LessThanOperator))
                {
                    tree = new LessThanExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.LessThanOrEqualOperator))
                {
                    tree = new LessThanOrEqualExpression();
                }
                else
                {
                    tree = new DistinctExpression();
                }

                tree.LeftOperand    = attributes["EXP"] as Expression;
                successfullyParsed &= ParseAdditionOrSubstractionIfExists(lexer, lexer.GetNextToken(), attributes);
                tree.RightOperand   = attributes["EXP"] as Expression;

                // SEM: Sólo pueden compararse expresiones del mismo tipo
                if (tree.LeftOperand.Type != tree.RightOperand.Type)
                {
                    LogTypeMismatch(lexer.GetCurrentToken(), tree.LeftOperand.Type, tree.RightOperand.Type);
                    successfullyParsed = false;
                }
                // SEM: Las comparaciones de tipo >, >=, <, <= sólo pueden realizarse entre enteros
                else if (!lexer.GetCurrentToken().Is(TokenType.EqualOperator) &&
                         !lexer.GetCurrentToken().Is(TokenType.DistinctOperator) && tree.LeftOperand.Type != DataType.Integer)
                {
                    LogTypeExpressionInvalid(lexer.GetCurrentToken(), DataType.Integer, tree.LeftOperand.Type);
                    successfullyParsed = false;
                }

                attributes["EXP"] = tree;
            }

            return(successfullyParsed);
        }
Ejemplo n.º 12
0
        public override IQueryState Accept(DistinctExpression exp)
        {
            IQueryState state = this.AsSubQueryState();

            return(state.Accept(exp));
        }
Ejemplo n.º 13
0
        public override JoinQueryResult Visit(DistinctExpression exp)
        {
            JoinQueryResult ret = this.Visit(exp);

            return(ret);
        }
 public override SqlFragment Visit(DistinctExpression expression)
 {
     SelectStatement select = VisitInputExpressionEnsureSelect(expression.Argument, null, null);
     select.IsDistinct = true;
     return select;
 }
 protected abstract Expression VisitDistinct([NotNull] DistinctExpression distinctExpression);
 protected override Expression VisitDistinct([NotNullAttribute] DistinctExpression distinctExpression)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     Visits the children of the distinct expression.
 /// </summary>
 /// <param name="distinctExpression"> The expression to visit. </param>
 /// <returns> The modified expression, if it or any subexpression was modified; otherwise, returns the original expression. </returns>
 protected abstract Expression VisitDistinct(DistinctExpression distinctExpression);