diff --git a/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/util/Reflection.java b/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/util/Reflection.java
new file mode 100644
index 000000000000..f6c60cc93a31
--- /dev/null
+++ b/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/util/Reflection.java
@@ -0,0 +1,47 @@
+/*
+ * 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.base.util;
+
+import io.trino.spi.TrinoException;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+
+import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
+
+/**
+ * @apiNote This mirrors {@code io.trino.util.Reflection}.
+ */
+public final class Reflection
+{
+ private Reflection() {}
+
+ /**
+ * Returns a MethodHandle corresponding to the specified method.
+ *
+ * Warning: The way Oracle JVM implements producing MethodHandle for a method involves creating
+ * JNI global weak references. G1 processes such references serially. As a result, calling this
+ * method in a tight loop can create significant GC pressure and significantly increase
+ * application pause time.
+ */
+ public static MethodHandle methodHandle(Class> clazz, String name, Class>... parameterTypes)
+ {
+ try {
+ return MethodHandles.lookup().unreflect(clazz.getMethod(name, parameterTypes));
+ }
+ catch (IllegalAccessException | NoSuchMethodException e) {
+ throw new TrinoException(GENERIC_INTERNAL_ERROR, e);
+ }
+ }
+}
diff --git a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/procedure/FlushJdbcMetadataCacheProcedure.java b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/procedure/FlushJdbcMetadataCacheProcedure.java
index 78da58f40768..bc44599f7a67 100644
--- a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/procedure/FlushJdbcMetadataCacheProcedure.java
+++ b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/procedure/FlushJdbcMetadataCacheProcedure.java
@@ -23,22 +23,13 @@
import java.lang.invoke.MethodHandle;
import java.util.Optional;
-import static java.lang.invoke.MethodHandles.lookup;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static java.util.Objects.requireNonNull;
public class FlushJdbcMetadataCacheProcedure
implements Provider
{
- private static final MethodHandle FLUSH_JDBC_METADATA_CACHE;
-
- static {
- try {
- FLUSH_JDBC_METADATA_CACHE = lookup().unreflect(FlushJdbcMetadataCacheProcedure.class.getMethod("flushMetadataCache"));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle FLUSH_JDBC_METADATA_CACHE = methodHandle(FlushJdbcMetadataCacheProcedure.class, "flushMetadataCache");
private final CachingJdbcClient cachingJdbcClient;
private final Optional cachingIdentifierMapping;
diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/DropExtendedStatsProcedure.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/DropExtendedStatsProcedure.java
index 6728b496a9c6..251d073aa304 100644
--- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/DropExtendedStatsProcedure.java
+++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/DropExtendedStatsProcedure.java
@@ -30,25 +30,16 @@
import java.util.List;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class DropExtendedStatsProcedure
implements Provider
{
- private static final MethodHandle PROCEDURE_METHOD;
-
- static {
- try {
- PROCEDURE_METHOD = lookup().unreflect(DropExtendedStatsProcedure.class.getMethod("dropStats", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle PROCEDURE_METHOD = methodHandle(DropExtendedStatsProcedure.class, "dropStats", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class);
private final DeltaLakeMetadataFactory metadataFactory;
private final ExtendedStatisticsAccess statsAccess;
diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/FlushMetadataCacheProcedure.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/FlushMetadataCacheProcedure.java
index 94bde897865b..a24c5125c186 100644
--- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/FlushMetadataCacheProcedure.java
+++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/FlushMetadataCacheProcedure.java
@@ -27,9 +27,9 @@
import java.lang.invoke.MethodHandle;
import java.util.Optional;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT;
import static io.trino.spi.type.VarcharType.VARCHAR;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class FlushMetadataCacheProcedure
@@ -40,16 +40,7 @@ public class FlushMetadataCacheProcedure
private static final String PARAM_SCHEMA_NAME = "SCHEMA_NAME";
private static final String PARAM_TABLE_NAME = "TABLE_NAME";
- private static final MethodHandle FLUSH_METADATA_CACHE;
-
- static {
- try {
- FLUSH_METADATA_CACHE = lookup().unreflect(FlushMetadataCacheProcedure.class.getMethod("flushMetadataCache", String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle FLUSH_METADATA_CACHE = methodHandle(FlushMetadataCacheProcedure.class, "flushMetadataCache", String.class, String.class);
private final Optional cachingHiveMetastore;
private final TransactionLogAccess transactionLogAccess;
diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/RegisterTableProcedure.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/RegisterTableProcedure.java
index 5bdb437f3dfa..e2278700e0ef 100644
--- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/RegisterTableProcedure.java
+++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/RegisterTableProcedure.java
@@ -40,6 +40,7 @@
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.deltalake.DeltaLakeErrorCode.DELTA_LAKE_FILESYSTEM_ERROR;
import static io.trino.plugin.deltalake.DeltaLakeErrorCode.DELTA_LAKE_INVALID_TABLE;
import static io.trino.plugin.deltalake.DeltaLakeMetadata.buildTable;
@@ -49,13 +50,12 @@
import static io.trino.spi.StandardErrorCode.PERMISSION_DENIED;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class RegisterTableProcedure
implements Provider
{
- private static final MethodHandle REGISTER_TABLE;
+ private static final MethodHandle REGISTER_TABLE = methodHandle(RegisterTableProcedure.class, "registerTable", ConnectorSession.class, String.class, String.class, String.class);
private static final String PROCEDURE_NAME = "register_table";
private static final String SYSTEM_SCHEMA = "system";
@@ -64,15 +64,6 @@ public class RegisterTableProcedure
private static final String TABLE_NAME = "TABLE_NAME";
private static final String TABLE_LOCATION = "TABLE_LOCATION";
- static {
- try {
- REGISTER_TABLE = lookup().unreflect(RegisterTableProcedure.class.getMethod("registerTable", ConnectorSession.class, String.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
-
private final DeltaLakeMetadataFactory metadataFactory;
private final TransactionLogAccess transactionLogAccess;
private final CachingExtendedStatisticsAccess statisticsAccess;
diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/UnregisterTableProcedure.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/UnregisterTableProcedure.java
index 9d800ec8d61e..acee81d8fc35 100644
--- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/UnregisterTableProcedure.java
+++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/UnregisterTableProcedure.java
@@ -33,14 +33,14 @@
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.spi.type.VarcharType.VARCHAR;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class UnregisterTableProcedure
implements Provider
{
- private static final MethodHandle UNREGISTER_TABLE;
+ private static final MethodHandle UNREGISTER_TABLE = methodHandle(UnregisterTableProcedure.class, "unregisterTable", ConnectorAccessControl.class, ConnectorSession.class, String.class, String.class);
private static final String PROCEDURE_NAME = "unregister_table";
private static final String SYSTEM_SCHEMA = "system";
@@ -48,15 +48,6 @@ public class UnregisterTableProcedure
private static final String SCHEMA_NAME = "SCHEMA_NAME";
private static final String TABLE_NAME = "TABLE_NAME";
- static {
- try {
- UNREGISTER_TABLE = lookup().unreflect(UnregisterTableProcedure.class.getMethod("unregisterTable", ConnectorAccessControl.class, ConnectorSession.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
-
private final DeltaLakeMetadataFactory metadataFactory;
private final TransactionLogAccess transactionLogAccess;
private final CachingExtendedStatisticsAccess statisticsAccess;
diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/VacuumProcedure.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/VacuumProcedure.java
index 138afe6ec6f4..c4b0b1e44b31 100644
--- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/VacuumProcedure.java
+++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/procedure/VacuumProcedure.java
@@ -57,6 +57,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.deltalake.DeltaLakeMetadata.MAX_WRITER_VERSION;
import static io.trino.plugin.deltalake.DeltaLakeMetadata.checkValidTableHandle;
import static io.trino.plugin.deltalake.DeltaLakeSessionProperties.getVacuumMinRetention;
@@ -65,7 +66,6 @@
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Comparator.naturalOrder;
import static java.util.Objects.requireNonNull;
@@ -75,16 +75,7 @@ public class VacuumProcedure
private static final Logger log = Logger.get(VacuumProcedure.class);
private static final int DELETE_BATCH_SIZE = 1000;
- private static final MethodHandle VACUUM;
-
- static {
- try {
- VACUUM = lookup().unreflect(VacuumProcedure.class.getMethod("vacuum", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle VACUUM = methodHandle(VacuumProcedure.class, "vacuum", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, String.class);
private final CatalogName catalogName;
private final TrinoFileSystemFactory fileSystemFactory;
diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/procedure/FlushMetadataCacheProcedure.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/procedure/FlushMetadataCacheProcedure.java
index 0daf0cef0419..44d5400404a7 100644
--- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/procedure/FlushMetadataCacheProcedure.java
+++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/procedure/FlushMetadataCacheProcedure.java
@@ -29,9 +29,9 @@
import java.util.Optional;
import static com.google.common.base.Preconditions.checkState;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
@@ -69,17 +69,8 @@ public class FlushMetadataCacheProcedure
PARAM_PARTITION_COLUMN.toLowerCase(ENGLISH),
PARAM_PARTITION_VALUE.toLowerCase(ENGLISH));
- private static final MethodHandle FLUSH_HIVE_METASTORE_CACHE;
-
- static {
- try {
- FLUSH_HIVE_METASTORE_CACHE = lookup().unreflect(FlushMetadataCacheProcedure.class.getMethod(
- "flushMetadataCache", String.class, String.class, List.class, List.class, List.class, List.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle FLUSH_HIVE_METASTORE_CACHE = methodHandle(FlushMetadataCacheProcedure.class,
+ "flushMetadataCache", String.class, String.class, List.class, List.class, List.class, List.class);
private final Optional cachingHiveMetastore;
diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/recording/WriteHiveMetastoreRecordingProcedure.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/recording/WriteHiveMetastoreRecordingProcedure.java
index 1827d3a53047..cf595d84104e 100644
--- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/recording/WriteHiveMetastoreRecordingProcedure.java
+++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/recording/WriteHiveMetastoreRecordingProcedure.java
@@ -22,22 +22,13 @@
import java.io.IOException;
import java.lang.invoke.MethodHandle;
-import static java.lang.invoke.MethodHandles.lookup;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static java.util.Objects.requireNonNull;
public class WriteHiveMetastoreRecordingProcedure
implements Provider
{
- private static final MethodHandle WRITE_HIVE_METASTORE_RECORDING;
-
- static {
- try {
- WRITE_HIVE_METASTORE_RECORDING = lookup().unreflect(WriteHiveMetastoreRecordingProcedure.class.getMethod("writeHiveMetastoreRecording"));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle WRITE_HIVE_METASTORE_RECORDING = methodHandle(WriteHiveMetastoreRecordingProcedure.class, "writeHiveMetastoreRecording");
private final RateLimiter rateLimiter = RateLimiter.create(0.2);
private final HiveMetastoreRecording hiveMetastoreRecording;
diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/CreateEmptyPartitionProcedure.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/CreateEmptyPartitionProcedure.java
index 6a1096222001..55f10a59de77 100644
--- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/CreateEmptyPartitionProcedure.java
+++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/CreateEmptyPartitionProcedure.java
@@ -45,28 +45,19 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.hive.util.HiveUtil.makePartName;
import static io.trino.spi.StandardErrorCode.ALREADY_EXISTS;
import static io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT;
import static io.trino.spi.connector.RetryMode.NO_RETRIES;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class CreateEmptyPartitionProcedure
implements Provider
{
- private static final MethodHandle CREATE_EMPTY_PARTITION;
-
- static {
- try {
- CREATE_EMPTY_PARTITION = lookup().unreflect(CreateEmptyPartitionProcedure.class.getMethod("createEmptyPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle CREATE_EMPTY_PARTITION = methodHandle(CreateEmptyPartitionProcedure.class, "createEmptyPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class);
private final TransactionalMetadataFactory hiveMetadataFactory;
private final LocationService locationService;
diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/DropStatsProcedure.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/DropStatsProcedure.java
index 834784802597..2b83e00d5124 100644
--- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/DropStatsProcedure.java
+++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/DropStatsProcedure.java
@@ -39,12 +39,12 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.hive.acid.AcidTransaction.NO_ACID_TRANSACTION;
import static io.trino.plugin.hive.util.HiveUtil.makePartName;
import static io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
/**
@@ -55,16 +55,7 @@
public class DropStatsProcedure
implements Provider
{
- private static final MethodHandle DROP_STATS;
-
- static {
- try {
- DROP_STATS = lookup().unreflect(DropStatsProcedure.class.getMethod("dropStats", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle DROP_STATS = methodHandle(DropStatsProcedure.class, "dropStats", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class);
private final TransactionalMetadataFactory hiveMetadataFactory;
diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/RegisterPartitionProcedure.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/RegisterPartitionProcedure.java
index 308655d520c1..ae00e4095d8d 100644
--- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/RegisterPartitionProcedure.java
+++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/RegisterPartitionProcedure.java
@@ -42,6 +42,7 @@
import java.util.Optional;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.hive.HiveMetadata.PRESTO_QUERY_ID_NAME;
import static io.trino.plugin.hive.procedure.Procedures.checkIsPartitionedTable;
import static io.trino.plugin.hive.procedure.Procedures.checkPartitionColumns;
@@ -51,22 +52,12 @@
import static io.trino.spi.StandardErrorCode.PERMISSION_DENIED;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class RegisterPartitionProcedure
implements Provider
{
- private static final MethodHandle REGISTER_PARTITION;
-
- static {
- try {
- REGISTER_PARTITION = lookup().unreflect(RegisterPartitionProcedure.class.getMethod("registerPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle REGISTER_PARTITION = methodHandle(RegisterPartitionProcedure.class, "registerPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class, String.class);
private final boolean allowRegisterPartition;
private final TransactionalMetadataFactory hiveMetadataFactory;
diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/SyncPartitionMetadataProcedure.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/SyncPartitionMetadataProcedure.java
index f25b56bd9917..00b995a096f7 100644
--- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/SyncPartitionMetadataProcedure.java
+++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/SyncPartitionMetadataProcedure.java
@@ -50,6 +50,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR;
import static io.trino.plugin.hive.HiveMetadata.PRESTO_QUERY_ID_NAME;
import static io.trino.plugin.hive.HivePartitionManager.extractPartitionValues;
@@ -57,7 +58,6 @@
import static io.trino.spi.type.BooleanType.BOOLEAN;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.Boolean.TRUE;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
@@ -71,16 +71,7 @@ public enum SyncMode
private static final int BATCH_GET_PARTITIONS_BY_NAMES_MAX_PAGE_SIZE = 1000;
- private static final MethodHandle SYNC_PARTITION_METADATA;
-
- static {
- try {
- SYNC_PARTITION_METADATA = lookup().unreflect(SyncPartitionMetadataProcedure.class.getMethod("syncPartitionMetadata", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, String.class, boolean.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle SYNC_PARTITION_METADATA = methodHandle(SyncPartitionMetadataProcedure.class, "syncPartitionMetadata", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, String.class, boolean.class);
private final TransactionalMetadataFactory hiveMetadataFactory;
private final HdfsEnvironment hdfsEnvironment;
diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/UnregisterPartitionProcedure.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/UnregisterPartitionProcedure.java
index 2ff444f2f30e..cf05c4234a17 100644
--- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/UnregisterPartitionProcedure.java
+++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/procedure/UnregisterPartitionProcedure.java
@@ -33,28 +33,19 @@
import java.util.List;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.hive.procedure.Procedures.checkIsPartitionedTable;
import static io.trino.plugin.hive.procedure.Procedures.checkPartitionColumns;
import static io.trino.plugin.hive.util.HiveUtil.makePartName;
import static io.trino.spi.StandardErrorCode.NOT_FOUND;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class UnregisterPartitionProcedure
implements Provider
{
- private static final MethodHandle UNREGISTER_PARTITION;
-
- static {
- try {
- UNREGISTER_PARTITION = lookup().unreflect(UnregisterPartitionProcedure.class.getMethod("unregisterPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle UNREGISTER_PARTITION = methodHandle(UnregisterPartitionProcedure.class, "unregisterPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class);
private final TransactionalMetadataFactory hiveMetadataFactory;
diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/RollbackToSnapshotProcedure.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/RollbackToSnapshotProcedure.java
index 7a64bd520ffb..266863960ed1 100644
--- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/RollbackToSnapshotProcedure.java
+++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/RollbackToSnapshotProcedure.java
@@ -26,24 +26,15 @@
import java.lang.invoke.MethodHandle;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.VarcharType.VARCHAR;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class RollbackToSnapshotProcedure
implements Provider
{
- private static final MethodHandle ROLLBACK_TO_SNAPSHOT;
-
- static {
- try {
- ROLLBACK_TO_SNAPSHOT = lookup().unreflect(RollbackToSnapshotProcedure.class.getMethod("rollbackToSnapshot", ConnectorSession.class, String.class, String.class, Long.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle ROLLBACK_TO_SNAPSHOT = methodHandle(RollbackToSnapshotProcedure.class, "rollbackToSnapshot", ConnectorSession.class, String.class, String.class, Long.class);
private final TrinoCatalogFactory catalogFactory;
diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/MigrateProcedure.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/MigrateProcedure.java
index 6c57853c9e4b..6dbfa02e2a16 100644
--- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/MigrateProcedure.java
+++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/MigrateProcedure.java
@@ -84,6 +84,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Streams.concat;
import static io.airlift.slice.Slices.utf8Slice;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.hive.HiveMetadata.TRANSACTIONAL;
import static io.trino.plugin.hive.HiveMetadata.extractHiveStorageFormat;
import static io.trino.plugin.hive.metastore.MetastoreUtil.buildInitialPrivilegeSet;
@@ -101,7 +102,6 @@
import static io.trino.spi.type.TinyintType.TINYINT;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.Boolean.parseBoolean;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
import static org.apache.iceberg.BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE;
@@ -137,16 +137,7 @@ private enum RecursiveDirectory
/**/
}
- private static final MethodHandle MIGRATE;
-
- static {
- try {
- MIGRATE = lookup().unreflect(MigrateProcedure.class.getMethod("migrate", ConnectorSession.class, String.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle MIGRATE = methodHandle(MigrateProcedure.class, "migrate", ConnectorSession.class, String.class, String.class, String.class);
@Inject
public MigrateProcedure(
diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/RegisterTableProcedure.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/RegisterTableProcedure.java
index 8c8984247c2a..7212047711fa 100644
--- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/RegisterTableProcedure.java
+++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/RegisterTableProcedure.java
@@ -41,6 +41,7 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.plugin.iceberg.IcebergErrorCode.ICEBERG_FILESYSTEM_ERROR;
import static io.trino.plugin.iceberg.IcebergErrorCode.ICEBERG_INVALID_METADATA;
import static io.trino.plugin.iceberg.IcebergUtil.METADATA_FILE_EXTENSION;
@@ -51,14 +52,13 @@
import static io.trino.spi.StandardErrorCode.SCHEMA_NOT_FOUND;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
import static org.apache.iceberg.util.LocationUtil.stripTrailingSlash;
public class RegisterTableProcedure
implements Provider
{
- private static final MethodHandle REGISTER_TABLE;
+ private static final MethodHandle REGISTER_TABLE = methodHandle(RegisterTableProcedure.class, "registerTable", ConnectorSession.class, String.class, String.class, String.class, String.class);
private static final String PROCEDURE_NAME = "register_table";
private static final String SYSTEM_SCHEMA = "system";
@@ -68,15 +68,6 @@ public class RegisterTableProcedure
private static final String TABLE_LOCATION = "TABLE_LOCATION";
private static final String METADATA_FILE_NAME = "METADATA_FILE_NAME";
- static {
- try {
- REGISTER_TABLE = lookup().unreflect(RegisterTableProcedure.class.getMethod("registerTable", ConnectorSession.class, String.class, String.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
-
private final TrinoCatalogFactory catalogFactory;
private final TrinoFileSystemFactory fileSystemFactory;
private final boolean registerTableProcedureEnabled;
diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/UnregisterTableProcedure.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/UnregisterTableProcedure.java
index f12ad559fcb5..745f15fc8723 100644
--- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/UnregisterTableProcedure.java
+++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/procedure/UnregisterTableProcedure.java
@@ -29,14 +29,14 @@
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.spi.type.VarcharType.VARCHAR;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class UnregisterTableProcedure
implements Provider
{
- private static final MethodHandle UNREGISTER_TABLE;
+ private static final MethodHandle UNREGISTER_TABLE = methodHandle(UnregisterTableProcedure.class, "unregisterTable", ConnectorAccessControl.class, ConnectorSession.class, String.class, String.class);
private static final String PROCEDURE_NAME = "unregister_table";
private static final String SYSTEM_SCHEMA = "system";
@@ -44,15 +44,6 @@ public class UnregisterTableProcedure
private static final String SCHEMA_NAME = "SCHEMA_NAME";
private static final String TABLE_NAME = "TABLE_NAME";
- static {
- try {
- UNREGISTER_TABLE = lookup().unreflect(UnregisterTableProcedure.class.getMethod("unregisterTable", ConnectorAccessControl.class, ConnectorSession.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
-
private final TrinoCatalogFactory catalogFactory;
@Inject
diff --git a/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/procedures/RangePartitionProcedures.java b/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/procedures/RangePartitionProcedures.java
index 14e15ce5bae2..8ffc726590cc 100644
--- a/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/procedures/RangePartitionProcedures.java
+++ b/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/procedures/RangePartitionProcedures.java
@@ -24,24 +24,14 @@
import java.lang.invoke.MethodHandle;
+import static io.trino.plugin.base.util.Reflection.methodHandle;
import static io.trino.spi.type.VarcharType.VARCHAR;
-import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Objects.requireNonNull;
public class RangePartitionProcedures
{
- private static final MethodHandle ADD;
- private static final MethodHandle DROP;
-
- static {
- try {
- ADD = lookup().unreflect(RangePartitionProcedures.class.getMethod("addRangePartition", String.class, String.class, String.class));
- DROP = lookup().unreflect(RangePartitionProcedures.class.getMethod("dropRangePartition", String.class, String.class, String.class));
- }
- catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
+ private static final MethodHandle ADD = methodHandle(RangePartitionProcedures.class, "addRangePartition", String.class, String.class, String.class);
+ private static final MethodHandle DROP = methodHandle(RangePartitionProcedures.class, "dropRangePartition", String.class, String.class, String.class);
private final KuduClientSession clientSession;