1

我在集群上运行 Spark 1.5.0。我想使用 ESRI 的 API 中的 Hive UDF。我可以在 Spark 应用程序中使用这些 API,但由于集群中的一些问题,我无法使用 HiveContext。我想在 Spark-SQL 应用程序中使用现有的 Hive UDF。

//    val sqlContext = new SQLContext(sc)
//    import sqlContext.implicits._
//    val hc = new HiveContext(sc)
//    hc.sql("create temporary function ST_Point as 'com.esri.hadoop.hive.ST_Point'")
//    hc.sql("create temporary function ST_Within as 'com.esri.hadoop.hive.ST_Within'")
//    hc.sql("create temporary function ST_Polygon as 'com.esri.hadoop.hive.ST_Polygon'")
//    val resultDF = hc.sql("select ST_Within(ST_Point(2, 3), ST_Polygon(1,1, 1,4, 4,4, 4,1))")

上面的代码是针对 HiveContext 的,但我想在 SparkContext 中使用类似的东西,所以按照这个写了一些东西-

sqlContext.sql("""create function ST_Point as 'com.esri.hadoopcom.esri.hadoop.hive.ST_Point'""") 

但似乎我得到了同样的错误。(见下文)

Exception in thread "main" java.lang.RuntimeException: [1.1] failure: ``with'' expected but identifier create found

create function ST_Point as 'com.esri.hadoopcom.esri.hadoop.hive.ST_Point'
^
    at scala.sys.package$.error(package.scala:27)

我试图用现有的 UDF 制作函数,但似乎需要制作 scala 包装器来调用 java 类。我尝试如下-

def ST_Point_Spark = new ST_Point()
sqlContext.udf.register("ST_Point_Spark", ST_Point_Spark _)
def ST_Within_Spark = new ST_Within()
sqlContext.udf.register("ST_Within_Spark", ST_Within_Spark _)
def ST_Polygon_Spark = new ST_Polygon()
sqlContext.udf.register("ST_Polygon_Spark", ST_Polygon_Spark _)   
sqlContext.sql("select ST_Within_Spark(ST_Point_Spark(2, 3), ST_Polygon_Spark(1,1, 1,4, 4,4, 4,1))")  

但在这种情况下得到错误 -

Exception in thread "main" scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving object InterfaceAudience
    at scala.reflect.internal.Symbols$Symbol$$anonfun$info$3.apply(Symbols.scala:1220)
    at scala.reflect.internal.Symbols$Symbol$$anonfun$info$3.apply(Symbols.scala:1218)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)

我只是想知道,有没有什么方法可以在不使用 HiveContext 的情况下直接使用 SqlContext 来调用 Hive/Java UDF。注意:是一个有用的帖子,但不符合我的要求。

4

0 回答 0