From d45178ce944b00bc75228f04d8f62cd647ce29ee Mon Sep 17 00:00:00 2001 From: yash30201 <54198301+yash30201@users.noreply.github.com> Date: Tue, 7 May 2024 06:39:02 +0000 Subject: [PATCH 1/2] fix(Spanner):Properly remove redundant keys from request options --- Datastore/src/Operation.php | 42 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Datastore/src/Operation.php b/Datastore/src/Operation.php index 88a7f0cc7215..a5a1feb82923 100644 --- a/Datastore/src/Operation.php +++ b/Datastore/src/Operation.php @@ -455,19 +455,18 @@ public function lookup(array $keys, array $options = []) $serviceKeys[] = $key->keyObject(); }); - list($data, $optionalArgs) = $this->splitOptionalArgs($options, [ - 'transaction', - 'className', - 'sort', - 'readTime', - 'readConsistency' - ]); + list($data, $optionalArgs) = $this->splitOptionalArgs($options); $data += $this->readOptions($options) + [ 'projectId' => $this->projectId, 'databaseId' => $this->databaseId, 'keys' => $this->keysList($serviceKeys), ]; + $this->pluckArray( + ['transaction', 'className', 'sort', 'readTime', 'readConsistency'], + $data + ); + $request = $this->serializer->decodeMessage(new LookupRequest(), $data); $res = $this->requestHandler->sendRequest( @@ -586,13 +585,13 @@ public function runQuery(QueryInterface $query, array $options = []) $runQueryObj->queryKey() => $requestQueryArr, ] + $this->readOptions($options) + $options; - list($data, $optionalArgs) = $this->splitOptionalArgs($req, [ - 'className', - 'namespaceId', - 'readTime', - 'readConsistency', - 'transaction' - ]); + list($data, $optionalArgs) = $this->splitOptionalArgs($req); + + $this->pluckArray( + ['className', 'namespaceId', 'readTime', 'readConsistency', 'transaction'], + $data + ); + if (isset($data['query'])) { $data['query'] = $this->parseQuery($data['query']); } @@ -680,12 +679,12 @@ public function runAggregationQuery(AggregationQuery $runQueryObj, array $option ), ] + $requestQueryArr + $this->readOptions($options) + $options; - list($data, $optionalArgs) = $this->splitOptionalArgs($req, [ - 'namespaceId', - 'readTime', - 'readConsistency', - 'transaction' - ]); + $this->pluckArray( + ['namespaceId', 'readTime', 'readConsistency', 'transaction'], + $req + ); + + list($data, $optionalArgs) = $this->splitOptionalArgs($req); if (isset($data['aggregationQuery'])) { if (isset($data['aggregationQuery']['nestedQuery'])) { @@ -765,7 +764,8 @@ public function commit(array $mutations, array $options = []) // Remove 'transaction' if set to `null` to avoid serialization error unset($options['transaction']); } - list($data, $optionalArgs) = $this->splitOptionalArgs($options, ['allowOverwrite', 'baseVersion']); + list($data, $optionalArgs) = $this->splitOptionalArgs($options); + $this->pluckArray(['allowOverwrite', 'baseVersion'], $data); $request = $this->serializer->decodeMessage(new CommitRequest(), $data); $res = $this->requestHandler->sendRequest( DatastoreClient::class, From b9f0661ca8ca663b3c4720855fb59644357a180d Mon Sep 17 00:00:00 2001 From: yash30201 <54198301+yash30201@users.noreply.github.com> Date: Tue, 7 May 2024 08:59:49 +0000 Subject: [PATCH 2/2] Add comments --- Datastore/src/Operation.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Datastore/src/Operation.php b/Datastore/src/Operation.php index a5a1feb82923..8eba08fc5341 100644 --- a/Datastore/src/Operation.php +++ b/Datastore/src/Operation.php @@ -462,6 +462,7 @@ public function lookup(array $keys, array $options = []) 'keys' => $this->keysList($serviceKeys), ]; + // Remove redundant keys for request. $this->pluckArray( ['transaction', 'className', 'sort', 'readTime', 'readConsistency'], $data @@ -587,6 +588,7 @@ public function runQuery(QueryInterface $query, array $options = []) list($data, $optionalArgs) = $this->splitOptionalArgs($req); + // Remove redundant keys for request. $this->pluckArray( ['className', 'namespaceId', 'readTime', 'readConsistency', 'transaction'], $data @@ -679,13 +681,14 @@ public function runAggregationQuery(AggregationQuery $runQueryObj, array $option ), ] + $requestQueryArr + $this->readOptions($options) + $options; + list($data, $optionalArgs) = $this->splitOptionalArgs($req); + + // Remove redundant keys for request. $this->pluckArray( ['namespaceId', 'readTime', 'readConsistency', 'transaction'], - $req + $data ); - list($data, $optionalArgs) = $this->splitOptionalArgs($req); - if (isset($data['aggregationQuery'])) { if (isset($data['aggregationQuery']['nestedQuery'])) { $data['aggregationQuery']['nestedQuery'] = $this->parseQuery( @@ -765,7 +768,10 @@ public function commit(array $mutations, array $options = []) unset($options['transaction']); } list($data, $optionalArgs) = $this->splitOptionalArgs($options); + + // Remove redundant keys for request. $this->pluckArray(['allowOverwrite', 'baseVersion'], $data); + $request = $this->serializer->decodeMessage(new CommitRequest(), $data); $res = $this->requestHandler->sendRequest( DatastoreClient::class,