-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(datastore): query limit more than 300 #5592
Changes from all commits
63655f5
0fc89a1
f902098
74d8ddd
8ba0ac3
5086fa0
4fd4c7f
29e660b
e60e12e
5940fdf
291b45b
691531e
950c2af
9976618
e88e152
8e348f7
a37b3c4
71ac41c
31448e4
89b682c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -152,7 +152,7 @@ public function keys($kind, array $options = []) | |||||||||
'number' => 1, | ||||||||||
'ancestors' => [], | ||||||||||
'id' => null, | ||||||||||
'name' => null | ||||||||||
'name' => null, | ||||||||||
]; | ||||||||||
|
||||||||||
if ($options['number'] < 1) { | ||||||||||
|
@@ -167,7 +167,7 @@ public function keys($kind, array $options = []) | |||||||||
$path[] = array_filter([ | ||||||||||
'kind' => $kind, | ||||||||||
'id' => $options['id'], | ||||||||||
'name' => $options['name'] | ||||||||||
'name' => $options['name'], | ||||||||||
]); | ||||||||||
|
||||||||||
$key = new Key($this->projectId, [ | ||||||||||
|
@@ -226,7 +226,7 @@ public function keys($kind, array $options = []) | |||||||||
public function entity($key = null, array $entity = [], array $options = []) | ||||||||||
{ | ||||||||||
$options += [ | ||||||||||
'className' => null | ||||||||||
'className' => null, | ||||||||||
]; | ||||||||||
|
||||||||||
if ($key && !is_string($key) && !($key instanceof Key)) { | ||||||||||
|
@@ -362,7 +362,7 @@ public function lookup(array $keys, array $options = []) | |||||||||
{ | ||||||||||
$options += [ | ||||||||||
'className' => Entity::class, | ||||||||||
'sort' => false | ||||||||||
'sort' => false, | ||||||||||
]; | ||||||||||
|
||||||||||
$serviceKeys = []; | ||||||||||
|
@@ -446,7 +446,7 @@ public function runQuery(QueryInterface $query, array $options = []) | |||||||||
$options += [ | ||||||||||
'className' => Entity::class, | ||||||||||
'namespaceId' => $this->namespaceId, | ||||||||||
'databaseId' => $this->databaseId | ||||||||||
'databaseId' => $this->databaseId, | ||||||||||
]; | ||||||||||
|
||||||||||
$iteratorConfig = [ | ||||||||||
|
@@ -465,25 +465,31 @@ public function runQuery(QueryInterface $query, array $options = []) | |||||||||
} | ||||||||||
|
||||||||||
return false; | ||||||||||
} | ||||||||||
}, | ||||||||||
]; | ||||||||||
|
||||||||||
if (array_key_exists('limit', $query->queryObject())) { | ||||||||||
$remainingLimit = $query->queryObject()['limit']; | ||||||||||
} | ||||||||||
$runQueryObj = clone $query; | ||||||||||
$runQueryFn = function (array $args = []) use (&$runQueryObj, $options) { | ||||||||||
$runQueryFn = function (array $args = []) use (&$runQueryObj, $options, &$remainingLimit) { | ||||||||||
$args += [ | ||||||||||
'query' => [] | ||||||||||
'query' => [], | ||||||||||
]; | ||||||||||
|
||||||||||
// The iterator provides the startCursor for subsequent pages as an argument. | ||||||||||
$requestQueryArr = $args['query'] + $runQueryObj->queryObject(); | ||||||||||
if (isset($remainingLimit)) { | ||||||||||
$requestQueryArr['limit'] = $remainingLimit; | ||||||||||
} | ||||||||||
$request = [ | ||||||||||
'projectId' => $this->projectId, | ||||||||||
'partitionId' => $this->partitionId( | ||||||||||
$this->projectId, | ||||||||||
$options['namespaceId'], | ||||||||||
$options['databaseId'] | ||||||||||
), | ||||||||||
$runQueryObj->queryKey() => $requestQueryArr | ||||||||||
$runQueryObj->queryKey() => $requestQueryArr, | ||||||||||
] + $this->readOptions($options) + $options; | ||||||||||
|
||||||||||
$res = $this->connection->runQuery($request); | ||||||||||
|
@@ -497,6 +503,17 @@ public function runQuery(QueryInterface $query, array $options = []) | |||||||||
if (isset($res['query'])) { | ||||||||||
$runQueryObj = new Query($this->entityMapper, $res['query']); | ||||||||||
} | ||||||||||
if (isset($res['query']['limit'])) { | ||||||||||
// limit for GqlQuery in REST mode | ||||||||||
$remainingLimit = $res['query']['limit']; | ||||||||||
} | ||||||||||
if (isset($remainingLimit['value'])) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks redundant - if (isset($res['query']['limit']['value'])) {
$remainingLimit = $res['query']['limit']['value'];
} But maybe there's something I'm missing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are several cases here:
|
||||||||||
// limit for GqlQuery in GRPC mode | ||||||||||
$remainingLimit = $remainingLimit['value']; | ||||||||||
} | ||||||||||
if (!is_null($remainingLimit)) { | ||||||||||
$remainingLimit -= count($res['batch']['entityResults']); | ||||||||||
} | ||||||||||
|
||||||||||
return $res; | ||||||||||
}; | ||||||||||
|
@@ -541,7 +558,7 @@ public function commit(array $mutations, array $options = []) | |||||||||
$res = $this->connection->commit($options + [ | ||||||||||
'mode' => ($options['transaction']) ? 'TRANSACTIONAL' : 'NON_TRANSACTIONAL', | ||||||||||
'mutations' => $mutations, | ||||||||||
'projectId' => $this->projectId | ||||||||||
'projectId' => $this->projectId, | ||||||||||
]); | ||||||||||
|
||||||||||
return $res; | ||||||||||
|
@@ -622,7 +639,7 @@ public function mutation( | |||||||||
|
||||||||||
return array_filter([ | ||||||||||
$operation => $data, | ||||||||||
'baseVersion' => $baseVersion | ||||||||||
'baseVersion' => $baseVersion, | ||||||||||
]); | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -657,9 +674,9 @@ public function checkOverwrite(array $entities, $allowOverwrite = false) | |||||||||
foreach ($entities as $entity) { | ||||||||||
if (!$entity->populatedByService() && !$allowOverwrite) { | ||||||||||
throw new \InvalidArgumentException(sprintf( | ||||||||||
'Given entity cannot be saved because it may overwrite an '. | ||||||||||
'existing record. When updating manually created entities, '. | ||||||||||
'please set the options `$allowOverwrite` flag to `true`. '. | ||||||||||
'Given entity cannot be saved because it may overwrite an ' . | ||||||||||
'existing record. When updating manually created entities, ' . | ||||||||||
'please set the options `$allowOverwrite` flag to `true`. ' . | ||||||||||
'Invalid entity key was %s', | ||||||||||
(string) $entity->key() | ||||||||||
)); | ||||||||||
|
@@ -734,7 +751,7 @@ private function mapEntityResult(array $result, $class) | |||||||||
'className' => $className, | ||||||||||
'populatedByService' => true, | ||||||||||
'excludeFromIndexes' => $excludes, | ||||||||||
'meanings' => $meanings | ||||||||||
'meanings' => $meanings, | ||||||||||
]); | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -754,16 +771,16 @@ private function readOptions(array $options = []) | |||||||||
{ | ||||||||||
$options += [ | ||||||||||
'readConsistency' => null, | ||||||||||
'transaction' => null | ||||||||||
'transaction' => null, | ||||||||||
]; | ||||||||||
|
||||||||||
$readOptions = array_filter([ | ||||||||||
'readConsistency' => $options['readConsistency'], | ||||||||||
'transaction' => $options['transaction'] | ||||||||||
'transaction' => $options['transaction'], | ||||||||||
]); | ||||||||||
|
||||||||||
return array_filter([ | ||||||||||
'readOptions' => $readOptions | ||||||||||
'readOptions' => $readOptions, | ||||||||||
]); | ||||||||||
} | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vishwarajanand why was this added? This seems like it could break existing implementations if they supplied something like
$query['limit'] = '1'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bshaffer I mentioned this in point #1 in
PR description > Changes
:In Grpc mode, the non-Gql query provides
$query['limit']
as anint
which needs to be parsed into an array, but your comment suggests we support int-likestring
also.If so, we should change the
is_int
to!is_array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bshaffer I raised another PR to fix this bug: #5826