dimas-b commented on code in PR #1378:
URL: https://github.com/apache/polaris/pull/1378#discussion_r2051185713
##########
service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java:
##########
@@ -1184,16 +1200,55 @@ public ViewBuilder withLocation(String newLocation) {
}
}
- private class BasePolarisTableOperations extends
BaseMetastoreTableOperations {
+ public class BasePolarisTableOperations extends BaseMetastoreTableOperations
{
private final TableIdentifier tableIdentifier;
private final String fullTableName;
+ private final boolean updateMetadataOnCommit;
private FileIO tableFileIO;
- BasePolarisTableOperations(FileIO defaultFileIO, TableIdentifier
tableIdentifier) {
+ // TODO remove the following if the Iceberg library allows us to do this
without reflection
+ // For more details see:
+ // https://github.com/apache/polaris/pull/1378
+ private static final Unsafe unsafe;
+ private static final Field tableMetadataField;
+ private static final long changesFieldOffset;
+ private static final Field currentMetadataLocationField;
+ private static final Field currentMetadataField;
+
+ static {
+ try {
+ tableMetadataField =
TableMetadata.class.getDeclaredField("metadataFileLocation");
+ tableMetadataField.setAccessible(true);
+
+ Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
+ unsafeField.setAccessible(true);
+ unsafe = (Unsafe) unsafeField.get(null);
+ Field changesField = TableMetadata.class.getDeclaredField("changes");
+ changesField.setAccessible(true);
+ changesFieldOffset = unsafe.objectFieldOffset(changesField);
+
+ currentMetadataLocationField =
+
BaseMetastoreTableOperations.class.getDeclaredField("currentMetadataLocation");
+ currentMetadataLocationField.setAccessible(true);
+
+ currentMetadataField =
+
BaseMetastoreTableOperations.class.getDeclaredField("currentMetadata");
+ currentMetadataField.setAccessible(true);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ LOGGER.error(
+ "Encountered an unexpected error while attempting to access
private fields in TableMetadata",
Review Comment:
If we want to hide reflection behind the same feature flag, we should put it
in a separate utility class with a static `getInstance()` method. This way, the
static code in the utility class will not get triggered until it is used. At
the same time we'll keep the benefit of one time static init.
Something like this:
```
class Util {
private class Instance {
private Util instance = new Util();
}
static Util getInstance() {
return Instance.instance;
}
private Util() {
// reflection here
}
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]