hive內置方法一覽

来源:https://www.cnblogs.com/peter-yan/archive/2020/01/16/12199867.html
-Advertisement-
Play Games

引用 https://www.cnblogs.com/qingyunzong/p/8744593.html#_label0 官方文檔 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 目錄 數學函數 集合函數 類型 ...


引用 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_hexBINARY 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 
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 10.3 彙總數據 我們經常需要彙總數據而不用把它們實際檢索處出來,為此MySQL提供了專門的函數。使用這些函數,MySQL查詢可用於檢索數據,以便分析和報表的生成。這種類型的檢索例子有以下幾種: 確定表中的行數(或者滿足某個條件或包含某個特定值的行數)。 獲得表中行組的和。 找出表列(或所有行或某 ...
  • 一次偶然的機會,發現在登陸驗證時,改變用戶名的大小寫,同樣可以登錄成功,這是由於,當時使用的mysql資料庫對大小寫不敏感,查詢時總是能查詢到數據。一番查找資料,給出的原因是:在創建資料庫的時候,選擇了utf8_general_ci排序規則。 創建資料庫時,需要同時選擇字元集和排序規則,字元集大家都 ...
  • 發現一段經典SQL,不用迴圈游標,一句update代碼實現滾動計算結存。為方便理解,結合實例測試之 --1,源數據#t1,jcshl初值為每個sid的當前庫存數量,要實現的效果:每個sid的後一結存數量為前一jcshl結存數量-chkshl出庫數量 SELECT * FROM #t1 ORDER B ...
  • 1、 查看電腦名use master go select @@servername select serverproperty('servername') 2、同步更新SQLserverif serverproperty('servername') <> @@servername begin de ...
  • Linux平臺環境下主要有兩種連接方式,一種是TCP/IP連接方式,另一種就是socket連接。 在Windows平臺下,有name pipe和share memory(不考慮)兩種。 TCP/IP連接是網路中用得最多的一種方式。 環境: MySQL資料庫實例IP:192.168.0.2 MySQL ...
  • 9.1 計算欄位 存儲在資料庫表中的數據一般不是應用程式所需要的格式。比如: 如果想要在一個欄位中既顯示公司名,又顯示公式的地址,但這兩個信息一般包含在不同的表列中。 城市、州和郵政編碼存儲在不同的列中,但郵件標簽列印程式卻需要把它們作為一個恰當格式的欄位檢索出來。 列數據是大小寫混合的,但報表程式 ...
  • 對於DBA來說,丟失超管用戶root的密碼是致命的, 可以通過添加--ship-grant-tables參數來跳過許可權表。 1、忘記root密碼,進不去資料庫: 這個時候需要強制停庫,先查看MySQL進程號 Kill掉MySQL進程,命令如下: Kill完可以再查看是否還有進程 [root@tse2 ...
  • oracle 12.2 RAC監聽日誌報錯:15-JAN-2020 22:27:53 * (CONNECT_DATA=(COMMAND=VERSION)) * version * 1189TNS-01189: The listener could not authenticate the user ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...