使用bulkloader上传数据 [英] Uploading data with bulkloader

查看:153
本文介绍了使用bulkloader上传数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之:如何配置bulkloader以将数据插入到具有引用的2个模型中?

我有一个人和水果类,其中有人链接到水果:

  class Fruit(db.Model):
name = db.StringProperty()
class Person .Model):
name = db.StringProperty()
customer = db.ReferenceProperty(Fruit)

我想上传CSV数据:

 名称,水果
鲍勃,香蕉
Joe,Apple
Tim,Banana

我尝试使用create_foreign_key作为< a href =http://code.google.com/appengine/docs/python/tools/uploadingdata.html =nofollow> docs :

 变形金刚:

- 种类:fruit
连接符:csv
property_map:
- 属性:fruit
external_name:Fruit

- kind:person
connector:csv
connector_options:
encoding:utf-8
列:from_ header
property_map:
- property:title
external_name:Name
- property:fruit
external_name:Fruit
import_transform:transform.create_foreign_key('fruit' )

运行命令时:

  appcfg.py upload_data --config_file = bulkloader.yaml --filename = food.csv --kind = person。 

这些人是上传的,他们有水果的外键,但他们指向的水果实体不存在。



当我尝试 - kind = fruit 水果上传时,但有许多重复项。



我试图将这个人连接到水果,没有重复的水果 - 这是可以通过批量加载吗?

解决方案

我没有弄清楚如何做到这一点干净,所以最后只是将我的数据分成多个文件并预先生成ID。


In short: how can I configure bulkloader to insert data into 2 models with references?

I have a person and fruit class, with person linking to fruit:

class Fruit(db.Model): 
    name = db.StringProperty()
class Person(db.Model): 
    name = db.StringProperty() 
    customer = db.ReferenceProperty(Fruit)

And I want to upload this CSV data:

Name,Fruit
Bob,Banana
Joe,Apple
Tim,Banana

I tried using create_foreign_key as in the docs:

transformers:

- kind: fruit
  connector: csv
  property_map:
    - property: fruit
      external_name: Fruit

- kind: person
  connector: csv
  connector_options:
    encoding: utf-8
    columns: from_header
  property_map:
    - property: title
      external_name: Name
    - property: fruit
      external_name: Fruit
      import_transform: transform.create_foreign_key('fruit')

When I run the command:

appcfg.py upload_data --config_file=bulkloader.yaml --filename=food.csv --kind=person .

The persons are uploaded and they have foreign keys for the fruit, but the fruits entities they point to do not exist.

When I try --kind=fruit the fruit are uploaded, but there are many duplicates.

I am trying to link the person to fruit, with no duplicate fruit - is this possible through bulkloader?

解决方案

I didn't figure out how to do this cleanly so ended up just splitting my data into multiple files and pregenerating the ID's.

这篇关于使用bulkloader上传数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆