Skip to content

Commit c796929

Browse files
committed
moved helpers to MetaStoreUtils
Change-Id: Ic0fefede8b079205c5580a31f59f195b6b1e94e0
1 parent abf1903 commit c796929

4 files changed

Lines changed: 31 additions & 25 deletions

File tree

iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.commons.lang3.StringUtils;
3535
import org.apache.hadoop.conf.Configuration;
3636
import org.apache.hadoop.hive.metastore.HiveMetaHook;
37-
import org.apache.hadoop.hive.metastore.TableType;
3837
import org.apache.hadoop.hive.metastore.api.CreateTableRequest;
3938
import org.apache.hadoop.hive.metastore.api.EnvironmentContext;
4039
import org.apache.hadoop.hive.metastore.api.FieldSchema;
@@ -79,6 +78,7 @@
7978
import org.slf4j.Logger;
8079
import org.slf4j.LoggerFactory;
8180

81+
import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.isIcebergView;
8282
import static org.apache.iceberg.RowLevelOperationMode.MERGE_ON_READ;
8383
import static org.apache.iceberg.mr.InputFormatConfig.SORT_COLUMNS;
8484
import static org.apache.iceberg.mr.InputFormatConfig.SORT_ORDER;
@@ -118,16 +118,6 @@ public BaseHiveIcebergMetaHook(Configuration conf) {
118118
this.conf = conf;
119119
}
120120

121-
public static boolean isIcebergView(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
122-
if (hmsTable == null ||
123-
hmsTable.getParameters() == null ||
124-
!TableType.VIRTUAL_VIEW.toString().equals(hmsTable.getTableType())) {
125-
return false;
126-
}
127-
String storageHandler = hmsTable.getParameters().get(hive_metastoreConstants.META_TABLE_STORAGE);
128-
return HiveMetaHook.HIVE_ICEBERG_STORAGE_HANDLER.equals(storageHandler);
129-
}
130-
131121
@Override
132122
public void preCreateTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
133123
CreateTableRequest request = new CreateTableRequest(hmsTable);

iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@
143143
import org.slf4j.Logger;
144144
import org.slf4j.LoggerFactory;
145145

146+
import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.isIcebergView;
147+
146148
public class HiveIcebergMetaHook extends BaseHiveIcebergMetaHook {
147149
private static final Logger LOG = LoggerFactory.getLogger(HiveIcebergMetaHook.class);
148150
static final EnumSet<AlterTableType> SUPPORTED_ALTER_OPS = EnumSet.of(
@@ -266,7 +268,7 @@ public void commitDropTable(org.apache.hadoop.hive.metastore.api.Table hmsTable,
266268
@Override
267269
public void preAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTable, EnvironmentContext context)
268270
throws MetaException {
269-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable)) {
271+
if (isIcebergView(hmsTable)) {
270272
currentAlterTableOp = null;
271273
if (commitLock == null) {
272274
commitLock = new NoLock();
@@ -503,7 +505,7 @@ public void commitAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTable
503505
if (commitLock == null) {
504506
throw new IllegalStateException("Hive commit lock should already be set");
505507
}
506-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable)) {
508+
if (isIcebergView(hmsTable)) {
507509
tableProperties = IcebergTableProperties.getTableProperties(hmsTable, conf);
508510
Map<String, String> tblProps =
509511
hmsTable.getParameters() == null ? Maps.newHashMap() : Maps.newHashMap(hmsTable.getParameters());

iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public boolean canProvidePartitionStatistics(org.apache.hadoop.hive.ql.metadata.
433433
if (!getStatsSource().equals(HiveMetaHook.ICEBERG)) {
434434
return false;
435435
}
436-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable.getTTable())) {
436+
if (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
437437
return false;
438438
}
439439
Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
@@ -899,7 +899,7 @@ public boolean supportsPartitionTransform() {
899899

900900
@Override
901901
public List<TransformSpec> getPartitionTransformSpec(org.apache.hadoop.hive.ql.metadata.Table hmsTable) {
902-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable.getTTable())) {
902+
if (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
903903
return Collections.emptyList();
904904
}
905905
Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
@@ -916,7 +916,7 @@ public List<TransformSpec> getPartitionTransformSpec(org.apache.hadoop.hive.ql.m
916916
@Override
917917
public Map<Integer, List<TransformSpec>> getPartitionTransformSpecs(
918918
org.apache.hadoop.hive.ql.metadata.Table hmsTable) {
919-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable.getTTable())) {
919+
if (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
920920
return Collections.emptyMap();
921921
}
922922
Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
@@ -1584,7 +1584,7 @@ public boolean supportsSortColumns() {
15841584

15851585
@Override
15861586
public List<FieldSchema> sortColumns(org.apache.hadoop.hive.ql.metadata.Table hmsTable) {
1587-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable.getTTable())) {
1587+
if (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
15881588
return Collections.emptyList();
15891589
}
15901590
TableDesc tableDesc = Utilities.getTableDesc(hmsTable);
@@ -2147,13 +2147,12 @@ public List<Partition> getPartitions(org.apache.hadoop.hive.ql.metadata.Table hm
21472147
}
21482148

21492149
public boolean isPartitioned(org.apache.hadoop.hive.ql.metadata.Table hmsTable) {
2150-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable.getTTable()) ||
2151-
!MetaStoreUtils.isIcebergTable(hmsTable.getParameters())) {
2152-
return !hmsTable.getPartitionKeys().isEmpty();
2153-
}
21542150
if (hmsTable.getMetaTable() != null || !hmsTable.getTTable().isSetId()) {
21552151
return false;
21562152
}
2153+
if (MetaStoreUtils.lacksIcebergPartSpec(hmsTable.getTTable())) {
2154+
return !hmsTable.getPartitionKeys().isEmpty();
2155+
}
21572156
Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
21582157
Snapshot snapshot = IcebergTableUtil.getTableSnapshot(table, hmsTable);
21592158

@@ -2296,13 +2295,12 @@ public boolean canPerformMetadataDelete(org.apache.hadoop.hive.ql.metadata.Table
22962295

22972296
@Override
22982297
public List<FieldSchema> getPartitionKeys(org.apache.hadoop.hive.ql.metadata.Table hmsTable) {
2299-
if (BaseHiveIcebergMetaHook.isIcebergView(hmsTable.getTTable()) ||
2300-
!MetaStoreUtils.isIcebergTable(hmsTable.getParameters())) {
2301-
return hmsTable.getPartitionKeys();
2302-
}
23032298
if (hmsTable.getMetaTable() != null || !hmsTable.getTTable().isSetId()) {
23042299
return Collections.emptyList();
23052300
}
2301+
if (MetaStoreUtils.lacksIcebergPartSpec(hmsTable.getTTable())) {
2302+
return hmsTable.getPartitionKeys();
2303+
}
23062304
Table icebergTable = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
23072305
return MetastoreUtil.getPartitionKeys(icebergTable, icebergTable.spec().specId());
23082306
}

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,22 @@ public static boolean isIcebergTable(Map<String, String> params) {
300300
HiveMetaHook.ICEBERG.equalsIgnoreCase(params.get(HiveMetaHook.TABLE_TYPE));
301301
}
302302

303+
public static boolean isIcebergView(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
304+
if (hmsTable == null ||
305+
hmsTable.getParameters() == null ||
306+
!TableType.VIRTUAL_VIEW.toString().equals(hmsTable.getTableType())) {
307+
return false;
308+
}
309+
String storageHandler = hmsTable.getParameters().get(hive_metastoreConstants.META_TABLE_STORAGE);
310+
return HiveMetaHook.HIVE_ICEBERG_STORAGE_HANDLER.equals(storageHandler);
311+
}
312+
313+
/** Checks whether the table lacks an Iceberg metadata part spec ({@link #isIcebergView} or
314+
* {@code table_type != ICEBERG}). */
315+
public static boolean lacksIcebergPartSpec(org.apache.hadoop.hive.metastore.api.Table table) {
316+
return isIcebergView(table) || !isIcebergTable(table.getParameters());
317+
}
318+
303319
public static boolean isIcebergTable(Properties params) {
304320
return HiveMetaHook.ICEBERG.equalsIgnoreCase((String) params.get(HiveMetaHook.TABLE_TYPE));
305321
}

0 commit comments

Comments
 (0)