Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5685b37
Add QueryMode protos.
ehsannas Oct 18, 2023
16fcd28
WIP: Query profiling APIs.
ehsannas Jul 25, 2023
e806883
Use generic type.
ehsannas Jul 31, 2023
0d1febb
WIP WIP.
ehsannas Oct 20, 2023
265f1ff
WIP WIP WIP.
ehsannas Oct 25, 2023
af54637
Update integration tests.
ehsannas Oct 26, 2023
8cb527d
clean up.
ehsannas Oct 26, 2023
69da273
lint.
ehsannas Oct 26, 2023
cc35f56
Fix: Do not re-use _stream().
ehsannas Nov 21, 2023
9f987dd
Address more feedback.
ehsannas Nov 21, 2023
40ded3a
introduce QueryPlan class to make it possible to add node-level info …
ehsannas Jan 4, 2024
ce6df90
Merge remote-tracking branch 'origin/main' into query_profiling_impl_2
ehsannas Jan 4, 2024
9819c5e
fix lint errors.
ehsannas Jan 4, 2024
ccaad87
Revert host setting.
ehsannas Jan 4, 2024
834ddc9
undo manual proto updates.
ehsannas Jan 10, 2024
bb2fbe8
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas Jan 10, 2024
74b7f15
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas Jan 11, 2024
7c3cf77
Update the public APIs to v2.
ehsannas Feb 9, 2024
2c4944c
Reuse existing _stream methods.
ehsannas Feb 10, 2024
71935d1
Introduce ExplainMetrics and PlanSummary.
ehsannas Feb 23, 2024
4621073
Update tests.
ehsannas Feb 23, 2024
3bdb616
Manually import query profile protos.
ehsannas Mar 7, 2024
81d0bf6
WIP: Update impl and tests with new protos.
ehsannas Mar 8, 2024
2e9d274
WIP (2): Update impl and tests with new protos.
ehsannas Mar 8, 2024
a31a514
WIP (3): Update impl and tests with new protos.
ehsannas Mar 8, 2024
0c7c9da
WIP (4): Update impl and tests with new protos.
ehsannas Mar 8, 2024
985a972
Add test for explainStream.
ehsannas Mar 8, 2024
b735f47
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Mar 9, 2024
7bf7078
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas Mar 13, 2024
371c66d
Remove bytesReturned from the API.
ehsannas Mar 13, 2024
95a2111
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas Mar 15, 2024
0fd0f9e
minor improvements.
ehsannas Mar 15, 2024
4f984fe
minor improvements.
ehsannas Mar 15, 2024
d00b7cf
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Mar 15, 2024
c52d77d
improve documentation.
ehsannas Mar 15, 2024
74c2f3f
Fix unit test failure.
ehsannas Mar 15, 2024
460d3f1
minor improvements.
ehsannas Mar 18, 2024
fd2d50e
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Mar 18, 2024
1e13262
explain options should be optional.
ehsannas Mar 19, 2024
974ca2a
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Mar 19, 2024
4a3f8c2
Address feedback.
ehsannas Mar 22, 2024
391edb8
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Mar 22, 2024
7501e4f
Merge branch 'main' into ehsann/query_profiling_impl_v2_4
MarkDuckworth Mar 25, 2024
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
7 changes: 3 additions & 4 deletions dev/src/aggregate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/**
* @license
* Copyright 2023 Google LLC
/*!
* Copyright 2023 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
41 changes: 41 additions & 0 deletions dev/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,47 @@ export function detectValueType(proto: ProtobufJsValue): string {
return detectedValues[0];
}

/**
* Detects the value kind from a Proto3 JSON `google.protobuf.Value` proto.
*
* @private
* @internal
* @param proto The `firestore.v1.Value` proto.
* @return The string value for 'valueType'.
*/
export function detectGoogleProtobufValueType(
proto: google.protobuf.IValue
): string {
const detectedValues: string[] = [];

if (proto.nullValue !== undefined) {
detectedValues.push('nullValue');
}
if (proto.numberValue !== undefined) {
detectedValues.push('numberValue');
}
if (proto.stringValue !== undefined) {
detectedValues.push('stringValue');
}
if (proto.boolValue !== undefined) {
detectedValues.push('boolValue');
}
if (proto.structValue !== undefined) {
detectedValues.push('structValue');
}
if (proto.listValue !== undefined) {
detectedValues.push('listValue');
}

if (detectedValues.length !== 1) {
throw new Error(
`Unable to infer type value from '${JSON.stringify(proto)}'.`
);
}

return detectedValues[0];
}

/**
* Converts a `firestore.v1.Value` in Proto3 JSON encoding into the
* Protobuf JS format expected by this client.
Expand Down
6 changes: 6 additions & 0 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ export type {
AggregateSpec,
AggregateType,
} from './aggregate';
export type {
PlanSummary,
ExecutionStats,
ExplainMetrics,
ExplainResults,
} from './query-profile';

const libVersion = require('../../package.json').version;
setLibVersion(libVersion);
Expand Down
139 changes: 139 additions & 0 deletions dev/src/query-profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*!
* Copyright 2024 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import {google} from '../protos/firestore_v1_proto_api';
import {Serializer} from './serializer';
import IPlanSummary = google.firestore.v1.IPlanSummary;
import IExecutionStats = google.firestore.v1.IExecutionStats;
import IExplainMetrics = google.firestore.v1.IExplainMetrics;

/**
* PlanSummary contains information about the planning stage of a query.
*
* @class PlanSummary
*/
export class PlanSummary implements firestore.PlanSummary {
/**
* @private
* @internal
*/
constructor(readonly indexesUsed: Record<string, unknown>[]) {}

/**
* @private
* @internal
*/
static _fromProto(
plan: IPlanSummary | null | undefined,
serializer: Serializer
): PlanSummary {
const indexes: Record<string, unknown>[] = [];
if (plan && plan.indexesUsed) {
for (const index of plan.indexesUsed) {
indexes.push(serializer.decodeGoogleProtobufStruct(index));
}
}
return new PlanSummary(indexes);
}
}

/**
* ExecutionStats contains information about the execution of a query.
*
* @class ExecutionStats
*/
export class ExecutionStats implements firestore.ExecutionStats {
/**
* @private
* @internal
*/
constructor(
readonly resultsReturned: number,
readonly executionDuration: firestore.Duration,
readonly readOperations: number,
readonly debugStats: Record<string, unknown>
) {}

/**
* @private
* @internal
*/
static _fromProto(
stats: IExecutionStats | null | undefined,
serializer: Serializer
): ExecutionStats | null {
if (stats) {
return new ExecutionStats(
Number(stats.resultsReturned),
{
seconds: Number(stats.executionDuration?.seconds),
nanoseconds: Number(stats.executionDuration?.nanos),
},
Number(stats.readOperations),
serializer.decodeGoogleProtobufStruct(stats.debugStats)
);
}
return null;
}
}

/**
* ExplainMetrics contains information about planning and execution of a query.
*
* @class ExplainMetrics
*/
export class ExplainMetrics implements firestore.ExplainMetrics {
/**
* @private
* @internal
*/
constructor(
readonly planSummary: PlanSummary,
readonly executionStats: ExecutionStats | null
) {}

/**
* @private
* @internal
*/
static _fromProto(
metrics: IExplainMetrics,
serializer: Serializer
): ExplainMetrics {
return new ExplainMetrics(
PlanSummary._fromProto(metrics.planSummary, serializer),
ExecutionStats._fromProto(metrics.executionStats, serializer)
);
}
}

/**
* ExplainResults contains information about planning, execution, and results
* of a query.
*
* @class ExplainResults
*/
export class ExplainResults<T> implements firestore.ExplainResults<T> {
/**
* @private
* @internal
*/
constructor(
readonly metrics: ExplainMetrics,
readonly snapshot: T | null
) {}
}
Loading