-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SPI, syntax and execution for table procedures
Commit adds SPI and execution support for new table procedures. New syntax extends ALTER TABLE family allowing for proper semantic analysis of target table (unlike what we have with CALL when table schema and table name are passed as string literals via table arguments). New syntax example: * ALTER TABLE <table> EXECUTE * ALTER TABLE <table> EXECUTE(value1, value2, ...) * ALTER TABLE <table> EXECUTE(param1 => value1, param2 => value2, ...) WHERE ... New table procedures allow for rewriting table data which makes them feasible for implementing data cleansing routines like: * compacting small files into larger ones for HIVE table * changing files sorting or bucketing scheme for a table * Iceberg OPTIMIZE Currently exectuion flow which _does not_ rewrite table data is not implemented. It will be implemented as a followup. Then current procedures available via `CALL` will be migrated to new mechanism. Procedures are exposed via connectors to engine via a set of new SPI methods and classes: * io.trino.spi.connector.TableProcedureMetadata * io.trino.spi.connector.TableProcedureExecutionMode * io.trino.spi.connector.ConnectorTableExecuteHandle * io.trino.spi.connector.ConnectorMetadata#getTableHandleForExecute * io.trino.spi.connector.ConnectorMetadata#getLayoutForTableExecute * io.trino.spi.connector.ConnectorMetadata#beginTableExecute * io.trino.spi.connector.ConnectorMetadata#finishTableExecute
- Loading branch information
Showing
95 changed files
with
2,328 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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
45 changes: 45 additions & 0 deletions
45
core/trino-main/src/main/java/io/trino/execution/TableExecuteContext.java
This file contains 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,45 @@ | ||
/* | ||
* 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.execution; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import javax.annotation.concurrent.GuardedBy; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class TableExecuteContext | ||
{ | ||
@GuardedBy("this") | ||
private List<Object> splitsInfo; | ||
|
||
public synchronized void setSplitsInfo(List<Object> splitsInfo) | ||
{ | ||
requireNonNull(splitsInfo, "splitsInfo is null"); | ||
if (this.splitsInfo != null) { | ||
throw new IllegalStateException("splitsInfo already set to " + this.splitsInfo); | ||
} | ||
this.splitsInfo = ImmutableList.copyOf(splitsInfo); | ||
} | ||
|
||
public synchronized List<Object> getSplitsInfo() | ||
{ | ||
if (splitsInfo == null) { | ||
throw new IllegalStateException("splitsInfo not set yet"); | ||
} | ||
return splitsInfo; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
core/trino-main/src/main/java/io/trino/execution/TableExecuteContextManager.java
This file contains 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,49 @@ | ||
/* | ||
* 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.execution; | ||
|
||
import io.trino.spi.QueryId; | ||
|
||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
@ThreadSafe | ||
public class TableExecuteContextManager | ||
{ | ||
private final ConcurrentMap<QueryId, TableExecuteContext> contexts = new ConcurrentHashMap<>(); | ||
|
||
public void registerTableExecuteContextForQuery(QueryId queryId) | ||
{ | ||
TableExecuteContext newContext = new TableExecuteContext(); | ||
if (contexts.putIfAbsent(queryId, newContext) != null) { | ||
throw new IllegalStateException("TableExecuteContext already registered for query " + queryId); | ||
} | ||
} | ||
|
||
public void unregisterTableExecuteContextForQuery(QueryId queryId) | ||
{ | ||
contexts.remove(queryId); | ||
} | ||
|
||
public TableExecuteContext getTableExecuteContextForQuery(QueryId queryId) | ||
{ | ||
TableExecuteContext context = contexts.get(queryId); | ||
if (context == null) { | ||
throw new IllegalStateException("TableExecuteContext not registered for query " + queryId); | ||
} | ||
return context; | ||
} | ||
} |
This file contains 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 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.