Greetings, everyone.
Right now I am working on this JIRA: 
IMPALA-889<http://issues.cloudera.org/browse/IMPALA-889>: Add support for 
ISO-SQL trim()
In order to confirm the SQL standard like SELECT trim(where chars FROM source);
It is necessary to modify the /root/Impala/fe/src/main/cup/sql-parser.cup file.
The following code is added:

function_call_expr ::=
  function_name:fn_name LPAREN RPAREN
  {:
    RESULT = FunctionCallExpr.createExpr(
        fn_name, new FunctionParams(new ArrayList<Expr>()));
  :}
  | function_name:fn_name LPAREN function_params:params RPAREN
  {: RESULT = FunctionCallExpr.createExpr(fn_name, params); :}
  // Below is a special case for EXTRACT. Idents are used to avoid adding new 
keywords.
  | function_name:fn_name LPAREN IDENT:u KW_FROM expr:t RPAREN
  {:  RESULT = new ExtractFromExpr(fn_name, u, t); :}

// MY NEW CODE
  | function_name:fn_name LPAREN STRING_LITERAL:w expr:c KW_FROM expr:s RPAREN
  {:  RESULT = new TrimExpr(fn_name, w, c, s); :}
  ;

And then I also implemented the corresponding TrimExpr.java file.
After that, I build the front end code like:
cd ${IMPALA_HOME}/fe && mvn clean package dependency:copy-dependencies 
-DskipTests=true

In the Impala shell, I run the following query:
select trim("a" "xyz" from "abc")
And then I got this error:

ERROR: AnalysisException: Expression ''xyz'' in 'TRIM(a 'xyz'  FROM 'abc')' has 
a return type of STRING but a STRING is required.

This ERROR is thrown by a routine in the TrimExpr.java
  @Override
  protected String getFunctionNotFoundError(Type[] argTypes) {
    Expr e = children_.get(2);
    return "Expression '" + e.toSql() + "' in '" + toSql() + "' has a return 
type of "
          + e.getType().toSql() + " but a STRING is required.";
  }

It seems Impala can't find the back-end implementation for this front-end 
expression
SELECT trim(where chars FROM source);

So here comes my question: how to associate the front-end expression coded in 
the sql-parser.cup with back-end implementation? I know there exists some other 
similar function named extract(IDENT from Timestamp) which is implemented in 
the udf-builtins.h and I have done the same thing. But that does not work - so 
I must miss something important.

Any hint or clue is highly appreciated. Thank you. :)

Reply via email to