Youwei Wang has uploaded a new patch set (#2).

Change subject: IMPALA-889: Add support for ISO-SQL trim()

IMPALA-889: Add support for ISO-SQL trim()

Add support for an ISO-SQL compliant trim() function.
Form 1: Impala UDF calling
  Syntax: BTRIM(where, characters, string_to_be_trimmed);
  "where": an enumerate value denoting the trim direction.
    Available choices are: 'left|leading|right|trailing|both'.
    This field is case-insensitive, which means 'left' equals 'LeFt'.
    left|leading - trimming characters from the start of the source string;
    right|trailing - trimming characters from the end of the source string;
    both - trimming characters from both ends of the source string;
  "characters": the characters to trim, which are represented as a string.
    The order of such characters doesn't matter. Multiple occurrances of
    one same letter will be ignored. This field is case-sensitive.
  "string_to_be_trimmed": the source string to trim. This field is

  btrim('left', 'a%', 'abc%%defg%%%%%'); returns 'bc%%defg%%%%%';
  btrim('right', 'fg%', 'abc%%defg%%%%%'); returns 'abc%%de';
  btrim('leading', 'ab%', 'abc%%defg%%%%%'); returns 'c%%defg%%%%%';
  btrim('trailing', 'bfg%', 'abc%%defg%%%%%'); returns 'abc%%de';
  btrim('both', 'abfg%', 'abc%%defg%%%%%'); returns 'c%%de';

Form 2: Standard SQL syntax (Core SQL feature ID E021-09)
  Syntax: BTRIM(where characters FROM string_to_be_trimmed);
  "where": this field has the same meaning as form 1.
    Available choices are: leading/trailing/both. Since left and right are
    Impala keywords, they are not available in this form.
  "characters": this field has the same meaning as form 1.
  "string_to_be_trimmed": this field has the same meaning as form 1.

  btrim(leading 'ab%' from 'abc%%defg%%%%%'); returns 'c%%defg%%%%%';
  btrim(trailing 'bfg%' from 'abc%%defg%%%%%'); returns 'abc%%de';
  btrim(both 'abfg%' from 'abc%%defg%%%%%'); returns 'c%%de';

Change-Id: I4753c608b0b00569bf8c5e95b132df6df358e602
M be/src/exprs/
M be/src/exprs/
M be/src/exprs/string-functions.h
M common/function-registry/
M common/thrift/Exprs.thrift
M fe/src/main/cup/sql-parser.cup
A fe/src/main/java/com/cloudera/impala/analysis/
M fe/src/test/java/com/cloudera/impala/analysis/
8 files changed, 295 insertions(+), 13 deletions(-)

  git pull ssh:// refs/changes/74/4474/2
To view, visit
To unsubscribe, visit

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4753c608b0b00569bf8c5e95b132df6df358e602
Gerrit-PatchSet: 2
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Youwei Wang <>
Gerrit-Reviewer: Jim Apple <>

Reply via email to