core/src/main/java/com/orientechnologies/orient/core/sql/functions/OSQLFunctionRuntime.java
public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult,
      final OCommandContext iContext) {
    // RESOLVE VALUES USING THE CURRENT RECORD
    for (int i = 0; i < configuredParameters.length; ++i) {
      runtimeParameters[i] = configuredParameters[i];

      if (configuredParameters[i] instanceof OSQLFilterItemField) {
        runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult, iContext);
      } else if (configuredParameters[i] instanceof OSQLFunctionRuntime)
        runtimeParameters[i] = ((OSQLFunctionRuntime) configuredParameters[i]).execute(iThis, iCurrentRecord, iCurrentResult,
            iContext);
      else if (configuredParameters[i] instanceof OSQLFilterItemVariable) {
        runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i])
            .getValue(iCurrentRecord, iCurrentResult, iContext);
      } else if (configuredParameters[i] instanceof OCommandSQL) {
        try {
          runtimeParameters[i] = ((OCommandSQL) configuredParameters[i]).setContext(iContext).execute();
        } catch (OCommandExecutorNotFoundException ignore) {
          // TRY WITH SIMPLE CONDITION
          final String text = ((OCommandSQL) configuredParameters[i]).getText();
          final OSQLPredicate pred = new OSQLPredicate(text);
          runtimeParameters[i] = pred.evaluate(iCurrentRecord instanceof ORecord ? (ORecord) iCurrentRecord : null,
              (ODocument) iCurrentResult, iContext);
          // REPLACE ORIGINAL PARAM
          configuredParameters[i] = pred;

        }
      } else if (configuredParameters[i] instanceof OSQLPredicate)
        runtimeParameters[i] = ((OSQLPredicate) configuredParameters[i]).evaluate(iCurrentRecord.getRecord(),
            (iCurrentRecord instanceof ODocument ? (ODocument) iCurrentResult : null), iContext);
      else if (configuredParameters[i] instanceof String) {
        if (configuredParameters[i].toString().startsWith("\"") || configuredParameters[i].toString().startsWith("'"))
          runtimeParameters[i] = OIOUtils.getStringContent(configuredParameters[i]);
      }
    }

    if (function.getMaxParams() == -1 || function.getMaxParams() > 0) {
      if (runtimeParameters.length < function.getMinParams()
          || (function.getMaxParams() > -1 && runtimeParameters.length > function.getMaxParams()))
        throw new OCommandExecutionException("Syntax error: function '"
            + function.getName()
            + "' needs "
            + (function.getMinParams() == function.getMaxParams() ? function.getMinParams() : function.getMinParams() + "-"
                + function.getMaxParams()) + " argument(s) while has been received " + runtimeParameters.length);
    }

    final Object functionResult = function.execute(iThis, iCurrentRecord, iCurrentResult, runtimeParameters, iContext);

    if (functionResult instanceof OAutoConvertToRecord)
      // FORCE AVOIDING TO CONVERT IN RECORD
      ((OAutoConvertToRecord) functionResult).setAutoConvertToRecord(false);

    return transformValue(iCurrentRecord, iContext, functionResult);
  }
public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult,
      final OCommandContext iContext) {
    // RESOLVE VALUES USING THE CURRENT RECORD
    for (int i = 0; i < configuredParameters.length; ++i) {
      runtimeParameters[i] = configuredParameters[i];

      if (configuredParameters[i] instanceof OSQLFilterItemField) {
        runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult, iContext);
      } else if (configuredParameters[i] instanceof OSQLFunctionRuntime)
        runtimeParameters[i] = ((OSQLFunctionRuntime) configuredParameters[i]).execute(iThis, iCurrentRecord, iCurrentResult,
            iContext);
      else if (configuredParameters[i] instanceof OSQLFilterItemVariable) {
        runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i])
            .getValue(iCurrentRecord, iCurrentResult, iContext);
      } else if (configuredParameters[i] instanceof OCommandSQL) {
        try {
          runtimeParameters[i] = ((OCommandSQL) configuredParameters[i]).setContext(iContext).execute();
        } catch (OCommandExecutorNotFoundException ignore) {
          // TRY WITH SIMPLE CONDITION
          final String text = ((OCommandSQL) configuredParameters[i]).getText();
          final OSQLPredicate pred = new OSQLPredicate(text);
          runtimeParameters[i] = pred.evaluate(iCurrentRecord instanceof ORecord ? (ORecord) iCurrentRecord : null,
              (ODocument) iCurrentResult, iContext);
          // REPLACE ORIGINAL PARAM
          configuredParameters[i] = pred;

        }
      } else if (configuredParameters[i] instanceof OSQLPredicate)
        runtimeParameters[i] = ((OSQLPredicate) configuredParameters[i]).evaluate(iCurrentRecord.getRecord(),
            (iCurrentRecord instanceof ODocument ? (ODocument) iCurrentResult : null), iContext);
      else if (configuredParameters[i] instanceof String) {
        if (configuredParameters[i].toString().startsWith("\"") || configuredParameters[i].toString().startsWith("'"))
          runtimeParameters[i] = OIOUtils.getStringContent(configuredParameters[i]);
      }
    }

    if (function.getMaxParams() == -1 || function.getMaxParams() > 0) {
      if (runtimeParameters.length < function.getMinParams()
          || (function.getMaxParams() > -1 && runtimeParameters.length > function.getMaxParams()))
        throw new OCommandExecutionException("Syntax error: function '"
            + function.getName()
            + "' needs "
            + (function.getMinParams() == function.getMaxParams() ? function.getMinParams() : function.getMinParams() + "-"
                + function.getMaxParams()) + " argument(s) while has been received " + runtimeParameters.length);
    }

    final Object functionResult = function.execute(iThis, iCurrentRecord, iCurrentResult, runtimeParameters, iContext);

    if (functionResult instanceof OAutoConvertToRecord)
      // FORCE AVOIDING TO CONVERT IN RECORD
      ((OAutoConvertToRecord) functionResult).setAutoConvertToRecord(false);

    return transformValue(iCurrentRecord, iContext, functionResult);
  }
Execute a function.

@param iCurrentRecord
Current record
@param iCurrentResult
TODO
@param iContext
@return