Analyze table function arguments#13602
Conversation
3a172d1 to
a2cd5c4
Compare
martint
left a comment
There was a problem hiding this comment.
(still reviewing the last commit)
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Why are they lower cased? What happens with delimited names? That would seem to go against what the SQL spec describes.
There was a problem hiding this comment.
The comment is not precise. It should say "All names are resolved case-insensitive".
I am aware that this is not compliant with the SQL spec. Regarding resolution of co-partitioned tables, I chose to follow how table references are resolved in Trino.
Currently in Trino, all table references, including CTEs and aliased relations, are resolved case-insensitive, and sadly, the 'delimited' property is disregarded. In theory, we could do spec-compliant resolution for the co-partitioned tables, but I think it would be unintuitive to the user. Similarly, we decided to resolve TF names in the usual non-ANSI way to avoid confusion between different function types.
If we decided to resolve co-partitioned table references in the spec-compliant way, we'd have to decide how "permissive" we want to be with respect to schema and catalog names.
core/trino-spi/src/main/java/io/trino/spi/ptf/DescriptorArgument.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Can you point out where is the name conflict? I can't see it.
There was a problem hiding this comment.
It happened in the StatementAnalyzer where we analyze the incoming io.trino.sql.tree.TableArgument, and use the io.trino.spi.ptf.TableArgument.Builder. I renamed the former (tree). Analogically with the descriptor arguments.
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
This method has two outputs -- the return value Argument, and the tableArgumentAnalyses output list via side effects. That makes the code more complicated than necessary and harder to understand. Instead, one option make the method return TableArgumentAnalysis, add the Argument to it, and remove the side effects from the function. The caller should be responsible for unpacking and collecting the TableArgumentAnalysis objects into a list if so desired.
There was a problem hiding this comment.
I added a helper class to return both the Argument, and the optional TableArgumentAnalysis. TableArgumentAnalysis couldn't be extended to carry the Argument, because it only applies to table arguments, while Argument is created for each argument regardless of its type.
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java
Outdated
Show resolved
Hide resolved
72aa347 to
617bca2
Compare
8e726a4 to
bdc1b8e
Compare
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
bdc1b8e to
5cd35fa
Compare
Prune when empty is enforced for a table argument with row semantics. For a table argument with set semantocs, keep when empty is the default, and it can be changed to prune when empty.
According to the SQL standard, the only properties of a table argument used during analysis are: the row type, partitioning, and ordering. Other information, like the prune / keep when empty property, are not involved in the analysis.
This is a change of approach on resolving arguments of table functions. Before this change, the mapping of descriptor arguments to table arguments had to be determined during query analysis. It was too limiting: in that model, input table references were limited to the specified descriptor fields. After this change, any input fields can be referenced, and the required fields (channels) are to be determined dynamically during function compilation. One advantage of determining the required fields early was the possibility to prune any columns that were not required by the table function. This should be replaced by adding a way for a table function to declare required fields during query optimization.
It should make using descriptor arguments easier for the table function author, and allow to compare with NULL_DESCRIPTOR by equality.
5cd35fa to
dbef4d9
Compare
This PR adds the Analyzer support for table and descriptor arguments of table functions.
These arguments are not yet supported in further phases of query processing, and they are caught in
RelationPlanner.No docs required. We should document how table and descriptor arguments work when we add full support for them.
Some SPI changes are introduced. However, the affected classes are marked as experimental, so probably we don't need to announce the changes in the release notes. Also, the changed classes can't be effectively used, as the related argument types are not supported beyond the Analyzer.
Beside the SPI changes mentioned above, no release notes required.