SAP HANA空间功能

时间:2016-03-18 14:41:30

标签: sap hana

我想在SAP HANA数据库中创建功能,以计算两点之间的距离。

create function "kostya"."calc_distance" (in a ST_Point, in b ST_Point)
returns dist DOUBLE
AS
BEGIN
    dist = a.ST_Distance(b);
END

当我尝试执行此代码时,我遇到了错误:

feature not supported: Unsupported parameter type:ST_POINT: line 2 col 48 (at pos 48)

但是当我执行类似的SQL查询时:

select NEW ST_Point(10, 1).ST_Distance( NEW ST_Point(1, 1)) FROM dummy;

我有写作结果。

任何提示?

1 个答案:

答案 0 :(得分:2)

从我们学习的docs

  

过程的输入和输出参数可以包含任何原始SQL类型或表类型。

遗憾的是,地理空间数据类型并未如此列出。

因此,您必须将a.ST_X()之类的scalare值传递给该函数,并使用ST_Point(DOUBLE, DOUBLE) constructor将其合并回过程中的ST_Point,如下所示:

CREATE FUNCTION "calc_distance" (
    IN a_long DOUBLE, 
    IN a_lat DOUBLE, 
    IN b_long DOUBLE, 
    IN b_lat DOUBLE
) RETURNS dist DOUBLE
AS
BEGIN
    SELECT NEW ST_Point(:a_long, :a_lat).ST_Distance(
        NEW ST_Point(:b_long, :b_lat)) INTO dist FROM dummy;
END;

-- sample usage
SELECT "calc_distance"(a.ST_X(), a.ST_Y(), b.ST_X(), b.ST_Y())
FROM (
    SELECT NEW ST_Point(10.0, 50.0) AS a, NEW ST_Point(11.0, 51.0) AS b FROM dummy
);

此工作无需HANA 102.01的基于Web的开发工作台的投诉。从安装了SAP Development Tools for Eclipse的Eclipse Luna开始,我们得到了

java.sql.SQLWarning: Not recommended feature: Using SELECT INTO in Scalar UDF
Statement 'CREATE FUNCTION "calc_distance" ( IN a_long DOUBLE, IN a_lat DOUBLE, IN b_long DOUBLE, IN b_lat ...' 
successfully executed in 16 ms 272 µs  (server processing time: 7 ms 460 µs) - Rows Affected: 0 

在SAP HANA Studio中,警告可能会出错。似乎事情正在那里进行:)

从SAP HANA SPS11开始,扩展了对空间数据类型的支持。请参阅SAP HANA学院的this video