Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions packages/google_cloud_firestore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,92 @@ for (final doc in querySnapshot.docs) {
}
```

### Firestore Pipeline Operations

Firestore Pipeline operations are available for Firestore Enterprise edition
databases. They are server-side queries for projections, expressions,
aggregates, and vector search.

```dart
final snapshot = await firestore
.pipeline()
.collection('books')
.where(Expression.field('active').equalValue(true))
.sort([Expression.field('price').ascending()])
.select([
Expression.field('title'),
Expression.field('price'),
Expression.field('title').toUpperCase().as('upperTitle'),
Expression.field('tags').arrayLength().as('tagCount'),
])
.limit(10)
.execute();

for (final result in snapshot.results) {
print(result.data());
}
```

#### Aggregates

Aggregate stages use aliased aggregate expressions:

```dart
final snapshot = await firestore
.pipeline()
.collection('books')
.where(Expression.field('active').equalValue(true))
.aggregate([
Expression.field('price').sum().as('totalPrice'),
Expression.field('rating').average().as('averageRating'),
PipelineFunctions.count().as('bookCount'),
])
.execute();

final data = snapshot.results.single.data();
print(data);
```

#### Expressions

Use `Expression.field`, `Expression.constant`, and `Expression.variable` to
build expressions. Most helpers are also available as fluent methods:

```dart
final expression = Expression.field('createdAt')
.timestampSubtract('day', 7)
.timestampToUnixSeconds()
.as('createdSeconds');
```

Expressions can be selected with an alias, used in filters, passed to aggregate
stages, or composed with other expression helpers.

#### E2E Testing

Real-project Pipeline E2E tests live in `test/e2e/pipeline_e2e_test.dart`.
They are skipped unless you provide a project and credentials:

```bash
export FIRESTORE_PIPELINE_E2E_PROJECT_ID="your-project-id"
export FIRESTORE_PIPELINE_E2E_DATABASE_ID="your-enterprise-database-id"
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
dart test -P prod test/e2e/pipeline_e2e_test.dart
```

The E2E suite includes vector nearest-neighbor coverage. Create the vector index
once for the test collection group before running the suite in CI:

```bash
gcloud firestore indexes composite create \
--project="your-project-id" \
--database="your-enterprise-database-id" \
--collection-group="pipeline_e2e_books" \
--query-scope=COLLECTION \
--field-config=field-path="runId",order=ASCENDING \
--field-config=field-path="embedding",vector-config='{"dimension":"3","flat":"{}"}'
```

#### Get All

```dart
Expand Down
32 changes: 32 additions & 0 deletions packages/google_cloud_firestore/lib/google_cloud_firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export 'src/firestore.dart'
AggregateField,
AggregateQuery,
AggregateQuerySnapshot,
AliasedExpression,
BooleanExpression,
BulkWriter,
BulkWriterError,
BulkWriterOptions,
Expand All @@ -39,12 +41,26 @@ export 'src/firestore.dart'
ExplainMetrics,
ExplainOptions,
ExplainResults,
Expression,
FieldMask,
FieldPath,
FieldValue,
Filter,
Firestore,
GeoPoint,
Ordering,
Pipeline,
PipelineAggregateFunction,
PipelineAliasedExpression,
PipelineBooleanExpression,
PipelineExpression,
PipelineField,
PipelineFunctions,
PipelineOrdering,
PipelineResult,
PipelineSnapshot,
PipelineSource,
PipelineValueType,
PlanSummary,
Precondition,
Query,
Expand All @@ -54,6 +70,7 @@ export 'src/firestore.dart'
ReadOnlyTransactionOptions,
ReadOptions,
ReadWriteTransactionOptions,
Selectable,
SetOptions,
Settings,
Timestamp,
Expand All @@ -67,8 +84,23 @@ export 'src/firestore.dart'
WhereFilter,
WriteBatch,
WriteResult,
and,
ascending,
average,
constant,
count,
currentDocument,
descending,
equal,
field,
greaterThan,
greaterThanOrEqual,
lessThan,
lessThanOrEqual,
not,
notEqual,
or,
Comment thread
Lyokone marked this conversation as resolved.
pipelineFunction,
sum;
export 'src/firestore_exception.dart'
show FirestoreClientErrorCode, FirestoreException;
Expand Down
8 changes: 8 additions & 0 deletions packages/google_cloud_firestore/lib/src/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ part 'filter.dart';
part 'geo_point.dart';
part 'order.dart';
part 'path.dart';
part 'pipeline.dart';
part 'query_partition.dart';
part 'query_profile.dart';
part 'rate_limiter.dart';
Expand Down Expand Up @@ -467,6 +468,13 @@ class Firestore {
);
}

/// Creates a [PipelineSource], which defines a Firestore Pipeline operation.
///
/// Pipeline operations are available for Firestore Enterprise edition
/// databases and support server-side projections, expressions, aggregates,
/// and vector search.
PipelineSource pipeline() => PipelineSource._(this);

/// Fetches the root collections that are associated with this Firestore
/// database.
///
Expand Down
Loading
Loading