日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[Hive_6] Hive 的内置函数应用

發布時間:2025/3/8 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [Hive_6] Hive 的内置函数应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

0. 說明

  Hive 的內置函數的基本操作 | 時間函數 | String 函數 | 條件語句 | explode | split | substring?

?


1. 基本操作

  查看函數

  show functions;

?

  查看函數的用法

desc function function_name;

?

  查看函數的擴展信息

  desc function extended format_name;

?

?


?

2. 時間函數

?

select current_database() //當前數據庫 select current_date() //當前日期 select current_timestamp() //當前時間戳,精確到毫秒 select date_format( current_timestamp(), 'yyyy-MM-dd HH:mm:ss'); //將時間格式化 select unix_timestamp(current_timestamp()); //將日期轉換成時間戳,精確到秒 select from_unixtime(153361440000, 'yyyy-MM-dd'); //將時間戳轉化成日期 select datediff('2018-03-01','2018-02-01'); //計算兩個指定日期相差多少天

?

?


?

3. String 函數

select split('hello world',' '); // 以空格進行切割成 Array 數組 select substr('hello world', 7); // 切割字符串 worldselect trim(' world'); //去掉前后的空格format_number() //select format_number(1234.345,2); => 1,234.35 //select format_number(1234.345,'000000.00'); => 001234.35 //select format_number(1234.345,'########.##'); => 1234.35select concat('hello', ' world'); // 拼串操作,返回 hello worldselect length('helloworld'); // 10

?

?


?

4. 條件語句

  4.1 if

select if( age > 10 ,'old', 'young') from user_par;

  // 相當于三元運算符。
  // 第一個表達式成立返回第二個表達式
  // 第一個不成立返回第三個表達式

?

  4.2 case

select case when age<20 then 'young' when age<40 then 'middle' else 'old' end from user_par;

  // 小于20,返回 young
  // 小于40,返回 middle
  // 否則,返回 old

?


?5.?explode

  5.1 描述

  separates the elements of array a into multiple rows
  or the elements of a map into multiple rows and columns

  分裂 array 數組的中的元素變成多行
  或者分裂 map 中的元素變成多行和多列
  是一個表生成函數

  5.2 使用方法

  explode(array)

?

?


?

6.?split

  6.1 描述

  Splits str around occurances that match regex

  拆分與正則表達式匹配的事件

?

  6.2 使用方法

  split(str, regex)

?

?


7. substr

  7.1 描述

  截取從指定位置開始指定長度的的字符串

  默認從第一位開始截取

?

  7.2 使用方法

  substr(str, pos[, len])

?

?

?


?

轉載于:https://www.cnblogs.com/share23/p/10223898.html

總結

以上是生活随笔為你收集整理的[Hive_6] Hive 的内置函数应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。