我想在aerospike中导入以下csv文件数据,并希望使用 python作为客户端来激发简单的选择查询以显示数据
e.g
policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
query = client.query( 'test', 'csvfile' )
query.select( 'policyID', 'statecode' )
答案 0 :(得分:4)
您可以尝试将python csv模块与Aerospike Python客户端一起使用:
https://docs.python.org/2/library/csv.html
http://www.aerospike.com/docs/client/python/
做类似以下的事情:
import aerospike
import sys
import csv
global rec
rec = {}
csvfile = open('aerospike.csv', "rb")
reader = csv.reader(csvfile)
rownum = 0
for row in reader:
# Save First Row with headers
if rownum == 0:
header = row
else:
colnum = 0
for col in row:
# print (rownum,header[colnum],col)
rec[header[colnum]] = col
colnum += 1
rownum += 1
# print(rownum,rec)
if rec:
client.put(('test', 'demo', str(rownum)), rec)
rec = {}
csvfile.close()
注意:您可能需要检查标题的大小,并确保它们不超过14个字符。 如果没有,你可以得到以下内容:
error: (21L, 'A bin name should not exceed 14 characters limit', 'src/main/conversions.c', 500)
答案 1 :(得分:2)
据我所知,除了允许您导入CSV的加载程序之外,没有预先构建的工具。或许,您可以使用现有的客户端工具构建一个。