我正在尝试将csv文件导入Cassandra。我的桌子是
copy info_by_vinid_search (vin_id,vinnumber,vin_start_date,vin_stop_date,cartype,bi_symbol,mercury_liability_symbol,pip_symbol,driving_wheels,cylinders,brakes,antitheft_code,daytime_lamps_ind, restraint,vsr_symbol_id,base_list_price,bodystyle_id,model_id,make_id,make_symbol,model_symbol,style_symbol,aux_symbol,polk_make,polk_model,polk_bodystyle,polk_engine_info_turbocharged,comp_symbol,coll_symbol,mb_symbol,ev_indicator,year,make,ncic_code,model,bodystyle,symbol_twodigit)FROM '36_vinid.csv' WITH DELIMITER = ',' AND HEADER=TRUE;
当我运行上面的复制命令时,它抛出以下异常:
Process Process-21:
Traceback (most recent call last):
File "/usr/lib64/python2.6/multiprocessing/process.py", line 232, in _bootstrap
self.run()
File "/usr/lib64/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "./cqlsh", line 1703, in multiproc_import
cqltypes = [table_meta.columns[name].typestring for name in columns]
KeyError: 'antitheft_code'
表架构:
CREATE TABLE vin_service_development.info_by_vinid_search (
vin_id int PRIMARY KEY,
aux_symbol text,
base_list_price text,
bi_symbol text,
bodystyle text,
bodystyle_id int,
brakes text,
coll_symbol text,
comp_symbol text,
cylinders text,
driving_wheels text,
ev_indicator text,
make text,
make_id int,
make_symbol text,
mb_symbol text,
antitheft_code int,
cartype text,
daytime_lamps_ind text,
liability_symbol text,
model text,
model_id int,
model_symbol text,
ncic_code text,
pip_symbol text,
polk_bodystyle text,
polk_engine_info_turbocharged text,
polk_make text,
polk_model text,
restraint text,
style_symbol text,
symbol_twodigit text,
vin_start_date timestamp,
vin_stop_date timestamp,
vinnumber text,
vsr_symbol_id int,
year int
)
csv文件的示例数据是
36_vinid.csv
VIN_ID VINNUMBER VIN_START_DATE VIN_STOP_DATE CARTYPE BI_SYMBOL LIABILITY_SYMBOL PIP_SYMBOL DRIVING_WHEELS CYLINDERS BRAKES ANTITHEFT_CODE DAYTIME_LAMPS_IND RESTRAINT VSR_SYMBOL_ID BASE_LIST_PRICE BODYSTYLE_ID MODEL_ID MAKE_ID MAKE_SYMBOL MODEL_SYMBOL STYLE_SYMBOL AUX_SYMBOL POLK_MAKE POLK_MODEL POLK_BODYSTYLE POLK_ENGINE_INFO_TURBOCHARGED COMP_SYMBOL COLL_SYMBOL MB_SYMBOL EV_INDICATOR YEAR MAKE NCIC_CODE MODEL BODYSTYLE SYMBOL_TWODIGIT
10591781,B5A5F5A---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12801,121020,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,GREMLIN,SED 2DR,4
10591361,B5A465E---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12801,121020,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,GREMLIN,SED 2DR,4
10591508,B5H465H---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12801,121020,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,GREMLIN,SED 2DR,4
10591548,B5A017A---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12669,121093,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,HORNET,HCHBK 2DR,4
10591869,B5F037E---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12669,121093,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,HORNET,HCHBK 2DR,4
10597770,B5A037H---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,544,(null),12669,121093,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,HORNET,HCHBK 2DR,5
10598750,B5A027A---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12801,121093,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,HORNET,SED 2DR,4
10592751,B5A037E---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12801,121093,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,HORNET,SED 2DR,4
10599752,B5A057H---------- ,1997-10-01 00:00,9999-12-31 00:00,DM,,,,42,(null),,, ,,543,(null),12801,121093,7925,(null),(null),(null),(null),(null),(null),(null), ,(null),(null),X,N,1975,AMERICAN,AMER,HORNET,SED 2DR,4
我确实导入了许多没有空值的csv文件。我能够将数据导入Cassandra。是否由于csv文件中存在空值而发生异常。我在这里错过了什么吗?请帮忙。
谢谢.. !!
答案 0 :(得分:1)
你可以张贴你的桌子定义吗?
此外,您的文件看起来以逗号分隔,但您的标题似乎以制表符分隔。你需要告诉COPY你的标题存在(FileInput
)。