-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add procedures support for Lakehouse #26917
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
Open
codluca
wants to merge
1
commit into
trinodb:master
Choose a base branch
from
codluca:26753-lakehouse-procedures
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
104 changes: 104 additions & 0 deletions
104
...house/src/main/java/io/trino/plugin/lakehouse/procedures/LakehouseDropStatsProcedure.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,104 @@ | ||||||||||||||||||||||
/* | ||||||||||||||||||||||
* 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.plugin.lakehouse.procedures; | ||||||||||||||||||||||
|
||||||||||||||||||||||
import com.google.common.collect.ImmutableList; | ||||||||||||||||||||||
import com.google.inject.Inject; | ||||||||||||||||||||||
import com.google.inject.Provider; | ||||||||||||||||||||||
import io.trino.plugin.deltalake.procedure.DropExtendedStatsProcedure; | ||||||||||||||||||||||
import io.trino.plugin.hive.procedure.DropStatsProcedure; | ||||||||||||||||||||||
import io.trino.plugin.lakehouse.TableType; | ||||||||||||||||||||||
import io.trino.spi.connector.ConnectorAccessControl; | ||||||||||||||||||||||
import io.trino.spi.connector.ConnectorSession; | ||||||||||||||||||||||
import io.trino.spi.procedure.Procedure; | ||||||||||||||||||||||
import io.trino.spi.type.ArrayType; | ||||||||||||||||||||||
|
||||||||||||||||||||||
import java.lang.invoke.MethodHandle; | ||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||
|
||||||||||||||||||||||
import static io.trino.spi.type.VarcharType.VARCHAR; | ||||||||||||||||||||||
import static java.lang.invoke.MethodHandles.lookup; | ||||||||||||||||||||||
import static java.util.Objects.requireNonNull; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* A procedure that drops statistics. | ||||||||||||||||||||||
* <p> | ||||||||||||||||||||||
* It is delegated to the appropriate underlying procedure based on the table type. | ||||||||||||||||||||||
* Currently, it supports Delta Lake and Hive table types. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public class LakehouseDropStatsProcedure | ||||||||||||||||||||||
implements Provider<Procedure> | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
private static final MethodHandle DROP_STATS; | ||||||||||||||||||||||
|
||||||||||||||||||||||
private static final String SYSTEM_SCHEMA = "system"; | ||||||||||||||||||||||
private static final String PROCEDURE_NAME = "drop_stats"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
private static final String TABLE_TYPE = "TABLE_TYPE"; | ||||||||||||||||||||||
private static final String SCHEMA_NAME = "SCHEMA_NAME"; | ||||||||||||||||||||||
private static final String TABLE_NAME = "TABLE_NAME"; | ||||||||||||||||||||||
private static final String PARTITION_VALUES = "PARTITION_VALUES"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
static { | ||||||||||||||||||||||
try { | ||||||||||||||||||||||
DROP_STATS = lookup().unreflect(LakehouseDropStatsProcedure.class.getMethod( | ||||||||||||||||||||||
"dropStats", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, String.class, List.class)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
catch (ReflectiveOperationException e) { | ||||||||||||||||||||||
throw new AssertionError(e); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
private final DropExtendedStatsProcedure deltaLakeDropStatsProcedure; | ||||||||||||||||||||||
private final DropStatsProcedure hiveDropStatsProcedure; | ||||||||||||||||||||||
|
||||||||||||||||||||||
@Inject | ||||||||||||||||||||||
public LakehouseDropStatsProcedure( | ||||||||||||||||||||||
DropExtendedStatsProcedure deltaLakeDropStatsProcedure, | ||||||||||||||||||||||
DropStatsProcedure hiveDropStatsProcedure) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
this.deltaLakeDropStatsProcedure = requireNonNull(deltaLakeDropStatsProcedure, "deltaLakeDropStatsProcedure is null"); | ||||||||||||||||||||||
this.hiveDropStatsProcedure = requireNonNull(hiveDropStatsProcedure, "hiveDropStatsProcedure is null"); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
@Override | ||||||||||||||||||||||
public Procedure get() | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
return new Procedure( | ||||||||||||||||||||||
SYSTEM_SCHEMA, | ||||||||||||||||||||||
PROCEDURE_NAME, | ||||||||||||||||||||||
ImmutableList.of( | ||||||||||||||||||||||
new Procedure.Argument(TABLE_TYPE, VARCHAR), | ||||||||||||||||||||||
new Procedure.Argument(SCHEMA_NAME, VARCHAR), | ||||||||||||||||||||||
new Procedure.Argument(TABLE_NAME, VARCHAR), | ||||||||||||||||||||||
new Procedure.Argument(PARTITION_VALUES, new ArrayType(new ArrayType(VARCHAR)), false, null)), | ||||||||||||||||||||||
DROP_STATS.bindTo(this)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public void dropStats(ConnectorSession session, ConnectorAccessControl accessControl, String tableType, String schema, String table, List<?> partitionValues) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
if (TableType.DELTA.name().equals(tableType)) { | ||||||||||||||||||||||
if (partitionValues != null) { | ||||||||||||||||||||||
throw new IllegalArgumentException("Partition values are not supported for Delta Lake procedure"); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
deltaLakeDropStatsProcedure.dropStats(session, accessControl, schema, table); | ||||||||||||||||||||||
Comment on lines
+91
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Partition values check for Delta Lake could be stricter. Also check that partitionValues is not empty to prevent unintended acceptance of empty lists.
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
else if (TableType.HIVE.name().equals(tableType)) { | ||||||||||||||||||||||
hiveDropStatsProcedure.dropStats(session, accessControl, schema, table, partitionValues); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
else { | ||||||||||||||||||||||
throw new IllegalArgumentException("Unsupported table type: " + tableType); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
107 changes: 107 additions & 0 deletions
107
.../main/java/io/trino/plugin/lakehouse/procedures/LakehouseFlushMetadataCacheProcedure.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,107 @@ | ||
/* | ||
* 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.plugin.lakehouse.procedures; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.inject.Inject; | ||
import com.google.inject.Provider; | ||
import io.trino.plugin.deltalake.procedure.FlushMetadataCacheProcedure; | ||
import io.trino.plugin.lakehouse.TableType; | ||
import io.trino.spi.connector.ConnectorSession; | ||
import io.trino.spi.procedure.Procedure; | ||
import io.trino.spi.type.ArrayType; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.util.List; | ||
|
||
import static io.trino.spi.type.VarcharType.VARCHAR; | ||
import static java.lang.invoke.MethodHandles.lookup; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* A procedure that flushes the metadata cache for a table or a specific partition of a table. | ||
* <p> | ||
* It is delegated to the appropriate underlying procedure based on the table type. | ||
* Currently, it supports Delta Lake and Hive table types. | ||
*/ | ||
public class LakehouseFlushMetadataCacheProcedure | ||
implements Provider<Procedure> | ||
{ | ||
private static final MethodHandle FLUSH_METADATA_CACHE; | ||
|
||
private static final String SYSTEM_SCHEMA = "system"; | ||
private static final String PROCEDURE_NAME = "flush_metadata_cache"; | ||
|
||
private static final String TABLE_TYPE = "TABLE_TYPE"; | ||
private static final String SCHEMA_NAME = "SCHEMA_NAME"; | ||
private static final String TABLE_NAME = "TABLE_NAME"; | ||
private static final String PARAM_PARTITION_COLUMNS = "PARTITION_COLUMNS"; | ||
private static final String PARAM_PARTITION_VALUES = "PARTITION_VALUES"; | ||
|
||
static { | ||
try { | ||
FLUSH_METADATA_CACHE = lookup().unreflect(LakehouseFlushMetadataCacheProcedure.class.getMethod( | ||
"flushMetadataCache", ConnectorSession.class, String.class, String.class, String.class, List.class, List.class)); | ||
} | ||
catch (ReflectiveOperationException e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
|
||
private final FlushMetadataCacheProcedure deltaLakeFlushMetadataCacheProcedure; | ||
private final io.trino.plugin.hive.procedure.FlushMetadataCacheProcedure hiveFlushMetadataCacheProcedure; | ||
|
||
@Inject | ||
public LakehouseFlushMetadataCacheProcedure( | ||
FlushMetadataCacheProcedure deltaLakeFlushMetadataCacheProcedure, | ||
io.trino.plugin.hive.procedure.FlushMetadataCacheProcedure hiveFlushMetadataCacheProcedure) | ||
{ | ||
this.deltaLakeFlushMetadataCacheProcedure = requireNonNull(deltaLakeFlushMetadataCacheProcedure, "deltaLakeFlushMetadataCacheProcedure is null"); | ||
this.hiveFlushMetadataCacheProcedure = requireNonNull(hiveFlushMetadataCacheProcedure, "hiveFlushMetadataCacheProcedure is null"); | ||
} | ||
|
||
@Override | ||
public Procedure get() | ||
{ | ||
return new Procedure( | ||
SYSTEM_SCHEMA, | ||
PROCEDURE_NAME, | ||
ImmutableList.of( | ||
new Procedure.Argument(TABLE_TYPE, VARCHAR), | ||
new Procedure.Argument(SCHEMA_NAME, VARCHAR), | ||
new Procedure.Argument(TABLE_NAME, VARCHAR), | ||
new Procedure.Argument(PARAM_PARTITION_COLUMNS, new ArrayType(VARCHAR), false, null), | ||
new Procedure.Argument(PARAM_PARTITION_VALUES, new ArrayType(VARCHAR), false, null)), | ||
FLUSH_METADATA_CACHE.bindTo(this)); | ||
} | ||
|
||
public void flushMetadataCache(ConnectorSession session, String tableType, String schema, String table, List<String> partitionColumns, List<String> partitionValues) | ||
{ | ||
if (TableType.DELTA.name().equals(tableType)) { | ||
if (partitionColumns != null && !partitionColumns.isEmpty()) { | ||
throw new IllegalArgumentException("Partition columns are not supported for Delta Lake tables"); | ||
} | ||
if (partitionValues != null && !partitionValues.isEmpty()) { | ||
throw new IllegalArgumentException("Partition values are not supported for Delta Lake tables"); | ||
} | ||
deltaLakeFlushMetadataCacheProcedure.flushMetadataCache(schema, table); | ||
} | ||
else if (TableType.HIVE.name().equals(tableType)) { | ||
hiveFlushMetadataCacheProcedure.flushMetadataCache(session, schema, table, partitionColumns, partitionValues); | ||
} | ||
else { | ||
throw new IllegalArgumentException("Unsupported table type: " + tableType); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a more specific type for partitionValues.
List<?> reduces type safety. If partitionValues should be List<List>, use that type to prevent runtime errors and improve code clarity.
Suggested implementation: