2016-11-27 67 views
2

我使用spark 1.6.1,并在java中的代码。当我使用callUDF()时,它显示为什么我不能使用callUDF方法?

The method callUDF(String, Column) is undefined for the type PhaseOne 

和callUdf()不起作用。我的代码如下:

sqlContext.udf().register("stringToLong", new UDF1<String, Long>() { 

     @Override 
     public Long call(String arg0) throws Exception { 
      // TODO Auto-generated method stub 
      IPTypeConvert itc = new IPTypeConvert(); 
      return itc.stringtoLong(arg0); 
     } 
    }, DataTypes.LongType); 
    DataFrame interDF = initInterDF.withColumn("interIPInt", callUDF("stringToLong", initInterDF.col("interIP"))); 

回答

2

您必须添加开头:

import static org.apache.spark.sql.functions.callUDF; 

,然后使用它:

sqlContext.udf().register("stringToLong", new UDF1<String, Long>() { 

     @Override 
     public Long call(String arg0) throws Exception { 
      // TODO Auto-generated method stub 
      IPTypeConvert itc = new IPTypeConvert(); 
      return itc.stringtoLong(arg0); 
     } 
    }, DataTypes.LongType); 
DataFrame interDF = initInterDF.withColumn("interIPInt", callUDF("stringToLong", initInterDF.col("interIP"))); 
+0

它的工作原理,谢谢! – volity

相关问题