zoukankan      html  css  js  c++  java
  • hive复杂格式array,map,struct使用

    -- 创建数据库表,以array作为数据类型
    drop table if exists person;
    create table person(
         name string
        ,work_locations array<string>
    )
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY ' '
    COLLECTION ITEMS TERMINATED BY ','
    stored as textfile
    ;
    
    -- 数据
    biansutao beijing,shanghai,tianjin,hangzhou
    linan changchu,chengdu,wuhan
    
    -- 入库数据
    LOAD DATA LOCAL INPATH 'tmpa' OVERWRITE INTO TABLE person;
    
    -- 查询
    select * from person;
    select name from person;
    select work_locations[0] from person;
    select work_locations from person;
    select work_locations[3] from person;
    select work_locations[4] from person;
    -- 创建数据库表
    create table score(
         name string
        ,score map<string,int>
    )
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY ' '
    COLLECTION ITEMS TERMINATED BY ','
    MAP KEYS TERMINATED BY ':'
    stored as textfile
    ;
    
    -- 数据
    biansutao 数学:80,语文:89,英语:95
    jobs 语文:60,数学:80,英语:99
    
    -- 入库数据
    LOAD DATA LOCAL INPATH 'tmpb' OVERWRITE INTO TABLE score;
    
    -- 查询
    select * from score;
    select name from score;
    select t.score from score t;
    select t.score['语文'] from score t;
    select t.score['英语'] from score t;
    -- 创建数据表
    CREATE TABLE test(
         id int
        ,course struct<course:string,score:int>
    )
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY ' '
    COLLECTION ITEMS TERMINATED BY ','
    stored as textfile
    ;
    
    -- 数据
    1 english,80
    2 math,89
    3 chinese,95
    
    -- 入库
    LOAD DATA LOCAL INPATH 'tmpc' OVERWRITE INTO TABLE test;
    
    -- 查询
    select * from test;
    select course from test;
    select t.course.course from test t; 
    select t.course.score from test t;
    -- 创建数据表 (异常)
    create table test1(
         id int
        ,a MAP<STRING,ARRAY<STRING>>
    )
    row format delimited fields terminated by ' '
    collection items terminated by ','
    MAP KEYS TERMINATED BY ':'
    stored as textfile
    ;
    
    -- 数据
    1 english:80,90,70
    2 math:89,78,86
    3 chinese:99,100,82
    
    -- 入库
    LOAD DATA LOCAL INPATH 'tmpd' OVERWRITE INTO TABLE test1;
    
    -- 查询

    ref: https://blog.csdn.net/u010670689/article/details/72885944

  • 相关阅读:
    Unieap3.5-Grid+Form下拉列表高度设置
    Unieap3.5-Grid翻页不提示修改
    Unieap3.5-需要用到window.setTimeout的地方
    Unieap3.5-前台js判断表单必录
    JavaScript空判断
    JavaScript字符串转日期格式
    Unieap3.5-前台js用SQL语句执行数据请求
    Unieap3.5-JS常用方法
    mysql之索引查询1
    mysql之多表查询和pymysql模块
  • 原文地址:https://www.cnblogs.com/chenzechao/p/9817868.html
Copyright © 2011-2022 走看看