@Before
  public void setUp() throws Exception {
    HiveConf hiveConf = new HiveConf();
    hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_ALLOW_UDF_LOAD_ON_DEMAND, true);
    SessionState sessionState = new SessionState(hiveConf, System.getProperty("user.name"));
    SessionState.setCurrentSessionState(sessionState);
    Function function = new Function("myupper", sessionState.getCurrentDatabase(),
        "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper", sessionState.getUserName(),
        PrincipalType.USER, (int) (System.currentTimeMillis() / 1000), FunctionType.JAVA, null);
    Hive.get().createFunction(function);
  }
Check the genericUDF field of FunctionInfo returned on demand.
ql/src/test/org/apache/hadoop/hive/ql/parse/type/TestExprProcessorGetFuncExpr.java