এগ্রিগেট
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 প্রদান করা না হলে, আগের ধাপ থেকে
ডকুমেন্টের মোট সংখ্যা রিটার্ন করে।
Node.js
// 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")) );
Swift
// 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();
Python
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();
Go
// Total number of books in the collection countAll, err := client.Pipeline().Collection("books"). Aggregate(firestore.Accumulators(firestore.CountAll().As("count"))). Execute(ctx).Results().GetAll() if err != nil { fmt.Fprintf(w, "GetAll failed: %v", err) return err } // Number of books with nonnull `ratings` field countField, err := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators(firestore.Count("ratings").As("count"))). Execute(ctx).Results().GetAll() if err != nil { fmt.Fprintf(w, "GetAll failed: %v", err) return err }
COUNT_IF
সিনট্যাক্স:
count_if(expression: BOOLEAN) -> INT64
বিবরণ:
আগের ধাপ থেকে ডকুমেন্টের সংখ্যা দেখায় যেখানে expression
TRUE হিসেবে মূল্যায়ন করে।
Node.js
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") ) );
Swift
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();
Python
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();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.CountIf(firestore.FieldOf("rating").GreaterThan(4)).As("filteredCount"), )). Execute(ctx)
COUNT_DISTINCT
সিনট্যাক্স:
count_distinct(expression: ANY) -> INT64
বিবরণ:
expression-এর অনন্য নন-NULL, নন-ABSENT মানের সংখ্যা দেখায়।
Node.js
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")) );
Swift
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();
Python
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();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.CountDistinct("author").As("unique_authors"), )). Execute(ctx)
SUM
সিনট্যাক্স:
sum(expression: ANY) -> NUMBER
বিবরণ:
সংখ্যা নয় এমন মান বাদ দিয়ে সব সংখ্যাগত মানের যোগফল দেখায়। কোনও ভ্যালু NaN হলে
NaN রিটার্ন করে।
এইসব ক্ষেত্রে ছাড়া, আউটপুটের ধরন ইনপুটের সবচেয়ে বড় ধরনের মতোই হবে:
INTEGER-কেINTEGERহিসেবে দেখানো না গেলে, সেটিDOUBLE-এ কনভার্ট করা হবে।
Node.js
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")) );
Swift
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();
Python
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();
Go
snapshot := client.Pipeline(). Collection("cities"). Aggregate(firestore.Accumulators( firestore.Sum("population").As("totalPopulation"), )). Execute(ctx)
AVERAGE
সিনট্যাক্স:
average(expression: ANY) -> FLOAT64
বিবরণ:
সংখ্যা নয় এমন মান বাদ দিয়ে, সব সংখ্যাগত মানের গড় দেখায়।
কোনও ভ্যালু NaN হলে NaN হিসেবে মূল্যায়ন করে, অথবা কোনও সংখ্যাসূচক ভ্যালু অ্যাগ্রিগেট করা না হলে NULL হিসেবে মূল্যায়ন করে।
এইসব ক্ষেত্রে ছাড়া, আউটপুটের ধরন ইনপুটের ধরনের মতোই হবে:
INTEGER-কেINTEGERহিসেবে দেখানো না গেলে, সেটিDOUBLE-এ কনভার্ট করা হবে।
Node.js
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")) );
Swift
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();
Python
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();
Go
snapshot := client.Pipeline(). Collection("cities"). Aggregate(firestore.Accumulators( firestore.Average("population").As("averagePopulation"), )). Execute(ctx)
ন্যূনতম
সিনট্যাক্স:
minimum(expression: ANY) -> ANY
বিবরণ:
প্রতিটি ডকুমেন্ট মূল্যায়ন করার সময় expression-এর সর্বনিম্ন নন-NULL, নন-অ্যাবসেন্ট ভ্যালু দেখায়।
যদি কোনও নন-NULL, নন-অ্যাবসেন্ট ভ্যালু না থাকে, তাহলে NULL রিটার্ন করা হয়। কোনও ডকুমেন্ট বিবেচনা করা না হলে এটি অন্তর্ভুক্ত করা হয়।
একাধিক ন্যূনতম সমতুল্য মান থাকলে, সেই মানগুলির মধ্যে যেকোনও একটি ফেরত দেওয়া যেতে পারে। ভ্যালুর ধরন ডকুমেন্ট করা ক্রম অনুযায়ী সাজানো হয়।
Node.js
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")) );
Swift
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();
Python
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();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.Minimum("price").As("minimumPrice"), )). Execute(ctx)
সর্বাধিক
সিনট্যাক্স:
maximum(expression: ANY) -> ANY
বিবরণ:
প্রতিটি ডকুমেন্টে মূল্যায়ন করার সময় expression-এর সর্বাধিক নন-NULL, নন-অ্যাবসেন্ট ভ্যালু দেখায়।
যদি কোনও নন-NULL, নন-অ্যাবসেন্ট ভ্যালু না থাকে, তাহলে NULL রিটার্ন করা হয়। কোনও ডকুমেন্ট বিবেচনা করা না হলে এটি অন্তর্ভুক্ত করা হয়।
একাধিক সর্বাধিক সমতুল্য মান থাকলে, সেই মানগুলির মধ্যে যেকোনও একটি ফেরত দেওয়া যেতে পারে। ভ্যালুর ধরন ডকুমেন্ট করা ক্রম অনুযায়ী সাজানো হয়।
Node.js
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")) );
Swift
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();
Python
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();
Go
snapshot := client.Pipeline(). Collection("books"). Aggregate(firestore.Accumulators( firestore.Maximum("price").As("maximumPrice"), )). Execute(ctx)
প্রথম
সিনট্যাক্স:
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-এ কনভার্ট করা হয়।
আউটপুট অ্যারেতে এলিমেন্টের ক্রম স্থির নয় এবং এর উপর নির্ভর করা উচিত নয়।