【问题标题】:Import large chunk of data into Google App Engine Data Store at one go一次性将大量数据导入 Google App Engine 数据存储
【发布时间】:2010-07-10 07:03:58
【问题描述】:

我有一个大 CSV 文件,大小约为 10 MB,其中包含需要导入 Google App Engine DataStore 的所有数据。 我尝试了以下方法来执行导入,但总是半途而废。

  • 使用将命令映射到 url 然后执行 url 导入,由于请求超时而失败...
  • 使用创建 cron 作业导入,但出现 DeadlineExceededError...
  • 使用 remort_api_shell 导入,但操作超时。

您能否建议我和方法(使用您可以想象的虚拟数据)如何做到这一点...用代码提出建议会更有帮助..

** 我正在使用 Python 和谷歌的网络应用程序框架来开发上述应用程序。

【问题讨论】:

    标签: python google-app-engine google-cloud-datastore


    【解决方案1】:

    您可以逐行发布。使用内置的批量加载器。

    http://code.google.com/appengine/docs/python/tools/uploadingdata.html

    这是一篇好文章。

    这是我 2 年前用作参考的contactloader.py。自从我上次使用以来它更加复杂,但仍然......

    import datetime
    from google.appengine.ext import db
    from google.appengine.tools import bulkloader
    
    class Contact(db.Model):
    
        date = db.DateTimeProperty(auto_now_add=True)
    
        owner = db.StringProperty()
    
        companyname = db.StringProperty()
    
        companyemail = db.EmailProperty()
    
    def myfunc(x):
        temp = x.split(":mailto:")
        if len(temp) > 0:
            temp = temp[-1].split(":")
        else:
            return "defaultvalue"
        if len(temp) > 0:
            temp = temp[0]
        else:
            return "defaultvalue"
        temp = temp.split("<1>")[0]
        if temp is None or len(temp) < 5:
            return "defaultvalue"
        return temp
    
    def mysecfunc(x):
        return x.split("<0>")[0]
    
    class ContactLoader(bulkloader.Loader):
        def __init__(self):
            bulkloader.Loader.__init__(self, 'Contact',
                                       [
                                        ('companyname',mysecfunc),
                                        ('owner', lambda x:"somevalue"),
                                        ('companyemail',myfunc),
                                        ("date",lambda x:datetime.datetime.now()),
                                       ])
    
    loaders = [ContactLoader]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多