private static QueryFieldName ExtractIndexFieldName(Query query, BlittableJsonReaderObject parameters, QueryExpression field, QueryMetadata metadata) { if (field is FieldExpression fe) { return(metadata.GetIndexFieldName(fe, parameters)); } if (field is ValueExpression ve) { return(metadata.GetIndexFieldName(new QueryFieldName(ve.Token, false), parameters)); } if (field is MethodExpression me) { var methodType = QueryMethod.GetMethodType(me.Name.Value); switch (methodType) { case MethodType.Id: if (me.Arguments == null || me.Arguments.Count == 0) { return(QueryFieldName.DocumentId); } if (me.Arguments[0] is FieldExpression docAlias && docAlias.Compound.Count == 1 && docAlias.Compound[0].Equals(query.From.Alias)) { return(QueryFieldName.DocumentId); } throw new InvalidQueryException("id() can only be used on the root query alias but got: " + me.Arguments[0], query.QueryText, parameters); case MethodType.Count: if (me.Arguments == null || me.Arguments.Count == 0) { return(QueryFieldName.Count); } if (me.Arguments[0] is FieldExpression countAlias && countAlias.Compound.Count == 1 && countAlias.Compound[0].Equals(query.From.Alias)) { return(QueryFieldName.Count); } throw new InvalidQueryException("count() can only be used on the root query alias but got: " + me.Arguments[0], query.QueryText, parameters); case MethodType.Sum: if (me.Arguments != null && me.Arguments.Count == 1 && me.Arguments[0] is FieldExpression f && f.Compound.Count == 1) { return(new QueryFieldName(f.Compound[0], f.IsQuoted)); } throw new InvalidQueryException("sum() must be called with a single field name, but was called: " + me, query.QueryText, parameters); default: throw new InvalidQueryException("Method " + me.Name.Value + " cannot be used in an expression in this manner", query.QueryText, parameters); } } throw new InvalidQueryException("Expected field, got: " + field, query.QueryText, parameters); }
private static QueryFieldName ExtractIndexFieldName(ValueExpression field, QueryMetadata metadata, BlittableJsonReaderObject parameters) { return(metadata.GetIndexFieldName(new QueryFieldName(field.Token.Value, field.Value == ValueTokenType.String), parameters)); }