转载请注明转自:http://www.cnblogs.com/feiyumo/p/8763186.html

1.concat对于字符串进行拼接

concat(str1, str2, ..., strN) - Returns the concatenation of str1, str2, ..., strN.

Examples:> SELECT concat('Spark', 'SQL');  SparkSQL

2.concat_ws在拼接的字符串中间添加某种格式

concat_ws(sep, [str | array(str)]+) - Returns the concatenation of the strings separated by sep.

Examples:> SELECT concat_ws(' ', 'Spark', 'SQL');  Spark SQL

3.decode转码

decode(bin, charset) - Decodes the first argument using the second argument character set.

Examples: > SELECT decode(encode('abc', 'utf-8'), 'utf-8');   abc

4.encode设置编码格式

encode(str, charset) - Encodes the first argument using the second argument character set.

Examples: > SELECT encode('abc', 'utf-8');abc

5.format_string/printf 格式化字符串

format_string(strfmt, obj, ...) - Returns a formatted string from printf-style format strings.

Examples:> SELECT format_string("Hello World %d %s", 100, "days");  Hello World 100 days

6.initcap将每个单词的首字母变为大写,其他字母小写; lower全部转为小写,upper大写

initcap(str) - Returns str with the first letter of each word in uppercase. All other letters are in lowercase. Words are delimited by white space.

Examples:> SELECT initcap('sPark sql');  Spark Sql

7.length返回字符串的长度

Examples:> SELECT length('Spark SQL ');  10

8.levenshtein编辑距离(将一个字符串变为另一个字符串的距离)

levenshtein(str1, str2) - Returns the Levenshtein distance between the two given strings.

Examples:> SELECT levenshtein('kitten', 'sitting');   3

9.lpad返回固定长度的字符串,如果长度不够,用某种字符补全,rpad右补全

lpad(str, len, pad) - Returns str, left-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters.

Examples:> SELECT lpad('hi', 5, '??');   ???hi

10.ltrim去除空格或去除开头的某些字符,rtrim右去除,trim两边同时去除

ltrim(str) - Removes the leading space characters from str.

ltrim(trimStr, str) - Removes the leading string contains the characters from the trim string

Examples:

> SELECT ltrim('    SparkSQL   ');   SparkSQL
> SELECT ltrim('Sp', 'SSparkSQLS');   arkSQLS

11.regexp_extract 正则提取某些字符串,regexp_replace正则替换

Examples:> SELECT regexp_extract('100-200', '(\d+)-(\d+)', 1);   100

Examples: > SELECT regexp_replace('100-200', '(\d+)', 'num');   num-num

12.repeat复制给的字符串n次

Examples: > SELECT repeat('123', 2);  123123

13.instr返回截取字符串的位置/locate

instr(str, substr) - Returns the (1-based) index of the first occurrence of substr in str.

Examples:> SELECT instr('SparkSQL', 'SQL');  6

Examples:SELECT locate('bar', 'foobarbar');   4

14.space 在字符串前面加n个空格

space(n) - Returns a string consisting of n spaces.

Examples:> SELECT concat(space(2), '1');  1

15.split以某些字符拆分字符串

split(str, regex) - Splits str around occurrences that match regex.

Examples:> SELECT split('oneAtwoBthreeC', '[ABC]');      ["one","two","three",""]

16.substr截取字符串,substring_index

Examples:

> SELECT substr('Spark SQL', 5);  k SQL
> SELECT substr('Spark SQL', -3);  SQL
> SELECT substr('Spark SQL', 5, 1);   k
> SELECT substring_index('www.apache.org', '.', 2);   www.apache

17.translate 替换某些字符串为

Examples: > SELECT translate('AaBbCc', 'abc', '123');   A1B2C3

18.get_json_object

get_json_object(json_txt, path) - Extracts a json object from path.

Examples:> SELECT get_json_object('{"a":"b"}', '$.a');  b

19.unhex

unhex(expr) - Converts hexadecimal expr to binary.

Examples:> SELECT decode(unhex('537061726B2053514C'), 'UTF-8');   Spark SQL

20.to_json

to_json(expr[, options]) - Returns a json string with a given struct value

Examples:

> SELECT to_json(named_struct('a', 1, 'b', 2));   {"a":1,"b":2}
> SELECT to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));   {"time":"26/08/2015"}
> SELECT to_json(array(named_struct('a', 1, 'b', 2));   [{"a":1,"b":2}]
> SELECT to_json(map('a', named_struct('b', 1)));  {"a":{"b":1}}
> SELECT to_json(map(named_struct('a', 1),named_struct('b', 2)));   {"[1]":{"b":2}}
> SELECT to_json(map('a', 1));  {"a":1}
> SELECT to_json(array((map('a', 1))));  [{"a":1}]

Since: 2.2.0

SPARK-SQL内置函数之字符串函数的更多相关文章

  1. Spark SQL内置函数

    Spark SQL内置函数官网API:http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.sql.fun ...

  2. [转] Spark sql 内置配置(V2.2)

    [From] https://blog.csdn.net/u010990043/article/details/82842995 最近整理了一下spark SQL内置配.加粗配置项是对sparkSQL ...

  3. Hive学内置条件和字符串函数

    https://blog.csdn.net/skywalker_only/article/details/38752003 条件函数 下表为Hive支持的一些条件函数. 返回类型 函数名 描述 T i ...

  4. sql内置函数pivot强大的行转列功能

    原文:sql内置函数pivot强大的行转列功能 语法: PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVO ...

  5. SQL函数大全(字符串函数).

    SQL Server 2005  函数大全 字符串函数 字符串函数 SubString在SQL和C#中不同, 一,select  substring('abcde',-1,3) select LEN( ...

  6. python内置常用高阶函数(列出了5个常用的)

    原文使用的是python2,现修改为python3,全部都实际输出过,可以运行. 引用自:http://www.cnblogs.com/duyaya/p/8562898.html https://bl ...

  7. jquery (内置遍历数组的函数,事件)

    内置遍历数组的函数: 1. $.map(array, function() { }); 取到数组或者对象array中每一项进行遍历  然后在function中处理: var attr = [1,2,3 ...

  8. SQL Server系统函数:字符串函数

    原文:SQL Server系统函数:字符串函数 1.字符转化为ASCII,把ASCII转化为字符,注意返回的值是十进制数 select ASCII('A'),ASCII('B'),ASCII('a') ...

  9. SQL serve 聚合函数、字符串函数

    1.聚合函数 sum,avg,max,min,count        having后面只能跟聚合函数 2.数学函数和字符串函数 3.练习: 1)新建一个学生信息表,根据问题写出程序. 2)新建一个超 ...

  10. SQL server聚合函数、数学函数、字符串函数

    一.基础语句 二.数学函数与字符串函数 三.练习 1.创建一个学生信息表,根据要求写出程序 2.新建一个超市表,进了十种商品,个数都是十件

随机推荐

  1. Java虚拟机系列(一)---Java内存划分

    Java和C++之间有一堵由内存管理和垃圾收集技术所围成的“高墙”,墙外的人想进去,墙内的人却想出来.  ------摘自<深入理解Java虚拟机> 作为一个Java程序员,因为虚拟机的好 ...

  2. 左神算法书籍《程序员代码面试指南》——2_03删除链表的中间节点和a/b处的节点

    [题目]给定链表的头节点head,实现删除链表的中间节点的函数.例如:不删除任何节点:1->2,删除节点1:1->2->3,删除节点2:1->2->3->4,删除节 ...

  3. java 异常捕获小记

    java 中异常捕获常用的为: try{ //业务代码 }catch(Exception e){ //异常捕获 }finally{ // 不管有无异常, 最后都会执行到这里 } 在方法体内如果想要把异 ...

  4. css3之属性选择器

    总体来看一下都有哪些选择器 1.属性选择器  1)[att*=val] 2)[att^=val] 3)[att$=val] 2.结构伪类选择器 3.UI伪类选择器 其中E:read-only伪类选择器 ...

  5. 架构hive2mysql流程

    1.分析参数 args = new String[5]; args[0]="d:/3-20.sql"; args[1]="-date"; args[2]=&qu ...

  6. Effective Modern C++ 条款3:理解decltype

    说起decltype,这是个古灵精怪的东西.对于给定的名字或表达式,decltype能告诉你该名字或表达式的型别.一般来说,它告诉你的结果和你预测的是一样的.不过,偶尔它也会给出某个结果,让你抓耳挠腮 ...

  7. 关于在静态html中实现语言切换的思路与实现

    在项目中只用到了三种语言:英文.中文简体.中文繁体.所以我首先想到了最笨的方法:1.直接将三种语言写在html中,显示当前设置的语言隐藏其它两种来实现.2.使用css伪元素的content:attr( ...

  8. 通过游戏学python 3.6 第一季 第五章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆 可复制直接使用 娱乐 可封装 函数

    #猜数字--核心代码--猜测次数--随机函数和屏蔽错误代码---优化代码及注释--账号密码登陆 #!usr/bin/env python #-*-coding:utf-8-*- #QQ12411129 ...

  9. writing-mode,文字竖直书写,字符之间距离,单词之间距离

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. WebBrowser修改默认白色背景

      背景:在使用Winform的WebBrowser显示网页的时候,在网页还未加载完成之前会显示白色,刚好网页内容呈现黑色,这样视觉效果上就十分差,想把这层白色的去掉. 试了很久之后发现根本去不掉,应 ...