示例#1
0
        /// <summary>
        /// Combines elements from both collections into one without eliminating duplicates.
        /// </summary>
        /// <param name="collection">The input collection for the union all operation</param>
        /// <returns>Combined elements from both collections.</returns>
        public QueryCollectionValue UnionAll(QueryCollectionValue collection)
        {
            List <QueryValue> resultValues = new List <QueryValue>();

            resultValues.AddRange(this.Elements);
            resultValues.AddRange(collection.Elements);
            return(new QueryCollectionValue(this.Type, this.EvaluationStrategy, QueryError.GetErrorFromValues(resultValues), resultValues));
        }
示例#2
0
        /// <summary>
        /// Checks if both input collections have common elements
        /// </summary>
        /// <param name="collection">The input collection for the overlaps operation</param>
        /// <returns>A true if both collections have common elements</returns>
        public QueryScalarValue Overlaps(QueryCollectionValue collection)
        {
            IEnumerable <QueryValue> intersectingElements = this.Intersect(collection).Elements;

            if (intersectingElements.Count() > 0)
            {
                return(this.EvaluationStrategy.BooleanType.CreateValue(true));
            }

            return(this.EvaluationStrategy.BooleanType.CreateValue(false));
        }
示例#3
0
        private QueryStructuralValue CreateGroupingValue(QueryValue key, QueryCollectionValue elements)
        {
            QueryGroupingType groupingType = new QueryGroupingType(key.Type, elements.Type.ElementType, key.Type.EvaluationStrategy);

            var error  = QueryError.GetErrorFromValues(elements.Elements.Concat(new[] { key }));
            var result = new QueryStructuralValue(groupingType, false, error, groupingType.EvaluationStrategy);

            result.SetValue("Key", key);
            result.SetValue("Elements", elements);

            return(result);
        }
示例#4
0
        /// <summary>
        /// Determines if the current value is of a given type or an equivalent type in the type hierarchy
        /// </summary>
        /// <param name="resultType">The type to compare against</param>
        /// <param name="performExactMatch">A flag that determines if an exact match needs to be performed</param>
        /// <returns>The elements from the collection, that match the input type or an equivalent type</returns>
        public QueryValue OfType(QueryStructuralType resultType, bool performExactMatch)
        {
            QueryCollectionValue result = resultType.CreateCollectionType().CreateCollectionWithValues(Enumerable.Empty <QueryValue>());

            if (!this.IsNull)
            {
                foreach (QueryStructuralValue element in this.Elements)
                {
                    bool isOfEquivalentType = (bool)((QueryScalarValue)element.IsOf(resultType, performExactMatch)).Value;
                    if (isOfEquivalentType)
                    {
                        result.Elements.Add(element.TreatAs(resultType));
                    }
                }
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Returns the first collection without the common elements from both input collections.
        /// </summary>
        /// <param name="collection">The input collection for the except operation</param>
        /// <returns>The firt collection with commmon elements removed.</returns>
        public QueryCollectionValue Except(QueryCollectionValue collection)
        {
            var resultValues = new List <QueryValue>();

            foreach (QueryValue element in this.Elements)
            {
                if (!collection.Elements.Any(v => this.ValuesAreEqual(v, element)))
                {
                    resultValues.Add(element);
                }
            }

            // except removes duplicates from the result, so applying distinct at the end
            var exceptResult = new QueryCollectionValue(this.Type, this.EvaluationStrategy, QueryError.GetErrorFromValues(resultValues), resultValues);
            var result       = exceptResult.Distinct();

            return(result);
        }
示例#6
0
        /// <summary>
        /// Returns the first collection concatenanted with the second collection.
        /// </summary>
        /// <param name="collection">The collection to concatenate with.</param>
        /// <returns>The concatenated result.</returns>
        public QueryCollectionValue Concat(QueryCollectionValue collection)
        {
            var resultValues = this.Elements.Concat(collection.Elements);

            return(new QueryCollectionValue(this.Type, this.EvaluationStrategy, QueryError.GetErrorFromValues(resultValues), resultValues));
        }
示例#7
0
 /// <summary>
 /// Combines elements from both collections into one and eliminates duplicates.
 /// </summary>
 /// <param name="collection">The input collection for the union operation</param>
 /// <returns>Combined elements from both collections.</returns>
 public QueryCollectionValue Union(QueryCollectionValue collection)
 {
     return(this.UnionAll(collection).Distinct());
 }
示例#8
0
        private bool CollectionValuesAreEqual(QueryCollectionValue firstValueCollection, QueryCollectionValue secondValueCollection)
        {
            if (firstValueCollection.IsNull)
            {
                return(secondValueCollection.IsNull);
            }
            else if (secondValueCollection.IsNull)
            {
                return(false);
            }

            if (firstValueCollection.Elements.Count != secondValueCollection.Elements.Count)
            {
                return(false);
            }

            for (int i = 0; i < firstValueCollection.Elements.Count; i++)
            {
                if (!firstValueCollection.Elements.Any(e => this.ValuesAreEqual(e, secondValueCollection.Elements[i])) ||
                    !secondValueCollection.Elements.Any(e => this.ValuesAreEqual(e, firstValueCollection.Elements[i])))
                {
                    return(false);
                }
            }

            return(true);
        }
 /// <summary>
 /// Computes the Minimum value of a collection as a <see cref="QueryScalarValue"/>.
 /// </summary>
 /// <param name="collection">The collection of values.</param>
 /// <returns>The min value.</returns>
 public QueryScalarValue Min(QueryCollectionValue collection)
 {
     throw new TaupoNotSupportedException("Attempt to use evaluation strategy from " + typeof(QueryUnresolvedType).Name + ". Please resolve expression first.");
 }
 /// <summary>
 /// Filters the specified source using given predicate.
 /// </summary>
 /// <typeparam name="TElement">The type of the element.</typeparam>
 /// <param name="source">The source.</param>
 /// <param name="predicate">The predicate.</param>
 /// <returns>Filtered collection (including elements where the predicate matches).</returns>
 /// <remarks>The value can be store-dependent w.r.t. handling of NULL values of the input collection
 /// and/or result of the predicate.</remarks>
 public QueryCollectionValue Filter(QueryCollectionValue source, Func <QueryValue, QueryScalarValue> predicate)
 {
     throw new TaupoNotSupportedException("Attempt to use evaluation strategy from " + typeof(QueryUnresolvedType).Name + ". Please resolve expression first.");
 }
示例#11
0
        public static QueryValue ChooseRandomEvaluationResult(this IQueryExpressionEvaluator evaluator, QueryExpression queryExpression, IRandomNumberGenerator random, out QueryCollectionValue collection)
        {
            ExceptionUtilities.CheckArgumentNotNull(evaluator, "evaluator");
            ExceptionUtilities.CheckArgumentNotNull(queryExpression, "queryExpression");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            collection = evaluator.Evaluate(queryExpression) as QueryCollectionValue;
            ExceptionUtilities.CheckObjectNotNull(collection, "Query unexpectedly evaluated to null or was not a collection: {0}", queryExpression);
            ExceptionUtilities.Assert(collection.EvaluationError == null, "Query resulted in evaluation error: {0}", collection.EvaluationError);

            if (collection.IsNull || collection.Elements.Count == 0)
            {
                return(null);
            }

            return(random.ChooseFrom(collection.Elements));
        }