From 5f7b26ea54c5ea47a98893e7c8f0e2cae1c2b96f Mon Sep 17 00:00:00 2001 From: David Phillips Date: Wed, 9 Aug 2023 21:15:45 -0700 Subject: [PATCH] Revert "Reduce redundant code in procedure declarations" This reverts commit 3c1cc8e410ab9f972fcb705405451e231497ef70. IntelliJ understands reflection getMethod calls, allowing navigation to the method, marking the method as used, code completion for the calls, warning if the method cannot be resolved, etc. Unfortunately, none of this works when the reflection is hidden behind a utility. --- .../io/trino/plugin/base/util/Reflection.java | 47 ------------------- .../FlushJdbcMetadataCacheProcedure.java | 13 ++++- .../procedure/DropExtendedStatsProcedure.java | 13 ++++- .../FlushMetadataCacheProcedure.java | 13 ++++- .../procedure/RegisterTableProcedure.java | 13 ++++- .../procedure/UnregisterTableProcedure.java | 13 ++++- .../deltalake/procedure/VacuumProcedure.java | 13 ++++- .../FlushMetadataCacheProcedure.java | 15 ++++-- .../WriteHiveMetastoreRecordingProcedure.java | 13 ++++- .../CreateEmptyPartitionProcedure.java | 13 ++++- .../hive/procedure/DropStatsProcedure.java | 13 ++++- .../procedure/RegisterPartitionProcedure.java | 13 ++++- .../SyncPartitionMetadataProcedure.java | 13 ++++- .../UnregisterPartitionProcedure.java | 13 ++++- .../iceberg/RollbackToSnapshotProcedure.java | 13 ++++- .../iceberg/procedure/MigrateProcedure.java | 13 ++++- .../procedure/RegisterTableProcedure.java | 13 ++++- .../procedure/UnregisterTableProcedure.java | 13 ++++- .../procedures/RangePartitionProcedures.java | 16 +++++-- 19 files changed, 201 insertions(+), 85 deletions(-) delete mode 100644 lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/util/Reflection.java 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 deleted file mode 100644 index f6c60cc93a31..000000000000 --- a/lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/util/Reflection.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 bc44599f7a67..78da58f40768 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,13 +23,22 @@ import java.lang.invoke.MethodHandle; import java.util.Optional; -import static io.trino.plugin.base.util.Reflection.methodHandle; +import static java.lang.invoke.MethodHandles.lookup; import static java.util.Objects.requireNonNull; public class FlushJdbcMetadataCacheProcedure implements Provider { - private static final MethodHandle FLUSH_JDBC_METADATA_CACHE = methodHandle(FlushJdbcMetadataCacheProcedure.class, "flushMetadataCache"); + 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 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 251d073aa304..6728b496a9c6 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,16 +30,25 @@ 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 = methodHandle(DropExtendedStatsProcedure.class, "dropStats", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class); + 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 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 a24c5125c186..94bde897865b 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,7 +40,16 @@ 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 = methodHandle(FlushMetadataCacheProcedure.class, "flushMetadataCache", String.class, String.class); + 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 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 e2278700e0ef..5bdb437f3dfa 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,7 +40,6 @@ 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; @@ -50,12 +49,13 @@ 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 = methodHandle(RegisterTableProcedure.class, "registerTable", ConnectorSession.class, String.class, String.class, String.class); + private static final MethodHandle REGISTER_TABLE; private static final String PROCEDURE_NAME = "register_table"; private static final String SYSTEM_SCHEMA = "system"; @@ -64,6 +64,15 @@ 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 acee81d8fc35..9d800ec8d61e 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 = methodHandle(UnregisterTableProcedure.class, "unregisterTable", ConnectorAccessControl.class, ConnectorSession.class, String.class, String.class); + private static final MethodHandle UNREGISTER_TABLE; private static final String PROCEDURE_NAME = "unregister_table"; private static final String SYSTEM_SCHEMA = "system"; @@ -48,6 +48,15 @@ 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 c4b0b1e44b31..138afe6ec6f4 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,7 +57,6 @@ 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; @@ -66,6 +65,7 @@ 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,7 +75,16 @@ 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 = methodHandle(VacuumProcedure.class, "vacuum", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, String.class); + 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 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 44d5400404a7..0daf0cef0419 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,8 +69,17 @@ public class FlushMetadataCacheProcedure PARAM_PARTITION_COLUMN.toLowerCase(ENGLISH), PARAM_PARTITION_VALUE.toLowerCase(ENGLISH)); - 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 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 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 cf595d84104e..1827d3a53047 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,13 +22,22 @@ import java.io.IOException; import java.lang.invoke.MethodHandle; -import static io.trino.plugin.base.util.Reflection.methodHandle; +import static java.lang.invoke.MethodHandles.lookup; import static java.util.Objects.requireNonNull; public class WriteHiveMetastoreRecordingProcedure implements Provider { - private static final MethodHandle WRITE_HIVE_METASTORE_RECORDING = methodHandle(WriteHiveMetastoreRecordingProcedure.class, "writeHiveMetastoreRecording"); + 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 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 55f10a59de77..6a1096222001 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,19 +45,28 @@ 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 = methodHandle(CreateEmptyPartitionProcedure.class, "createEmptyPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class); + 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 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 2b83e00d5124..834784802597 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,7 +55,16 @@ public class DropStatsProcedure implements Provider { - private static final MethodHandle DROP_STATS = methodHandle(DropStatsProcedure.class, "dropStats", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class); + 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 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 ae00e4095d8d..308655d520c1 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,7 +42,6 @@ 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; @@ -52,12 +51,22 @@ 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 = methodHandle(RegisterPartitionProcedure.class, "registerPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class, String.class); + 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 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 00b995a096f7..f25b56bd9917 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,7 +50,6 @@ 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; @@ -58,6 +57,7 @@ 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,7 +71,16 @@ public enum SyncMode private static final int BATCH_GET_PARTITIONS_BY_NAMES_MAX_PAGE_SIZE = 1000; - private static final MethodHandle SYNC_PARTITION_METADATA = methodHandle(SyncPartitionMetadataProcedure.class, "syncPartitionMetadata", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, String.class, boolean.class); + 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 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 cf05c4234a17..2ff444f2f30e 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,19 +33,28 @@ 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 = methodHandle(UnregisterPartitionProcedure.class, "unregisterPartition", ConnectorSession.class, ConnectorAccessControl.class, String.class, String.class, List.class, List.class); + 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 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 266863960ed1..7a64bd520ffb 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,15 +26,24 @@ 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 = methodHandle(RollbackToSnapshotProcedure.class, "rollbackToSnapshot", ConnectorSession.class, String.class, String.class, Long.class); + 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 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 6dbfa02e2a16..6c57853c9e4b 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,7 +84,6 @@ 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; @@ -102,6 +101,7 @@ 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,7 +137,16 @@ private enum RecursiveDirectory /**/ } - private static final MethodHandle MIGRATE = methodHandle(MigrateProcedure.class, "migrate", ConnectorSession.class, String.class, String.class, String.class); + 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); + } + } @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 7212047711fa..8c8984247c2a 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,7 +41,6 @@ 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; @@ -52,13 +51,14 @@ 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 = methodHandle(RegisterTableProcedure.class, "registerTable", ConnectorSession.class, String.class, String.class, String.class, String.class); + private static final MethodHandle REGISTER_TABLE; private static final String PROCEDURE_NAME = "register_table"; private static final String SYSTEM_SCHEMA = "system"; @@ -68,6 +68,15 @@ 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 745f15fc8723..f12ad559fcb5 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 = methodHandle(UnregisterTableProcedure.class, "unregisterTable", ConnectorAccessControl.class, ConnectorSession.class, String.class, String.class); + private static final MethodHandle UNREGISTER_TABLE; private static final String PROCEDURE_NAME = "unregister_table"; private static final String SYSTEM_SCHEMA = "system"; @@ -44,6 +44,15 @@ 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 8ffc726590cc..14e15ce5bae2 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,14 +24,24 @@ 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 = 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 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 final KuduClientSession clientSession;