简体   繁体   English

Hive - 根据 ZDFCCFC63F86DED406799FE52A9888 中三个 csv 文件的特定数据创建 hive 表

[英]Hive - create hive table from specific data of three csv files in hdfs

I have three .csv files, each in different hdfs directory.我有三个.csv文件,每个文件位于不同的 hdfs 目录中。 I now want to make a Hive internal table with data from those three files.我现在想用这三个文件中的数据制作一个 Hive 内部表。 I want four columns from first file, three columns from second file and two columns from third file.我想要第一个文件的四列,第二个文件的三列和第三个文件的两列。 first file share an unique id column with second file and third file share another unique id column with third file.第一个文件与第二个文件共享一个唯一的 id 列,第三个文件与第三个文件共享另一个唯一的 id 列。 both unique ids are present in second file;两个唯一 ID 都存在于第二个文件中; using these ids I would like to left-outer-join to make table.使用这些 id 我想左外连接来制作表格。

file 1: '/directory_1/sub_directory_1/table1_data_on_01_01_2014.csv'文件 1:'/directory_1/sub_directory_1/table1_data_on_01_01_2014.csv'
file 2: '/directory_2/sub_directory_2/table2_data_on_01_01_2014.csv'文件 2:'/directory_2/sub_directory_2/table2_data_on_01_01_2014.csv'
file 3: '/directory_3/sub_directory_3/table3_data_on_01_01_2014.csv'文件 3:'/directory_3/sub_directory_3/table3_data_on_01_01_2014.csv'

contents of file 1:文件1的内容:

unique_id_1,age,department,reason_of_visit,--more columns--,,,
id_11,entry_12,entry_13,entry_14,--more entries--
id_12,entry_22,entry_23,entry_24,--more entries--
id_13,entry_32,entry_33,entry_34,--more entries--

contents of file 2:文件2的内容:

unique_id_1,date_of_transaction,transaction_fee,unique_id_2--more columns--,,,
id_11,entry_121,entry_131,id_21,--more entries--
id_12,entry_221,entry_231,id_22,--more entries--
id_13,entry_321,entry_331,id_23,--more entries--

contents of file 3:文件 3 的内容:

unique_id_2,diagnosis,gender --more columns--,,,
id_21,entry_141,entry_151,--more entries--
id_22,entry_241,entry_151,--more entries--
id_23,entry_341,entry_151,--more entries--

I now want to make an internal table like this:我现在想制作一个像这样的内部表:

unique_id_1 age department reason_of_visit date_of_transaction unique_id_2 transaction_fee diagnosis gender
id_11 entry_12 entry_13 entry_14 entry_121 entry_131 id_21 entry_141 entry_151
id_12 entry_22 entry_23 entry_24 entry_221 entry_231 id_22 entry_241 entry_251
id_13 entry_32 entry_33 entry_34 entry_321 entry_331 id_23 entry_341 entry_251

How do i accomplish this?我如何做到这一点?

@Naveen Kumar The solution here is to create external tables for your 3 sources. @Naveen Kumar 这里的解决方案是为您的 3 个来源创建外部表。 Next create combined internal table with the schema for columns you need from the 3 sources.接下来为您需要的来自 3 个来源的列的架构创建组合内部表。 I call these temp or staging tables.我称这些临时表或临时表。 Once these staging tables are created, you should be able to do your joined select as an INSERT INTO combined_table SELECT...创建这些临时表后,您应该能够将您加入的 select 作为 INSERT INTO combined_table SELECT ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM