সমষ্টি
সমস্ত অ্যাগ্রিগেট ফাংশন ` 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() -> INT64
count(expression: ANY) -> INT64
বর্ণনা:
পূর্ববর্তী ধাপের সেইসব ডকুমেন্টের সংখ্যা ফেরত দেয়, যেখানে expression মান যেকোনো নন- NULL ভ্যালু হয়। যদি কোনো expression প্রদান করা না হয়, তবে পূর্ববর্তী ধাপের ডকুমেন্টগুলোর মোট সংখ্যা ফেরত দেওয়া হয়।
নোড.জেএস
// Total number of books in the collection const countOfAll = await db.pipeline() .collection("books") .aggregate(countAll().as("count")) .execute(); // Number of books with nonnull `ratings` field const countField = await db.pipeline() .collection("books") .aggregate(field("ratings").count().as("count")) .execute();
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() )
জাভা
// Total number of books in the collection Pipeline.Snapshot countAll = firestore.pipeline().collection("books").aggregate(countAll().as("count")).execute().get(); // Number of books with nonnull `ratings` field Pipeline.Snapshot countField = firestore .pipeline() .collection("books") .aggregate(count("ratings").as("count")) .execute() .get();
COUNT_IF
সিনট্যাক্স:
count_if(expression: BOOLEAN) -> INT64
বর্ণনা:
পূর্ববর্তী ধাপের সেইসব ডকুমেন্টের সংখ্যা ফেরত দেয় যেখানে expression মান TRUE হয়।
নোড.জেএস
const result = await db.pipeline() .collection("books") .aggregate( field("rating").greaterThan(4).countIf().as("filteredCount") ) .execute();
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() )
জাভা
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countIf(field("rating").greaterThan(4)).as("filteredCount")) .execute() .get();
COUNT_DISTINCT
সিনট্যাক্স:
count_distinct(expression: ANY) -> INT64
বর্ণনা:
expression অনন্য, নন- NULL ও নন- ABSENT মানগুলোর সংখ্যা ফেরত দেয়।
নোড.জেএস
const result = await db.pipeline() .collection("books") .aggregate(field("author").countDistinct().as("unique_authors")) .execute();
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() )
জাভা
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countDistinct("author").as("unique_authors")) .execute() .get();
যোগফল
সিনট্যাক্স:
sum(expression: ANY) -> NUMBER
বর্ণনা:
অ-সংখ্যাসূচক মান উপেক্ষা করে সমস্ত সংখ্যাসূচক মানের যোগফল ফেরত দেয়। যদি কোনো মান NaN হয়, তবে NaN ফেরত দেয়।
নিম্নলিখিত ক্ষেত্রগুলি ব্যতীত, আউটপুটের ধরণ প্রশস্ততম ইনপুট ধরণের মতোই হবে:
- যদি কোনো
INTEGERINTEGERহিসেবে প্রকাশ করা না যায়, তবে সেটিকেDOUBLEএ রূপান্তর করা হবে।
নোড.জেএস
const result = await db.pipeline() .collection("cities") .aggregate(field("population").sum().as("totalPopulation")) .execute();
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() )
জাভা
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(sum("population").as("totalPopulation")) .execute() .get();
গড়
সিনট্যাক্স:
average(expression: ANY) -> FLOAT64
বর্ণনা:
অ-সংখ্যাসূচক মান উপেক্ষা করে সমস্ত সংখ্যাসূচক মানের গড় ফেরত দেয়। যদি কোনো মান NaN হয়, তবে এর মান NaN হয়, অথবা যদি কোনো সংখ্যাসূচক মানের যোগফল বের না করা হয়, তবে এর মান NULL ।
নিম্নলিখিত ক্ষেত্রগুলি ব্যতীত আউটপুটের ধরণ ইনপুটের ধরনের মতোই হবে:
- যদি কোনো
INTEGERINTEGERহিসেবে প্রকাশ করা না যায়, তবে সেটিকেDOUBLEএ রূপান্তর করা হবে।
নোড.জেএস
const result = await db.pipeline() .collection("cities") .aggregate(field("population").average().as("averagePopulation")) .execute();
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() )
জাভা
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(average("population").as("averagePopulation")) .execute() .get();
সর্বনিম্ন
সিনট্যাক্স:
minimum(expression: ANY) -> ANY
বর্ণনা:
প্রতিটি ডকুমেন্টের উপর মূল্যায়ন করার পর expression সর্বনিম্ন নন-নাল ( NULL ও নন-অ্যাবসেন্ট (absent) মান ফেরত দেয়।
যদি NULL নয় এমন বা অনুপস্থিত নয় এমন কোনো মান না থাকে, তাহলে NULL রিটার্ন করা হয়। কোনো ডকুমেন্ট বিবেচনা না করা হলেও এটি প্রযোজ্য।
যদি একাধিক সর্বনিম্ন সমতুল্য মান থাকে, তবে সেই মানগুলোর যেকোনো একটি ফেরত দেওয়া যেতে পারে। মানের প্রকারের ক্রম নথিভুক্ত ক্রম অনুসরণ করে।
নোড.জেএস
const result = await db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) .execute();
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() )
জাভা
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(minimum("price").as("minimumPrice")) .execute() .get();
সর্বোচ্চ
সিনট্যাক্স:
maximum(expression: ANY) -> ANY
বর্ণনা:
প্রতিটি ডকুমেন্টের উপর মূল্যায়ন করার পর expression সর্বোচ্চ নন-নাল ( NULL ও নন-অ্যাবসেন্ট (absent) মান ফেরত দেয়।
যদি NULL নয় এমন বা অনুপস্থিত নয় এমন কোনো মান না থাকে, তাহলে NULL রিটার্ন করা হয়। কোনো ডকুমেন্ট বিবেচনা না করা হলেও এটি প্রযোজ্য।
যদি একাধিক সর্বোচ্চ সমতুল্য মান থাকে, তবে সেই মানগুলোর যেকোনো একটি ফেরত দেওয়া যেতে পারে। মানের প্রকারের ক্রম নথিভুক্ত ক্রম অনুসরণ করে।
নোড.জেএস
const result = await db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) .execute();
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() )
জাভা
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(maximum("price").as("maximumPrice")) .execute() .get();
প্রথম
সিনট্যাক্স:
first(expression: ANY) -> ANY
বর্ণনা:
প্রথম ফেরত আসা ডকুমেন্টটির জন্য expression মান প্রদান করে।
শেষ
সিনট্যাক্স:
last(expression: ANY) -> ANY
বর্ণনা:
সর্বশেষ ফেরত আসা ডকুমেন্টের expression মান প্রদান করে।
অ্যারে_এজিজি
সিনট্যাক্স:
array_agg(expression: ANY) -> ARRAY<ANY>
বর্ণনা:
প্রতিটি ডকুমেন্টে মূল্যায়ন করার পর expression সমস্ত মান ধারণকারী একটি অ্যারে ফেরত দেয়।
যদি এক্সপ্রেশনটির মান অনুপস্থিত থাকে, তবে সেটিকে NULL এ রূপান্তর করা হয়।
আউটপুট অ্যারের উপাদানগুলোর ক্রম স্থিতিশীল নয় এবং এর ওপর নির্ভর করা উচিত নয়।
অ্যারে_এজিজি_ডিস্টিংক্ট
সিনট্যাক্স:
array_agg_distinct(expression: ANY) -> ARRAY<ANY>
বর্ণনা:
প্রতিটি ডকুমেন্টে মূল্যায়ন করার পর expression সমস্ত স্বতন্ত্র মান ধারণকারী একটি অ্যারে ফেরত দেয়।
যদি এক্সপ্রেশনটির মান অনুপস্থিত থাকে, তবে সেটিকে NULL এ রূপান্তর করা হয়।
আউটপুট অ্যারের উপাদানগুলোর ক্রম স্থিতিশীল নয় এবং এর ওপর নির্ভর করা উচিত নয়।