示例#1
0
        public void TestGetType()
        {
            Assert.AreEqual(typeof(string), _constantNode.ConstantType);

            _constantNode = new ExprConstantNodeImpl(null);
            Assert.IsNull(_constantNode.ConstantType);
        }
示例#2
0
        public void TestToExpressionString()
        {
            _constantNode = new ExprConstantNodeImpl("5");
            Assert.AreEqual("\"5\"", _constantNode.ToExpressionStringMinPrecedenceSafe());

            _constantNode = new ExprConstantNodeImpl(10);
            Assert.AreEqual("10", _constantNode.ToExpressionStringMinPrecedenceSafe());
        }
示例#3
0
        public void TestEqualsNode()
        {
            Assert.IsTrue(_constantNode.EqualsNode(new ExprConstantNodeImpl("5")));
            Assert.IsFalse(_constantNode.EqualsNode(new ExprOrNode()));
            Assert.IsFalse(_constantNode.EqualsNode(new ExprConstantNodeImpl(null)));
            Assert.IsFalse(_constantNode.EqualsNode(new ExprConstantNodeImpl(3)));

            _constantNode = new ExprConstantNodeImpl(null);
            Assert.IsTrue(_constantNode.EqualsNode(new ExprConstantNodeImpl(null)));
        }
示例#4
0
 public void SetUp()
 {
     _constantNode = new ExprConstantNodeImpl("5");
 }
示例#5
0
        private CountMinSketchSpecForge ValidateSpecification(ExprValidationContext exprValidationContext)
        {
            // default specification
            CountMinSketchSpecHashes hashes = new CountMinSketchSpecHashes(DEFAULT_EPS_OF_TOTAL_COUNT, DEFAULT_CONFIDENCE, DEFAULT_SEED);
            CountMinSketchSpecForge  spec   = new CountMinSketchSpecForge(hashes, null, DEFAULT_AGENT);

            // no parameters
            if (this.ChildNodes.Length == 0)
            {
                return(spec);
            }

            // check expected parameter type: a json object
            if (this.ChildNodes.Length > 1 || !(this.ChildNodes[0] is ExprConstantNode))
            {
                throw GetDeclaredWrongParameterExpr();
            }

            ExprConstantNode constantNode = (ExprConstantNode)this.ChildNodes[0];
            object           value        = constantNode.ConstantValue;

            if (!(value is IDictionary <string, object>))
            {
                throw GetDeclaredWrongParameterExpr();
            }

            // define what to populate
            PopulateFieldWValueDescriptor[] descriptors = new PopulateFieldWValueDescriptor[] {
                new PopulateFieldWValueDescriptor(
                    NAME_EPS_OF_TOTAL_COUNT,
                    typeof(double?),
                    spec.HashesSpec.GetType(),
                    value => {
                    if (value != null)
                    {
                        spec.HashesSpec.EpsOfTotalCount = value.AsDouble();
                    }
                },
                    true),
                new PopulateFieldWValueDescriptor(
                    NAME_CONFIDENCE,
                    typeof(double?),
                    spec.HashesSpec.GetType(),
                    value => {
                    if (value != null)
                    {
                        spec.HashesSpec.Confidence = value.AsDouble();
                    }
                },
                    true),
                new PopulateFieldWValueDescriptor(
                    NAME_SEED,
                    typeof(int?),
                    spec.HashesSpec.GetType(),
                    value => {
                    if (value != null)
                    {
                        spec.HashesSpec.Seed = value.AsInt32();
                    }
                },
                    true),
                new PopulateFieldWValueDescriptor(
                    NAME_TOPK,
                    typeof(int?),
                    spec.GetType(),
                    value => {
                    if (value != null)
                    {
                        spec.TopkSpec = (int?)value;
                    }
                },
                    true),
                new PopulateFieldWValueDescriptor(
                    NAME_AGENT,
                    typeof(string),
                    spec.GetType(),
                    value => {
                    if (value != null)
                    {
                        CountMinSketchAgentForge transform;
                        try {
                            var transformClass = exprValidationContext.ImportService.ResolveClass(
                                (string)value,
                                false,
                                ExtensionClassEmpty.INSTANCE);
                            transform = TypeHelper.Instantiate <CountMinSketchAgentForge>(transformClass);
                        }
                        catch (Exception e) {
                            throw new ExprValidationException("Failed to instantiate agent provider: " + e.Message, e);
                        }

                        spec.Agent = transform;
                    }
                },
                    true),
            };

            // populate from json, validates incorrect names, coerces types, instantiates transform
            PopulateUtil.PopulateSpecCheckParameters(descriptors, (IDictionary <string, object>)value, spec, ExprNodeOrigin.AGGPARAM, exprValidationContext);

            return(spec);
        }
示例#6
0
        // Since static method calls such as "Class.method('a')" and mapped properties "Stream.property('key')"
        // look the same, however as the validation could not resolve "Stream.property('key')" before calling this method,
        // this method tries to resolve the mapped property as a static method.
        // Assumes that this is an ExprIdentNode.
        private static ExprNode ResolveStaticMethodOrField(
            ExprIdentNode identNode,
            ExprValidationException propertyException,
            ExprValidationContext validationContext)
        {
            // Reconstruct the original string
            StringBuilder mappedProperty = new StringBuilder(identNode.UnresolvedPropertyName);
            if (identNode.StreamOrPropertyName != null) {
                mappedProperty.Insert(0, identNode.StreamOrPropertyName + '.');
            }

            // Parse the mapped property format into a class name, method and single string parameter
            MappedPropertyParseResult parse = ParseMappedProperty(mappedProperty.ToString());
            if (parse == null) {
                ExprConstantNode constNode = ResolveIdentAsEnumConst(
                    mappedProperty.ToString(),
                    validationContext.ImportService);
                if (constNode == null) {
                    throw propertyException;
                }
                else {
                    return constNode;
                }
            }

            // If there is a class name, assume a static method is possible.
            if (parse.ClassName != null) {
                IList<ExprNode> parameters =
                    Collections.SingletonList((ExprNode) new ExprConstantNodeImpl(parse.ArgString));
                IList<ExprChainedSpec> chain = new List<ExprChainedSpec>();
                chain.Add(new ExprChainedSpec(parse.ClassName, Collections.GetEmptyList<ExprNode>(), false));
                chain.Add(new ExprChainedSpec(parse.MethodName, parameters, false));
                ConfigurationCompilerExpression exprConfig =
                    validationContext.StatementCompileTimeService.Configuration.Compiler.Expression;
                ExprNode result = new ExprDotNodeImpl(chain, exprConfig.IsDuckTyping, exprConfig.IsUdfCache);

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (ExprValidationException e) {
                    throw new ExprValidationException(
                        $"Failed to resolve enumeration method, date-time method or mapped property '{mappedProperty}': {e.Message}",
                        e);
                }

                return result;
            }

            // There is no class name, try a single-row function
            string functionName = parse.MethodName;
            try {
                Pair<Type, ImportSingleRowDesc> classMethodPair =
                    validationContext.ImportService.ResolveSingleRow(functionName);
                IList<ExprNode> parameters =
                    Collections.SingletonList((ExprNode) new ExprConstantNodeImpl(parse.ArgString));
                IList<ExprChainedSpec> chain = Collections.SingletonList(
                    new ExprChainedSpec(classMethodPair.Second.MethodName, parameters, false));
                ExprNode result = new ExprPlugInSingleRowNode(
                    functionName,
                    classMethodPair.First,
                    chain,
                    classMethodPair.Second);

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception ex) {
                    throw new ExprValidationException(
                        "Plug-in aggregation function '" + parse.MethodName + "' failed validation: " + ex.Message);
                }

                return result;
            }
            catch (ImportUndefinedException) {
                // Not an single-row function
            }
            catch (ImportException e) {
                throw new IllegalStateException("Error resolving single-row function: " + e.Message, e);
            }

            // Try an aggregation function factory
            try {
                AggregationFunctionForge aggregationForge =
                    validationContext.ImportService.ResolveAggregationFunction(parse.MethodName);
                ExprNode result = new ExprPlugInAggNode(false, aggregationForge, parse.MethodName);
                result.AddChildNode(new ExprConstantNodeImpl(parse.ArgString));

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception e) {
                    throw new ExprValidationException(
                        "Plug-in aggregation function '" + parse.MethodName + "' failed validation: " + e.Message);
                }

                return result;
            }
            catch (ImportUndefinedException) {
                // Not an aggregation function
            }
            catch (ImportException e) {
                throw new IllegalStateException("Error resolving aggregation: " + e.Message, e);
            }

            // absolutely cannot be resolved
            throw propertyException;
        }
示例#7
0
 public void SetUp()
 {
     _container    = SupportContainer.Reset();
     _constantNode = new ExprConstantNodeImpl("5");
 }