ããæè¿å¨ä½¿ç¨hiveæ¶ï¼éè¦å°hiveæ¥è¯¢çæ°æ®å¯¼åºå°æ¬å°æ件系ç»ï¼HQLè¯æ³å¦ä¸ï¼
ããINSERT OVERWRITE [LOCAL] DIRECTORY directory1 select_statement1
ããæ¥è¯¢ç»æ导åºå°æ¬å°æ件åï¼è¯å¾ä½¿ç¨excelå è½½æ¶éä¸äºéº»ç¦ï¼ä¸ç¥éhive导åºæ件æ¶ä½¿ç¨çåé符ï¼
ãã使ç¨ææ¬ç¼è¾å¨æå¼ä¹æ¾ç¤ºä¹±ç ã
ããæåå¨å®æ¹ææ¡£ä¸æ¾äºå天æåç°ï¼hiveä½¿ç¨ ^A 符å·ä½ä¸ºåçåé符ï¼åæå¦ä¸ï¼
ããData written to the filesystem is serialized as text with columns separated by ^A
ããå¨pythonä¸å¯ä»¥ä½¿ç¨line.split('\x01')æ¥è¿è¡ååï¼ä¹å¯ä»¥ä½¿ç¨line.split('\001')ï¼æ³¨æå
¶ä¸æ¯åå¼å·
ããå¨javaä¸å¯ä»¥ä½¿ç¨split("\\u0001")æ¥è¿è¡åå
ããå¦æç¡®å®éè¦å°æ¥è¯¢ç»æ导åºå°æ¬å°æ件ï¼æ好使ç¨hiveçå½ä»¤ï¼
ãã[sql] view plaincopyå¨CODEä¸æ¥ç代ç çæ´¾çå°æç代ç ç
ããbin/hive -e "select * from test" >> res.csv
ãã
ããæè
æ¯ï¼
ãã
ããbin/hive -f sql.q >> res.csv
ãã
ããå
¶ä¸æ件sql.qåå
¥ä½ æ³è¦æ§è¡çæ¥è¯¢è¯å¥
ããè¿é®é¢å¨ä½¿ç¨hive hql streamingæ¶ä¹ä¼éå°ï¼å½ä½ 使ç¨hql strreaming å°è¾åºç´æ¥åå
¥å°hdfsç®å½ï¼ç¶åä½ å¨è¯¥ç®å½ä¸å建hive å¤é¨è¡¨æ¶ï¼hiveçè¾åºç»æä¼å°streaming çkeyåvalueä¹é´çåé符修æ¹ä¸º \001ï¼æ以ï¼å¨hql streamingåè¾åºä¸ºhive å¤é¨è¡¨æ¶ï¼æ好å°streamingçæåè¾åºçåé符修æ¹ä¸º\001ï¼å¹¶ä¸hiveå¤é¨è¡¨çåé符åºè¯¥è®¾ç½®ä¸º\001ï¼æ³¨æï¼ä¸è¦ä½¿ç¨^Aå\x01ï¼å¦ï¼
ãã[html] view plaincopyå¨CODEä¸æ¥ç代ç çæ´¾çå°æç代ç ç
ããcreate external table site_user_mapping_info_month(uid String,tag string,project_ids string,site_interests string) PARTITIONED BY(year String, month String) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' LOCATION '/project/site_grouping/site_user_mapping_info_month';
温馨提示:内容为网友见解,仅供参考