コード例 #1
0
 public ContextSpecHashItem(
     Chainable function,
     FilterSpecRaw filterSpecRaw)
 {
     Function = function;
     FilterSpecRaw = filterSpecRaw;
 }
コード例 #2
0
        private static bool IsMappedProperty(Chainable chainable)
        {
            if (!(chainable is ChainableCall))
            {
                return(false);
            }

            var call = (ChainableCall)chainable;

            return(IsSingleParameterConstantOfType(call.Parameters, typeof(string)));
        }
コード例 #3
0
        private static bool IsArrayProperty(
            Chainable chainable,
            Chainable next)
        {
            if (!(next is ChainableArray))
            {
                return(false);
            }

            var array = (ChainableArray)next;

            return(chainable is ChainableName && IsSingleParameterConstantOfType(array.Indexes, typeof(int?)));
        }
コード例 #4
0
        private static ExprNode HandleMinMaxNode(
            string chainFirstLowerCase,
            Chainable spec)
        {
            MinMaxTypeEnum minMaxTypeEnum;
            var            filtered = chainFirstLowerCase.StartsWith("f");

            if (chainFirstLowerCase.Equals("min") || chainFirstLowerCase.Equals("fmin"))
            {
                minMaxTypeEnum = MinMaxTypeEnum.MIN;
            }
            else if (chainFirstLowerCase.Equals("max") || chainFirstLowerCase.Equals("fmax"))
            {
                minMaxTypeEnum = MinMaxTypeEnum.MAX;
            }
            else
            {
                throw new ValidationException("Uncountered unrecognized min or max node '" + spec.GetRootNameOrEmptyString() + "'");
            }

            var args              = spec.GetParametersOrEmpty();
            var distinct          = spec.IsDistinct;
            var numArgsPositional = ExprAggregateNodeUtil.CountPositionalArgs(args);

            if (numArgsPositional > 1 && spec.IsDistinct && !filtered)
            {
                throw new ValidationException(
                          "The distinct keyword is not valid in per-row min and max " +
                          "functions with multiple sub-expressions");
            }

            ExprNode minMaxNode;

            if (!distinct && numArgsPositional > 1 && !filtered)
            {
                // use the row function
                minMaxNode = new ExprMinMaxRowNode(minMaxTypeEnum);
            }
            else
            {
                // use the aggregation function
                minMaxNode = new ExprMinMaxAggrNode(distinct, minMaxTypeEnum, filtered, false);
            }

            minMaxNode.AddChildNodes(args);
            return(minMaxNode);
        }
コード例 #5
0
        private static bool DeterminePlainProperty(IList <Chainable> chain)
        {
            Chainable previous = null;

            foreach (var spec in chain)
            {
                if (spec is ChainableArray)
                {
                    // must be "[index]" with index being an integer constant
                    var array = (ChainableArray)spec;
                    if (!IsSingleParameterConstantOfType(array.Indexes, typeof(int?)))
                    {
                        return(false);
                    }

                    if (previous is ChainableArray)
                    {
                        // plain property expressions don't allow two-dimensional array
                        return(false);
                    }
                }

                if (spec is ChainableCall)
                {
                    // must be "x(key)" with key being a string constant
                    var call = (ChainableCall)spec;
                    if (!IsSingleParameterConstantOfType(call.Parameters, typeof(string)))
                    {
                        return(false);
                    }
                }

                previous = spec;
            }

            return(true);
        }
コード例 #6
0
        public static void ValidateContextDesc(
            string contextName,
            ContextSpecHash hashedSpec,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            if (hashedSpec.Items.IsEmpty()) {
                throw new ExprValidationException("Empty list of hash items");
            }

            foreach (var item in hashedSpec.Items) {
                Chainable chainable = item.Function;

                // determine type of hash to use
                var hashFuncName = chainable.GetRootNameOrEmptyString();
                var hashFuncParams = chainable.GetParametersOrEmpty();
                var hashFunction = HashFunctionEnumExtensions.Determine(contextName, hashFuncName);
                Pair<Type, ImportSingleRowDesc> hashSingleRowFunction = null;
                if (hashFunction == null) {
                    try {
                        hashSingleRowFunction = services.ImportServiceCompileTime.ResolveSingleRow(
                            hashFuncName, services.ClassProvidedExtension);
                    }
                    catch (Exception) {
                        // expected
                    }

                    if (hashSingleRowFunction == null) {
                        throw new ExprValidationException(
                            "For context '" +
                            contextName +
                            "' expected a hash function that is any of {" +
                            HashFunctionEnumExtensions.GetStringList() +
                            "} or a plug-in single-row function or script but received '" +
                            hashFuncName +
                            "'");
                    }
                }

                if (hashFuncParams.IsEmpty()) {
                    throw new ExprValidationException(
                        $"For context '{contextName}' expected one or more parameters to the hash function, but found no parameter list");
                }

                // get first parameter
                var paramExpr = hashFuncParams[0];
                var paramType = paramExpr.Forge.EvaluationType;
                EventPropertyValueGetterForge getter;

                if (hashFunction == HashFunctionEnum.CONSISTENT_HASH_CRC32) {
                    if (hashFuncParams.Count > 1 || paramType != typeof(string)) {
                        getter = new ContextControllerHashedGetterCRC32SerializedForge(
                            hashFuncParams,
                            hashedSpec.Granularity);
                    }
                    else {
                        getter = new ContextControllerHashedGetterCRC32SingleForge(
                            paramExpr, hashedSpec.Granularity);
                    }
                }
                else if (hashFunction == HashFunctionEnum.HASH_CODE) {
                    if (hashFuncParams.Count > 1) {
                        getter = new ContextControllerHashedGetterHashMultiple(
                            hashFuncParams,
                            hashedSpec.Granularity);
                    }
                    else {
                        getter = new ContextControllerHashedGetterHashSingleForge(paramExpr, hashedSpec.Granularity);
                    }
                }
                else if (hashSingleRowFunction != null) {
                    getter = new ContextControllerHashedGetterSingleRowForge(
                        hashSingleRowFunction,
                        hashFuncParams,
                        hashedSpec.Granularity,
                        item.FilterSpecCompiled.FilterForEventType,
                        statementRawInfo,
                        services);
                }
                else {
                    throw new ArgumentException("Unrecognized hash code function '" + hashFuncName + "'");
                }

                // create and register expression
                var expression = hashFuncName + "(" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(paramExpr) + ")";
                var valueSerde = new DataInputOutputSerdeForgeSingleton(typeof(DIONullableIntegerSerde));
                var eval = new ExprEventEvaluatorForgeFromProp(getter);
                var lookupable = new ExprFilterSpecLookupableForge(expression, eval, null, typeof(int), true, valueSerde);
                item.Lookupable = lookupable;
            }
        }
コード例 #7
0
        public void Chain_Dispatches_To_Objects_That_Implement_Chain()
        {
            var obj = new Chainable(100);

            CollectionAssert.AreEqual(R.Chain(add1, obj), new[] { 101 });
        }