সমষ্টিগত
সমস্ত সমষ্টিগত ফাংশন aggregate(...) পর্যায়ে শীর্ষ-স্তরের এক্সপ্রেশন হিসেবে ব্যবহার করা যেতে পারে।
| নাম | বিবরণ |
COUNT | নথির সংখ্যা প্রদান করে। |
COUNT_IF | একটি রাশির TRUE মূল্যায়নের ক্ষেত্রে ডকুমেন্টের সংখ্যা প্রদান করে। |
COUNT_DISTINCT | অনন্য, নন- NULL মানের গণনা প্রদান করে |
SUM | সকল NUMERIC মানের যোগফল প্রদান করে |
AVERAGE | সকল NUMERIC মানের গড় প্রদান করে |
MINIMUM | সর্বনিম্ন নন- NULL মান প্রদান করে |
MAXIMUM | সর্বোচ্চ নন- NULL মান প্রদান করে |
FIRST | প্রথম ডকুমেন্টের জন্য expression মান প্রদান করে। |
LAST | শেষ ডকুমেন্টের জন্য expression মান প্রদান করে। |
ARRAY_AGG | সকল ইনপুট মানের একটি অ্যারে প্রদান করে। |
ARRAY_AGG_DISTINCT | সকল স্বতন্ত্র ইনপুট মানের একটি অ্যারে প্রদান করে। |
COUNT টি
বাক্য গঠন:
count() -> INT64
count(expression: ANY) -> INT64
বর্ণনা:
পূর্ববর্তী পর্যায়ের নথির গণনা প্রদান করে যেখানে expression যেকোনো অ- NULL মানের মূল্যায়ন করে। যদি কোন expression প্রদান না করা হয়, তাহলে পূর্ববর্তী পর্যায়ের নথির মোট গণনা প্রদান করে।
Web
// Total number of books in the collection const countOfAll = await execute(db.pipeline() .collection("books") .aggregate(countAll().as("count")) ); // Number of books with nonnull `ratings` field const countField = await execute(db.pipeline() .collection("books") .aggregate(field("ratings").count().as("count")) );
সুইফট
// Total number of books in the collection let countAll = try await db.pipeline() .collection("books") .aggregate([CountAll().as("count")]) .execute() // Number of books with nonnull `ratings` field let countField = try await db.pipeline() .collection("books") .aggregate([Field("ratings").count().as("count")]) .execute()
Kotlin
// Total number of books in the collection val countAll = db.pipeline() .collection("books") .aggregate(AggregateFunction.countAll().alias("count")) .execute() // Number of books with nonnull `ratings` field val countField = db.pipeline() .collection("books") .aggregate(AggregateFunction.count("ratings").alias("count")) .execute()
Java
// Total number of books in the collection Task<Pipeline.Snapshot> countAll = db.pipeline() .collection("books") .aggregate(AggregateFunction.countAll().alias("count")) .execute(); // Number of books with nonnull `ratings` field Task<Pipeline.Snapshot> countField = db.pipeline() .collection("books") .aggregate(AggregateFunction.count("ratings").alias("count")) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Count # Total number of books in the collection count_all = ( client.pipeline().collection("books").aggregate(Count().as_("count")).execute() ) # Number of books with nonnull `ratings` field count_field = ( client.pipeline() .collection("books") .aggregate(Count("ratings").as_("count")) .execute() )
COUNT_IF হলে
বাক্য গঠন:
count_if(expression: BOOLEAN) -> INT64
বর্ণনা:
পূর্ববর্তী পর্যায়ের নথির সংখ্যা প্রদান করে যেখানে expression TRUE তে মূল্যায়ন করে।
Web
const result = await execute(db.pipeline() .collection("books") .aggregate( field("rating").greaterThan(4).countIf().as("filteredCount") ) );
সুইফট
let result = try await db.pipeline() .collection("books") .aggregate([ AggregateFunction("count_if", [Field("rating").greaterThan(4)]).as("filteredCount") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate( AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate( AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount") ) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("rating").greater_than(4).count_if().as_("filteredCount")) .execute() )
COUNT_DISTINCT টি
বাক্য গঠন:
count_distinct(expression: ANY) -> INT64
বর্ণনা:
expression অনন্য নন- NULL , নন- ABSENT মানের সংখ্যা প্রদান করে।
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("author").countDistinct().as("unique_authors")) );
সুইফট
let result = try await db.pipeline() .collection("books") .aggregate([AggregateFunction("count_distinct", [Field("author")]).as("unique_authors")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors")) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("author").count_distinct().as_("unique_authors")) .execute() )
যোগফল
বাক্য গঠন:
sum(expression: ANY) -> NUMBER
বর্ণনা:
অ-সাংখ্যিক মান উপেক্ষা করে সকল সংখ্যাসূচক মানের যোগফল প্রদান করে। যদি কোন মান NaN হয় তবে NaN প্রদান করে।
আউটপুটটি সবচেয়ে প্রশস্ত ইনপুট টাইপের মতো একই ধরণের হবে, তবে নিম্নলিখিত ক্ষেত্রেগুলি ছাড়া:
- একটি
INTEGERযদিINTEGERহিসেবে উপস্থাপন করা না যায়, তাহলে এটিকেDOUBLEতে রূপান্তরিত করা হবে।
Web
const result = await execute(db.pipeline() .collection("cities") .aggregate(field("population").sum().as("totalPopulation")) );
সুইফট
let result = try await db.pipeline() .collection("cities") .aggregate([Field("population").sum().as("totalPopulation")]) .execute()
Kotlin
val result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.sum("population").alias("totalPopulation")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.sum("population").alias("totalPopulation")) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("cities") .aggregate(Field.of("population").sum().as_("totalPopulation")) .execute() )
গড়
বাক্য গঠন:
average(expression: ANY) -> FLOAT64
বর্ণনা:
অ-সাংখ্যিক মান উপেক্ষা করে সকল সংখ্যাসূচক মানের গড় প্রদান করে। যদি কোন মান NaN হয় তাহলে NaN তে মূল্যায়ন করা হয়, অথবা যদি কোন সংখ্যাসূচক মান একত্রিত না হয় তাহলে NULL তে মূল্যায়ন করা হয়।
আউটপুট ইনপুট টাইপের মতো একই ধরণের হবে, তবে নিম্নলিখিত ক্ষেত্রে:
- একটি
INTEGERযদিINTEGERহিসেবে উপস্থাপন করা না যায়, তাহলে এটিকেDOUBLEতে রূপান্তরিত করা হবে।
Web
const result = await execute(db.pipeline() .collection("cities") .aggregate(field("population").average().as("averagePopulation")) );
সুইফট
let result = try await db.pipeline() .collection("cities") .aggregate([Field("population").average().as("averagePopulation")]) .execute()
Kotlin
val result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.average("population").alias("averagePopulation")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.average("population").alias("averagePopulation")) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("cities") .aggregate(Field.of("population").average().as_("averagePopulation")) .execute() )
ন্যূনতম
বাক্য গঠন:
minimum(expression: ANY) -> ANY
বর্ণনা:
প্রতিটি ডকুমেন্টে মূল্যায়ন করার সময় expression সর্বনিম্ন অ- NULL , অনুপস্থিত নয় এমন মান প্রদান করে।
যদি কোন অ- NULL , অনুপস্থিত মান না থাকে, তাহলে NULL ফেরত পাঠানো হয়। এর মধ্যে যখন কোন নথি বিবেচনা করা হয় না তখনও অন্তর্ভুক্ত থাকে।
যদি একাধিক ন্যূনতম সমতুল্য মান থাকে, তাহলে ঐ মানগুলির যেকোনো একটি ফেরত দেওয়া যেতে পারে। মান প্রকারের ক্রমবিন্যাস নথিভুক্ত ক্রম অনুসরণ করে।
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) );
সুইফট
let result = try await db.pipeline() .collection("books") .aggregate([Field("price").minimum().as("minimumPrice")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.minimum("price").alias("minimumPrice")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.minimum("price").alias("minimumPrice")) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("price").minimum().as_("minimumPrice")) .execute() )
সর্বাধিক
বাক্য গঠন:
maximum(expression: ANY) -> ANY
বর্ণনা:
প্রতিটি ডকুমেন্টে মূল্যায়ন করা হলে, expression সর্বাধিক অ- NULL , অনুপস্থিত মান প্রদান করে।
যদি কোন অ- NULL , অনুপস্থিত মান না থাকে, তাহলে NULL ফেরত পাঠানো হয়। এর মধ্যে যখন কোন নথি বিবেচনা করা হয় না তখনও অন্তর্ভুক্ত থাকে।
যদি একাধিক সর্বোচ্চ সমতুল্য মান থাকে, তাহলে ঐ মানগুলির যেকোনো একটি ফেরত দেওয়া যেতে পারে। মান প্রকারের ক্রমবিন্যাস নথিভুক্ত ক্রম অনুসরণ করে।
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) );
সুইফট
let result = try await db.pipeline() .collection("books") .aggregate([Field("price").maximum().as("maximumPrice")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.maximum("price").alias("maximumPrice")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.maximum("price").alias("maximumPrice")) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("price").maximum().as_("maximumPrice")) .execute() )
প্রথম
বাক্য গঠন:
first(expression: ANY) -> ANY
বর্ণনা:
প্রথম ফেরত দেওয়া ডকুমেন্টের জন্য expression মান প্রদান করে।
শেষ
বাক্য গঠন:
last(expression: ANY) -> ANY
বর্ণনা:
শেষ ফেরত দস্তাবেজের জন্য expression মান প্রদান করে।
ARRAY_AGG সম্পর্কে
বাক্য গঠন:
array_agg(expression: ANY) -> ARRAY<ANY>
বর্ণনা:
প্রতিটি ডকুমেন্টে মূল্যায়ন করা হলে, সমস্ত expression মান ধারণকারী একটি অ্যারে প্রদান করে।
যদি রাশিটি একটি অনুপস্থিত মানে সমাধান করে, তাহলে এটি NULL তে রূপান্তরিত হয়।
আউটপুট অ্যারেতে উপাদানগুলির ক্রম স্থিতিশীল নয় এবং এর উপর নির্ভর করা উচিত নয়।
ARRAY_AGG_DISTINCT সম্পর্কে
বাক্য গঠন:
array_agg_distinct(expression: ANY) -> ARRAY<ANY>
বর্ণনা:
প্রতিটি ডকুমেন্টে মূল্যায়ন করা হলে, expression সমস্ত স্বতন্ত্র মান ধারণকারী একটি অ্যারে প্রদান করে।
যদি রাশিটি একটি অনুপস্থিত মানে সমাধান করে, তাহলে এটি NULL তে রূপান্তরিত হয়।
আউটপুট অ্যারেতে উপাদানগুলির ক্রম স্থিতিশীল নয় এবং এর উপর নির্ভর করা উচিত নয়।