主頁 > 資料庫 > hive內置方法一覽

hive內置方法一覽

2020-09-14 13:36:27 資料庫

參考 https://www.cnblogs.com/qingyunzong/p/8744593.html#_label0

官方檔案 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF

 

目錄

  • 數學函式
  • 集合函式
  • 型別轉換函式
  • 日期函式
  • 條件函式
  • 字符函式
  • 聚合函式
  • 表生成函式

 

正文

回到頂部

數學函式

Return Type

Name (Signature)

Description

DOUBLE

round(DOUBLE a)

Returns the rounded BIGINT value of a.

回傳對a四舍五入的BIGINT值

DOUBLE

round(DOUBLE a, INT d)

Returns a rounded to d decimal places.

回傳DOUBLE型d的保留n位小數的DOUBLW型的近似值

DOUBLE bround(DOUBLE a) Returns the rounded BIGINT value of a using HALF_EVEN rounding mode (as of Hive 1.3.0, 2.0.0). Also known as Gaussian rounding or bankers' rounding. Example: bround(2.5) = 2, bround(3.5) = 4.
銀行家舍入法(1~4:舍,6~9:進,5->前位數是偶:舍,5->前位數是奇:進)
DOUBLE bround(DOUBLE a, INT d) Returns a rounded to d decimal places using HALF_EVEN rounding mode (as of Hive 1.3.0, 2.0.0). Example: bround(8.25, 1) = 8.2, bround(8.35, 1) = 8.4.
銀行家舍入法,保留d位小數

BIGINT

floor(DOUBLE a)

Returns the maximum BIGINT value that is equal to or less than a

向下取整,最數軸上最接近要求的值的左邊的值  如:6.10->6   -3.4->-4

BIGINT

ceil(DOUBLE a), ceiling(DOUBLE a)

Returns the minimum BIGINT value that is equal to or greater than a.

求其不小于小給定實數的最小整數如:ceil(6) = ceil(6.1)= ceil(6.9) = 6

DOUBLE

rand(), rand(INT seed)

Returns a random number (that changes from row to row) that is distributed uniformly from 0 to 1. Specifying the seed will make sure the generated random number sequence is deterministic.

每行回傳一個DOUBLE型亂數seed是隨機因子

DOUBLE

exp(DOUBLE a), exp(DECIMAL a)

Returns ea where e is the base of the natural logarithm. Decimal version added in Hive 0.13.0.

回傳e的a冪次方, a可為小數

DOUBLE

ln(DOUBLE a), ln(DECIMAL a)

Returns the natural logarithm of the argument a. Decimal version added in Hive 0.13.0.

以自然數為底d的對數,a可為小數

DOUBLE

log10(DOUBLE a), log10(DECIMAL a)

Returns the base-10 logarithm of the argument a. Decimal version added in Hive 0.13.0.

以10為底d的對數,a可為小數

DOUBLE

log2(DOUBLE a), log2(DECIMAL a)

Returns the base-2 logarithm of the argument a. Decimal version added in Hive 0.13.0.

以2為底數d的對數,a可為小數

DOUBLE

log(DOUBLE base, DOUBLE a)

log(DECIMAL base, DECIMAL a)

Returns the base-base logarithm of the argument a. Decimal versions added in Hive 0.13.0.

以base為底的對數,base 與 a都是DOUBLE型別

DOUBLE

pow(DOUBLE a, DOUBLE p), power(DOUBLE a, DOUBLE p)

Returns ap.

計算a的p次冪

DOUBLE

sqrt(DOUBLE a), sqrt(DECIMAL a)

Returns the square root of a. Decimal version added in Hive 0.13.0.

計算a的平方根

STRING

bin(BIGINT a)

Returns the number in binary format (see http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_bin).

計算二進制a的STRING型別,a為BIGINT型別

STRING

hex(BIGINT a) hex(STRING a) hex(BINARY a)

If the argument is an INT or binaryhex returns the number as a STRING in hexadecimal format. Otherwise if the number is a STRING, it converts each character into its hexadecimal representation and returns the resulting STRING. (Seehttp://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_hex, BINARY version as of Hive 0.12.0.)

計算十六進制a的STRING型別,如果a為STRING型別就轉換成字符相對應的十六進制

BINARY

unhex(STRING a)

Inverse of hex. Interprets each pair of characters as a hexadecimal number and converts to the byte representation of the number. (BINARY version as of Hive 0.12.0, used to return a string.)

hex的逆方法

STRING

conv(BIGINT num, INT from_base, INT to_base), conv(STRING num, INT from_base, INT to_base)

Converts a number from a given base to another (see http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_conv).

將GIGINT/STRING型別的num從from_base進制轉換成to_base進制

DOUBLE

abs(DOUBLE a)

Returns the absolute value.

計算a的絕對值

INT or DOUBLE

pmod(INT a, INT b), pmod(DOUBLE a, DOUBLE b)

Returns the positive value of a mod b.

a對b取模

DOUBLE

sin(DOUBLE a), sin(DECIMAL a)

Returns the sine of a (a is in radians). Decimal version added in Hive 0.13.0.

求a的正弦值

DOUBLE

asin(DOUBLE a), asin(DECIMAL a)

Returns the arc sin of a if -1<=a<=1 or NULL otherwise. Decimal version added in Hive 0.13.0.

求d的反正弦值

DOUBLE

cos(DOUBLE a), cos(DECIMAL a)

Returns the cosine of a (a is in radians). Decimal version added in Hive 0.13.0.

求余弦值

DOUBLE

acos(DOUBLE a), acos(DECIMAL a)

Returns the arccosine of a if -1<=a<=1 or NULL otherwise. Decimal version added in Hive 0.13.0.

求反余弦值

DOUBLE

tan(DOUBLE a), tan(DECIMAL a)

Returns the tangent of a (a is in radians). Decimal version added in Hive 0.13.0.

求正切值

DOUBLE

atan(DOUBLE a), atan(DECIMAL a)

Returns the arctangent of a. Decimal version added in Hive 0.13.0.

求反正切值

DOUBLE

degrees(DOUBLE a), degrees(DECIMAL a)

Converts value of a from radians to degrees. Decimal version added in Hive 0.13.0.

獎弧度值轉換角度值

DOUBLE

radians(DOUBLE a), radians(DOUBLE a)

Converts value of a from degrees to radians. Decimal version added in Hive 0.13.0.

將角度值轉換成弧度值

INT or DOUBLE

positive(INT a), positive(DOUBLE a)

Returns a.

回傳a

INT or DOUBLE

negative(INT a), negative(DOUBLE a)

Returns -a.

回傳a的相反數

DOUBLE or INT

sign(DOUBLE a), sign(DECIMAL a)

Returns the sign of a as '1.0' (if a is positive) or '-1.0' (if a is negative), '0.0' otherwise. The decimal version returns INT instead of DOUBLE. Decimal version added in Hive 0.13.0.

如果a是正數則回傳1.0,是負數則回傳-1.0,否則回傳0.0

DOUBLE

e()

Returns the value of e.

數學常數e

DOUBLE

pi()

Returns the value of pi.

數學常數pi

BIGINT factorial(INT a) Returns the factorial of a (as of Hive 1.2.0). Valid a is [0..20].
求a的階乘
DOUBLE cbrt(DOUBLE a) Returns the cube root of a double value (as of Hive 1.2.0).
求a的立方根

 

INT BIGINT

shiftleft(TINYINT|SMALLINT|INT a, INT b)

shiftleft(BIGINT a, INT b)

Bitwise left shift (as of Hive 1.2.0). Shifts a b positions to the left.

Returns int for tinyint, smallint and int a. Returns bigint for bigint a.

按位左移

INT

BIGINT

shiftright(TINYINT|SMALLINT|INT a, INTb)

shiftright(BIGINT a, INT b)

Bitwise right shift (as of Hive 1.2.0). Shifts a b positions to the right.

Returns int for tinyint, smallint and int a. Returns bigint for bigint a.

按拉右移

INT

BIGINT

shiftrightunsigned(TINYINT|SMALLINT|INTa, INT b),

shiftrightunsigned(BIGINT a, INT b)

Bitwise unsigned right shift (as of Hive 1.2.0). Shifts a b positions to the right.

Returns int for tinyint, smallint and int a. Returns bigint for bigint a.

無符號按位右移(<<<)

T greatest(T v1, T v2, ...) Returns the greatest value of the list of values (as of Hive 1.1.0). Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with ">" operator (as of Hive 2.0.0).
求最大值
T least(T v1, T v2, ...) Returns the least value of the list of values (as of Hive 1.1.0). Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with "<" operator (as of Hive 2.0.0).
求最小值
  回到頂部

集合函式

Return Type

Name(Signature)

Description

int

size(Map<K.V>)

Returns the number of elements in the map type.

求map的長度

int

size(Array<T>)

Returns the number of elements in the array type.

求陣列的長度

array<K>

map_keys(Map<K.V>)

Returns an unordered array containing the keys of the input map.

回傳map中的所有key

array<V>

map_values(Map<K.V>)

Returns an unordered array containing the values of the input map.

回傳map中的所有value

boolean

array_contains(Array<T>, value)

Returns TRUE if the array contains value.

如該陣列Array<T>包含value回傳true,,否則回傳false

array

sort_array(Array<T>)

Sorts the input array in ascending order according to the natural ordering of the array elements and returns it (as of version 0.9.0).

按自然順序對陣列進行排序并回傳

  回到頂部

型別轉換函式

Return Type

Name(Signature)

Description

binary

binary(string|binary)

Casts the parameter into a binary.

將輸入的值轉換成二進制

Expected "=" to follow "type"

cast(expr as <type>)

Converts the results of the expression expr to <type>. For example, cast('1' as BIGINT) will convert the string '1' to its integral representation. A null is returned if the conversion does not succeed. If cast(expr as boolean) Hive returns true for a non-empty string.

將expr轉換成type型別 如:cast("1" as BIGINT) 將字串1轉換成了BIGINT型別,如果轉換失敗將回傳NULL

    回到頂部

日期函式

Return Type

Name(Signature)

Description

string

from_unixtime(bigint unixtime[, string format])

Converts the number of seconds from unix epoch (1970-01-01 00:00:00 UTC) to a string representing the timestamp of that moment in the current system time zone in the format of "1970-01-01 00:00:00".

將時間的秒值轉換成format格式(format可為“yyyy-MM-dd hh:mm:ss”,“yyyy-MM-dd hh”,“yyyy-MM-dd hh:mm”等等)如from_unixtime(1250111000,"yyyy-MM-dd") 得到2009-03-12

bigint

unix_timestamp()

Gets current Unix timestamp in seconds.

獲取本地時區下的時間戳

bigint

unix_timestamp(string date)

Converts time string in format yyyy-MM-dd HH:mm:ss to Unix timestamp (in seconds), using the default timezone and the default locale, return 0 if fail: unix_timestamp('2009-03-20 11:30:01') = 1237573801

將格式為yyyy-MM-dd HH:mm:ss的時間字串轉換成時間戳  如unix_timestamp('2009-03-20 11:30:01') = 1237573801

bigint

unix_timestamp(string date, string pattern)

Convert time string with given pattern (see [http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html]) to Unix time stamp (in seconds), return 0 if fail: unix_timestamp('2009-03-20', 'yyyy-MM-dd') = 1237532400.

將指定時間字串格式字串轉換成Unix時間戳,如果格式不對回傳0 如:unix_timestamp('2009-03-20', 'yyyy-MM-dd') = 1237532400

string

to_date(string timestamp)

Returns the date part of a timestamp string: to_date("1970-01-01 00:00:00") = "1970-01-01".

回傳時間字串的日期部分

int

year(string date)

Returns the year part of a date or a timestamp string: year("1970-01-01 00:00:00") = 1970, year("1970-01-01") = 1970.

回傳時間字串的年份部分

int quarter(date/timestamp/string) Returns the quarter of the year for a date, timestamp, or string in the range 1 to 4 (as of Hive 1.3.0). Example: quarter('2015-04-08') = 2.

回傳當前時間屬性哪個季度 如quarter('2015-04-08') = 2

int

month(string date)

Returns the month part of a date or a timestamp string: month("1970-11-01 00:00:00") = 11, month("1970-11-01") = 11.

回傳時間字串的月份部分

int

day(string date) dayofmonth(date)

Returns the day part of a date or a timestamp string: day("1970-11-01 00:00:00") = 1, day("1970-11-01") = 1.

回傳時間字串的天

int

hour(string date)

Returns the hour of the timestamp: hour('2009-07-30 12:58:59') = 12, hour('12:58:59') = 12.

回傳時間字串的小時

int

minute(string date)

Returns the minute of the timestamp.

回傳時間字串的分鐘

int

second(string date)

Returns the second of the timestamp.

回傳時間字串的秒

int

weekofyear(string date)

Returns the week number of a timestamp string: weekofyear("1970-11-01 00:00:00") = 44, weekofyear("1970-11-01") = 44.

回傳時間字串位于一年中的第幾個周內  如weekofyear("1970-11-01 00:00:00") = 44, weekofyear("1970-11-01") = 44

int

datediff(string enddate, string startdate)

Returns the number of days from startdate to enddate: datediff('2009-03-01', '2009-02-27') = 2.

計算開始時間startdate到結束時間enddate相差的天數

string

date_add(string startdate, int days)

Adds a number of days to startdate: date_add('2008-12-31', 1) = '2009-01-01'.

從開始時間startdate加上days

string

date_sub(string startdate, int days)

Subtracts a number of days to startdate: date_sub('2008-12-31', 1) = '2008-12-30'.

從開始時間startdate減去days

timestamp

from_utc_timestamp(timestamp, string timezone)

Assumes given timestamp is UTC and converts to given timezone (as of Hive 0.8.0). For example, from_utc_timestamp('1970-01-01 08:00:00','PST') returns 1970-01-01 00:00:00.

如果給定的時間戳并非UTC,則將其轉化成指定的時區下時間戳

timestamp

to_utc_timestamp(timestamp, string timezone)

Assumes given timestamp is in given timezone and converts to UTC (as of Hive 0.8.0). For example, to_utc_timestamp('1970-01-01 00:00:00','PST') returns 1970-01-01 08:00:00.

如果給定的時間戳指定的時區下時間戳,則將其轉化成UTC下的時間戳

date current_date

Returns the current date at the start of query evaluation (as of Hive 1.2.0). All calls of current_date within the same query return the same value.

回傳當前時間日期

timestamp current_timestamp

Returns the current timestamp at the start of query evaluation (as of Hive 1.2.0). All calls of current_timestamp within the same query return the same value.

回傳當前時間戳

string add_months(string start_date, int num_months)

Returns the date that is num_months after start_date (as of Hive 1.1.0). start_date is a string, date or timestamp. num_months is an integer. The time part of start_date is ignored. If start_date is the last day of the month or if the resulting month has fewer days than the day component of start_date, then the result is the last day of the resulting month. Otherwise, the result has the same day component as start_date.

回傳當前時間下再增加num_months個月的日期

string last_day(string date) Returns the last day of the month which the date belongs to (as of Hive 1.1.0). date is a string in the format 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. The time part of date is ignored.

回傳這個月的最后一天的日期,忽略時分秒部分(HH:mm:ss)

string next_day(string start_date, string day_of_week) Returns the first date which is later than start_date and named as day_of_week (as of Hive1.2.0). start_date is a string/date/timestamp. day_of_week is 2 letters, 3 letters or full name of the day of the week (e.g. Mo, tue, FRIDAY). The time part of start_date is ignored. Example: next_day('2015-01-14', 'TU') = 2015-01-20.

回傳當前時間的下一個星期X所對應的日期 如:next_day('2015-01-14', 'TU') = 2015-01-20  以2015-01-14為開始時間,其下一個星期二所對應的日期為2015-01-20

string trunc(string date, string format) Returns date truncated to the unit specified by the format (as of Hive 1.2.0). Supported formats: MONTH/MON/MM, YEAR/YYYY/YY. Example: trunc('2015-03-17', 'MM') = 2015-03-01.

回傳時間的最開始年份或月份  如trunc("2016-06-26",“MM”)=2016-06-01  trunc("2016-06-26",“YY”)=2016-01-01   注意所支持的格式為MONTH/MON/MM, YEAR/YYYY/YY

double months_between(date1, date2) Returns number of months between dates date1 and date2 (as of Hive 1.2.0). If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise the UDF calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2. date1 and date2 type can be date, timestamp or string in the format 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss'. The result is rounded to 8 decimal places. Example: months_between('1997-02-28 10:30:00', '1996-10-30') = 3.94959677

回傳date1與date2之間相差的月份,如date1>date2,則回傳正,如果date1<date2,則回傳負,否則回傳0.0  如:months_between('1997-02-28 10:30:00', '1996-10-30') = 3.94959677  1997-02-28 10:30:00與1996-10-30相差3.94959677個月

string date_format(date/timestamp/string ts, string fmt)

Converts a date/timestamp/string to a value of string in the format specified by the date format fmt (as of Hive 1.2.0). Supported formats are Java SimpleDateFormat formats –https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html. The second argument fmt should be constant. Example: date_format('2015-04-08', 'y') = '2015'.

date_format can be used to implement other UDFs, e.g.:

  • dayname(date) is date_format(date, 'EEEE')
  • dayofyear(date) is date_format(date, 'D')

    按指定格式回傳時間date 如:date_format("2016-06-22","MM-dd")=06-22

    回到頂部

條件函式

Return Type

Name(Signature)

Description

T

if(boolean testCondition, T valueTrue, T valueFalseOrNull)

Returns valueTrue when testCondition is true, returns valueFalseOrNull otherwise.

如果testCondition 為true就回傳valueTrue,否則回傳valueFalseOrNull ,(valueTrue,valueFalseOrNull為泛型) 

T nvl(T value, T default_value) Returns default value if value is null else returns value (as of HIve 0.11).

如果value值為NULL就回傳default_value,否則回傳value

T

COALESCE(T v1, T v2, ...)

Returns the first v that is not NULL, or NULL if all v's are NULL.

回傳第一非null的值,如果全部都為NULL就回傳NULL  如:COALESCE (NULL,44,55)=44/strong>

T

CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END

When a = b, returns c; when a = d, returns e; else returns f.

如果a=b就回傳c,a=d就回傳e,否則回傳f  如CASE 4 WHEN 5  THEN 5 WHEN 4 THEN 4 ELSE 3 END 將回傳4

T

CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END

When a = true, returns b; when c = true, returns d; else returns e.

如果a=ture就回傳b,c= ture就回傳d,否則回傳e  如:CASE WHEN  5>0  THEN 5 WHEN 4>0 THEN 4 ELSE 0 END 將回傳5;CASE WHEN  5<0  THEN 5 WHEN 4<0 THEN 4 ELSE 0 END 將回傳0

boolean isnull( a ) Returns true if a is NULL and false otherwise.

如果a為null就回傳true,否則回傳false

boolean isnotnull ( a ) Returns true if a is not NULL and false otherwise.

如果a為非null就回傳true,否則回傳false

    回到頂部

字符函式

Return Type

Name(Signature)

Description

int

ascii(string str)

Returns the numeric value of the first  character of str.

回傳str中首個ASCII字串的整數值

string

base64(binary bin)

Converts the argument from binary to a base 64 string (as of Hive 0.12.0)..

將二進制bin轉換成64位的字串

string

concat(string|binary A, string|binary B...)

Returns the string or bytes resulting from concatenating the strings or bytes passed in as parameters in order. For example, concat('foo', 'bar') results in 'foobar'. Note that this function can take any number of input strings..

對二進制位元組碼或字串按次序進行拼接

array<struct<string,double>>

context_ngrams(array<array<string>>, array<string>, int K, int pf)

Returns the top-k contextual N-grams from a set of tokenized sentences, given a string of "context". See StatisticsAndDataMining for more information..

與ngram類似,但context_ngram()允許你預算指定背景關系(陣列)來去查找子序列,具體看StatisticsAndDataMining(這里的解釋更易懂)

string

concat_ws(string SEP, string A, string B...)

Like concat() above, but with custom separator SEP..

與concat()類似,但使用指定的分隔符喜進行分隔

string

concat_ws(string SEP, array<string>)

Like concat_ws() above, but taking an array of strings. (as of Hive 0.9.0).

拼接Array中的元素并用指定分隔符進行分隔

string

decode(binary bin, string charset)

Decodes the first argument into a String using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). If either argument is null, the result will also be null. (As of Hive 0.12.0.).

使用指定的字符集charset將二進制值bin解碼成字串,支持的字符集有:'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16',如果任意輸入引數為NULL都將回傳NULL

binary

encode(string src, string charset)

Encodes the first argument into a BINARY using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). If either argument is null, the result will also be null. (As of Hive 0.12.0.).

使用指定的字符集charset將字串編碼成二進制值,支持的字符集有:'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16',如果任一輸入引數為NULL都將回傳NULL

int

find_in_set(string str, string strList)

Returns the first occurance of str in strList where strList is a comma-delimited string. Returns null if either argument is null. Returns 0 if the first argument contains any commas. For example, find_in_set('ab', 'abc,b,ab,c,def') returns 3..

回傳以逗號分隔的字串中str出現的位置,如果引數str為逗號或查找失敗將回傳0,如果任一引數為NULL將回傳NULL回

string

format_number(number x, int d)

Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part. (As of Hive 0.10.0; bug with float types fixed in Hive 0.14.0, decimal type support added in Hive 0.14.0).

將數值X轉換成"#,###,###.##"格式字串,并保留d位小數,如果d為0,將進行四舍五入且不保留小數

string

get_json_object(string json_string, string path)

Extracts json object from a json string based on json path specified, and returns json string of the extracted json object. It will return null if the input json string is invalid. NOTE: The json path can only have the characters [0-9a-z_], i.e., no upper-case or special characters. Also, the keys *cannot start with numbers.* This is due to restrictions on Hive column names..

從指定路徑上的JSON字串抽取出JSON物件,并回傳這個物件的JSON格式,如果輸入的JSON是非法的將回傳NULL,注意此路徑上JSON字串只能由數字 字母 下劃線組成且不能有大寫字母和特殊字符,且key不能由數字開頭,這是由于Hive對列名的限制

boolean

in_file(string str, string filename)

Returns true if the string str appears as an entire line in filename..

如果檔案名為filename的檔案中有一行資料與字串str匹配成功就回傳true

int

instr(string str, string substr)

Returns the position of the first occurrence of substr in str. Returns null if either of the arguments are null and returns 0 if substr could not be found in str. Be aware that this is not zero based. The first character in str has index 1..

查找字串str中子字串substr出現的位置,如果查找失敗將回傳0,如果任一引數為Null將回傳null,注意位置為從1開始的

int

length(string A)

Returns the length of the string..

回傳字串的長度

int

locate(string substr, string str[, int pos])

Returns the position of the first occurrence of substr in str after position pos..

查找字串str中的pos位置后字串substr第一次出現的位置

string

lower(string A) lcase(string A)

Returns the string resulting from converting all characters of B to lower case. For example, lower('fOoBaR') results in 'foobar'..

將字串A的所有字母轉換成小寫字母

string

lpad(string str, int len, string pad)

Returns str, left-padded with pad to a length of len..

從左邊開始對字串str使用字串pad填充,最終len長度為止,如果字串str本身長度比len大的話,將去掉多余的部分

string

ltrim(string A)

Returns the string resulting from trimming spaces from the beginning(left hand side) of A. For example, ltrim(' foobar ') results in 'foobar '..

去掉字串A前面的空格

array<struct<string,double>>

ngrams(array<array<string>>, int N, int K, int pf)

Returns the top-k N-grams from a set of tokenized sentences, such as those returned by the sentences() UDAF. See StatisticsAndDataMining for more information..

回傳出現次數TOP K的的子序列,n表示子序列的長度,具體看StatisticsAndDataMining (這里的解釋更易懂)

string

parse_url(string urlString, string partToExtract [, string keyToExtract])

Returns the specified part from the URL. Valid values for partToExtract include HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO. For example, parse_url('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'HOST') returns 'facebook.com'. Also a value of a particular key in QUERY can be extracted by providing the key as the third argument, for example, parse_url('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'QUERY', 'k1') returns 'v1'..

回傳從URL中抽取指定部分的內容,引數url是URL字串,而引數partToExtract是要抽取的部分,這個引數包含(HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO,例如:parse_url('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'HOST') ='facebook.com',如果引數partToExtract值為QUERY則必須指定第三個引數key  如:parse_url('http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1', 'QUERY', 'k1') =‘v1’

string

printf(String format, Obj... args)

Returns the input formatted according do printf-style format strings (as of Hive0.9.0)..

按照printf風格格式輸出字串

string

regexp_extract(string subject, string pattern, int index)

Returns the string extracted using the pattern. For example, regexp_extract('foothebar', 'foo(.*?)(bar)', 2) returns 'bar.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\\s' is necessary to match whitespace, etc. The 'index' parameter is the Java regex Matcher group() method index. See docs/api/java/util/regex/Matcher.html for more information on the 'index' or Java regex group() method..

抽取字串subject中符合正則運算式pattern的第index個部分的子字串,注意些預定義字符的使用,如第二個引數如果使用'\s'將被匹配到s,'\\s'才是匹配空格

string

regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)

Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace("foobar", "oo|ar", "") returns 'fb.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\\s' is necessary to match whitespace, etc..

按照Java正則運算式PATTERN將字串INTIAL_STRING中符合條件的部分成REPLACEMENT所指定的字串,如里REPLACEMENT這空的話,抽符合正則的部分將被去掉  如:regexp_replace("foobar", "oo|ar", "") = 'fb.' 注意些預定義字符的使用,如第二個引數如果使用'\s'將被匹配到s,'\\s'才是匹配空格

string

repeat(string str, int n)

Repeats str n times..

重復輸出n次字串str

string

reverse(string A)

Returns the reversed string..

反轉字串

string

rpad(string str, int len, string pad)

Returns str, right-padded with pad to a length of len..

從右邊開始對字串str使用字串pad填充,最終len長度為止,如果字串str本身長度比len大的話,將去掉多余的部分

string

rtrim(string A)

Returns the string resulting from trimming spaces from the end(right hand side) of A. For example, rtrim(' foobar ') results in ' foobar'..

去掉字串后面出現的空格

array<array<string>>

sentences(string str, string lang, string locale)

Tokenizes a string of natural language text into words and sentences, where each sentence is broken at the appropriate sentence boundary and returned as an array of words. The 'lang' and 'locale' are optional arguments. For example, sentences('Hello there! How are you?') returns ( ("Hello", "there"), ("How", "are", "you") )..

字串str將被轉換成單詞陣列,如:sentences('Hello there! How are you?') =( ("Hello", "there"), ("How", "are", "you") )

string

space(int n)

Returns a string of n spaces..

回傳n個空格

array

split(string str, string pat)

Splits str around pat (pat is a regular expression)..

按照正則運算式pat來分割字串str,并將分割后的陣列字串的形式回傳

map<string,string>

str_to_map(text[, delimiter1, delimiter2])

Splits text into key-value pairs using two delimiters. Delimiter1 separates text into K-V pairs, and Delimiter2 splits each K-V pair. Default delimiters are ',' for delimiter1 and '=' for delimiter2..

將字串str按照指定分隔符轉換成Map,第一個引數是需要轉換字串,第二個引數是鍵值對之間的分隔符,默認為逗號;第三個引數是鍵值之間的分隔符,默認為"="

string

substr(string|binary A, int start) substring(string|binary A, int start)

Returns the substring or slice of the byte array of A starting from start position till the end of string A. For example, substr('foobar', 4) results in 'bar' (see [http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr])..

對于字串A,從start位置開始截取字串并回傳

string

substr(string|binary A, int start, int len) substring(string|binary A, int start, int len)

Returns the substring or slice of the byte array of A starting from start position with length len. For example, substr('foobar', 4, 1) results in 'b' (see [http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr])..

對于二進制/字串A,從start位置開始截取長度為length的字串并回傳

string substring_index(string A, string delim, int count) Returns the substring from string A before count occurrences of the delimiter delim (as of Hive 1.3.0). If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. Substring_index performs a case-sensitive match when searching for delim. Example: substring_index('www.apache.org', '.', 2) = 'www.apache'..

截取第count分隔符之前的字串,如count為正則從左邊開始截取,如果為負則從右邊開始截取

string

translate(string|char|varchar input, string|char|varchar from, string|char|varchar to)

Translates the input string by replacing the characters present in the from string with the corresponding characters in the to string. This is similar to the translatefunction in PostgreSQL. If any of the parameters to this UDF are NULL, the result is NULL as well. (Available as of Hive 0.10.0, for string types)

Char/varchar support added as of Hive 0.14.0..

將input出現在from中的字串替換成to中的字串 如:translate("MOBIN","BIN","M")="MOM"

string

trim(string A)

Returns the string resulting from trimming spaces from both ends of A. For example, trim(' foobar ') results in 'foobar'.

將字串A前后出現的空格去掉

binary

unbase64(string str)

Converts the argument from a base 64 string to BINARY. (As of Hive 0.12.0.).

將64位的字串轉換二進制值

string

upper(string A) ucase(string A)

Returns the string resulting from converting all characters of A to upper case. For example, upper('fOoBaR') results in 'FOOBAR'..

將字串A中的字母轉換成大寫字母

string initcap(string A) Returns string, with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by whitespace. (As of Hive 1.1.0.).

將字串A轉換第一個字母大寫其余字母的字串

int levenshtein(string A, string B) Returns the Levenshtein distance between two strings (as of Hive 1.2.0). For example, levenshtein('kitten', 'sitting') results in 3..

計算兩個字串之間的差異大小  如:levenshtein('kitten', 'sitting') = 3

string soundex(string A) Returns soundex code of the string (as of Hive 1.2.0). For example, soundex('Miller') results in M460..

將普通字串轉換成soundex字串

    回到頂部

聚合函式

Return Type

Name(Signature)

Description

BIGINT

count(*), count(expr), count(DISTINCT expr[, expr...])

count(*) - Returns the total number of retrieved rows, including rows containing NULL values.

統計總行數,包括含有NULL值的行

count(expr) - Returns the number of rows for which the supplied expression is non-NULL.

統計提供非NULL的expr運算式值的行數

count(DISTINCT expr[, expr]) - Returns the number of rows for which the supplied expression(s) are unique and non-NULL. Execution of this can be optimized with hive.optimize.distinct.rewrite.

統計提供非NULL且去重后的expr運算式值的行數

DOUBLE

sum(col), sum(DISTINCT col)

Returns the sum of the elements in the group or the sum of the distinct values of the column in the group.

sum(col),表示求指定列的和,sum(DISTINCT col)表示求去重后的列的和

DOUBLE

avg(col), avg(DISTINCT col)

Returns the average of the elements in the group or the average of the distinct values of the column in the group.

avg(col),表示求指定列的平均值,avg(DISTINCT col)表示求去重后的列的平均值

DOUBLE

min(col)

Returns the minimum of the column in the group.

求指定列的最小值

DOUBLE

max(col)

Returns the maximum value of the column in the group.

求指定列的最大值

DOUBLE

variance(col), var_pop(col)

Returns the variance of a numeric column in the group.

求指定列數值的方差

DOUBLE

var_samp(col)

Returns the unbiased sample variance of a numeric column in the group.

求指定列數值的樣本方差

DOUBLE

stddev_pop(col)

Returns the standard deviation of a numeric column in the group.

求指定列數值的標準偏差

DOUBLE

stddev_samp(col)

Returns the unbiased sample standard deviation of a numeric column in the group.

求指定列數值的樣本標準偏差

DOUBLE

covar_pop(col1, col2)

Returns the population covariance of a pair of numeric columns in the group.

求指定列數值的協方差

DOUBLE

covar_samp(col1, col2)

Returns the sample covariance of a pair of a numeric columns in the group.

求指定列數值的樣本協方差

DOUBLE

corr(col1, col2)

Returns the Pearson coefficient of correlation of a pair of a numeric columns in the group.

回傳兩列數值的相關系數

DOUBLE

 percentile(BIGINT col, p)

Returns the exact pth percentile of a column in the group (does not work with floating point types). p must be between 0 and 1. NOTE: A true percentile can only be computed for integer values. Use PERCENTILE_APPROX if your input is non-integral.

回傳col的p%分位數

    回到頂部

表生成函式

Return Type

Name(Signature)

Description

Array Type

explode(array<TYPE> a)

For each element in a, generates a row containing that element.

對于a中的每個元素,將生成一行且包含該元素

N rows

explode(ARRAY)

Returns one row for each element from the array..

每行對應陣列中的一個元素

N rows

explode(MAP)

Returns one row for each key-value pair from the input map with two columns in each row: one for the key and another for the value. (As of Hive 0.8.0.).

每行對應每個map鍵-值,其中一個欄位是map的鍵,另一個欄位是map的值

N rows

posexplode(ARRAY)

Behaves like explode for arrays, but includes the position of items in the original array by returning a tuple of (pos, value). (As of Hive 0.13.0.).

與explode類似,不同的是還回傳各元素在陣列中的位置

N rows

stack(INT n, v_1, v_2, ..., v_k)

Breaks up v_1, ..., v_k into n rows. Each row will have k/n columns. n must be constant..

把M列轉換成N行,每行有M/N個欄位,其中n必須是個常數

tuple

json_tuple(jsonStr, k1, k2, ...)

Takes a set of names (keys) and a JSON string, and returns a tuple of values. This is a more efficient version of the get_json_object UDF because it can get multiple keys with just one call..

從一個JSON字串中獲取多個鍵并作為一個元組回傳,與get_json_object不同的是此函式能一次獲取多個鍵值

tuple

parse_url_tuple(url, p1, p2, ...)

This is similar to the parse_url() UDF but can extract multiple parts at once out of a URL. Valid part names are: HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, USERINFO, QUERY:<KEY>..

回傳從URL中抽取指定N部分的內容,引數url是URL字串,而引數p1,p2,....是要抽取的部分,這個引數包含HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, USERINFO, QUERY:<KEY>

 

inline(ARRAY<STRUCT[,STRUCT]>)

Explodes an array of structs into a table. (As of Hive 0.10.).

將結構體陣列提取出來并插入到表中

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/35402.html

標籤:大數據

上一篇:hdfs/hbase 程式利用Kerberos認證超過ticket_lifetime期限后例外

下一篇:Elasticsearch必知必會的干貨知識一:ES索引檔案的CRUD

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • GPU虛擬機創建時間深度優化

    **?桔妹導讀:**GPU虛擬機實體創建速度慢是公有云面臨的普遍問題,由于通常情況下創建虛擬機屬于低頻操作而未引起業界的重視,實際生產中還是存在對GPU實體創建時間有苛刻要求的業務場景。本文將介紹滴滴云在解決該問題時的思路、方法、并展示最終的優化成果。 從公有云服務商那里購買過虛擬主機的資深用戶,一 ......

    uj5u.com 2020-09-10 06:09:13 more
  • 可編程網卡芯片在滴滴云網路的應用實踐

    **?桔妹導讀:**隨著云規模不斷擴大以及業務層面對延遲、帶寬的要求越來越高,采用DPDK 加速網路報文處理的方式在橫向縱向擴展都出現了局限性。可編程芯片成為業界熱點。本文主要講述了可編程網卡芯片在滴滴云網路中的應用實踐,遇到的問題、帶來的收益以及開源社區貢獻。 #1. 資料中心面臨的問題 隨著滴滴 ......

    uj5u.com 2020-09-10 06:10:21 more
  • 滴滴資料通道服務演進之路

    **?桔妹導讀:**滴滴資料通道引擎承載著全公司的資料同步,為下游實時和離線場景提供了必不可少的源資料。隨著任務量的不斷增加,資料通道的整體架構也隨之發生改變。本文介紹了滴滴資料通道的發展歷程,遇到的問題以及今后的規劃。 #1. 背景 資料,對于任何一家互聯網公司來說都是非常重要的資產,公司的大資料 ......

    uj5u.com 2020-09-10 06:11:05 more
  • 滴滴AI Labs斬獲國際機器翻譯大賽中譯英方向世界第三

    **桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......

    uj5u.com 2020-09-10 06:11:29 more
  • MPP (Massively Parallel Processing)大規模并行處理

    1、什么是mpp? MPP (Massively Parallel Processing),即大規模并行處理,在資料庫非共享集群中,每個節點都有獨立的磁盤存盤系統和記憶體系統,業務資料根據資料庫模型和應用特點劃分到各個節點上,每臺資料節點通過專用網路或者商業通用網路互相連接,彼此協同計算,作為整體提供 ......

    uj5u.com 2020-09-10 06:11:41 more
  • 滴滴資料倉庫指標體系建設實踐

    **桔妹導讀:**指標體系是什么?如何使用OSM模型和AARRR模型搭建指標體系?如何統一流程、規范化、工具化管理指標體系?本文會對建設的方法論結合滴滴資料指標體系建設實踐進行解答分析。 #1. 什么是指標體系 ##1.1 指標體系定義 指標體系是將零散單點的具有相互聯系的指標,系統化的組織起來,通 ......

    uj5u.com 2020-09-10 06:12:52 more
  • 單表千萬行資料庫 LIKE 搜索優化手記

    我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......

    uj5u.com 2020-09-10 06:13:25 more
  • 滴滴Ceph分布式存盤系統優化之鎖優化

    **桔妹導讀:**Ceph是國際知名的開源分布式存盤系統,在工業界和學術界都有著重要的影響。Ceph的架構和演算法設計發表在國際系統領域頂級會議OSDI、SOSP、SC等上。Ceph社區得到Red Hat、SUSE、Intel等大公司的大力支持。Ceph是國際云計算領域應用最廣泛的開源分布式存盤系統, ......

    uj5u.com 2020-09-10 06:14:51 more
  • es~通過ElasticsearchTemplate進行聚合~嵌套聚合

    之前寫過《es~通過ElasticsearchTemplate進行聚合操作》的文章,這一次主要寫一個嵌套的聚合,例如先對sex集合,再對desc聚合,最后再對age求和,共三層嵌套。 Aggregations的部分特性類似于SQL語言中的group by,avg,sum等函式,Aggregation ......

    uj5u.com 2020-09-10 06:14:59 more
  • 爬蟲日志監控 -- Elastc Stack(ELK)部署

    傻瓜式部署,只需替換IP與用戶 導讀: 現ELK四大組件分別為:Elasticsearch(核心)、logstash(處理)、filebeat(采集)、kibana(可視化) 下載均在https://www.elastic.co/cn/downloads/下tar包,各組件版本最好一致,配合fdm會 ......

    uj5u.com 2020-09-10 06:15:05 more
最新发布
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:33:24 more
  • MySQL中binlog備份腳本分享

    關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......

    uj5u.com 2023-04-20 08:28:06 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:27:27 more
  • 快取與資料庫雙寫一致性幾種策略分析

    本文將對幾種快取與資料庫保證資料一致性的使用方式進行分析。為保證高并發性能,以下分析場景不考慮執行的原子性及加鎖等強一致性要求的場景,僅追求最終一致性。 ......

    uj5u.com 2023-04-20 08:26:48 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:26:35 more
  • 云時代,MySQL到ClickHouse資料同步產品對比推薦

    ClickHouse 在執行分析查詢時的速度優勢很好的彌補了MySQL的不足,但是對于很多開發者和DBA來說,如何將MySQL穩定、高效、簡單的同步到 ClickHouse 卻很困難。本文對比了 NineData、MaterializeMySQL(ClickHouse自帶)、Bifrost 三款產品... ......

    uj5u.com 2023-04-20 08:26:29 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:25:13 more
  • Redis 報”OutOfDirectMemoryError“(堆外記憶體溢位)

    Redis 報錯“OutOfDirectMemoryError(堆外記憶體溢位) ”問題如下: 一、報錯資訊: 使用 Redis 的業務介面 ,產生 OutOfDirectMemoryError(堆外記憶體溢位),如圖: 格式化后的報錯資訊: { "timestamp": "2023-04-17 22: ......

    uj5u.com 2023-04-20 08:24:54 more
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:24:03 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:23:11 more