同样数据和表,命令行可导入、http导入失败
发布于 1 个月前 作者 kikanjuu 120 次浏览 来自 问答

我有一批csv数据,首先尝试用clickhouse-client命令行导入成功;然后用curl进行http post导入失败。所以怀疑是curl命令行不正确,如编码。 具体如下图:

aa.jpg

求助。感觉ClickHouse报错信息好少。

附: 表结构: CREATE TABLE IF NOT EXISTS client_log_100w ( serverDate Date, channel String, version String, carrierOperator String, deviceId String, deviceName String, deviceType String, manufacturer String, networkMode String, os String, ip String, userAgent String, serverTime UInt64, uid String, height UInt32, width UInt32, latitude Float64, longitude Float64, responseCode String, resource String, clientTime UInt64, tid String, traffic String, playResource String, srcPage String, srcPageId String, srcModule String, srcPosition String, srcSubModule String, moduleType String, item String, itemId String, appName String, x_abtest_bucketIds String, offline_data_gentime UInt64, x_client_sendtime UInt64, type String, copy UInt32 ) ENGINE = MergeTree(serverDate, (deviceId), 8192)

curl命令行: curl -H “Content-Type:text/plain; charset=utf-8” --data-ascii @test.csv ‘http://localhost:8123/?query=INSERT INTO client_log_100w FORMAT CSVWithNames VALUES

csv源数据 test.csv: === START === serverDate,channel,version,carrierOperator,deviceId,deviceName,deviceType,manufacturer,networkMode,os,ip,userAgent,serverTime,uid,height,width,latitude,longitude,responseCode,resource,clientTime,tid,traffic,playResource,srcPage,srcPageId,srcModule,srcPosition,srcSubModule,moduleType,item,itemId,props[appName],props[x-abtest-bucketIds],props[offline_data_gentime],props[x_client_sendtime],props[type],copy 2018-04-16,and-inapp,6.3.81,中国移动,00000000-0a8f-ceff-cb60-80493a7fdafe,android,M3s,Meizu,WIFI,Android22,1.1.1.1,“aa(M3s,Android22)”,1523888919327,1280,720,99.61421585083008,99.93814086914062,xm_source:relationRecommend&xm_medium:track&rec_track:ItemG.105&rec_src:MAIN,1523888982890,1669616570337501418,album,12262096,TAB,button,content,event,100146,1523888284727,1523888982509,0 2018-04-16,and-d10,6.3.84,中国联通,ffffffff-a0b5-e647-b8f0-f9933d7ff2ee,android,MIX 2,Xiaomi,WIFI,Android26,1.1.1.2,“aa(MIX+2,Android26)”,1523888924229,52992687,2030,1080,99.09974670410156,99.2834243774414,xm_source:search&xm_term:学会说话,1523888924539,2762763508220026884,album,12473536,TAB,button,content,event,100146,1523888924382,1523888924382,0 === END ===

1 回复

问题已解决。

  1. 我应该用INSERT INTO … FORMAT CSVWithNames而不是INSERT INTO … FORMAT CSVWithNames VALUES 应该去掉最后的VALUES。加了VALUES,就变成SQL标准语法,后面必须是一个左括号了。

  2. curl要加–data-binary参数。否则curl会把换行都去掉。

回到顶部