Add table function exclude_columns#16584
Conversation
a32efdf to
b8e84ac
Compare
|
CI but is |
942545e to
51b8293
Compare
|
@ebyhr I added the ability to return anonymous columns from a table function (as a prep commit). |
51b8293 to
5f58c33
Compare
|
@martint I enabled returning anonymous columns from a table function. I believe we discussed it offline some time ago. Please take a look. |
12f9fc0 to
a69e48e
Compare
There was a problem hiding this comment.
Maybe better to be explicit and say "COLUMNS descriptor is null".
BTW, under what conditions would this happen? The argument is marked as required, so the query should fail during analysis if it's missing.
There was a problem hiding this comment.
Yes, the argument is required, but the user can pass null descriptor: columns => cast(null AS descriptor). There is a test case that covers it.
There was a problem hiding this comment.
This is something we'll have to fix when we address identifier semantics. Let's add a TODO.
There was a problem hiding this comment.
Also, since descriptor columns names are canonical, maybe we keep them as is here and canonicalize the TableArgument columns instead when matching (for now, canonicalize to lower-case to preserve current semantics)
There was a problem hiding this comment.
I don't think we should do this.
If we uppercase one side of comparison (which is common in SQL-standard canonicalization), and lowercase the other side, we have little chance for a match. Effectively, the user would have to write all names in COLUMNS in lowercase and quoted.
a69e48e to
ed44a44
Compare
|
@martint Updated. Please re-review. |
Before this change, if a table function did not pass a ConnectorTableFunctionHandle in the TableFunctionAnalysis, the default handle was used, which was an anonymous implementation of ConnectorTableFunctionHandle. It did not work with table functions executed by operator, due to lack of serialization. This change introduces EmptyTableFunctionHandle, and sets it as default.
Per SQL standard, all columns must be named. In Trino, we support unnamed columns. This change adjusts table functions so that they can return anonymous columns. It is achieved by changing the Descriptor structure so that field name is optional. This optionality can only be used for the returned type of table functions. Descriptor arguments pased by the user as well as default values for descriptor argumens have mandatory field names.
ed44a44 to
0940038
Compare
Description
Adds a new table function
exclude_columnsas a built-in table function.This function is a replacement for syntax
SELECT * EXCEPT(...). Such syntax, in a few variants, is supported by different databases (as discussed here https://stackoverflow.com/questions/413819/select-except). However, it is not part of the SQL standard, and so Trino does not support it.Additional context and related issues
There is a related optimization PR submitted for review: #16012. Technically, the optimization is not a prerequisite, but it could affect the performance a lot by enabling column pruning.
Release notes
( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(X) Release notes are required, with the following suggested text:
Docs included.