zoukankan      html  css  js  c++  java
  • hive函数之~复杂类型访问操作

    1、array类型访问: A[n]

    语法: A[n]
    操作类型: A为array类型,n为int类型
    说明:返回数组A中的第n个变量值。数组的起始下标为0。比如,A是个值为['foo', 'bar']的数组类型,那么A[0]将返回'foo',而A[1]将返回'bar'

    hive> create table arr_table2 as select array("tom","mary","tim") as t

     from tableName;

    hive> select t[0],t[1] from arr_table2;

    tom     mary    tim

    2、map类型访问: M[key]

    语法: M[key]
    操作类型: M为map类型,key为map中的key值
    说明:返回map类型M中,key值为指定值的value值。比如,M是值为{'f' -> 'foo', 'b' -> 'bar', 'all' -> 'foobar'}的map类型,那么M['all']将会返回'foobar'

    hive> Create table map_table2 as select map('100','tom','200','mary') as t from tableName;

    hive> select t['200'],t['100'] from map_table2;

    mary    tom

    3、struct类型访问: S.x

    语法: S.x
    操作类型: S为struct类型
    说明:返回结构体S中的x字段。比如,对于结构体struct foobar {int foo, int bar},foobar.foo返回结构体中的foo字段

    hive> create table str_table2 as select struct('tom','mary','tim') as t from tableName;

    hive> describe tableName;

    t       struct<col1:string ,col2:string,col3:string>

    hive> select t.col1,t.col3 from str_table2;

    tom     tim

  • 相关阅读:
    珍珠项链——容斥的应用
    协程库中 WaitGroup / CountDownLatch 实现
    简单C++线程池
    switch 比 if/else 效率更高?
    [LeetCode 264.] 丑数 II
    [LeetCode 229.] 求众数 II
    [NC41] 最长无重复子数组
    [NC105] 二分查找-II
    高楼扔鸡蛋
    C++ 编译期计算
  • 原文地址:https://www.cnblogs.com/lojun/p/13249033.html
Copyright © 2011-2022 走看看