莲见天明 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 请问如何查看手机root记录?
  • ¥15 商城小程序订单号重复
  • ¥15 学校优化算法sbo和蚁群算法怎么结合
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known