doris icon indicating copy to clipboard operation
doris copied to clipboard

[feature](function) support type template in SQL function

Open xiaokang opened this issue 2 years ago • 5 comments

Proposed changes

Issue Number: close #xxx

Problem summary

Currently, for ARRAY and MAP functions, sub item datatype need to be enumerated in FE function registration. It's tedious and hard to maintain for adding new datatypes.

# map element extract functions
[['element_at', '%element_extract%'], 'DECIMAL64', ['ARRAY_DECIMAL64', 'BIGINT'], 'ALWAYS_NULLABLE'],
[['element_at', '%element_extract%'], 'DECIMAL128', ['ARRAY_DECIMAL128', 'BIGINT'], 'ALWAYS_NULLABLE'],
[['element_at', '%element_extract%'], 'VARCHAR', ['ARRAY_VARCHAR', 'BIGINT'], 'ALWAYS_NULLABLE'],
[['element_at', '%element_extract%'], 'STRING', ['ARRAY_STRING', 'BIGINT'], 'ALWAYS_NULLABLE'],
and many more ...

# map element extract functions
[['element_at', '%element_extract%'], 'INT', ['MAP_STRING_INT', 'STRING'], 'ALWAYS_NULLABLE'],
[['element_at', '%element_extract%'], 'STRING', ['MAP_INT_STRING', 'INT'], 'ALWAYS_NULLABLE'],
and many more ...

A new way just like c++ template is proposed in this PR. The previous functions can be defined much simpler using template function. # map element extract template function [['element_at', '%element_extract%'], 'E', ['ARRAY<E>', 'BIGINT'], 'ALWAYS_NULLABLE', ['E']],

# map element extract template function
[['element_at', '%element_extract%'], 'V', ['MAP<K, V>', 'K'], 'ALWAYS_NULLABLE', ['K', 'V']],

BTW, the plain type function is not affected and the legacy ARRAY_X MAP_K_V is still supported for compatability.

Checklist(Required)

  • [ ] Does it affect the original behavior
  • [ ] Has unit tests been added
  • [ ] Has document been added or modified
  • [ ] Does it need to update dependencies
  • [ ] Is this PR support rollback (If NO, please explain WHY)

Further comments

If this is a relatively large or complex change, kick off the discussion at [email protected] by explaining why you chose the solution you did and what alternatives you considered, etc...

xiaokang avatar Mar 02 '23 09:03 xiaokang

run buildall

xiaokang avatar Mar 02 '23 09:03 xiaokang

run p0

xiaokang avatar Mar 03 '23 06:03 xiaokang

run buildall

xiaokang avatar Mar 03 '23 08:03 xiaokang

PR approved by at least one committer and no changes requested.

github-actions[bot] avatar Mar 03 '23 09:03 github-actions[bot]

PR approved by anyone and no changes requested.

github-actions[bot] avatar Mar 03 '23 09:03 github-actions[bot]

run buildall

xiaokang avatar Mar 05 '23 02:03 xiaokang

run buildall

xiaokang avatar Mar 07 '23 08:03 xiaokang

run feut

xiaokang avatar Mar 08 '23 00:03 xiaokang

PR approved by at least one committer and no changes requested.

github-actions[bot] avatar Mar 08 '23 02:03 github-actions[bot]