莲见天明 2022-11-22 10:22 采纳率: 50%
浏览 5
已结题

在kettle调用的java组件中提取手机号码报错。

在kettle里调用的java组件代码报错。

//导入包
import java.util.regex.*;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
  if (first) {
    first = false;

    /* TODO: Your code here. (Using info fields)

    FieldHelper infoField = get(Fields.Info, "info_field_name");

    RowSet infoStream = findInfoRowSet("info_stream_tag");

    Object[] infoRow = null;

    int infoRowCount = 0;

    // Read all rows from info step before calling getRow() method, which returns first row from any
    // input rowset. As rowMeta for info and input steps varies getRow() can lead to errors.
    while((infoRow = getRowFrom(infoStream)) != null){

      // do something with info data
      infoRowCount++;
    }
    */
  }

  Object[] r = getRow();

  if (r == null) {
    setOutputDone();
    return false;
  }

  // It is always safest to call createOutputRow() to ensure that your output row's Object[] is large
  // enough to handle any new fields you are creating in this step.
  r = createOutputRow(r, data.outputRowMeta.size());

  /* TODO: Your code here. (See Sample)

  // Get the value from an input field
  String foobar = get(Fields.In, "a_fieldname").getString(r);

  foobar += "bar";
    
  // Set a value in a new output field
  get(Fields.Out, "output_fieldname").setValue(r, foobar);

  */

  //获取电话集
  String phone_set = get(Fields.In, "phone_set").getString(r);

  //正则表达式获取手机号
  if(phone_set == null || phone_set.length()<=0)
    return null;
  Pattern pattern = Pattern.compile("(1|861)([0-9])\\d{9}$*");
  Matcher matcher = pattern.matcher(phone_set);
  StringBuffer bf = new StringBuffer();
  while (matcher.find()) {
    bf.append(matcher.group()).append(",");
  }
  int len = bf.length();
  if (len > 0) {
    bf.deleteCharAt(len - 1);
  }
  return bf.toString();

  //输出
  get(Fields.Out, "newphone").setValue(r,phone_set);

  // Send the row on to the next step.
  putRow(data.outputRowMeta, r);

  return true;
}

报错内容为:第54行,第9列 -- if(phone_set == null || phone_set.length()<=0)
assignment conversion not possible from type "void" to type "boolean"

请问这个脚本问题点在哪,正确的提取手机号脚本如何编写?

  • 写回答

2条回答 默认 最新

  • 游一游走一走 2022-11-22 10:29
    关注

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月30日
  • 已采纳回答 11月22日
  • 创建了问题 11月22日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器