Skip to main content
 首页 » 编程设计

python之appengine bulkload 中 DateTimeProperty 的精度

2025年05月04日25haluo1

我正在尝试使用 Bulkloader 从我的数据存储下载数据,但 DateTimeProperty 的精度似乎不准确,除非我以错误的方式做事。

这是我要下载的数据的属性:

class LoggingPrimitive(polymodel.PolyModel): 
    [...] 
    start = ndb.DateTimeProperty(auto_now_add=True, required=True) 

这是我的 bulkloader.yaml 文件

- kind: LoggingPrimitive 
  connector: csv 
  connector_options: 
    export_options: 
      delimiter: "|" 
  property_map: 
    [...] 
    - property: start 
      external_name: start 
      # Type: Date/Time Stats: 5123 properties of this type in this kind. 
      import_transform: transform.import_date_time('%Y-%m-%dT%H:%M:%S') 
      export_transform: transform.export_date_time('%Y-%m-%d %H:%M:%S.%f') 

我下载的 CSV 中的数据如下所示:

    2013-05-25 22:06:17. 

因此,下载的 CSV 数据不包含毫秒。

当我在交互式控制台中使用 transform.export_date_time 函数时,我确实得到了毫秒数。

fn=transform.export_date_time('%Y-%m-%d %H:%M:%S.%f') 
print fn(l.start) 

所以毫秒信息在数据存储中,但似乎在批量加载过程中丢失了。

有什么线索吗?

请您参考如下方法:

使用 Python 2.7 运行 bulkloader 解决了这个问题。

显然,我运行 bulkloader 的机器使用的是 Python 2.5,它不支持 %f 宏,参见 How can I parse a time string containing milliseconds in it with python?