AWS redshift->hdb pg(Greenplum), plpython, pljava UDF 以及upload library

背景
AWS redshift UDF 支持sql, plpython編寫。

阿里雲hdb pg UDF支持plpgsql, sql, plpython, pljava編寫。

aws redshift通過create library導入外部LIB。

阿里雲hdb pg同樣通過CREATE LIBRARY導入外部LIB。

redshift 創建UDF函數
https://docs.aws.amazon.com/redshift/latest/dg/udf-creating-a-scalar-udf.html

CREATE [ OR REPLACE ] FUNCTION f_function_name
( { [py_arg_name py_arg_data_type |
sql_arg_data_type } [ , ... ] ] )
RETURNS data_type
{ VOLATILE | STABLE | IMMUTABLE }
AS

$$ { python_program | SELECT_clause } $$

LANGUAGE { plpythonu | sql }

create function f_py_greater (a float, b float)
returns float
stable
as

$$ if a > b: return a return b $$

language plpythonu;
redshift 導入python lib
CREATE [ OR REPLACE ] LIBRARY library_name LANGUAGE plpythonu
FROM
{ 'https://file_url'
| 's3://bucketname/file_name'
authorization
[ REGION [AS] 'aws_region']
}
阿里雲hdb pg創建UDF函數
https://help.aliyun.com/document_detail/50594.html

create extension pljava;

create library example language java from 'oss://oss-cn-hangzhou.aliyuncs.com filepath=analytics.jar id=xxx key=yyy bucket=zzz';

create table temp (a varchar) distributed randomly;
insert into temp values ('my string');
create or replace function java_substring(varchar, int, int) returns varchar as 'Test.substring' language java;
select java_substring(a, 1, 5) from temp;
阿里雲hdb pg導入java lib
https://help.aliyun.com/document_detail/50595.html

CREATE LIBRARY library_name LANGUAGE [JAVA] FROM oss_location OWNER ownername
CREATE LIBRARY library_name LANGUAGE [JAVA] VALUES file_content_hex OWNER ownername
DROP LIBRARY library_name
create library example language java from 'oss://oss-cn-hangzhou.aliyuncs.com filepath=analytics.jar id=xxx key=yyy bucket=zzz';
參考
https://help.aliyun.com/document_detail/50595.html

https://help.aliyun.com/document_detail/50594.html

https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_LIBRARY.html
轉自阿里雲德哥

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章