mirror of
https://github.com/apache/impala.git
synced 2026-01-03 06:00:52 -05:00
This patch extends the SHOW statement to also support user-defined functions and user-defined aggregate functions. The syntax of the new SHOW statements is as follows: SHOW CREATE [AGGREGATE] FUNCTION [<db_name>.]<func_name>; <db_name> and <func_name> are the names of the database and udf/uda respectively. Sample outputs of the new SHOW statements are as follows: Query: show create function fn +------------------------------------------------------------------+ | result | +------------------------------------------------------------------+ | CREATE FUNCTION default.fn() | | RETURNS INT | | LOCATION 'hdfs://localhost:20500/test-warehouse/libTestUdfs.so' | | SYMBOL='_Z2FnPN10impala_udf15FunctionContextE' | | | +------------------------------------------------------------------+ Query: show create aggregate function agg_fn +------------------------------------------------------------------------------------------+ | result | +------------------------------------------------------------------------------------------+ | CREATE AGGREGATE FUNCTION default.agg_fn(INT) | | RETURNS BIGINT | | LOCATION 'hdfs://localhost:20500/test-warehouse/libudasample.so' | | UPDATE_FN='_Z11CountUpdatePN10impala_udf15FunctionContextERKNS_6IntValEPNS_9BigIntValE' | | INIT_FN='_Z9CountInitPN10impala_udf15FunctionContextEPNS_9BigIntValE' | | MERGE_FN='_Z10CountMergePN10impala_udf15FunctionContextERKNS_9BigIntValEPS2_' | | FINALIZE_FN='_Z13CountFinalizePN10impala_udf15FunctionContextERKNS_9BigIntValE' | | | +------------------------------------------------------------------------------------------+ Please note that all the overloaded functions which match the given function name and category will be printed. This patch also extends the python test infrastructure to support expected results which include newline characters. A new subsection comment called 'MULTI_LINE' has been added for the 'RESULT' section. With this comment, a test can include its multi-line output inside [ ] and the content inside [ ] will be treated as a single line, including the newline character. Change-Id: Idbe433eeaf5e24ed55c31d905fea2a6160c46011 Reviewed-on: http://gerrit.cloudera.org:8080/1271 Reviewed-by: Dimitris Tsirogiannis <dtsirogiannis@cloudera.com> Tested-by: Internal Jenkins
380 lines
11 KiB
Plaintext
380 lines
11 KiB
Plaintext
====
|
|
---- QUERY
|
|
# Drop the dummy udfs this test uses.
|
|
drop function if exists default.fn();
|
|
drop function if exists function_ddl_test.fn();
|
|
drop function if exists function_ddl_test.fn(int);
|
|
drop function if exists function_ddl_test.fn(int, string);
|
|
drop function if exists function_ddl_test.fn(string, int);
|
|
drop function if exists function_ddl_test.fn2(int);
|
|
drop function if exists function_ddl_test.fn2(int, string);
|
|
drop function if exists function_ddl_test.fn_var_arg(int...);
|
|
drop function if exists function_ddl_test.agg_fn(int);
|
|
drop function if exists function_ddl_test.agg_fn(int, string);
|
|
====
|
|
---- QUERY
|
|
# Verify all the test functions are removed
|
|
show functions in function_ddl_test
|
|
---- RESULTS
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Verify all the test functions are removed
|
|
show aggregate functions in function_ddl_test
|
|
---- RESULTS
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Add them and test function overloading and scoping.
|
|
create function default.fn() RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='Fn'
|
|
====
|
|
---- QUERY
|
|
create function function_ddl_test.fn() RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='Fn'
|
|
====
|
|
---- QUERY
|
|
create function function_ddl_test.fn(int) RETURNS double
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='Fn'
|
|
====
|
|
---- QUERY
|
|
create function function_ddl_test.fn(int, string) RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='Fn'
|
|
====
|
|
---- QUERY
|
|
create function function_ddl_test.fn(string, int) RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='Fn'
|
|
====
|
|
---- QUERY
|
|
create function function_ddl_test.fn2(int) RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='Fn2'
|
|
====
|
|
---- QUERY
|
|
create function function_ddl_test.fn2(int, string) RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='Fn2'
|
|
====
|
|
---- QUERY
|
|
create function function_ddl_test.fn_var_arg(int...) RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdfs.so' SYMBOL='VarSum'
|
|
====
|
|
---- QUERY
|
|
create aggregate function function_ddl_test.agg_fn(int) RETURNS bigint
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libudasample.so' UPDATE_FN='CountUpdate'
|
|
====
|
|
---- QUERY
|
|
create aggregate function function_ddl_test.agg_fn(int, string) RETURNS int
|
|
LOCATION '$FILESYSTEM_PREFIX/test-warehouse/libTestUdas.so' UPDATE_FN='TwoArgUpdate'
|
|
====
|
|
---- QUERY
|
|
show functions in default
|
|
---- RESULTS
|
|
'INT','fn()'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
show functions in function_ddl_test
|
|
---- RESULTS
|
|
'INT','fn_var_arg(INT...)'
|
|
'INT','fn2(INT)'
|
|
'INT','fn2(INT, STRING)'
|
|
'INT','fn()'
|
|
'DOUBLE','fn(INT)'
|
|
'INT','fn(INT, STRING)'
|
|
'INT','fn(STRING, INT)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
show aggregate functions in function_ddl_test
|
|
---- RESULTS
|
|
'BIGINT','agg_fn(INT)'
|
|
'INT','agg_fn(INT, STRING)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Check that none of the functions show up as analytic functions.
|
|
show analytic functions in function_ddl_test
|
|
---- RESULTS
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
show create function default.fn
|
|
---- RESULTS: MULTI_LINE
|
|
['CREATE FUNCTION default.fn()
|
|
RETURNS INT
|
|
LOCATION '$NAMENODE/test-warehouse/libTestUdfs.so'
|
|
SYMBOL='_Z2FnPN10impala_udf15FunctionContextE'
|
|
']
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
show create function function_ddl_test.fn_var_arg
|
|
---- RESULTS: MULTI_LINE
|
|
['CREATE FUNCTION function_ddl_test.fn_var_arg(INT...)
|
|
RETURNS INT
|
|
LOCATION '$NAMENODE/test-warehouse/libTestUdfs.so'
|
|
SYMBOL='_Z6VarSumPN10impala_udf15FunctionContextEiPKNS_6IntValE'
|
|
']
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
show create aggregate function function_ddl_test.agg_fn
|
|
---- RESULTS: MULTI_LINE
|
|
['CREATE AGGREGATE FUNCTION function_ddl_test.agg_fn(INT)
|
|
RETURNS BIGINT
|
|
LOCATION '$NAMENODE/test-warehouse/libudasample.so'
|
|
UPDATE_FN='_Z11CountUpdatePN10impala_udf15FunctionContextERKNS_6IntValEPNS_9BigIntValE'
|
|
INIT_FN='_Z9CountInitPN10impala_udf15FunctionContextEPNS_9BigIntValE'
|
|
MERGE_FN='_Z10CountMergePN10impala_udf15FunctionContextERKNS_9BigIntValEPS2_'
|
|
FINALIZE_FN='_Z13CountFinalizePN10impala_udf15FunctionContextERKNS_9BigIntValE'
|
|
CREATE AGGREGATE FUNCTION function_ddl_test.agg_fn(INT, STRING)
|
|
RETURNS INT
|
|
LOCATION '$NAMENODE/test-warehouse/libTestUdas.so'
|
|
UPDATE_FN='_Z12TwoArgUpdatePN10impala_udf15FunctionContextERKNS_6IntValERKNS_9StringValEPS2_'
|
|
INIT_FN='_Z10TwoArgInitPN10impala_udf15FunctionContextEPNS_6IntValE'
|
|
MERGE_FN='_Z11TwoArgMergePN10impala_udf15FunctionContextERKNS_6IntValEPS2_'
|
|
']
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
show create function _impala_builtins.sin
|
|
---- RESULTS: MULTI_LINE
|
|
['CREATE FUNCTION _impala_builtins.sin(DOUBLE)
|
|
RETURNS DOUBLE
|
|
LOCATION 'null'
|
|
SYMBOL='_ZN6impala13MathFunctions3SinEPN10impala_udf15FunctionContextERKNS1_9DoubleValE'
|
|
']
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
show create aggregate function _impala_builtins.avg
|
|
---- RESULTS: MULTI_LINE
|
|
['CREATE AGGREGATE FUNCTION _impala_builtins.avg(BIGINT)
|
|
RETURNS DOUBLE
|
|
INTERMEDIATE STRING
|
|
LOCATION 'null'
|
|
UPDATE_FN='_ZN6impala18AggregateFunctions9AvgUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE'
|
|
INIT_FN='_ZN6impala18AggregateFunctions7AvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE'
|
|
MERGE_FN='_ZN6impala18AggregateFunctions8AvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_'
|
|
SERIALIZE_FN='_ZN6impala18AggregateFunctions28StringValSerializeOrFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
FINALIZE_FN='_ZN6impala18AggregateFunctions11AvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
CREATE AGGREGATE FUNCTION _impala_builtins.avg(DECIMAL(*,*))
|
|
RETURNS DECIMAL(*,*)
|
|
INTERMEDIATE STRING
|
|
LOCATION 'null'
|
|
UPDATE_FN='_ZN6impala18AggregateFunctions16DecimalAvgUpdateEPN10impala_udf15FunctionContextERKNS1_10DecimalValEPNS1_9StringValE'
|
|
INIT_FN='_ZN6impala18AggregateFunctions14DecimalAvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE'
|
|
MERGE_FN='_ZN6impala18AggregateFunctions15DecimalAvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_'
|
|
SERIALIZE_FN='_ZN6impala18AggregateFunctions28StringValSerializeOrFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
FINALIZE_FN='_ZN6impala18AggregateFunctions18DecimalAvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
CREATE AGGREGATE FUNCTION _impala_builtins.avg(DOUBLE)
|
|
RETURNS DOUBLE
|
|
INTERMEDIATE STRING
|
|
LOCATION 'null'
|
|
UPDATE_FN='_ZN6impala18AggregateFunctions9AvgUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE'
|
|
INIT_FN='_ZN6impala18AggregateFunctions7AvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE'
|
|
MERGE_FN='_ZN6impala18AggregateFunctions8AvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_'
|
|
SERIALIZE_FN='_ZN6impala18AggregateFunctions28StringValSerializeOrFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
FINALIZE_FN='_ZN6impala18AggregateFunctions11AvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
CREATE AGGREGATE FUNCTION _impala_builtins.avg(TIMESTAMP)
|
|
RETURNS TIMESTAMP
|
|
INTERMEDIATE STRING
|
|
LOCATION 'null'
|
|
UPDATE_FN='_ZN6impala18AggregateFunctions18TimestampAvgUpdateEPN10impala_udf15FunctionContextERKNS1_12TimestampValEPNS1_9StringValE'
|
|
INIT_FN='_ZN6impala18AggregateFunctions7AvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE'
|
|
MERGE_FN='_ZN6impala18AggregateFunctions8AvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_'
|
|
SERIALIZE_FN='_ZN6impala18AggregateFunctions28StringValSerializeOrFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
FINALIZE_FN='_ZN6impala18AggregateFunctions20TimestampAvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE'
|
|
']
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
drop function function_ddl_test.fn2(int, string)
|
|
====
|
|
---- QUERY
|
|
show functions
|
|
---- RESULTS
|
|
'INT','fn_var_arg(INT...)'
|
|
'INT','fn2(INT)'
|
|
'INT','fn()'
|
|
'DOUBLE','fn(INT)'
|
|
'INT','fn(INT, STRING)'
|
|
'INT','fn(STRING, INT)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
drop function if exists function_ddl_test.fn2(int, string)
|
|
====
|
|
---- QUERY
|
|
show functions in function_ddl_test
|
|
---- RESULTS
|
|
'INT','fn_var_arg(INT...)'
|
|
'INT','fn2(INT)'
|
|
'INT','fn()'
|
|
'DOUBLE','fn(INT)'
|
|
'INT','fn(INT, STRING)'
|
|
'INT','fn(STRING, INT)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
show functions in default;
|
|
---- RESULTS
|
|
'INT','fn()'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
drop function default.fn()
|
|
====
|
|
---- QUERY
|
|
show functions in default;
|
|
---- RESULTS
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
show functions in function_ddl_test;
|
|
---- RESULTS
|
|
'INT','fn_var_arg(INT...)'
|
|
'INT','fn2(INT)'
|
|
'INT','fn()'
|
|
'DOUBLE','fn(INT)'
|
|
'INT','fn(INT, STRING)'
|
|
'INT','fn(STRING, INT)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
drop function fn()
|
|
====
|
|
---- QUERY
|
|
show functions;
|
|
---- RESULTS
|
|
'INT','fn_var_arg(INT...)'
|
|
'INT','fn2(INT)'
|
|
'DOUBLE','fn(INT)'
|
|
'INT','fn(INT, STRING)'
|
|
'INT','fn(STRING, INT)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
drop function fn_var_arg(INT...)
|
|
====
|
|
---- QUERY
|
|
show functions;
|
|
---- RESULTS
|
|
'INT','fn2(INT)'
|
|
'DOUBLE','fn(INT)'
|
|
'INT','fn(INT, STRING)'
|
|
'INT','fn(STRING, INT)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
drop function agg_fn(int)
|
|
====
|
|
---- QUERY
|
|
show aggregate functions
|
|
---- RESULTS
|
|
'INT','agg_fn(INT, STRING)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Call invalidate metadata and make sure the functions are still there
|
|
invalidate metadata
|
|
---- RESULTS
|
|
---- TYPES
|
|
====
|
|
---- QUERY
|
|
show functions
|
|
---- RESULTS
|
|
'INT','fn2(INT)'
|
|
'DOUBLE','fn(INT)'
|
|
'INT','fn(INT, STRING)'
|
|
'INT','fn(STRING, INT)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
show aggregate functions
|
|
---- RESULTS
|
|
'INT','agg_fn(INT, STRING)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
show analytic functions
|
|
---- RESULTS
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Negative test for showing builtin scalar functions. The result
|
|
# should not contain aggregate or analytic functions. Note that
|
|
# the result must be non-empty for the test to suceed.
|
|
show functions in _impala_builtins;
|
|
---- RESULTS: VERIFY_IS_NOT_IN
|
|
'DOUBLE','avg(BIGINT)'
|
|
'BIGINT','rank()'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Positive test for showing builtin scalar functions.
|
|
show functions in _impala_builtins;
|
|
---- RESULTS: VERIFY_IS_SUBSET
|
|
'STRING','upper(STRING)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Negative test for showing builtin aggregate fuctions. The result should
|
|
# not contain scalar or analytic functions.
|
|
show aggregate functions in _impala_builtins;
|
|
---- RESULTS: VERIFY_IS_NOT_IN
|
|
'BIGINT','rank()'
|
|
'STRING','upper(STRING)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Positive test for showing builtin aggregate functions.
|
|
show aggregate functions in _impala_builtins;
|
|
---- RESULTS: VERIFY_IS_SUBSET
|
|
'STRING','group_concat(STRING)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Negative test for showing builtin analytic functions. The result should
|
|
# not contain non-analytic aggregate functions or scalar functions.
|
|
show analytic functions in _impala_builtins;
|
|
---- RESULTS: VERIFY_IS_NOT_IN
|
|
'STRING','group_concat(STRING)'
|
|
'STRING','upper(STRING)'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|
|
---- QUERY
|
|
# Positive test for showing builtin analytic functions.
|
|
show analytic functions in _impala_builtins;
|
|
---- RESULTS: VERIFY_IS_SUBSET
|
|
'BIGINT','rank()'
|
|
---- TYPES
|
|
STRING, STRING
|
|
====
|