莲见天明 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日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改