public AggregationStateCountMinSketchForge( ExprAggMultiFunctionCountMinSketchNode parent, CountMinSketchSpecForge specification) { this.parent = parent; this.specification = specification; }
public override AggregationForgeFactory ValidateAggregationChild(ExprValidationContext validationContext) { if (IsDistinct) { throw new ExprValidationException(MessagePrefix + "is not supported with distinct"); } // for declaration, validate the specification and return the state factory if (aggType == CountMinSketchAggType.STATE) { if (validationContext.StatementRawInfo.StatementType != StatementType.CREATE_TABLE) { throw new ExprValidationException(MessagePrefix + "can only be used in create-table statements"); } CountMinSketchSpecForge specification = ValidateSpecification(validationContext); AggregationStateCountMinSketchForge stateFactory = new AggregationStateCountMinSketchForge(this, specification); forgeFactory = new AggregationForgeFactoryAccessCountMinSketchState(this, stateFactory); return(forgeFactory); } if (aggType != CountMinSketchAggType.ADD) { // other methods are only used with table-access expressions throw new ExprValidationException(MessagePrefix + "requires the use of a table-access expression"); } if (validationContext.StatementRawInfo.IntoTableName == null) { throw new ExprValidationException(MessagePrefix + "can only be used with into-table"); } if (positionalParams.Length == 0 || positionalParams.Length > 1) { throw new ExprValidationException(MessagePrefix + "requires a single parameter expression"); } ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.AGGPARAM, this.ChildNodes, validationContext); // obtain evaluator ExprForge addOrFrequencyEvaluator = null; Type addOrFrequencyEvaluatorReturnType = null; if (aggType == CountMinSketchAggType.ADD) { addOrFrequencyEvaluator = ChildNodes[0].Forge; addOrFrequencyEvaluatorReturnType = addOrFrequencyEvaluator.EvaluationType; } forgeFactory = new AggregationForgeFactoryAccessCountMinSketchAdd(this, addOrFrequencyEvaluator, addOrFrequencyEvaluatorReturnType); return(forgeFactory); }
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); }