简体   繁体   中英

BigQuery UDF & String.prototype.indexOf()

I'm trying to use String.prototype.indexOf() in a BigQuery UDF to check if one String contains another ie use basic JavaScript.

But it gives me this error:

在此处输入图片说明

What am I doing wrong?

I didn't take into consideration that my incoming table row in BigQuery might have null values.

Easy fix by just checking s :

function decodeHelper(s) {
  if(s){
      if(s.indexOf("foo") > -1){
         return "true";
      }else{
         return "false";
      }
  }
}

Depends on how you then deal with result of decodeHelper, you might consider below option

function decodeHelper(s) {
  if(s){
      if(s.indexOf("b") > -1){
         return "true";
      }else{
         return "false";
      }
  }else{
      return "false";
  }  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM