[英]Selecting multiple parameters from UDF or procedure
I'm trying to compute multiple values and fetch them in a select clause. 我正在尝试计算多个值并在select子句中获取它们。 Whether its computed via UDF or procedure does not matter to me but I can't figure out how to do it in either way.
它是通过UDF计算还是通过过程计算对我来说都无关紧要,但我无法弄清楚如何以任何一种方式进行计算。 I want to use it like this:
我想这样使用它:
SELECT ID, BITMAP(ID) FROM X;
which then should return a table with columns ID, Bitset1, Bitset2
. 然后,该表应返回具有
ID, Bitset1, Bitset2
。 If possible it should be as performant as possible. 如果可能的话,它应该表现得尽可能好。
I have three versions currently (simplified, there's actual more computation): 我目前有三个版本(简化后,实际上还有更多计算):
Table UDF 表UDF
CREATE FUNCTION TPCH.BITMAP(IN col BIGINT)
RETURNS table("BITSET1" bigint, "BITSET2" bigint)
AS BEGIN
declare bitset1, bitset2 bigint;
bitset1 = 1;
bitset2 = 2;
return select bitset1 as "BITSET1", bitset2 as "BITSET2" from sys.dummy;
END;
Scalar UDF 标量UDF
CREATE FUNCTION BITMAP(IN col BIGINT)
RETURNS bitset1 bigint, bitset2 bigint
AS BEGIN
declare bitset1, bitset2 bigint;
bitset1 = 1;
bitset2 = 2;
END;
Procedure 程序
create procedure BITMAP(in col BIGINT,
out bitsets table("BITSET1" bigint, "BITSET2" bigint))
as begin
bitsets = select 1 as "BITSET1", 2 as "BITSET2" from sys.dummy;
end;
If I execute the select statement from above I get different exceptions: 如果我从上面执行select语句,则会得到不同的异常:
For TUDF / Procedure : cannot use procedure or table function in select projection column or cannot use window function w/o OVER: P_BITMAP
对于TUDF / Procedure :
cannot use procedure or table function in select projection column or cannot use window function w/o OVER: P_BITMAP
For SUDF : This user defined function has multiple outputs, but this usage requires a single output. Specify a single output.
对于SUDF :
This user defined function has multiple outputs, but this usage requires a single output. Specify a single output.
This user defined function has multiple outputs, but this usage requires a single output. Specify a single output.
I figured out that for SUDF I can write it like this: 我发现对于SUDF,我可以这样写:
select ID, BITMAP(ID).bitset1, BITMAP(ID).bitset2 from X;
But this executes BITMAP(ID) twice which makes it slow. 但这会两次执行BITMAP(ID),这会使它变慢。 I want to fetch both values in one go.
我想一次性获取两个值。
Is this even possible to do in Hana or are there other options? 在Hana甚至可以做到这一点,或者还有其他选择吗?
EDIT 1: for clarification the udfs and procedure usually depend on the input. 编辑1:为澄清起见,udf和过程通常取决于输入。 I just return 1 and 2 in the example for simplicity.
为了简单起见,我仅在示例中返回1和2。
As discussed, in HANA 1 there exist the following limitation concerning user defined functions: 如所讨论的,在HANA 1中,存在有关用户定义功能的以下限制:
To apply a user defined function to many values in parallel, HANA 2 provides multiple new features, eg 为了将用户定义的函数并行应用于多个值,HANA 2提供了多种新功能,例如
MAP_MERGE
function, to implement a map-reduce calling pattern MAP_MERGE
函数,用于实现map-reduce调用模式 add : a good example for the MAP_MERGE feature in HANA 2 can be found here: https://blogs.sap.com/2016/12/01/sap-hana-2.0-sps-0-new-developer-features-database-development/ 添加 :可以在此处找到HANA 2中MAP_MERGE功能的一个很好的示例: https ://blogs.sap.com/2016/12/01/sap-hana-2.0-sps-0-new-developer-features-database -发展/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.