private static FilterValueSetParam GetFilterMayEqualOrNull(FilterSpecLookupable lookupable, Object keyValue)
 {
     if (keyValue == null)
     {
         return(new FilterValueSetParamImpl(lookupable, FilterOperator.IS, null));
     }
     return(new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keyValue));
 }
 public SupportFilterParamIndex(FilterSpecLookupable lookupable)
     : base(FilterOperator.EQUAL, lookupable)
 {
 }
Beispiel #3
0
        public static FilterValueSetParam[][] GetAddendumFilters(
            object keyValue,
            FilterSpecCompiled filtersSpec,
            ContextDetailPartitioned segmentedSpec,
            StatementSpecCompiled optionalStatementSpecCompiled)
        {
            // determine whether create-named-window
            var isCreateWindow = optionalStatementSpecCompiled != null &&
                                 optionalStatementSpecCompiled.CreateWindowDesc != null;
            ContextDetailPartitionItem foundPartition = null;

            if (!isCreateWindow)
            {
                foreach (var partitionItem in segmentedSpec.Items)
                {
                    var typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf(
                        filtersSpec.FilterForEventType, partitionItem.FilterSpecCompiled.FilterForEventType);
                    if (typeOrSubtype)
                    {
                        foundPartition = partitionItem;
                    }
                }
            }
            else
            {
                var declaredAsName = optionalStatementSpecCompiled.CreateWindowDesc.AsEventTypeName;
                if (declaredAsName == null)
                {
                    return(null);
                }
                foreach (var partitionItem in segmentedSpec.Items)
                {
                    if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                    {
                        foundPartition = partitionItem;
                        break;
                    }
                }
            }

            if (foundPartition == null)
            {
                return(null);
            }

            var addendumFilters = new List <FilterValueSetParam>(foundPartition.PropertyNames.Count);

            if (foundPartition.PropertyNames.Count == 1)
            {
                var propertyName           = foundPartition.PropertyNames[0];
                var getter                 = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(propertyName);
                var resultType             = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(propertyName);
                var lookupable             = new FilterSpecLookupable(propertyName, getter, resultType, false);
                FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keyValue);
                addendumFilters.Add(filter);
            }
            else
            {
                var keys = ((MultiKeyUntyped)keyValue).Keys;
                for (var i = 0; i < foundPartition.PropertyNames.Count; i++)
                {
                    var partitionPropertyName = foundPartition.PropertyNames[i];
                    var getter                 = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(partitionPropertyName);
                    var resultType             = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(partitionPropertyName);
                    var lookupable             = new FilterSpecLookupable(partitionPropertyName, getter, resultType, false);
                    FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keys[i]);
                    addendumFilters.Add(filter);
                }
            }

            var addendum = new FilterValueSetParam[1][];

            addendum[0] = addendumFilters.ToArray();

            var partitionFilters = foundPartition.ParametersCompiled;

            if (partitionFilters != null)
            {
                addendum = ContextControllerAddendumUtil.AddAddendum(partitionFilters, addendum[0]);
            }

            return(addendum);
        }
Beispiel #4
0
        private void ValidatePopulateContextDesc()
        {
            if (_hashedSpec.Items.IsEmpty())
            {
                throw new ExprValidationException("Empty list of hash items");
            }

            foreach (var item in _hashedSpec.Items)
            {
                if (item.Function.Parameters.IsEmpty())
                {
                    throw new ExprValidationException("For context '" + _factoryContext.ContextName + "' expected one or more parameters to the hash function, but found no parameter list");
                }

                // determine type of hash to use
                var hashFuncName = item.Function.Name;
                var hashFunction = HashFunctionEnumExtensions.Determine(_factoryContext.ContextName, hashFuncName);
                Pair <Type, EngineImportSingleRowDesc> hashSingleRowFunction = null;
                if (hashFunction == null)
                {
                    try {
                        hashSingleRowFunction = _factoryContext.AgentInstanceContextCreate.StatementContext.MethodResolutionService.ResolveSingleRow(hashFuncName);
                    }
                    catch (Exception e) {
                        // expected
                    }

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

                // get first parameter
                var paramExpr = item.Function.Parameters[0];
                var eval      = paramExpr.ExprEvaluator;
                var paramType = eval.ReturnType;
                EventPropertyGetter getter;

                if (hashFunction == HashFunctionEnum.CONSISTENT_HASH_CRC32)
                {
                    if (item.Function.Parameters.Count > 1 || paramType != typeof(string))
                    {
                        getter = new ContextControllerHashedGetterCRC32Serialized(
                            _factoryContext.AgentInstanceContextCreate.StatementContext.StatementName, item.Function.Parameters, _hashedSpec.Granularity);
                    }
                    else
                    {
                        getter = new ContextControllerHashedGetterCRC32Single(
                            eval, _hashedSpec.Granularity);
                    }
                }
                else if (hashFunction == HashFunctionEnum.HASH_CODE)
                {
                    if (item.Function.Parameters.Count > 1)
                    {
                        getter = new ContextControllerHashedGetterHashMultiple(item.Function.Parameters, _hashedSpec.Granularity);
                    }
                    else
                    {
                        getter = new ContextControllerHashedGetterHashSingle(eval, _hashedSpec.Granularity);
                    }
                }
                else if (hashSingleRowFunction != null)
                {
                    getter = new ContextControllerHashedGetterSingleRow(
                        _factoryContext.AgentInstanceContextCreate.StatementContext.StatementName, hashFuncName, hashSingleRowFunction, item.Function.Parameters, _hashedSpec.Granularity,
                        _factoryContext.AgentInstanceContextCreate.StatementContext.MethodResolutionService,
                        item.FilterSpecCompiled.FilterForEventType,
                        _factoryContext.AgentInstanceContextCreate.StatementContext.EventAdapterService,
                        _factoryContext.AgentInstanceContextCreate.StatementId,
                        _factoryContext.ServicesContext.TableService);
                }
                else
                {
                    throw new ArgumentException("Unrecognized hash code function '" + hashFuncName + "'");
                }

                // create and register expression
                var expression = item.Function.Name + "(" + ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(paramExpr) + ")";
                var lookupable = new FilterSpecLookupable(expression, getter, typeof(int?), true);
                item.Lookupable = lookupable;
                _factoryContext.ServicesContext.FilterNonPropertyRegisteryService.RegisterNonPropertyExpression(_factoryContext.AgentInstanceContextCreate.StatementName, item.FilterSpecCompiled.FilterForEventType, lookupable);
                _nonPropertyExpressions.Put(item.FilterSpecCompiled.FilterForEventType, lookupable);
            }
        }
Beispiel #5
0
        // Compare filters in statement with filters in segmented context, addendum filter compilation
        public static void PopulateAddendumFilters(
            Object keyValue,
            IList <FilterSpecCompiled> filtersSpecs,
            ContextDetailPartitioned segmentedSpec,
            StatementSpecCompiled optionalStatementSpecCompiled,
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums)
        {
            // determine whether create-named-window
            bool isCreateWindow = optionalStatementSpecCompiled != null && optionalStatementSpecCompiled.CreateWindowDesc != null;

            if (!isCreateWindow)
            {
                foreach (FilterSpecCompiled filtersSpec in filtersSpecs)
                {
                    ContextDetailPartitionItem foundPartition = null;
                    foreach (ContextDetailPartitionItem partitionItem in segmentedSpec.Items)
                    {
                        bool typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf(filtersSpec.FilterForEventType, partitionItem.FilterSpecCompiled.FilterForEventType);
                        if (typeOrSubtype)
                        {
                            foundPartition = partitionItem;
                        }
                    }

                    if (foundPartition == null)
                    {
                        continue;
                    }

                    var addendumFilters = new List <FilterValueSetParam>(foundPartition.PropertyNames.Count);
                    if (foundPartition.PropertyNames.Count == 1)
                    {
                        var propertyName = foundPartition.PropertyNames[0];
                        var getter       = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(propertyName);
                        var resultType   = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(propertyName);
                        var lookupable   = new FilterSpecLookupable(propertyName, getter, resultType);
                        var filter       = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keyValue);
                        addendumFilters.Add(filter);
                    }
                    else
                    {
                        var keys = ((MultiKeyUntyped)keyValue).Keys;
                        for (int i = 0; i < foundPartition.PropertyNames.Count; i++)
                        {
                            var partitionPropertyName = foundPartition.PropertyNames[i];
                            var getter     = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(partitionPropertyName);
                            var resultType = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(partitionPropertyName);
                            var lookupable = new FilterSpecLookupable(partitionPropertyName, getter, resultType);
                            var filter     = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keys[i]);
                            addendumFilters.Add(filter);
                        }
                    }

                    // add those predefined filter parameters, if any
                    FilterValueSetParam[][] partitionFilters = foundPartition.ParametersCompiled;

                    // add to existing if any are present
                    AddAddendums(addendums, addendumFilters, filtersSpec, partitionFilters);
                }
            }
            // handle segmented context for create-window
            else
            {
                String declaredAsName = optionalStatementSpecCompiled.CreateWindowDesc.AsEventTypeName;
                if (declaredAsName != null)
                {
                    foreach (FilterSpecCompiled filtersSpec in filtersSpecs)
                    {
                        ContextDetailPartitionItem foundPartition = null;
                        foreach (ContextDetailPartitionItem partitionItem in segmentedSpec.Items)
                        {
                            if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                            {
                                foundPartition = partitionItem;
                                break;
                            }
                        }

                        if (foundPartition == null)
                        {
                            continue;
                        }

                        var addendumFilters = new List <FilterValueSetParam>(foundPartition.PropertyNames.Count);
                        var propertyNumber  = 0;
                        foreach (String partitionPropertyName in foundPartition.PropertyNames)
                        {
                            var getter     = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(partitionPropertyName);
                            var resultType = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(partitionPropertyName);
                            var lookupable = new FilterSpecLookupable(partitionPropertyName, getter, resultType);

                            Object propertyValue;
                            if (keyValue is MultiKeyUntyped)
                            {
                                propertyValue = ((MultiKeyUntyped)keyValue).Get(propertyNumber);
                            }
                            else
                            {
                                propertyValue = keyValue;
                            }

                            FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, propertyValue);
                            addendumFilters.Add(filter);
                            propertyNumber++;
                        }

                        // add to existing if any are present
                        AddAddendums(addendums, addendumFilters, filtersSpec, foundPartition.ParametersCompiled);
                    }
                }
            }
        }