【问题标题】:Why I cannot use callUDF method?为什么我不能使用 callUDF 方法?
【发布时间】:2017-04-11 08:48:24
【问题描述】:

我使用 spark 1.6.1 和 java 代码。当我使用 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")));

【问题讨论】:

    标签: java apache-spark dataframe


    【解决方案1】:

    你必须在开头添加:

    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")));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-02
      • 2011-12-09
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      相关资源
      最近更新 更多