none
Failure to consume R code after which has been successfully published RRS feed

  • Question

  • Hi experts,

    So far I have been successfully published and then consumed the example R function as instruction here(link https://docs.microsoft.com/en-us/machine-learning-server/operationalize/how-to-deploy-web-service-publish-manage-in-r).

    And then I tried to publish  and consume another R function like

    #------------------------------function----------------------------
    fund.daily.return<-function(fundcode,startdate,enddate){
             #get mapping table
      library(ROracle)
      library(dplyr)
      library(data.table)
      drv<- dbDriver("Oracle")
      connect.string<- "(DESCRIPTION =(ADDRESS=(PROTOCOL=TCP)(HOST = 172.16.8.116)(PORT = 1521)) (CONNECT_DATA= (SERVER = DEDICATED)(SERVICE_NAME = htfk_dg2)))"
      
      hengtai<- dbConnect(drv,username = "xrisk", password = "xrisk", dbname = connect.string)
      
    
      connect_fengkong<- "(DESCRIPTION =(ADDRESS=(PROTOCOL=TCP)(HOST = 172.26.100.17)(PORT = 1521)) (CONNECT_DATA= (SERVER = DEDICATED)(SERVICE_NAME = fengkong)))"
      fengkong<- dbConnect(drv,username = "fengkong",password = "fengkong",dbname = connect_fengkong)
      
        
      
      ysb<- dbGetQuery(hengtai,paste0("select * from t_ysb where port_code_t in (",paste0("'",fundcode,"'",collapse = ","),")"))
    
      #get daily return
      daily.return<- dbGetQuery(hengtai,paste0("select b.port_code,a.t_date,case when b.port_code in ('SB1103','SB0416','SB0117','SB0909','SB9091','YL0504','SB1007','YL0806') and a.pf_pre_nv <> 0 then (a.pf_nv-a.pf_pre_nv-a.pf_cf_in-a.pf_cf_out)/a.pf_pre_nv else a.pf_tw_return end as pf_tw_return from tbsi_acct a left join tprt b on (a.p_id = b.p_id) where b.p_type = 12 and b.port_code in (",paste0("'",ysb$PORT_CODE,"'",collapse = ",") ,")and a.t_date between'",startdate,"'and'",enddate,"'"))
      #(1+daily.return$PF_TW_RETURN)-1
    
      #get setup day
      fundcode_info<- dbGetQuery(hengtai,paste0("select PORT_CODE,P_DATE from tprt_define where port_code in(",paste0("'",ysb$PORT_CODE,"'",collapse = ","),")"))
    #fundcode_info
    
      daily.return<- daily.return%>%
       left_join(fundcode_info, by = "PORT_CODE")%>%
        group_by(PORT_CODE)%>%
        filter(as.Date(T_DATE)>=as.Date(P_DATE))%>%
        ungroup()
    
    #mapping table
      daily.return<- daily.return%>%
        left_join(ysb, by = "PORT_CODE")%>%
        dplyr::select(-PORT_CODE)%>%
        dplyr::rename("PORT_CODE"= "PORT_CODE_T")%>%
        dplyr::select(PORT_CODE,T_DATE,PF_TW_RETURN)
    
      return(daily.return)
    }
    #------------------publish service---------------------------------
    api<-publishService(name="fund_daily_return",
                        code=fund.daily.return, 
                        inputs=list(fundcode="character",
                                    startdate="character",
                                    enddate="character"),
                       outputs=list(daily.return="data.frame"),
                        v="v.0.0.15")
    #-------------------consume service-------------------------------
    api$fund.daily.return('519069','2018-01-01','2018-08-08')

    The publish step went fine but consume step went error. My console reports

     Error: 
    <Error>
       ----------------------------------------------------------------
       success: FALSE
       url: http://172.26.100.49:12800/api/fund_daily_return/v.0.0.15
       method: POST
       status_code: 500
       content: 
          Link: NULL
          Message: 9a80b7f8-2586-4cf4-b378-3407462d594d
          ExceptionType: NULL
       ---------------------------------------------------------------- 
    7.
    stop(err$stringify, call. = FALSE) at <text>#23
    6.
    fn(res) 
    5.
    request$end(fn = function(res) {
        if (!is.null(outputSchema)) {
            tryCatch({
                res[["artifact"]] <- eval(substitute(function(filename,  ... at <text>#63
    4.
    self$apiClient$execute(request, outputSchema) at <text>#319
    3.
    private$execute(private$path, InputModel$new(c(as.list(environment())), 
        private$inputSchema)$toList(), outputSchema = private$outputSchema) at <text>#182
    2.
    self$consume(fundcode, startdate, enddate) at <text>#201
    1.
    api$fund.daily.return("519069", "2018-01-01", "2018-03-31") 

    The function works fine when directly used in the Rstudio of the server machine.

    Did anyone meet similar situation before? Any help on getting this up and running would be much appreciated.


    • Edited by Ruoyu Dong Wednesday, September 26, 2018 9:01 AM
    Wednesday, September 26, 2018 8:58 AM

Answers

  • Question solved. It looks like the api call can't resolve certain types of data return(in this case, data.frame). As I convert the return value of fund.daily.return to JSON, the api call works well.
    • Marked as answer by Ruoyu Dong Thursday, September 27, 2018 1:44 AM
    Thursday, September 27, 2018 1:44 AM