Skip to content

Commit c17d2c3

Browse files
feat(Datastore): Add support for the ExplainOptions (#8361)
1 parent fec2cbe commit c17d2c3

14 files changed

Lines changed: 718 additions & 104 deletions

Core/src/GrpcTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,20 @@ private function formatDurationForApi($value)
313313
];
314314
}
315315

316+
/**
317+
* Format a duration from the API
318+
*
319+
* @param array $value
320+
* @return string
321+
*/
322+
private function formatDurationFromApi($value): string
323+
{
324+
$seconds = $value['seconds'];
325+
$nanos = str_pad($value['nanos'], 9, 0, STR_PAD_LEFT);
326+
327+
return "{$seconds}.{$nanos}s";
328+
}
329+
316330
/**
317331
* Construct a gapic client. Allows for tests to intercept.
318332
*

Datastore/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"minimum-stability": "stable",
66
"require": {
77
"php": "^8.0",
8-
"google/cloud-core": "^1.57",
8+
"google/cloud-core": "^1.63.0",
99
"google/gax": "^1.36.0"
1010
},
1111
"require-dev": {

Datastore/src/Connection/Grpc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function __construct(array $config = [])
7676
},
7777
'google.protobuf.Timestamp' => function ($v) {
7878
return $this->formatTimestampFromApi($v);
79+
},
80+
'google.protobuf.Duration' => function ($v) {
81+
return $this->formatDurationFromApi($v);
7982
}
8083
], [], [
8184
'google.protobuf.Timestamp' => function ($v) {

Datastore/src/Connection/Rest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ public function rollback(array $args)
116116
*/
117117
public function runQuery(array $args)
118118
{
119+
// There is a push to stop using generic arrays for options.
120+
// We will transition into using structured options in the future
121+
// hence we add this to handle options with the message type
122+
if (isset($args['explainOptions'])) {
123+
$args['explainOptions'] = json_decode($args['explainOptions']->serializeToJsonString());
124+
}
125+
119126
return $this->sendWithHeaders('projects', 'runQuery', $args);
120127
}
121128

@@ -135,6 +142,12 @@ public function runAggregationQuery(array $args)
135142
);
136143
}
137144
}
145+
// There is a push to stop using generic arrays for options.
146+
// We will transition into using structured options in the future
147+
// hence we add this to handle options with the message type
148+
if (isset($args['explainOptions'])) {
149+
$args['explainOptions'] = json_decode($args['explainOptions']->serializeToJsonString());
150+
}
138151
return $this->sendWithHeaders('projects', 'runAggregationQuery', $args);
139152
}
140153

0 commit comments

Comments
 (0)