hive collection data type

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值