0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HiveとPrestoのTRIM関数の違い

Last updated at Posted at 2017-03-10

文字列の空白を除去するTRIM関数で、HiveとPrestoに違いがあったのでメモ。

基本は半角スペースを除去。

SELECT TRIM(' a')
=> 'a'

では全角スペースは?

SELECT TRIM(' a')

Hive - 除去されない
Presto - 除去される。

PrestoのTrimは、 SliceUtf8.trimで実現されていて、ライブラリ独自の挙動みたいですね。
https://github.com/airlift/slice

HiveでPrestoのTRIMと動作を揃えるには、regexp_replaceをしないとだめかなー、というところですね。

SELECT regexp_replace(TRIM(' a '), '^ | $', '')

ryukoba-sanのコメントより複数全角空白を考慮した場合は下記。

SELECT regexp_replace(TRIM(' a '), '^ +| +$', '')

ちゃんちゃん。

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?