/// <summary> /// Orders the collection by applying given ordering. /// </summary> /// <param name="ordering">The ordering to use.</param> /// <returns>Ordered collection.</returns> /// <remarks>This overload allows for more intellisense-friendly way of specifying ordering.</remarks> public QueryCollectionValue OrderBy(QueryOrdering ordering) { ExceptionUtilities.CheckArgumentNotNull(ordering, "ordering"); ExceptionUtilities.CheckCollectionNotEmpty(ordering.Selectors, "ordering.Selectors"); if (this.IsNull) { return(this); } IEnumerable <QueryValue> orderedElements = ordering.Apply(this.Elements.Cast <object>()).Cast <QueryValue>(); QueryError currentError = QueryError.Combine(this.EvaluationError, QueryError.GetErrorFromValues(orderedElements)); if (currentError != null) { return((QueryCollectionValue)this.Type.CreateErrorValue(currentError)); } // if this collection contains duplicate order by key selectors if (HasNondeterministicOrdering(ordering, orderedElements)) { return(new QueryCollectionValue(this.Type, this.EvaluationStrategy, null, orderedElements, false)); } else { return(new QueryCollectionValue(this.Type, this.EvaluationStrategy, null, orderedElements, true)); } }
/// <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)); }
/// <summary> /// Initializes a new instance of the QueryValue class. /// </summary> /// <param name="evaluationError">The evaluation error.</param> /// <param name="evaluationStrategy">The evaluation strategy.</param> protected QueryValue(QueryError evaluationError, IQueryEvaluationStrategy evaluationStrategy) : base() { ExceptionUtilities.CheckArgumentNotNull(evaluationStrategy, "evaluationStrategy"); this.EvaluationStrategy = evaluationStrategy; this.EvaluationError = evaluationError; }
/// <summary> /// Initializes a new instance of the QueryScalarValue class. /// </summary> /// <param name="type">The type of the value.</param> /// <param name="value">The value.</param> /// <param name="evaluationError">The evaluation error.</param> /// <param name="evaluationStrategy">The evaluation strategy.</param> public QueryScalarValue(QueryScalarType type, object value, QueryError evaluationError, IQueryEvaluationStrategy evaluationStrategy) : base(evaluationError, evaluationStrategy) { ExceptionUtilities.CheckArgumentNotNull(type, "type"); this.Type = type; this.Value = value; }
/// <summary> /// Initializes a new instance of the QueryStructuralValue class. /// </summary> /// <param name="type">The type of the value.</param> /// <param name="isNull">If set to <c>true</c> the structural value is null.</param> /// <param name="evaluationError">The evaluation error.</param> /// <param name="evaluationStrategy">The evaluation strategy.</param> public QueryStructuralValue(QueryStructuralType type, bool isNull, QueryError evaluationError, IQueryEvaluationStrategy evaluationStrategy) : base(evaluationError, evaluationStrategy) { ExceptionUtilities.CheckArgumentNotNull(type, "type"); this.Type = type; this.isNull = isNull; }
/// <summary> /// Initializes a new instance of the QueryRecordValue class. /// </summary> /// <param name="type">The type of the value.</param> /// <param name="isNull">If set to <c>true</c> the record value is null.</param> /// <param name="evaluationError">The evaluation error.</param> /// <param name="evaluationStrategy">The evaluation strategy.</param> public QueryRecordValue(QueryRecordType type, bool isNull, QueryError evaluationError, IQueryEvaluationStrategy evaluationStrategy) : base(evaluationError, evaluationStrategy) { ExceptionUtilities.CheckArgumentNotNull(type, "type"); this.Type = type; this.isNull = isNull; this.SetupInitialMemberValues(); }
/// <summary> /// Creates the collection value with the specified elements. /// </summary> /// <param name="elementType">The type of each collection element.</param> /// <param name="elements">The elements.</param> /// <returns> /// Strongly-typed collection with the specified values. /// </returns> public static QueryCollectionValue Create(QueryType elementType, params QueryValue[] elements) { ExceptionUtilities.CheckArgumentNotNull(elementType, "elementType"); return(new QueryCollectionValue( elementType.CreateCollectionType(), elementType.EvaluationStrategy, QueryError.GetErrorFromValues(elements), elements)); }
/// <summary> /// Applies a projection operator which selects a value from each collection element. /// </summary> /// <param name="selector">The selector.</param> /// <returns> /// Collection of values containing results of the selector applied to all elements of the collection. /// </returns> public QueryCollectionValue Select(Func <QueryValue, QueryValue> selector) { ExceptionUtilities.CheckArgumentNotNull(selector, "selector"); IEnumerable <QueryValue> result; QueryCollectionType resultType; this.ComputeSelectResult(selector, out result, out resultType); return(new QueryCollectionValue(resultType, this.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted)); }
/// <summary> /// Combines the specified errors into one. /// </summary> /// <param name="firstError">The first error.</param> /// <param name="secondError">The second error.</param> /// <returns>Combined error.</returns> public static QueryError Combine(QueryError firstError, QueryError secondError) { if (firstError != null) { return(firstError); } else { return(secondError); } }
/// <summary> /// Creates the collection value with the specified elements. /// </summary> /// <param name="elementType">The type of each collection element.</param> /// <param name="elements">The elements.</param> /// <param name="isSorted">Indicating if the collection is sorted.</param> /// <returns>Strongly-typed collection with the specified values.</returns> public static QueryCollectionValue Create(QueryType elementType, IEnumerable <QueryValue> elements, bool isSorted) { ExceptionUtilities.CheckArgumentNotNull(elementType, "elementType"); return(new QueryCollectionValue( elementType.CreateCollectionType(), elementType.EvaluationStrategy, QueryError.GetErrorFromValues(elements), elements, isSorted)); }
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); }
/// <summary> /// Applies a projection operator which selects a value from each collection element. /// </summary> /// <param name="selector">The selector.</param> /// <param name="resultType">Type of the result</param> /// <returns> /// Collection of values containing results of the selector applied to all elements of the collection. /// </returns> public QueryCollectionValue Select(Func <QueryValue, QueryValue> selector, QueryCollectionType resultType) { ExceptionUtilities.CheckArgumentNotNull(selector, "selector"); IEnumerable <QueryValue> result = null; if (!this.IsNull) { result = this.Elements.Cast <QueryValue>().Select(e => selector(e)).ToList(); } return(new QueryCollectionValue(resultType, this.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted)); }
/// <summary> /// Gets distinct elements from the collection. /// </summary> /// <returns>Distinct elements of the collection.</returns> public QueryCollectionValue Distinct() { List <QueryValue> distinctValues = new List <QueryValue>(); foreach (var element in this.Elements) { if (!distinctValues.Any(v => this.ValuesAreEqual(v, element))) { distinctValues.Add(element); } } return(new QueryCollectionValue(this.Type, this.EvaluationStrategy, QueryError.GetErrorFromValues(distinctValues), distinctValues)); }
private QueryScalarValue EvaluateBinaryOperation(QueryScalarValue otherValue, QueryBinaryOperation operation) { ExceptionUtilities.CheckArgumentNotNull(otherValue, "otherValue"); var result = this.EvaluationStrategy.Evaluate(operation, this, otherValue); var error = QueryError.Combine(this.EvaluationError, otherValue.EvaluationError); if (error != null) { result.EvaluationError = error; } return(result); }
/// <summary> /// Applies the Take operation on the given collection. /// </summary> /// <param name="takeCount">How many elements to take.</param> /// <returns>Collection with the applied Take operation.</returns> public QueryCollectionValue Take(QueryScalarValue takeCount) { ExceptionUtilities.CheckArgumentNotNull(takeCount, "takeCount"); QueryError currentError = QueryError.Combine(this.EvaluationError, takeCount.EvaluationError); if (currentError != null) { return((QueryCollectionValue)this.Type.CreateErrorValue(currentError)); } IEnumerable <QueryValue> result = null; if (!this.IsNull) { result = this.Elements.Take((int)takeCount.Value).ToList(); } return(new QueryCollectionValue(this.Type, this.Type.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted)); }
/// <summary> /// Applies the Skip operation on the given collection. /// </summary> /// <param name="skipCount">How many elements to skip.</param> /// <returns>Collection with the applied Skip operation.</returns> public QueryCollectionValue Skip(QueryScalarValue skipCount) { ExceptionUtilities.CheckArgumentNotNull(skipCount, "skipCount"); QueryError currentError = QueryError.Combine(this.EvaluationError, skipCount.EvaluationError); if (currentError != null) { return((QueryCollectionValue)this.Type.CreateErrorValue(currentError)); } IEnumerable <QueryValue> result = null; if (!this.IsNull) { // perhaps this must be changed - moved to EvaluationStrategy result = this.Elements.Skip((int)skipCount.Value); } return(new QueryCollectionValue(this.Type, this.Type.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted)); }
/// <summary> /// Creates the non-strongly typed error value. /// </summary> /// <param name="evaluationError">The evaluation error.</param> /// <returns>Created error value.</returns> protected override QueryValue CreateErrorValueInternal(QueryError evaluationError) { throw new TaupoNotSupportedException("Operation not supported for the unresolved type."); }
/// <summary> /// Creates the non-strongly typed error value. /// </summary> /// <param name="evaluationError">The evaluation error.</param> /// <returns>Created error value.</returns> protected override QueryValue CreateErrorValueInternal(QueryError evaluationError) { return(this.CreateErrorValue(evaluationError)); }
/// <summary> /// Creates the null value with error information attached. /// </summary> /// <param name="error">The error information.</param> /// <returns>Newly created value.</returns> public new QueryScalarValue CreateErrorValue(QueryError error) { return((QueryScalarValue)this.CreateErrorValueInternal(error)); }
/// <summary> /// Creates the non-strongly typed error value. /// </summary> /// <param name="evaluationError">The evaluation error.</param> /// <returns>Created error value.</returns> protected override QueryValue CreateErrorValueInternal(QueryError evaluationError) { return(new QueryCollectionValue(this, this.EvaluationStrategy, evaluationError, null)); }
/// <summary> /// Initializes a new instance of the QueryCollectionValue class. /// </summary> /// <param name="type">The collection type.</param> /// <param name="evaluationStrategy">The evaluation strategy.</param> /// <param name="evaluationError">The evaluation error.</param> /// <param name="elements">The elements.</param> public QueryCollectionValue(QueryCollectionType type, IQueryEvaluationStrategy evaluationStrategy, QueryError evaluationError, IEnumerable <QueryValue> elements) : this(type, evaluationStrategy, evaluationError, elements, false) { }
/// <summary> /// Creates a collection with values the specified values. /// </summary> /// <param name="elements">The collection elements. If null is passed, the collection will be a null /// collection.</param> /// <returns>Newly created collection value.</returns> public virtual QueryCollectionValue CreateCollectionWithValues(IEnumerable <QueryValue> elements) { return(new QueryCollectionValue(this, this.EvaluationStrategy, QueryError.GetErrorFromValues(elements), elements)); }
/// <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); }
/// <summary> /// Creates the error value of this type. /// </summary> /// <param name="evaluationError">The evaluation error.</param> /// <returns>Created error value.</returns> public new QueryReferenceValue CreateErrorValue(QueryError evaluationError) { return(new QueryReferenceValue(this, evaluationError, this.EvaluationStrategy)); }
/// <summary> /// Creates the non-strongly typed error value. /// </summary> /// <param name="evaluationError">The evaluation error.</param> /// <returns>Created error value.</returns> protected override QueryValue CreateErrorValueInternal(QueryError evaluationError) { return(new QueryScalarValue(this, null, evaluationError, this.EvaluationStrategy)); }
/// <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)); }
/// <summary> /// Initializes a new instance of the QueryEntityValue class. /// </summary> /// <param name="type">The type of the value.</param> /// <param name="isNull">If set to <c>true</c> the structural value is null.</param> /// <param name="evaluationError">The evaluation error.</param> /// <param name="evaluationStrategy">The evaluation strategy.</param> internal QueryEntityValue(QueryEntityType type, bool isNull, QueryError evaluationError, IQueryEvaluationStrategy evaluationStrategy) : base(type, isNull, evaluationError, evaluationStrategy) { this.navigateResultLookup = new Dictionary <AssociationType, Dictionary <AssociationEnd, QueryValue> >(); }
/// <summary> /// Initializes a new instance of the QueryCollectionValue class. /// </summary> /// <param name="type">The collection type.</param> /// <param name="evaluationStrategy">The evaluation strategy.</param> /// <param name="evaluationError">The evaluation error.</param> /// <param name="elements">The elements.</param> /// <param name="isSorted">Determines whether the collection is sorted.</param> public QueryCollectionValue(QueryCollectionType type, IQueryEvaluationStrategy evaluationStrategy, QueryError evaluationError, IEnumerable <QueryValue> elements, bool isSorted) : base(evaluationError, evaluationStrategy) { ExceptionUtilities.CheckArgumentNotNull(type, "type"); this.IsSorted = isSorted; this.Type = type; if (elements == null) { this.Elements = null; } else { this.Elements = elements.ToList(); } }
/// <summary> /// Creates the error value of this type. /// </summary> /// <param name="evaluationError">The evaluation error.</param> /// <returns>Created error value.</returns> public new QueryRecordValue CreateErrorValue(QueryError evaluationError) { return(new QueryRecordValue(this, true, evaluationError, this.EvaluationStrategy)); }
/// <summary> /// Groups elements using key computed from the key selector. /// </summary> /// <param name="keySelector">Key selector lambda.</param> /// <returns>Elements grouped based on the provided key.</returns> public QueryCollectionValue GroupBy(Func <QueryValue, QueryValue> keySelector) { if (this.IsNull) { return(new QueryCollectionValue(this.Type.ElementType.CreateCollectionType(), this.EvaluationStrategy, this.EvaluationError, null)); } var keys = this.Elements.Select(keySelector).ToList(); var keyCollection = new QueryCollectionValue(this.Type.ElementType.CreateCollectionType(), this.EvaluationStrategy, this.EvaluationError, keys); var distinctKeys = keyCollection.Distinct().Elements; var elementType = this.Type.ElementType; var groupings = distinctKeys.Select(key => { if (key.IsNull) { var matchingNullElements = this.Elements.Where(element => keySelector(element).IsNull); return(this.CreateGroupingValue(key, QueryCollectionValue.Create(elementType, matchingNullElements.ToArray()))); } else { return(this.CreateGroupingValue(key, QueryCollectionValue.Create(elementType, this.Elements.Where(element => this.ValuesAreEqual(keySelector(element), key)).ToArray()))); } }); var keyType = keySelector(elementType.NullValue).Type; var groupingType = new QueryGroupingType(keyType, elementType, this.EvaluationStrategy); return(new QueryCollectionValue(groupingType.CreateCollectionType(), this.EvaluationStrategy, QueryError.GetErrorFromValues(groupings), groupings.Cast <QueryValue>())); }