Exemple #1
0
 public void Initialize(QueryEngine <TData> engine, QueryGraph graph, ICollection <QueryError> errors)
 {
     if (graph != null && !graph.empty)
     {
         m_QueryEnumerable = EnumerableCreator.Create(graph.root, engine, errors);
     }
 }
Exemple #2
0
        public IQueryEnumerable <T> Create <T>(IQueryNode root, QueryEngine <T> engine, ICollection <QueryError> errors)
        {
            if (root.leaf || root.children == null || root.children.Count != 2)
            {
                errors.Add(new QueryError(root.token.position, "Union node must have two children."));
                return(null);
            }

            var firstEnumerable  = EnumerableCreator.Create(root.children[0], engine, errors);
            var secondEnumerable = EnumerableCreator.Create(root.children[1], engine, errors);

            if (firstEnumerable == null || secondEnumerable == null)
            {
                errors.Add(new QueryError(root.token.position, "Could not create enumerables from Union node's children."));
            }

            return(new UnionEnumerable <T>(firstEnumerable, secondEnumerable));
        }
Exemple #3
0
        public IQueryEnumerable <T> Create <T>(IQueryNode root, QueryEngine <T> engine, ICollection <QueryError> errors)
        {
            if (root.leaf || root.children == null || root.children.Count != 1)
            {
                errors.Add(new QueryError(root.token.position, "Aggregator node must have a child."));
                return(null);
            }

            var aggregatorNode = root as AggregatorNode;

            if (!(aggregatorNode?.aggregator is NestedQueryAggregator <T> handler))
            {
                errors.Add(new QueryError(root.token.position, "Aggregator node does not have the proper aggregator set."));
                return(null);
            }
            var childEnumerable = EnumerableCreator.Create(root.children[0], engine, errors);

            return(new AggregateEnumerable <T>(childEnumerable, handler.aggregator));
        }
Exemple #4
0
        private Func <T, bool> GenerateInFilterFunctionWithTypes <T, TNested, TTransform>(InFilterNode node, BaseFilterOperation <T> filterOperation, QueryEngine <T> engine, ICollection <QueryError> errors)
        {
            var nestedQueryEnumerable = EnumerableCreator.Create <TNested>(node.children[0], null, errors);

            if (nestedQueryEnumerable == null)
            {
                return(null);
            }
            var nestedQueryTransformer = node.filter.queryHandlerTransformer as NestedQueryHandlerTransformer <TNested, TTransform>;

            if (nestedQueryTransformer == null)
            {
                return(null);
            }
            var transformerFunction    = nestedQueryTransformer.handler;
            var dynamicFilterOperation = filterOperation as IDynamicFilterOperation <TTransform>;

            if (dynamicFilterOperation == null)
            {
                return(null);
            }
            return(o =>
            {
                foreach (var item in nestedQueryEnumerable)
                {
                    var transformedValue = transformerFunction(item);
                    dynamicFilterOperation.SetFilterValue(transformedValue);
                    if (filterOperation.Match(o))
                    {
                        return true;
                    }
                }

                return false;
            });
        }