How to run the HANA SQL function where an output table is required? Example function (from this tutorial):
CREATE TYPE "TT_RESTAURANTS" AS TABLE ("node_id" INTEGER, "distance" INTEGER, "hops" BIGINT);
CREATE OR REPLACE PROCEDURE "NEAREST_RESTAURANT"(IN startV INT, OUT res "TT_RESTAURANTS")
LANGUAGE GRAPH READS SQL DATA AS
BEGIN
GRAPH g = Graph("SKIING");
VERTEX v_s = Vertex(:g, :startV);
MULTISET<Vertex> rests = v IN Vertices(:g) WHERE :v."restaurant" == N'TRUE';
ALTER g ADD TEMPORARY VERTEX ATTRIBUTE (INT "distance" = 0);
ALTER g ADD TEMPORARY VERTEX ATTRIBUTE (BIGINT "hops" = 0L);
FOREACH rest in :rests {
VERTEX v_rest = Vertex(:g, :rest."node_id");
WeightedPath<INT> p = Shortest_Path(:g, :v_s, :v_rest, (Edge conn) => INTEGER { return :conn."length"; } );
rest."hops" = Length(:p);
rest."distance" = Weight(:p);
}
res = SELECT :v."node_id", :v."distance", :v."hops" FOREACH v IN :rests;
END;
How to run it easily in an SQL environment?
DO
BEGIN
DECLARE lt_tab "TT_RESTAURANTS";
CALL "SKIING"."NEAREST_RESTAURANT"(15,lt_tab);
SELECT * FROM :lt_tab;
END;