FIRAggregateField.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2023 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. @class FIRFieldPath;
  19. // TODO(sum/avg) move this entire file to ../Public/FirebaseFirestore when the API can be public
  20. /**
  21. * Represents an aggregation that can be performed by Firestore.
  22. */
  23. NS_SWIFT_NAME(AggregateField)
  24. @interface FIRAggregateField : NSObject
  25. /** :nodoc: */
  26. - (instancetype)init NS_UNAVAILABLE;
  27. /**
  28. * Create an `AggregateField` object that can be used to compute the count of
  29. * documents in the result set of a query.
  30. *
  31. * The result of a count operation will always be a 64-bit integer value.
  32. *
  33. * @return `AggregateField` object that can be used to compute the count of
  34. * documents in the result set of a query.
  35. */
  36. + (instancetype)aggregateFieldForCount NS_SWIFT_NAME(count());
  37. /**
  38. * Create an `AggregateField` object that can be used to compute the sum of
  39. * a specified field over a range of documents in the result set of a query.
  40. *
  41. * The result of a sum operation will always be a 64-bit integer value, a double, or NaN.
  42. *
  43. * - Summing over zero documents or fields will result in 0L.
  44. * - Summing over NaN will result in a double value representing NaN.
  45. * - A sum that overflows the maximum representable 64-bit integer value will result in a double
  46. * return value. This may result in lost precision of the result.
  47. * - A sum that overflows the maximum representable double value will result in a double return
  48. * value representing infinity.
  49. *
  50. * @param field Specifies the field to sum across the result set.
  51. * @return `AggregateField` object that can be used to compute the sum of
  52. * a specified field over a range of documents in the result set of a query.
  53. */
  54. + (instancetype)aggregateFieldForSumOfField:(NSString *)field NS_SWIFT_NAME(sum(_:));
  55. /**
  56. * Create an `AggregateField` object that can be used to compute the sum of
  57. * a specified field over a range of documents in the result set of a query.
  58. *
  59. * The result of a sum operation will always be a 64-bit integer value, a double, or NaN.
  60. *
  61. * - Summing over zero documents or fields will result in 0L.
  62. * - Summing over NaN will result in a double value representing NaN.
  63. * - A sum that overflows the maximum representable 64-bit integer value will result in a double
  64. * return value. This may result in lost precision of the result.
  65. * - A sum that overflows the maximum representable double value will result in a double return
  66. * value representing infinity.
  67. *
  68. * @param fieldPath Specifies the field to sum across the result set.
  69. * @return `AggregateField` object that can be used to compute the sum of
  70. * a specified field over a range of documents in the result set of a query.
  71. */
  72. + (instancetype)aggregateFieldForSumOfFieldPath:(FIRFieldPath *)fieldPath NS_SWIFT_NAME(sum(_:));
  73. /**
  74. * Create an `AggregateField` object that can be used to compute the average of
  75. * a specified field over a range of documents in the result set of a query.
  76. *
  77. * The result of an average operation will always be a 64-bit integer value, a double, or NaN.
  78. *
  79. * - Averaging over zero documents or fields will result in a double value representing NaN.
  80. * - Averaging over NaN will result in a double value representing NaN.
  81. *
  82. * @param field Specifies the field to average across the result set.
  83. * @return `AggregateField` object that can be used to compute the average of
  84. * a specified field over a range of documents in the result set of a query.
  85. */
  86. + (instancetype)aggregateFieldForAverageOfField:(NSString *)field NS_SWIFT_NAME(average(_:));
  87. /**
  88. * Create an `AggregateField` object that can be used to compute the average of
  89. * a specified field over a range of documents in the result set of a query.
  90. *
  91. * The result of an average operation will always be a 64-bit integer value, a double, or NaN.
  92. *
  93. * - Averaging over zero documents or fields will result in a double value representing NaN.
  94. * - Averaging over NaN will result in a double value representing NaN.
  95. *
  96. * @param fieldPath Specifies the field to average across the result set.
  97. * @return `AggregateField` object that can be used to compute the average of
  98. * a specified field over a range of documents in the result set of a query.
  99. */
  100. + (instancetype)aggregateFieldForAverageOfFieldPath:(FIRFieldPath *)fieldPath
  101. NS_SWIFT_NAME(average(_:));
  102. @end
  103. NS_ASSUME_NONNULL_END