-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Support table functions with pushdown to connector #11336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2e00c8e
Support table function invocation in grammar and AST
kasiafi 395fd91
Add SPI support for declaring and analyzing TableFunctions
kasiafi e69a052
Pass TransactionManager to StatementAnalyzer
kasiafi 493f639
Register table functions
kasiafi 9e8d51a
Analyze table function invocation
kasiafi d4c7338
Plan table function invocation as TableFunctionNode
kasiafi 5657009
Add methods for table function pushdown into connector
kasiafi ec8b9fd
Add rule to push table function invocation into connector
kasiafi b4d4b51
Extract transaction manager from JdbcConnector
kasiafi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/trino-main/src/main/java/io/trino/metadata/TableFunctionHandle.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.metadata; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import io.trino.connector.CatalogName; | ||
| import io.trino.spi.connector.ConnectorTransactionHandle; | ||
| import io.trino.spi.ptf.ConnectorTableFunctionHandle; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class TableFunctionHandle | ||
| { | ||
| private final CatalogName catalogName; | ||
| private final ConnectorTableFunctionHandle functionHandle; | ||
| private final ConnectorTransactionHandle transactionHandle; | ||
|
|
||
| @JsonCreator | ||
| public TableFunctionHandle( | ||
| @JsonProperty("catalogName") CatalogName catalogName, | ||
| @JsonProperty("functionHandle") ConnectorTableFunctionHandle functionHandle, | ||
| @JsonProperty("transactionHandle") ConnectorTransactionHandle transactionHandle) | ||
| { | ||
| this.catalogName = requireNonNull(catalogName, "catalogName is null"); | ||
| this.functionHandle = requireNonNull(functionHandle, "functionHandle is null"); | ||
| this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public CatalogName getCatalogName() | ||
| { | ||
| return catalogName; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public ConnectorTableFunctionHandle getFunctionHandle() | ||
| { | ||
| return functionHandle; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public ConnectorTransactionHandle getTransactionHandle() | ||
| { | ||
| return transactionHandle; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
core/trino-main/src/main/java/io/trino/metadata/TableFunctionMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.metadata; | ||
|
|
||
| import io.trino.connector.CatalogName; | ||
| import io.trino.spi.ptf.ConnectorTableFunction; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class TableFunctionMetadata | ||
| { | ||
| private final CatalogName catalogName; | ||
| private final ConnectorTableFunction function; | ||
|
|
||
| public TableFunctionMetadata(CatalogName catalogName, ConnectorTableFunction function) | ||
| { | ||
| this.catalogName = requireNonNull(catalogName, "catalogName is null"); | ||
| this.function = requireNonNull(function, "function is null"); | ||
| } | ||
|
|
||
| public CatalogName getCatalogName() | ||
| { | ||
| return catalogName; | ||
| } | ||
|
|
||
| public ConnectorTableFunction getFunction() | ||
| { | ||
| return function; | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
core/trino-main/src/main/java/io/trino/metadata/TableFunctionRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.metadata; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import io.trino.Session; | ||
| import io.trino.connector.CatalogName; | ||
| import io.trino.spi.ptf.ConnectorTableFunction; | ||
| import io.trino.sql.tree.QualifiedName; | ||
|
|
||
| import javax.annotation.concurrent.ThreadSafe; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkState; | ||
| import static io.trino.metadata.FunctionResolver.toPath; | ||
| import static java.util.Locale.ENGLISH; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| @ThreadSafe | ||
| public class TableFunctionRegistry | ||
| { | ||
| // catalog name in the original case; schema and function name in lowercase | ||
| private final Map<CatalogName, Map<SchemaFunctionName, TableFunctionMetadata>> tableFunctions = new ConcurrentHashMap<>(); | ||
|
|
||
| public void addTableFunctions(CatalogName catalogName, Collection<ConnectorTableFunction> functions) | ||
| { | ||
| requireNonNull(catalogName, "catalogName is null"); | ||
| requireNonNull(functions, "functions is null"); | ||
|
|
||
| ImmutableMap.Builder<SchemaFunctionName, TableFunctionMetadata> builder = ImmutableMap.builder(); | ||
| for (ConnectorTableFunction function : functions) { | ||
| builder.put( | ||
| new SchemaFunctionName( | ||
| function.getSchema().toLowerCase(ENGLISH), | ||
| function.getName().toLowerCase(ENGLISH)), | ||
| new TableFunctionMetadata(catalogName, function)); | ||
| } | ||
| checkState(tableFunctions.putIfAbsent(catalogName, builder.buildOrThrow()) == null, "Table functions already registered for catalog: " + catalogName); | ||
| } | ||
|
|
||
| public void removeTableFunctions(CatalogName catalogName) | ||
| { | ||
| tableFunctions.remove(catalogName); | ||
| } | ||
|
|
||
| /** | ||
| * Resolve table function with given qualified name. | ||
| * Table functions are resolved case-insensitive for consistency with existing scalar function resolution. | ||
| */ | ||
| public TableFunctionMetadata resolve(Session session, QualifiedName qualifiedName) | ||
| { | ||
| for (CatalogSchemaFunctionName name : toPath(session, qualifiedName)) { | ||
| CatalogName catalogName = new CatalogName(name.getCatalogName()); | ||
| Map<SchemaFunctionName, TableFunctionMetadata> catalogFunctions = tableFunctions.get(catalogName); | ||
| if (catalogFunctions != null) { | ||
| String lowercasedSchemaName = name.getSchemaFunctionName().getSchemaName().toLowerCase(ENGLISH); | ||
| String lowercasedFunctionName = name.getSchemaFunctionName().getFunctionName().toLowerCase(ENGLISH); | ||
| TableFunctionMetadata function = catalogFunctions.get(new SchemaFunctionName(lowercasedSchemaName, lowercasedFunctionName)); | ||
| if (function != null) { | ||
| return function; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.