public void execSql(HplsqlParser.ExprContext ctx) {
    StringBuilder sql = new StringBuilder();
    if (ctx.T_OPEN_P() != null) {
      sql.append("(");
      if (ctx.select_stmt() != null) {
        exec.append(sql, evalPop(ctx.select_stmt()).toString(), ctx.T_OPEN_P().getSymbol(), ctx.select_stmt().getStart());
        exec.append(sql, ctx.T_CLOSE_P().getText(), ctx.select_stmt().stop, ctx.T_CLOSE_P().getSymbol()); 
      }
      else {
        sql.append(evalPop(ctx.expr(0)).toString());
        sql.append(")");
      }
    }
    else if (ctx.T_MUL() != null) {
      sql.append(evalPop(ctx.expr(0)).toString());
      sql.append(" * ");
      sql.append(evalPop(ctx.expr(1)).toString());
    }
    else if (ctx.T_DIV() != null) {
      sql.append(evalPop(ctx.expr(0)).toString());
      sql.append(" / ");
      sql.append(evalPop(ctx.expr(1)).toString());
    }
    else if (ctx.T_ADD() != null) {
      sql.append(evalPop(ctx.expr(0)).toString());
      sql.append(" + ");
      sql.append(evalPop(ctx.expr(1)).toString());
    }
    else if (ctx.T_SUB() != null) {
      sql.append(evalPop(ctx.expr(0)).toString());
      sql.append(" - ");
      sql.append(evalPop(ctx.expr(1)).toString());
    }
    else if (ctx.interval_item() != null) {
      sql.append(exec.getFormattedText(ctx));
    }
    else {
      visitChildren(ctx);
      Var value = exec.stackPop();
      if (value.type == Type.NULL && sql.toString().length() == 0) {
        exec.stackPush(new Var());
        return;
      } else {
        sql.append(value.toSqlString());
      }
    }
    exec.stackPush(sql);
  }
Evaluate an expression in executable SQL statement
hplsql/src/main/java/org/apache/hive/hplsql/Expression.java