id | Spark SQL | Presto SQL | 差异 |
1 | date_add(start_date, num_days) | date_add(unit, value, timestamp) unit = second,minute,hour,day,week,month,quarter,year | 1)函数入参不一样 |
2 | datediff(endDate, startDate) SELECT datediff('2009-07-31', '2009-07-30'); | date_diff(unit, timestamp1, timestamp2) unit = second,minute,hour,day,week,month,quarter,year Returns timestamp2 - timestamp1 expressed in terms of unit. | 1)函数名称不一样,下划线 2)函数入参顺序不一样,相反 |
3 | 1.current_date获取当前日期 2018-04-09 2.current_timestamp/now()获取当前时间 2018-04-09 15:20:49.247 | current_date current_time current_timestamp |
|
4 | 1.unix_timestamp返回当前时间的unix时间戳 SELECT unix_timestamp('2016-04-08', 'yyyy-MM-dd'); 1460041200 2.from_unixtime将时间戳换算成当前时间,to_unix_timestamp将时间转化为时间戳 SELECT from_unixtime(0, 'yyyy-MM-dd HH:mm:ss'); 1970-01-01 00:00:00 SELECT to_unix_timestamp('2016-04-08', 'yyyy-MM-dd'); 1460041200 | from_unixtime(unixtime) from_unixtime(unixtime, string) |
|
5 | to_date/date将字符串转化为日期格式,to_timestamp(Since: 2.2.0) |
|
|
6 | add_months返回日期后n个月后的日期 SELECT add_months('2016-08-31', 1); 2016-09-30 |
|
|
7 | last_day(date),next_day(start_date, day_of_week) SELECT last_day('2009-01-12'); 2009-01-31 |
|
|
8 | trunc截取某部分的日期 第二个参数 ["year", "yyyy", "yy", "mon", "month", "mm"] SELECT trunc('2009-02-12', 'MM'); 2009-02-01 date_trunc ["YEAR", "YYYY", "YY", "MON", "MONTH", "MM", "DAY", "DD", "HOUR", "MINUTE", "SECOND", "WEEK", "QUARTER"] SELECT date_trunc('2015-03-05T09:32:05.359', 'HOUR'); 2015-03-05T09:00:00 | date_trunc(unit, x) unit = second,minute,hour,day,week,month,quarter,year | 函数参数不一样 |
9 | SELECT date_format('2016-04-08', 'y'); |
|
|
10 | nvl(xxxx,'') | coalesce(xxx,'') | 函数名不一样 |
11 | select get_json_object(json_str, '$.name'); | json_extract_scalar(json_str, '$.name') | get单层json 函数名不一样 |
12 | get_json_object(json_str, '$.item.tabid'); | json_extract_scalar(json_str, '$.item.tabid') | get多层json 函数名不一样 |
13 | get_json_object(json_str, '$.item.uss_rule[0]'); | json_extract(json_str, '$.item.uss_rule[0]') | get json数组 函数名不一样 |
14 | msg['isBackgroundMode'] | element_at(msg,'isBackgroundMode') | hashmap元素的引用 语法格式不一样 |
15 | select student, score from tests lateral view explode(split(scores, ',')) t as score; | select student, score from tests cross json unnest(split(scores, ',') as t (score); | 列转行 语法格式不一样 |
16 |
|
|
|