public static ParseResult CreateAggregationKindsFromTokenList(IEnumerable <Token> tokenList, Field.Kind fieldKind, out List <Aggregation.Kinds> aggregationTypes) { aggregationTypes = new List <Aggregation.Kinds>(); foreach (var token in tokenList) { Aggregation.Kinds aggrType = Aggregation.Kinds.Undefined; // check whether the aggregation type name exists if (!SemanticsAnalyzer.CreateAggregationTypeFromName(token.Text, ref aggrType)) { return(new ParseResult(ParseCode.SemanticsInvalidAggregationType, "Invalid aggregation type", token.ColumnPos)); } // check whether the aggregation type is supported by the field type if (!Field.IsAggregationAvailable(fieldKind, aggrType)) { return(new ParseResult(ParseCode.SemanticsInvalidAggregationType, "Invalid aggregation type for the requested field type", token.ColumnPos)); } aggregationTypes.Add(aggrType); } return(new ParseResult(ParseCode.Success)); }
public static bool IsAggregationAvailable(Kind fieldType, Aggregation.Kinds aggrType) { switch (fieldType) { case Kind.Property: { switch (aggrType) { case Aggregation.Kinds.Snapshot: return(true); case Aggregation.Kinds.Count: return(true); default: return(false); } } case Kind.Metric: { switch (aggrType) { case Aggregation.Kinds.Undefined: return(false); default: return(true); } } default: return(false); } }
// Tries to translate the string describing into an Aggregation.Type // if there is not corresponding aggregator return false to signal the semantic failure public static bool CreateAggregationTypeFromName(string aggregationName, ref Aggregation.Kinds aggregationKind) { aggregationKind = Aggregation.CreateAggregationKindFromName(aggregationName); if (aggregationKind == Aggregation.Kinds.Undefined) { return(false); } return(true); }