public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index) { TransformingVisitor.StringBuilder.Append("."); switch (resultOperator) { case GroupResultOperator group: TransformingVisitor.StringBuilder.Append("GroupBy("); using (TransformingVisitor.StringBuilder.Indent()) { TransformingVisitor.Visit(group.KeySelector); TransformingVisitor.StringBuilder.Append(", "); TransformingVisitor.Visit(group.ElementSelector); TransformingVisitor.StringBuilder.Append(")"); } break; case CastResultOperator cast: TransformingVisitor.StringBuilder.Append("Cast<" + cast.CastItemType.ShortDisplayName() + ">()"); break; case OfTypeResultOperator ofType: TransformingVisitor.StringBuilder.Append("OfType<" + ofType.SearchedItemType.ShortDisplayName() + ">()"); break; default: TransformingVisitor.StringBuilder.Append(resultOperator.ToString()); break; } }
public override void SetSubjectOperator(ResultOperatorBase resultOperator) { base.SetSubjectOperator(resultOperator); if (SubjectVariable != null) { if (resultOperator is CountResultOperator) { var aggregate = new CountDistinctAggregate(new VariableTerm(SubjectVariable.Name)); SetSubjectVariable(aggregate.AsSparqlVariable(), true); } else if (resultOperator is FirstResultOperator) { if (!IsRoot) { // Note: We currently only support First operators on root queries. throw new NotSupportedException(); } } else { throw new NotImplementedException(resultOperator.ToString()); } } }
/// <summary> /// Overrides the <see cref="QueryModelVisitorBase.VisitResultOperator(ResultOperatorBase, QueryModel, int)"/>. /// </summary> /// <param name="resultOperator">The <see cref="ResultOperatorBase"/>.</param> /// <param name="queryModel">The <see cref="QueryModel"/>.</param> /// <param name="index">The index.</param> public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index) { if (resultOperator is FirstResultOperator fro) { _aggregator.Paging.OverrideTake(1); return; } if (resultOperator is TakeResultOperator tro) { _aggregator.Paging.OverrideTake(tro.GetConstantCount()); return; } if (resultOperator is SkipResultOperator sro) { _aggregator.Paging.OverrideSkip(sro.GetConstantCount()); return; } if (resultOperator is Remotion.Linq.Clauses.ResultOperators.FirstResultOperator) { return; } if (resultOperator is Remotion.Linq.Clauses.ResultOperators.SingleResultOperator) { return; } throw new NotSupportedException($"Result operator is not supported: {resultOperator.ToString()}."); }
public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index) { base.VisitResultOperator(resultOperator, queryModel, index); if (clause.HasFlag(VisitorClause.SkipTake)) { if (resultOperator.ToString().Contains("Skip")) { SkipResultOperator skip = resultOperator as SkipResultOperator; builderMongoQuery.AddModifier(Constants.STR_QUERY_MODIFIER_SKIP + skip.Count); } else if (resultOperator.ToString().Contains("Take")) { TakeResultOperator take = resultOperator as TakeResultOperator; builderMongoQuery.AddModifier(Constants.STR_QUERY_MODIFIER_LIMIT + take.Count); } else { throw new KinveyException(EnumErrorCategory.ERROR_GENERAL, EnumErrorCode.ERROR_METHOD_NOT_IMPLEMENTED, "LINQ result operator not supported."); } } }
private static string ResultOperatorString(ResultOperatorBase resultOperator) { switch (resultOperator) { case CastResultOperator cast: return("Cast<" + cast.CastItemType.ShortDisplayName() + ">()"); case OfTypeResultOperator ofType: return("OfType<" + ofType.SearchedItemType.ShortDisplayName() + ">()"); default: return(resultOperator.ToString()); } }
public override void SetObjectOperator(ResultOperatorBase resultOperator) { base.SetObjectOperator(resultOperator); if (ObjectVariable != null) { if (resultOperator is AnyResultOperator) { // When using x.Any(), we add a LIMIT 1 the query results in the SparqlQueryGenerator. // When using .Any(x => ..), the variable x is locally scoped and cannot be // used in outer queries. Therefore do not need to actually select it. // This avoids issues with Stardog: // https://community.stardog.com/t/sparql-union-only-working-with-inferencing-enabled/1040/9 } else if (resultOperator is AverageResultOperator) { var aggregate = new AverageAggregate(new VariableTerm(ObjectVariable.Name)); SetObjectVariable(aggregate.AsSparqlVariable(), true); } else if (resultOperator is CountResultOperator) { var aggregate = new CountDistinctAggregate(new VariableTerm(ObjectVariable.Name)); SetObjectVariable(aggregate.AsSparqlVariable(), true); } else if (resultOperator is FirstResultOperator) { // "Using LIMIT and OFFSET to select different subsets of the query solutions // will not be useful unless the order is made predictable by using ORDER BY." // Source: https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#modOffset // Therefore, if no ordering exists we add an ordering on the current subject // to make the query result predictable. if (!QueryModel.BodyClauses.OfType <OrderByClause>().Any()) { OrderBy(SubjectVariable); } else { // In case the order was make explicit, we have to do nothing. } Limit(1); } else if (resultOperator is LastResultOperator) { // "Using LIMIT and OFFSET to select different subsets of the query solutions // will not be useful unless the order is made predictable by using ORDER BY." // Source: https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#modOffset // Therefore, if no ordering exists we add an ordering on the current subject // to make the query result predictable. if (!QueryModel.BodyClauses.OfType <OrderByClause>().Any()) { OrderByDescending(SubjectVariable); } else { // Inverting the direction of the first ordering is handled in SparqlQueryModelVisitor.VisitOrdering(). // This is because the orderings are not necessarily processed *before* the result operators.. } Limit(1); } else if (resultOperator is MaxResultOperator) { var aggregate = new MaxAggregate(new VariableTerm(ObjectVariable.Name)); SetObjectVariable(aggregate.AsSparqlVariable(), true); } else if (resultOperator is MinResultOperator) { var aggregate = new MinAggregate(new VariableTerm(ObjectVariable.Name)); SetObjectVariable(aggregate.AsSparqlVariable(), true); } else if (resultOperator is SumResultOperator) { var aggregate = new SumAggregate(new VariableTerm(ObjectVariable.Name)); SetObjectVariable(aggregate.AsSparqlVariable(), true); } else if (resultOperator is OfTypeResultOperator) { OfTypeResultOperator ofType = resultOperator as OfTypeResultOperator; RdfClassAttribute type = ofType.SearchedItemType.TryGetCustomAttribute <RdfClassAttribute>(); if (type == null) { throw new ArgumentException("No RdfClass attrribute declared on type: " + ofType.SearchedItemType); } SparqlVariable s = ObjectVariable; SparqlVariable p = VariableGenerator.CreatePredicateVariable(); SparqlVariable o = VariableGenerator.CreateObjectVariable(); WhereResource(s, p, o); WhereResourceOfType(o, ofType.SearchedItemType); } else if (resultOperator is SkipResultOperator) { SkipResultOperator op = resultOperator as SkipResultOperator; Offset(int.Parse(op.Count.ToString())); } else if (resultOperator is TakeResultOperator) { TakeResultOperator op = resultOperator as TakeResultOperator; Limit(int.Parse(op.Count.ToString())); } else { throw new NotImplementedException(resultOperator.ToString()); } } }
#pragma warning restore 649 /// <summary> /// Process a result operator. If this result is amenable to be made into a function, then /// do so. /// </summary> /// <param name="resultOperator"></param> /// <param name="queryModel"></param> /// <param name="index"></param> public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index) { // Look for a single-result processor var processor = _operators.FindScalarROProcessor(resultOperator.GetType()); if (processor != null) { var result = processor.ProcessResultOperator(resultOperator, queryModel, _codeEnv, _codeContext, MEFContainer); if (result != null) { _codeEnv.SetResult(result); _scoping.Add(_codeContext.Add(queryModel, result)); } return; } // Look for a sequence processor var collectionProcessor = _operators.FindCollectionROProcessor(resultOperator.GetType()); if (collectionProcessor != null) { collectionProcessor.ProcessResultOperator(resultOperator, queryModel, _codeEnv, _codeContext, MEFContainer); _codeEnv.ResetResult(); return; } /// /// Uh oh - no idea how to do this! /// throw new InvalidOperationException("LINQToTTree can't translate the operator '" + resultOperator.ToString() + "'"); }
private void ThrowNotSupported(ResultOperatorBase resultOperator) { throw new NotSupportedException("Result operator is not supported by the SuperOffice Linq Provider: " + resultOperator.ToString()); }