如何写一个猪UDF斯卡拉 [英] How to write a Pig UDF in Scala

查看:104
本文介绍了如何写一个猪UDF斯卡拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个猪UDF在斯卡拉(使用Eclipse)。我已经加入pig.jar作为Java构建路径库,这似乎解决以下2进口:

I am trying to write a Pig UDF in Scala (using Eclipse). I have added pig.jar as a library in the java build path which seems to resolve the 2 imports below:


  • 进口org.apache.pig.EvalFunc

  • 进口org.apache.pig.data.Tuple

但是我得到2个错误,我不能解析:

however I get 2 errors which I cannot resolve:


  1. org.apache.pig.EvalFunc [T]不具有构造

  2. 的价值得到的并不是org.apache.pig.data.Tuple的成员(虽然我确信元组get方法)

下面是完整的code:

Here is the full code:

package datesUDFs
import org.apache.pig.EvalFunc
import org.apache.pig.data.Tuple
class getYear extends EvalFunc {
  val extractDate = """^(\d\d\d\d)-\d\d-\d\d \d\d:\d\d:\d\d""".r
  def isDate(dtString: String): Boolean = extractDate.findFirstIn(dtString).nonEmpty

  override def exec(input: Tuple): Int = input.get(0) match {
    case dtString: String =>
      if (!isDate(dtString)) throw new IllegalArgumentException("Invalid date string!")
      else (for (extractDate(year) <- extractDate.findFirstIn(dtString)) yield year).head.toInt
    case _ => throw new IllegalArgumentException("Invalid function call!")
  }
}

任何人可以帮助我解决这个问题?

Can anybody help me resolving this issue?

在此先感谢!

推荐答案

解决它!我加的 Hadoop的共2.2.0.jar 的commons-logging-1.1.3.jar ,以我的Java构建路径和解决了问题。

solved it! I added hadoop-common-2.2.0.jar and commons-logging-1.1.3.jar to my java build path and the problems were resolved.

这篇关于如何写一个猪UDF斯卡拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆