【问题标题】:Google data store inconsistent result fetch from select谷歌数据存储从选择中获取不一致的结果
【发布时间】:2016-12-14 11:26:00
【问题描述】:

我非常需要 GDS 和 PHP-GDS 库方面的帮助。

我正在使用出色的 php-gds 库从外部 google appengine 进行获取。到目前为止,图书馆工作正常。

我的问题是我从 GDS 获取的数据返回不一致的结果,我不知道问题可能是什么。

请看下面的代码:

    <?php
    //...
    //...
    $offset = 0;
    do{
       $query = "SELECT * FROM `KIND` order by _URI ASC limit 300 offset ".$offset;
       $tableList=[];
       $tableList = $this->obj_store->fetchAll($query);
       $offset += count($tableList);
       $allTables[] = $tableList;
       $totalRecords = $offset;
    }while(!empty($tableList));

    echo $totalRecords; // i expect total records to be equal to the number of entities in the KIND.
                        // but the results are inconsistent. In some cases, it is correct 
                        // but in most cases it is far less than the total records.
// I could have a KIND with 750 entities and only 721 will be returned in total.
// I could have a KIND with 900 entities and all entities will be returned.
// I could have a KIND with 4000 entities and only 1200 will be returned.
    ?>

请帮忙。此外,当我在云控制台中运行完全相同的查询时,我得到了正确的实体计数。 (希望这对某人有帮助)

更新

我最终使用了游标。新代码如下:

<?php
  $query = "SELECT * FROM `KIND`";
  $tableList=[];
  $queryInit = $this->obj_store->query($query);
  do{
      $page = $this->obj_store->fetchPage(300);// fetch page.
      $tableList = am($tableList,$page); //merge with existing records.
      $this->obj_store->setCursor($this->obj_store->getCursor());//set next cursor to previous last cursor
  }while(!empty($page)); //as long as page result is not empty.
?>

【问题讨论】:

  • 如果您查询的部分/全部实体是最近创建的,那么由于最终的一致性,这是预期的行为:cloud.google.com/datastore/docs/articles/…
  • 感谢 Dan,但在我查询的 KIND 中实际上没有最近创建的实体。我会继续寻找。

标签: php google-app-engine google-cloud-storage google-cloud-datastore


【解决方案1】:

尝试使用游标而不是偏移量。请参阅此处的游标讨论(包括 PHP 中的示例): https://cloud.google.com/datastore/docs/concepts/queries#datastore-cursor-paging-php

【讨论】:

  • 谢谢@JefferyRennie 我希望我可以在没有光标的情况下完成它。我打算发布我的最终解决方案,然后看到你的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-20
  • 2014-08-25
  • 1970-01-01
  • 2019-02-23
  • 1970-01-01
相关资源
最近更新 更多