是否可以将Java Method类用作Scala函数{0-22}类

时间:2018-02-05 23:55:09

标签: java scala casting type-conversion user-defined-functions

我想使用反射来获取所有Scala Object方法。之后,通过将Array of Method实例传递给Scala寄存器方法

,将其注册为Spark UDF
object Udfs {

    def main(args: Array[String]): Unit = {

      myFunk(List[String]("funk1", "funk2"))

    }
  def myFunk(list: List[String]) = {
    val methods = this.getClass.getMethods.filter(m => list.contains(m.getName))
    val spark = SparkSession.builder().getOrCreate()
    println(spark.conf.getAll.toString)
    spark.sqlContext.udf.register(methods(0).getName, /*Here I want to use methods(0)*/)

  }

  def funk1(ip: String): String = {
    //Some Logic ...
    ""
  }

  def funk2(s: String, i: Int): String = {
    //Some Logic
    ""
  }

注册方法签名:

def register[RT: TypeTag, A1: TypeTag](name: String, func: Function1[A1, RT]): UserDefinedFunction

或任何其他功能{0-22}

如果我通过

spark.sqlContext.udf.register(methods(0).getName, methods(0))

我收到错误:

Error:(25, 26) overloaded method value register with alternatives:
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22) => RT)(implicit evidence$254: reflect.runtime.universe.TypeTag[RT], implicit evidence$255: reflect.runtime.universe.TypeTag[A1], implicit evidence$256: reflect.runtime.universe.TypeTag[A2], implicit evidence$257: reflect.runtime.universe.TypeTag[A3], implicit evidence$258: reflect.runtime.universe.TypeTag[A4], implicit evidence$259: reflect.runtime.universe.TypeTag[A5], implicit evidence$260: reflect.runtime.universe.TypeTag[A6], implicit evidence$261: reflect.runtime.universe.TypeTag[A7], implicit evidence$262: reflect.runtime.universe.TypeTag[A8], implicit evidence$263: reflect.runtime.universe.TypeTag[A9], implicit evidence$264: reflect.runtime.universe.TypeTag[A10], implicit evidence$265: reflect.runtime.universe.TypeTag[A11], implicit evidence$266: reflect.runtime.universe.TypeTag[A12], implicit evidence$267: reflect.runtime.universe.TypeTag[A13], implicit evidence$268: reflect.runtime.universe.TypeTag[A14], implicit evidence$269: reflect.runtime.universe.TypeTag[A15], implicit evidence$270: reflect.runtime.universe.TypeTag[A16], implicit evidence$271: reflect.runtime.universe.TypeTag[A17], implicit evidence$272: reflect.runtime.universe.TypeTag[A18], implicit evidence$273: reflect.runtime.universe.TypeTag[A19], implicit evidence$274: reflect.runtime.universe.TypeTag[A20], implicit evidence$275: reflect.runtime.universe.TypeTag[A21], implicit evidence$276: reflect.runtime.universe.TypeTag[A22])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21) => RT)(implicit evidence$232: reflect.runtime.universe.TypeTag[RT], implicit evidence$233: reflect.runtime.universe.TypeTag[A1], implicit evidence$234: reflect.runtime.universe.TypeTag[A2], implicit evidence$235: reflect.runtime.universe.TypeTag[A3], implicit evidence$236: reflect.runtime.universe.TypeTag[A4], implicit evidence$237: reflect.runtime.universe.TypeTag[A5], implicit evidence$238: reflect.runtime.universe.TypeTag[A6], implicit evidence$239: reflect.runtime.universe.TypeTag[A7], implicit evidence$240: reflect.runtime.universe.TypeTag[A8], implicit evidence$241: reflect.runtime.universe.TypeTag[A9], implicit evidence$242: reflect.runtime.universe.TypeTag[A10], implicit evidence$243: reflect.runtime.universe.TypeTag[A11], implicit evidence$244: reflect.runtime.universe.TypeTag[A12], implicit evidence$245: reflect.runtime.universe.TypeTag[A13], implicit evidence$246: reflect.runtime.universe.TypeTag[A14], implicit evidence$247: reflect.runtime.universe.TypeTag[A15], implicit evidence$248: reflect.runtime.universe.TypeTag[A16], implicit evidence$249: reflect.runtime.universe.TypeTag[A17], implicit evidence$250: reflect.runtime.universe.TypeTag[A18], implicit evidence$251: reflect.runtime.universe.TypeTag[A19], implicit evidence$252: reflect.runtime.universe.TypeTag[A20], implicit evidence$253: reflect.runtime.universe.TypeTag[A21])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20) => RT)(implicit evidence$211: reflect.runtime.universe.TypeTag[RT], implicit evidence$212: reflect.runtime.universe.TypeTag[A1], implicit evidence$213: reflect.runtime.universe.TypeTag[A2], implicit evidence$214: reflect.runtime.universe.TypeTag[A3], implicit evidence$215: reflect.runtime.universe.TypeTag[A4], implicit evidence$216: reflect.runtime.universe.TypeTag[A5], implicit evidence$217: reflect.runtime.universe.TypeTag[A6], implicit evidence$218: reflect.runtime.universe.TypeTag[A7], implicit evidence$219: reflect.runtime.universe.TypeTag[A8], implicit evidence$220: reflect.runtime.universe.TypeTag[A9], implicit evidence$221: reflect.runtime.universe.TypeTag[A10], implicit evidence$222: reflect.runtime.universe.TypeTag[A11], implicit evidence$223: reflect.runtime.universe.TypeTag[A12], implicit evidence$224: reflect.runtime.universe.TypeTag[A13], implicit evidence$225: reflect.runtime.universe.TypeTag[A14], implicit evidence$226: reflect.runtime.universe.TypeTag[A15], implicit evidence$227: reflect.runtime.universe.TypeTag[A16], implicit evidence$228: reflect.runtime.universe.TypeTag[A17], implicit evidence$229: reflect.runtime.universe.TypeTag[A18], implicit evidence$230: reflect.runtime.universe.TypeTag[A19], implicit evidence$231: reflect.runtime.universe.TypeTag[A20])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19) => RT)(implicit evidence$191: reflect.runtime.universe.TypeTag[RT], implicit evidence$192: reflect.runtime.universe.TypeTag[A1], implicit evidence$193: reflect.runtime.universe.TypeTag[A2], implicit evidence$194: reflect.runtime.universe.TypeTag[A3], implicit evidence$195: reflect.runtime.universe.TypeTag[A4], implicit evidence$196: reflect.runtime.universe.TypeTag[A5], implicit evidence$197: reflect.runtime.universe.TypeTag[A6], implicit evidence$198: reflect.runtime.universe.TypeTag[A7], implicit evidence$199: reflect.runtime.universe.TypeTag[A8], implicit evidence$200: reflect.runtime.universe.TypeTag[A9], implicit evidence$201: reflect.runtime.universe.TypeTag[A10], implicit evidence$202: reflect.runtime.universe.TypeTag[A11], implicit evidence$203: reflect.runtime.universe.TypeTag[A12], implicit evidence$204: reflect.runtime.universe.TypeTag[A13], implicit evidence$205: reflect.runtime.universe.TypeTag[A14], implicit evidence$206: reflect.runtime.universe.TypeTag[A15], implicit evidence$207: reflect.runtime.universe.TypeTag[A16], implicit evidence$208: reflect.runtime.universe.TypeTag[A17], implicit evidence$209: reflect.runtime.universe.TypeTag[A18], implicit evidence$210: reflect.runtime.universe.TypeTag[A19])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18) => RT)(implicit evidence$172: reflect.runtime.universe.TypeTag[RT], implicit evidence$173: reflect.runtime.universe.TypeTag[A1], implicit evidence$174: reflect.runtime.universe.TypeTag[A2], implicit evidence$175: reflect.runtime.universe.TypeTag[A3], implicit evidence$176: reflect.runtime.universe.TypeTag[A4], implicit evidence$177: reflect.runtime.universe.TypeTag[A5], implicit evidence$178: reflect.runtime.universe.TypeTag[A6], implicit evidence$179: reflect.runtime.universe.TypeTag[A7], implicit evidence$180: reflect.runtime.universe.TypeTag[A8], implicit evidence$181: reflect.runtime.universe.TypeTag[A9], implicit evidence$182: reflect.runtime.universe.TypeTag[A10], implicit evidence$183: reflect.runtime.universe.TypeTag[A11], implicit evidence$184: reflect.runtime.universe.TypeTag[A12], implicit evidence$185: reflect.runtime.universe.TypeTag[A13], implicit evidence$186: reflect.runtime.universe.TypeTag[A14], implicit evidence$187: reflect.runtime.universe.TypeTag[A15], implicit evidence$188: reflect.runtime.universe.TypeTag[A16], implicit evidence$189: reflect.runtime.universe.TypeTag[A17], implicit evidence$190: reflect.runtime.universe.TypeTag[A18])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17) => RT)(implicit evidence$154: reflect.runtime.universe.TypeTag[RT], implicit evidence$155: reflect.runtime.universe.TypeTag[A1], implicit evidence$156: reflect.runtime.universe.TypeTag[A2], implicit evidence$157: reflect.runtime.universe.TypeTag[A3], implicit evidence$158: reflect.runtime.universe.TypeTag[A4], implicit evidence$159: reflect.runtime.universe.TypeTag[A5], implicit evidence$160: reflect.runtime.universe.TypeTag[A6], implicit evidence$161: reflect.runtime.universe.TypeTag[A7], implicit evidence$162: reflect.runtime.universe.TypeTag[A8], implicit evidence$163: reflect.runtime.universe.TypeTag[A9], implicit evidence$164: reflect.runtime.universe.TypeTag[A10], implicit evidence$165: reflect.runtime.universe.TypeTag[A11], implicit evidence$166: reflect.runtime.universe.TypeTag[A12], implicit evidence$167: reflect.runtime.universe.TypeTag[A13], implicit evidence$168: reflect.runtime.universe.TypeTag[A14], implicit evidence$169: reflect.runtime.universe.TypeTag[A15], implicit evidence$170: reflect.runtime.universe.TypeTag[A16], implicit evidence$171: reflect.runtime.universe.TypeTag[A17])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16) => RT)(implicit evidence$137: reflect.runtime.universe.TypeTag[RT], implicit evidence$138: reflect.runtime.universe.TypeTag[A1], implicit evidence$139: reflect.runtime.universe.TypeTag[A2], implicit evidence$140: reflect.runtime.universe.TypeTag[A3], implicit evidence$141: reflect.runtime.universe.TypeTag[A4], implicit evidence$142: reflect.runtime.universe.TypeTag[A5], implicit evidence$143: reflect.runtime.universe.TypeTag[A6], implicit evidence$144: reflect.runtime.universe.TypeTag[A7], implicit evidence$145: reflect.runtime.universe.TypeTag[A8], implicit evidence$146: reflect.runtime.universe.TypeTag[A9], implicit evidence$147: reflect.runtime.universe.TypeTag[A10], implicit evidence$148: reflect.runtime.universe.TypeTag[A11], implicit evidence$149: reflect.runtime.universe.TypeTag[A12], implicit evidence$150: reflect.runtime.universe.TypeTag[A13], implicit evidence$151: reflect.runtime.universe.TypeTag[A14], implicit evidence$152: reflect.runtime.universe.TypeTag[A15], implicit evidence$153: reflect.runtime.universe.TypeTag[A16])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) => RT)(implicit evidence$121: reflect.runtime.universe.TypeTag[RT], implicit evidence$122: reflect.runtime.universe.TypeTag[A1], implicit evidence$123: reflect.runtime.universe.TypeTag[A2], implicit evidence$124: reflect.runtime.universe.TypeTag[A3], implicit evidence$125: reflect.runtime.universe.TypeTag[A4], implicit evidence$126: reflect.runtime.universe.TypeTag[A5], implicit evidence$127: reflect.runtime.universe.TypeTag[A6], implicit evidence$128: reflect.runtime.universe.TypeTag[A7], implicit evidence$129: reflect.runtime.universe.TypeTag[A8], implicit evidence$130: reflect.runtime.universe.TypeTag[A9], implicit evidence$131: reflect.runtime.universe.TypeTag[A10], implicit evidence$132: reflect.runtime.universe.TypeTag[A11], implicit evidence$133: reflect.runtime.universe.TypeTag[A12], implicit evidence$134: reflect.runtime.universe.TypeTag[A13], implicit evidence$135: reflect.runtime.universe.TypeTag[A14], implicit evidence$136: reflect.runtime.universe.TypeTag[A15])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) => RT)(implicit evidence$106: reflect.runtime.universe.TypeTag[RT], implicit evidence$107: reflect.runtime.universe.TypeTag[A1], implicit evidence$108: reflect.runtime.universe.TypeTag[A2], implicit evidence$109: reflect.runtime.universe.TypeTag[A3], implicit evidence$110: reflect.runtime.universe.TypeTag[A4], implicit evidence$111: reflect.runtime.universe.TypeTag[A5], implicit evidence$112: reflect.runtime.universe.TypeTag[A6], implicit evidence$113: reflect.runtime.universe.TypeTag[A7], implicit evidence$114: reflect.runtime.universe.TypeTag[A8], implicit evidence$115: reflect.runtime.universe.TypeTag[A9], implicit evidence$116: reflect.runtime.universe.TypeTag[A10], implicit evidence$117: reflect.runtime.universe.TypeTag[A11], implicit evidence$118: reflect.runtime.universe.TypeTag[A12], implicit evidence$119: reflect.runtime.universe.TypeTag[A13], implicit evidence$120: reflect.runtime.universe.TypeTag[A14])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) => RT)(implicit evidence$92: reflect.runtime.universe.TypeTag[RT], implicit evidence$93: reflect.runtime.universe.TypeTag[A1], implicit evidence$94: reflect.runtime.universe.TypeTag[A2], implicit evidence$95: reflect.runtime.universe.TypeTag[A3], implicit evidence$96: reflect.runtime.universe.TypeTag[A4], implicit evidence$97: reflect.runtime.universe.TypeTag[A5], implicit evidence$98: reflect.runtime.universe.TypeTag[A6], implicit evidence$99: reflect.runtime.universe.TypeTag[A7], implicit evidence$100: reflect.runtime.universe.TypeTag[A8], implicit evidence$101: reflect.runtime.universe.TypeTag[A9], implicit evidence$102: reflect.runtime.universe.TypeTag[A10], implicit evidence$103: reflect.runtime.universe.TypeTag[A11], implicit evidence$104: reflect.runtime.universe.TypeTag[A12], implicit evidence$105: reflect.runtime.universe.TypeTag[A13])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) => RT)(implicit evidence$79: reflect.runtime.universe.TypeTag[RT], implicit evidence$80: reflect.runtime.universe.TypeTag[A1], implicit evidence$81: reflect.runtime.universe.TypeTag[A2], implicit evidence$82: reflect.runtime.universe.TypeTag[A3], implicit evidence$83: reflect.runtime.universe.TypeTag[A4], implicit evidence$84: reflect.runtime.universe.TypeTag[A5], implicit evidence$85: reflect.runtime.universe.TypeTag[A6], implicit evidence$86: reflect.runtime.universe.TypeTag[A7], implicit evidence$87: reflect.runtime.universe.TypeTag[A8], implicit evidence$88: reflect.runtime.universe.TypeTag[A9], implicit evidence$89: reflect.runtime.universe.TypeTag[A10], implicit evidence$90: reflect.runtime.universe.TypeTag[A11], implicit evidence$91: reflect.runtime.universe.TypeTag[A12])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) => RT)(implicit evidence$67: reflect.runtime.universe.TypeTag[RT], implicit evidence$68: reflect.runtime.universe.TypeTag[A1], implicit evidence$69: reflect.runtime.universe.TypeTag[A2], implicit evidence$70: reflect.runtime.universe.TypeTag[A3], implicit evidence$71: reflect.runtime.universe.TypeTag[A4], implicit evidence$72: reflect.runtime.universe.TypeTag[A5], implicit evidence$73: reflect.runtime.universe.TypeTag[A6], implicit evidence$74: reflect.runtime.universe.TypeTag[A7], implicit evidence$75: reflect.runtime.universe.TypeTag[A8], implicit evidence$76: reflect.runtime.universe.TypeTag[A9], implicit evidence$77: reflect.runtime.universe.TypeTag[A10], implicit evidence$78: reflect.runtime.universe.TypeTag[A11])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) => RT)(implicit evidence$56: reflect.runtime.universe.TypeTag[RT], implicit evidence$57: reflect.runtime.universe.TypeTag[A1], implicit evidence$58: reflect.runtime.universe.TypeTag[A2], implicit evidence$59: reflect.runtime.universe.TypeTag[A3], implicit evidence$60: reflect.runtime.universe.TypeTag[A4], implicit evidence$61: reflect.runtime.universe.TypeTag[A5], implicit evidence$62: reflect.runtime.universe.TypeTag[A6], implicit evidence$63: reflect.runtime.universe.TypeTag[A7], implicit evidence$64: reflect.runtime.universe.TypeTag[A8], implicit evidence$65: reflect.runtime.universe.TypeTag[A9], implicit evidence$66: reflect.runtime.universe.TypeTag[A10])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8, A9](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8, A9) => RT)(implicit evidence$46: reflect.runtime.universe.TypeTag[RT], implicit evidence$47: reflect.runtime.universe.TypeTag[A1], implicit evidence$48: reflect.runtime.universe.TypeTag[A2], implicit evidence$49: reflect.runtime.universe.TypeTag[A3], implicit evidence$50: reflect.runtime.universe.TypeTag[A4], implicit evidence$51: reflect.runtime.universe.TypeTag[A5], implicit evidence$52: reflect.runtime.universe.TypeTag[A6], implicit evidence$53: reflect.runtime.universe.TypeTag[A7], implicit evidence$54: reflect.runtime.universe.TypeTag[A8], implicit evidence$55: reflect.runtime.universe.TypeTag[A9])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7, A8](name: String, func: (A1, A2, A3, A4, A5, A6, A7, A8) => RT)(implicit evidence$37: reflect.runtime.universe.TypeTag[RT], implicit evidence$38: reflect.runtime.universe.TypeTag[A1], implicit evidence$39: reflect.runtime.universe.TypeTag[A2], implicit evidence$40: reflect.runtime.universe.TypeTag[A3], implicit evidence$41: reflect.runtime.universe.TypeTag[A4], implicit evidence$42: reflect.runtime.universe.TypeTag[A5], implicit evidence$43: reflect.runtime.universe.TypeTag[A6], implicit evidence$44: reflect.runtime.universe.TypeTag[A7], implicit evidence$45: reflect.runtime.universe.TypeTag[A8])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6, A7](name: String, func: (A1, A2, A3, A4, A5, A6, A7) => RT)(implicit evidence$29: reflect.runtime.universe.TypeTag[RT], implicit evidence$30: reflect.runtime.universe.TypeTag[A1], implicit evidence$31: reflect.runtime.universe.TypeTag[A2], implicit evidence$32: reflect.runtime.universe.TypeTag[A3], implicit evidence$33: reflect.runtime.universe.TypeTag[A4], implicit evidence$34: reflect.runtime.universe.TypeTag[A5], implicit evidence$35: reflect.runtime.universe.TypeTag[A6], implicit evidence$36: reflect.runtime.universe.TypeTag[A7])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5, A6](name: String, func: (A1, A2, A3, A4, A5, A6) => RT)(implicit evidence$22: reflect.runtime.universe.TypeTag[RT], implicit evidence$23: reflect.runtime.universe.TypeTag[A1], implicit evidence$24: reflect.runtime.universe.TypeTag[A2], implicit evidence$25: reflect.runtime.universe.TypeTag[A3], implicit evidence$26: reflect.runtime.universe.TypeTag[A4], implicit evidence$27: reflect.runtime.universe.TypeTag[A5], implicit evidence$28: reflect.runtime.universe.TypeTag[A6])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4, A5](name: String, func: (A1, A2, A3, A4, A5) => RT)(implicit evidence$16: reflect.runtime.universe.TypeTag[RT], implicit evidence$17: reflect.runtime.universe.TypeTag[A1], implicit evidence$18: reflect.runtime.universe.TypeTag[A2], implicit evidence$19: reflect.runtime.universe.TypeTag[A3], implicit evidence$20: reflect.runtime.universe.TypeTag[A4], implicit evidence$21: reflect.runtime.universe.TypeTag[A5])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3, A4](name: String, func: (A1, A2, A3, A4) => RT)(implicit evidence$11: reflect.runtime.universe.TypeTag[RT], implicit evidence$12: reflect.runtime.universe.TypeTag[A1], implicit evidence$13: reflect.runtime.universe.TypeTag[A2], implicit evidence$14: reflect.runtime.universe.TypeTag[A3], implicit evidence$15: reflect.runtime.universe.TypeTag[A4])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2, A3](name: String, func: (A1, A2, A3) => RT)(implicit evidence$7: reflect.runtime.universe.TypeTag[RT], implicit evidence$8: reflect.runtime.universe.TypeTag[A1], implicit evidence$9: reflect.runtime.universe.TypeTag[A2], implicit evidence$10: reflect.runtime.universe.TypeTag[A3])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1, A2](name: String, func: (A1, A2) => RT)(implicit evidence$4: reflect.runtime.universe.TypeTag[RT], implicit evidence$5: reflect.runtime.universe.TypeTag[A1], implicit evidence$6: reflect.runtime.universe.TypeTag[A2])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT, A1](name: String, func: A1 => RT)(implicit evidence$2: reflect.runtime.universe.TypeTag[RT], implicit evidence$3: reflect.runtime.universe.TypeTag[A1])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  [RT](name: String, func: () => RT)(implicit evidence$1: reflect.runtime.universe.TypeTag[RT])org.apache.spark.sql.expressions.UserDefinedFunction <and>
  (name: String,udaf: org.apache.spark.sql.expressions.UserDefinedAggregateFunction)org.apache.spark.sql.expressions.UserDefinedAggregateFunction
 cannot be applied to (String, java.lang.reflect.Method)
    spark.sqlContext.udf.register(methods(0).getName, methods(0))

如果我通过

spark.sqlContext.udf.register(methods(0).getName, methods(0)_)

Error:(25, 62) _ must follow method; cannot follow java.lang.reflect.Method
    spark.sqlContext.udf.register(methods(0).getName, methods(0) _)

没有将Java Method类自动转换为Scala。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

尝试

// for funk2
spark.sqlContext.udf.register(methods(0).getName, 
  (s: String, i: Int) => methods(0).invoke(Udfs, s, i.asInstanceOf[Object]))

// for funk1
spark.sqlContext.udf.register(methods(1).getName, 
  (s: String) => methods(1).invoke(Udfs, s))

https://docs.oracle.com/javase/tutorial/reflect/member/methodInvocation.html