Exemple #1
0
 public QueryComponent(ComponentOperator condition, string prefix, string value, int startIndex, int lastIndex)
 {
     Operator   = condition;
     Prefix     = prefix ?? string.Empty;
     Value      = value ?? string.Empty;
     StartIndex = startIndex;
     LastIndex  = lastIndex;
 }
Exemple #2
0
 private void ClearState(int position)
 {
     _StartIndex = position + 1;
     _Operator   = ComponentOperator.None;
     _Prefix     = null;
     _IsPrefix   = true;
     _IsQuoted   = false;
     if (_Buffer == null)
     {
         _Buffer = new StringBuilder();
     }
     else
     {
         _Buffer.Clear();
     }
 }
Exemple #3
0
        public ComponentPropertyDescriptor(PropertyDescriptor property)
            : base(property.Name, null)
        {
            _componentType = property.ComponentType;
            _isReadOnly    = property.IsReadOnly;
            _propertyType  = property.PropertyType;
            PropertyInfo propertyInfo = ComponentOperator.GetPropertyInfo(property);

            if (propertyInfo != null)
            {
                _getter = new Lazy <Getter>(() => ComponentOperator.GetPropertyGetter(_componentType, propertyInfo));
                _setter = new Lazy <Setter>(() => ComponentOperator.GetPropertySetter(_componentType, _propertyType, propertyInfo));
            }
            else
            {
                _getter = new Lazy <Getter>(() => ComponentOperator.GetPropertyGetter(_componentType, this.Name));
                _setter = new Lazy <Setter>(() => ComponentOperator.GetPropertySetter(_componentType, _propertyType, this.Name));
            }
        }
Exemple #4
0
        /// <summary>
        /// Initializes the operator resolver.
        /// </summary>
        /// <returns>The operator resolver.</returns>
        private static OperatorResolver InitOperatorResolver()
        {
            Mock <OperatorResolver> opResolverMock = new Mock <OperatorResolver>();
            IExpressionFactory      exprFactory    =
                new ExpressionFactory(
                    ModelResolvers.ExprResolver,
                    ModelResolvers.RuleExprResolver,
                    ModelResolvers.JoinExprResolver,
                    opResolverMock.Object);

            JoinApplyMeasuresOperator joinApplyMeasuresOp = new JoinApplyMeasuresOperator(
                exprFactory,
                ModelResolvers.DsResolver);

            opResolverMock.Setup(o => o(It.IsAny <string>()))
            .Returns((string key) =>
            {
                IOperatorDefinition op;

                if (key.In("count", "min", "max", "median", "sum", "avg", "stddev_pop", "stddev_samp", "var_pop", "var_samp"))
                {
                    op = new AggrFunctionOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "aggr")
                {
                    op = new AggrOperator();
                }
                else if (key.In("first_value", "last_value", "lag", "rank", "ratio_to_report", "lead"))
                {
                    op = new AnalyticFunctionOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key.In("+", "-", "*", "/"))
                {
                    op = new ArithmeticOperator(joinApplyMeasuresOp);
                }
                else if (key == "between")
                {
                    op = new BetweenOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key.In("and", "or", "xor", "not"))
                {
                    op = new BooleanOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "calc")
                {
                    op = new CalcOperator(ModelResolvers.DsResolver);
                }
                else if (key == "check_datapoint")
                {
                    op = new CheckDatapointOperator(ModelResolvers.DsResolver, exprFactory);
                }
                else if (key.In("=", "<>", "<", "<=", ">", ">="))
                {
                    op = new ComparisonOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "comp")
                {
                    op = new ComponentOperator(ModelResolvers.DsResolver, new ComponentTypeInference(ModelResolvers.DsResolver));
                }
                else if (key == "const")
                {
                    op = new ConstantOperator(ModelResolvers.DsResolver);
                }
                else if (key == "current_date")
                {
                    op = new CurrentDateOperator(ModelResolvers.DsResolver);
                }
                else if (key == "exists_in")
                {
                    op = new ExistsInOperator(ModelResolvers.DsResolver);
                }
                else if (key == "get")
                {
                    op = new GetOperator(new Mock <IDataModelProvider>().Object);                       // operator tests should mock IDataModel implementation
                }
                else if (key == "if")
                {
                    op = new IfThenElseOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key.In("in", "not_in"))
                {
                    op = new InOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "isnull")
                {
                    op = new IsNullOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "join")
                {
                    op = new JoinOperator(ModelResolvers.DsResolver);
                }
                else if (key.In("keep", "drop"))
                {
                    op = new KeepDropOperator(ModelResolvers.DsResolver);
                }
                else if (key == "match_characters")
                {
                    op = new MatchCharactersOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "#")
                {
                    op = new MembershipOperator();
                }
                else if (key.In("ceil", "floor", "abs", "exp", "ln", "sqrt", "mod", "round", "power", "log", "trunc"))
                {
                    op = new NumericOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "nvl")
                {
                    op = new NvlOperator(joinApplyMeasuresOp);
                }
                else if (key == "opt")
                {
                    op = new OptionalOperator(ModelResolvers.DsResolver);
                }
                else if (key == "period_indicator")
                {
                    op = new PeriodIndicatorOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver, exprFactory);
                }
                else if (key == "pivot")
                {
                    op = new PivotOperator(ModelResolvers.DsResolver);
                }
                else if (key == "ref")
                {
                    op = new ReferenceOperator();
                }
                else if (key == "rename")
                {
                    op = new RenameOperator(ModelResolvers.DsResolver);
                }
                else if (key.In("union", "intersect", "setdiff", "symdiff"))
                {
                    op = new SetOperator();
                }
                else if (key.In("||", "trim", "rtrim", "ltrim", "upper", "lower", "substr", "replace", "instr", "length"))
                {
                    op = new StringOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver);
                }
                else if (key == "sub")
                {
                    op = new SubspaceOperator(ModelResolvers.DsResolver);
                }
                else if (key.In("fill_time_series", "flow_to_stock", "stock_to_flow", "timeshift", "time_agg"))
                {
                    op = new TimeOperator();
                }
                else if (key.In("plus", "minus"))
                {
                    op = new UnaryArithmeticOperator(joinApplyMeasuresOp);
                }
                else if (key == "unpivot")
                {
                    op = new UnpivotOperator(ModelResolvers.DsResolver);
                }
                // ---
                else if (key == "calcExpr")
                {
                    op = new CalcExprOperator(ModelResolvers.DsResolver);
                }
                else if (key == "collection")
                {
                    op = new CollectionOperator(ModelResolvers.DsResolver);
                }
                else if (key == "datasetClause")
                {
                    op = new DatasetClauseOperator();
                }
                else if (key == "group")
                {
                    op = new GroupOperator(ModelResolvers.DsResolver);
                }
                else if (key == "order")
                {
                    op = new OrderOperator(ModelResolvers.DsResolver);
                }
                else if (key == "partition")
                {
                    op = new PartitionOperator(ModelResolvers.DsResolver);
                }
                else if (key == "renameExpr")
                {
                    op = new RenameExprOperator(ModelResolvers.DsResolver);
                }
                else if (key == "subExpr")
                {
                    op = new SubspaceExprOperator();
                }
                else if (key == "when")
                {
                    op = new WhenOperator();
                }
                else
                {
                    throw new InvalidOperationException("Operator not found");
                }

                op.Symbol = key;
                return(op);
            });

            return(opResolverMock.Object);
        }
Exemple #5
0
 private static object GetTypedNull(Type type)
 {
     return(ComponentOperator.GetTypedDefaultMethod(type)());
 }
Exemple #6
0
            public IEnumerable <QueryComponent> Parse(string query)
            {
                if (query == null)
                {
                    yield break;
                }

                var position = -1;

                ClearState(-1);

                foreach (var c in query)
                {
                    position++;

                    if (IsEmpty())
                    {
                        switch (c)
                        {
                        case '+':
                            _Operator = ComponentOperator.Required;
                            continue;

                        case '-':
                            _Operator = ComponentOperator.Excluded;
                            continue;
                        }
                    }
                    if (_IsPrefix)
                    {
                        if (IsWhitespace(c))
                        {
                            if (_Buffer.Length > 0)
                            {
                                yield return(CreateQueryComponent(position - 1));
                            }
                            ClearState(position);
                        }
                        else if (c == '"')
                        {
                            _Prefix   = null;
                            _IsPrefix = false;
                            _IsQuoted = _Buffer.Length == 0;
                        }
                        else if (c == ':')
                        {
                            if (_Buffer.Length == 0)
                            {
                                _Buffer.Append(c);
                            }
                            else
                            {
                                _Prefix = _Buffer.ToString();
                                _Buffer.Clear();
                            }
                            _IsPrefix = false;
                            _IsQuoted = false;
                        }
                        else
                        {
                            _Buffer.Append(c);
                        }
                    }
                    else
                    {
                        if (IsWhitespace(c))
                        {
                            if (_IsQuoted)
                            {
                                _Buffer.Append(c);
                            }
                            else
                            {
                                yield return(CreateQueryComponent(position - 1));

                                ClearState(position);
                            }
                        }
                        else if (c == '"')
                        {
                            if (_IsQuoted)
                            {
                                if (_Prefix != null || _Buffer.Length > 0)
                                {
                                    yield return(CreateQueryComponent(position));
                                }
                                ClearState(position);
                            }
                            else if (_Buffer.Length == 0)
                            {
                                _IsQuoted = true;
                            }
                            else
                            {
                                _Buffer.Append(c);
                            }
                        }
                        else
                        {
                            _Buffer.Append(c);
                        }
                    }
                }

                if (!_IsPrefix || _Buffer.Length > 0)
                {
                    yield return(CreateQueryComponent(query.Length - 1));
                }
            }