对于Hive 的 String 类型相当于数据库的 varchar 类型,该类型是一个可变的字符串,不过它不能声明其中最多能存储多少个字符,理论上它可以存储 2GB 的字符数。 3.2 集合数据类型 Hive 有三种复杂数据类型 ARRAY、MAP 和 STRUCT。ARRAY 和 MAP 与 Java 中的 Array 和 Map 类似,而 STRUCT 与 C 语言中的 Struct...
语法: concat(string A, string B…) 返回值: string 说明:返回输入字符串连接后的结果,支持任意个输入字符串 举例: hive> select concat('hello','world'); helloworld 4、字符串连接函数-带分隔符:concat_ws 语法: concat_ws(string SEP, string A, string B…) 返回值: string 说明:返回输入字符串连接...
语法: split(string str, string pat) 返回值: array 说明: 按照pat字符串分割str,会返回分割后的字符串数组 举例: 基本用法 hive> select split('abcdef', 'c') from test; ["ab", "def"] 1. 2. 截取字符串中的某个值 hive> select split('abcdef', 'c')[0] from test; ab 1. 2. 特殊...
ARRAY array<int>``array<struct> array(1, 2, 3)``array(array(1, 2), array(3, 4)) MAP map<string, string>``map<smallint, array<string>> map(“k1”, “v1”, “k2”, “v2”)``map(1S, array(‘a’, ‘b’), 2S, array(‘x’, ‘y’)) STRUCT struct<x:int, y:int...
(stringdate/timestamp) 返回值: 返回date所在季度 。 hive>selectquarter("2020-6-16")fromtableName; 返回:2 日期常用函数 //昨天 select format_datetime(date_add('day',-1,current_date),'yyyyMMdd') // 月份 select substr(cast(current_date as varchar) , 1 ,7 ) ...
语法: to_date(string timestamp) 返回值: string 说明:返回日期时间字段中的日期部分。 举例: hive> select to_date('2011-12-08 10:03:01') from lxw_dual; 2011-12-08 6. 日期转年函数: year 语法: year(string date) 返回值: int 说明:返回日期中的年。 举例: hive> select year('2011-12-...
set odps.sql.hive.compatible=false; select cast((a | b) as string) from values(java.lang.Long.MIN_VALUE, 0L) t(a, b); --返回NULL Hive兼容模式 set odps.sql.hive.compatible=true; select cast((a | b) as string) from values(java.lang.Lo...
所有整数类型、FLOAT 和 STRING 类型都可以隐式地转换成 DOUBLE; TINYINT、SMALLINT、INT 都可以转换为 FLOAT; BOOLEAN 类型不可以转换为任何其它的类型。 可以使用 CAST 操作显示进行数据类型转换 例如CAST('1' AS INT) 将把字符串 '1' 转换成整数 1;如果强制类型转换失败,如执行 CAST('X' AS INT),表达式...
from (select id, name, string_to_array(tag, ',') arr from book) t) t order by id, rn; 1. 2. 3. 4. 执行结果如下所示: test=# select name, (rec).val tag, (rec).ordinality rn test-# from (select *, f_unnest_ord(arr) as rec ...
cast : 基本格式为 cast(value as TYPE),能够将给定的数据 value 转化为 TYPE类型,如下所示: SELECT cast("100" AS INT); 日期函数 日期函数是一类专门处理日期数据的函数,能够方便地对日期数据进行转换和处理。 unix_timestamp:返回当前或指定时间的时间戳 select unix_timestamp(); select unix_timestamp("...