@Override
  public void meet(FunctionCall fc) throws RuntimeException {
    // special optimizations for frequent cases with variables
    if ((XMLSchema.DOUBLE.toString().equals(fc.getURI())
            || XMLSchema.FLOAT.toString().equals(fc.getURI()))
        && fc.getArgs().size() == 1) {
      optypes.push(ValueType.DOUBLE);
      fc.getArgs().get(0).visit(this);
      optypes.pop();
    } else if ((XMLSchema.INTEGER.toString().equals(fc.getURI())
            || XMLSchema.INT.toString().equals(fc.getURI()))
        && fc.getArgs().size() == 1) {
      optypes.push(ValueType.INT);
      fc.getArgs().get(0).visit(this);
      optypes.pop();
    } else if (XMLSchema.BOOLEAN.toString().equals(fc.getURI()) && fc.getArgs().size() == 1) {
      optypes.push(ValueType.BOOL);
      fc.getArgs().get(0).visit(this);
      optypes.pop();
    } else if (XMLSchema.DATE.toString().equals(fc.getURI()) && fc.getArgs().size() == 1) {
      optypes.push(ValueType.DATE);
      fc.getArgs().get(0).visit(this);
      optypes.pop();
    } else {

      String fnUri = fc.getURI();

      String[] args = new String[fc.getArgs().size()];

      NativeFunction nf = functionRegistry.get(fnUri);

      if (nf != null && nf.isSupported(parent.getDialect())) {

        for (int i = 0; i < args.length; i++) {
          args[i] =
              new ValueExpressionEvaluator(fc.getArgs().get(i), parent, nf.getArgumentType(i))
                  .build();
        }

        if (optypes.peek() != nf.getReturnType()) {
          builder.append(castExpression(nf.getNative(parent.getDialect(), args), optypes.peek()));
        } else {
          builder.append(nf.getNative(parent.getDialect(), args));
        }
      } else {
        throw new IllegalArgumentException(
            "the function " + fnUri + " is not supported by the SQL translation");
      }
    }
  }
Пример #2
0
 public String getURI() {
   return XMLSchema.BOOLEAN.toString();
 }