yuokada / presto-sample-udf

Sample UDF Plugin for Presto
MIT License
7 stars 3 forks source link

Translate function #2

Open yuokada opened 7 years ago

yuokada commented 7 years ago
SELECT translate('012345', '135', 'abc');
yuokada commented 7 years ago
hive> SELECT translate('012345', '135', 'abc');
OK
0a2b4c
Time taken: 2.867 seconds, Fetched: 1 row(s)
hive> SELECT translate('012345', '135', 'ab');
OK
0a2b4
Time taken: 0.067 seconds, Fetched: 1 row(s)
hive> SELECT translate('012345', '135', 'a');
OK
0a24
Time taken: 0.054 seconds, Fetched: 1 row(s)
hive> SELECT translate('012345', '135', 'aaa');
OK
0a2a4a
Time taken: 0.05 seconds, Fetched: 1 row(s)
hive> SELECT translate('012345', '135', '___');
OK
0_2_4_
Time taken: 0.043 seconds, Fetched: 1 row(s)
yuokada commented 7 years ago
hive> SELECT translate(null, '135', '___');
OK
NULL
Time taken: 2.587 seconds, Fetched: 1 row(s)
yuokada commented 7 years ago
hive> SELECT translate('12345', NULL, NULL);
OK
NULL

hive> SELECT translate('12345', '1', NULL);
OK
NULL

hive> SELECT translate('12345', '0', NULL);
OK
NULL
yuokada commented 7 years ago
hive> SELECT translate('12345', '101', '987');
OK
92345

Duplicate pattern.

yuokada commented 7 years ago

Like a this. Python String translate() Method

yuokada commented 7 years ago

sql - Hive : How does translate function works if string is NULL? - Stack Overflow

yuokada commented 7 years ago

ref: Hive Built-in Functions | Treasure Data