Hive supports columns that are structs, maps, and arrays
create table
hive >create table employees3(name STRING,
salary FLOAT, subordinates ARRAY<STRING>,
deductions MAP<STRING,FLOAT>,
address STRUCT<street:STRING,city:STRING,state:STRING,zip:INT>)
ROW FORMAT DELIMITED FIELDS TERMINATED BY'\001' COLLECTION ITEMS TERMINATED BY '\002' MAP KEYS TERMINATED BY '\003'lines terminated by '\n' stored as textfile;
load data
hive >loaddata LOCAL INPATH '/root/employees.txt.1' OVERWRITE INTO TABLE employee3;
注意: \001, \002,\003 这些分隔符是不能通过vim 输入的,我是写java 代码生成的。
public static void main(String[] args){
char[] a={1};
char[] b={2};
char[] c={3};
try {
File file =new File("/root/employees.txt.1");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("John Doe");
bw.write(a);
bw.write("100000.0");
bw.write(a);
bw.write("Mary Smith");
bw.write(b);
bw.write("Todd Jones");
bw.write(a);
bw.write("Federal Taxes");
bw.write(c);
bw.write(".2");
bw.write(b);
bw.write("BState Taxes");
bw.write(c);
bw.write(".5");
bw.write(b);
bw.write("Insurance");
bw.write(c);
bw.write(".1");
bw.write(a);
bw.write("1 Michigan Ave.");
bw.write(b);
bw.write("BChicago");
bw.write(b);
bw.write("IL");
bw.write(b);
bw.write("60600");
bw.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
Hive’s default record and field delimiters
Delimiter Description
\n For text files, each line is a record, so the line feed character separates records.
^A (“control” A) Separates all fields (columns). Written using the octal code \001 when explicitly
specified in CREATE TABLE statements.
^B Separate the elements in an ARRAY or STRUCT, or the key-value pairs in a MAP.
Written using the octal code \002 when explicitly specified in CREATE TABLE
statements.
^C Separate the key from the corresponding value in MAP key-value pairs. Written using
the octal code \003 when explicitly specified in CREATE TABLE statements.
More you can reference chapter3 of Programming Hive