未定义函数:"ST_GeomFromText",使用Spark/Java [英] Undefined function: 'ST_GeomFromText' Using Spark / Java
问题描述
我有以下数据框
------------------------------------------------------
|longitude | latitude | geomType | geom |
------------------------------------------------------
|-7.0737816 |33.82666166|Polygon |[GEOMETRY - 113 o]|
-------------------------------------------------------
我想将此查询应用于此数据框
I want to apply this query on this dataframe
我使用以下代码
dataframe= sparkSession.sql("select ST_GeomFromText('POINT("+col("longitude")+" , '',"+col("latitude")+")')");
我收到此错误
Exception in thread "main" org.apache.spark.sql.AnalysisException: Undefined function: 'ST_GeomFromText'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.
请注意,我在Spark上使用的是Java语言
Note that I'm using java language on spark
我需要你的帮助.
谢谢
推荐答案
由于ST_GeomFromText不是org.apache.spark.sql.functions的一部分,因此它无法在内部识别它.
您首先需要为此功能定义UDF.
意味着您需要定义该函数的定义,然后将该函数以spark作为UDF注册,那么只有您可以使用此函数.
您可以使用以下语法:
sqlContext.udf.register("ST_GeomFromText", <name of function or definition of function>)
Since the ST_GeomFromText is not the part of org.apache.spark.sql.functions so it will not recognise it internally.
You need to first define the UDF for this function.
means you need to define the definition of that function and then register that function with spark as UDF then only you can use this function.
You can use following syntax:
sqlContext.udf.register("ST_GeomFromText", <name of function or definition of function>)
谢谢
这篇关于未定义函数:"ST_GeomFromText",使用Spark/Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!