迭代整个数据存储并将默认值设置为修改后的架构的最有效方法?
我有一个现有架构:
class Example (db.Model) :
row_num = db.IntegerProperty(required=True)
updated = db.IntegerProperty()
...
...
我现在已将其更新为:
class Example (db.Model) :
row_num = db.IntegerProperty(required=True)
updated = db.IntegerProperty(default=0)
...
...
但是,数据存储区中有超过 200 万个实体默认情况下没有设置 update = 0。
做到这一点最简单的方法是什么?这可以通过管理终端的单个命令来完成吗?
I have an existing schema:
class Example (db.Model) :
row_num = db.IntegerProperty(required=True)
updated = db.IntegerProperty()
...
...
I have now updated this to :
class Example (db.Model) :
row_num = db.IntegerProperty(required=True)
updated = db.IntegerProperty(default=0)
...
...
However, there are over 2 million entities in the Datastore which do not have update = 0 set by default.
What is the easiest way to do this? Can this by done by a single command from the admin terminal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要编写一个脚本来迭代对象、抓取它们(一次最多 1000 个)、更新它们的属性值,然后将它们保存回来。
不,相对于执行同类操作的标准 SQL DB(您可以只发出单个
UPDATE
)而言,这并不是真正高效,但 BigTable(GAE 数据存储背后的支持技术)却不是SQL 关系数据库 - 它是一个完全不同的架构,旨在擅长不同的事情,并且没有针对一次更新数百万行中的单个字段进行优化 - 这就是为什么 GQL 语法 没有UPDATE
语句的概念。编辑:
正如 David 在评论中善意指出的那样,Google 最近发布了 Mapper API 可以用来帮助实现这一点。
You'll need to write a script that iterates through the objects, grabbing them (up to 1000 at a time), updating their property value, and then saving them back.
No, this is not really efficient relative to a standard SQL DB doing the same kind of thing (where you could just issue a single
UPDATE
), but BigTable (the backing technology behind the GAE Datastore) is not a SQL relational database - it's an entirely different architecture designed to be good at different things and not optimized for updating a single field across millions of rows at a time - hence why GQL syntax has no notion of anUPDATE
statement.Edit:
As David kindly pointed out in comments, Google recently released the Mapper API which can be used to assist with this.