/// <summary>
        /// Add a filter for the given field path.
        /// </summary>
        /// <remarks>
        /// This call adds additional filters to any previously-specified ones.
        /// </remarks>
        /// <param name="fieldPath">The field path to filter on. Must not be null.</param>
        /// <param name="op">The filter operator.</param>
        /// <param name="value">The value to compare in the filter.</param>
        /// <returns>A new query based on the current one, but with the additional specified filter applied.</returns>
        public Query Where(FieldPath fieldPath, QueryOperator op, object value)
        {
            FieldOp queryOp       = GetOperator(op);
            var     unaryOperator = GetUnaryOperator(value);
            Filter  filter;

            if (unaryOperator != UnaryFilter.Types.Operator.Unspecified)
            {
                if (queryOp == FieldOp.Equal)
                {
                    filter = new Filter {
                        UnaryFilter = new UnaryFilter {
                            Field = fieldPath.ToFieldReference(), Op = unaryOperator
                        }
                    };
                }
                else
                {
                    throw new ArgumentException(nameof(value), "null and NaN values can only be used with the Equal operator");
                }
            }
            else
            {
                var convertedValue = ValueSerializer.Serialize(value);
                filter = new Filter {
                    FieldFilter = new FieldFilter {
                        Field = fieldPath.ToFieldReference(), Op = queryOp, Value = convertedValue
                    }
                };
            }
            return(WithFilter(filter));
        }
Exemple #2
0
            internal static InternalFilter Create(FieldPath fieldPath, FieldOp op, object value)
            {
                GaxPreconditions.CheckNotNull(fieldPath, nameof(fieldPath));
                var unaryOperator = GetUnaryOperator(value);

                if (unaryOperator != UnaryOp.Unspecified)
                {
                    if (op == FieldOp.Equal)
                    {
                        return(new InternalFilter(fieldPath, (int)unaryOperator, null));
                    }
                    else
                    {
                        throw new ArgumentException(nameof(value), "null and NaN values can only be used with the Equal operator");
                    }
                }
                else
                {
                    var convertedValue = ValueSerializer.Serialize(value);
                    if (SentinelValue.GetKind(convertedValue) != SentinelValue.SentinelKind.None)
                    {
                        throw new ArgumentException(nameof(value), "Sentinel values cannot be specified in filters");
                    }
                    return(new InternalFilter(fieldPath, (int)op, convertedValue));
                }
            }
Exemple #3
0
            internal static InternalFilter Create(FieldPath fieldPath, QueryOperator op, object value)
            {
                GaxPreconditions.CheckNotNull(fieldPath, nameof(fieldPath));
                FieldOp queryOp       = GetOperator(op);
                var     unaryOperator = GetUnaryOperator(value);

                if (unaryOperator != UnaryOp.Unspecified)
                {
                    if (queryOp == FieldOp.Equal)
                    {
                        return(new InternalFilter(fieldPath, (int)unaryOperator, null));
                    }
                    else
                    {
                        throw new ArgumentException(nameof(value), "null and NaN values can only be used with the Equal operator");
                    }
                }
                else
                {
                    var convertedValue = ValueSerializer.Serialize(value);
                    if (convertedValue.IsDeleteSentinel() || convertedValue.IsServerTimestampSentinel())
                    {
                        throw new ArgumentException(nameof(value), "Sentinel values cannot be specified in filters");
                    }
                    return(new InternalFilter(fieldPath, (int)queryOp, convertedValue));
                }
            }
Exemple #4
0
        /// <summary>
        /// Add a filter for the given field path.
        /// </summary>
        /// <remarks>
        /// This call adds additional filters to any previously-specified ones.
        /// </remarks>
        /// <param name="fieldPath">The field path to filter on. Must not be null.</param>
        /// <param name="op">The filter operator.</param>
        /// <param name="value">The value to compare in the filter. Must not be a sentinel value.</param>
        /// <returns>A new query based on the current one, but with the additional specified filter applied.</returns>
        private Query Where(FieldPath fieldPath, FieldOp op, object value)
        {
            InternalFilter filter     = InternalFilter.Create(fieldPath, op, value);
            var            newFilters = _filters == null ? new List <InternalFilter>() : new List <InternalFilter>(_filters);

            newFilters.Add(filter);
            return(new Query(Collection, _offset, _limit, _orderings, newFilters, _projections, _startAt, _endAt));
        }
Exemple #5
0
        // Note: the two general Where methods were originally public, accepting a public QueryOperator enum.
        // If we ever want to make them public again, we should reinstate the QueryOperator enum to avoid an API
        // dependency on the proto enum.

        /// <summary>
        /// Add a filter for the given field path.
        /// </summary>
        /// <remarks>
        /// This call adds additional filters to any previously-specified ones.
        /// </remarks>
        /// <param name="fieldPath">The dot-separated field path to filter on. Must not be null or empty.</param>
        /// <param name="op">The filter operator. Must not be null.</param>
        /// <param name="value">The value to compare in the filter.</param>
        /// <returns>A new query based on the current one, but with the additional specified filter applied.</returns>
        private Query Where(string fieldPath, FieldOp op, object value)
        {
            GaxPreconditions.CheckNotNullOrEmpty(fieldPath, nameof(fieldPath));
            return(Where(FieldPath.FromDotSeparatedString(fieldPath), op, value));
        }