Skip to content

Commit 6cd6aee

Browse files
committed
moved to HiveTableUtil
Change-Id: I5a34151d5ec0d4e1759eee5fcc6339b5fd6b92d3
1 parent 2f8945d commit 6cd6aee

5 files changed

Lines changed: 35 additions & 29 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint;
4141
import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
4242
import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
43-
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
4443
import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFieldDesc;
4544
import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFields;
4645
import org.apache.hadoop.hive.ql.ddl.misc.sortoder.ZOrderFieldDesc;
@@ -130,7 +129,7 @@ public void preCreateTable(CreateTableRequest request) {
130129
if (hmsTable.isTemporary()) {
131130
throw new UnsupportedOperationException("Creation of temporary iceberg tables is not supported.");
132131
}
133-
if (MetaStoreUtils.isIcebergView(hmsTable)) {
132+
if (HiveTableUtil.isIcebergView(hmsTable)) {
134133
preCreateIcebergView(request);
135134
return;
136135
}
@@ -523,7 +522,7 @@ protected void setWriteModeDefaults(Table icebergTbl, Map<String, String> newPro
523522
public void postGetTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
524523
if (hmsTable != null) {
525524
try {
526-
if (MetaStoreUtils.isIcebergView(hmsTable)) {
525+
if (HiveTableUtil.isIcebergView(hmsTable)) {
527526
IcebergViewSupport.enrichHmsTableFromIcebergView(hmsTable, conf);
528527
return;
529528
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public HiveIcebergMetaHook(Configuration conf) {
179179

180180
@Override
181181
public void commitCreateTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
182-
if (MetaStoreUtils.isIcebergView(hmsTable)) {
182+
if (HiveTableUtil.isIcebergView(hmsTable)) {
183183
tableProperties = IcebergTableProperties.getTableProperties(hmsTable, conf);
184184
Map<String, String> tblProps =
185185
hmsTable.getParameters() == null ? Maps.newHashMap() : Maps.newHashMap(hmsTable.getParameters());
@@ -266,7 +266,7 @@ public void commitDropTable(org.apache.hadoop.hive.metastore.api.Table hmsTable,
266266
@Override
267267
public void preAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTable, EnvironmentContext context)
268268
throws MetaException {
269-
if (MetaStoreUtils.isIcebergView(hmsTable)) {
269+
if (HiveTableUtil.isIcebergView(hmsTable)) {
270270
currentAlterTableOp = null;
271271
if (commitLock == null) {
272272
commitLock = new NoLock();
@@ -503,7 +503,7 @@ public void commitAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTable
503503
if (commitLock == null) {
504504
throw new IllegalStateException("Hive commit lock should already be set");
505505
}
506-
if (MetaStoreUtils.isIcebergView(hmsTable)) {
506+
if (HiveTableUtil.isIcebergView(hmsTable)) {
507507
tableProperties = IcebergTableProperties.getTableProperties(hmsTable, conf);
508508
Map<String, String> tblProps =
509509
hmsTable.getParameters() == null ? Maps.newHashMap() : Maps.newHashMap(hmsTable.getParameters());

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

Lines changed: 9 additions & 9 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 (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
436+
if (HiveTableUtil.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 (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
902+
if (HiveTableUtil.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 (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
919+
if (HiveTableUtil.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 (MetaStoreUtils.isIcebergView(hmsTable.getTTable())) {
1587+
if (HiveTableUtil.isIcebergView(hmsTable.getTTable())) {
15881588
return Collections.emptyList();
15891589
}
15901590
TableDesc tableDesc = Utilities.getTableDesc(hmsTable);
@@ -1990,7 +1990,7 @@ public void setTableParametersForCTLT(org.apache.hadoop.hive.ql.metadata.Table t
19901990
}
19911991

19921992
// If source is Iceberg table set the schema and the partition spec
1993-
if (MetaStoreUtils.isIcebergTable(origParams)) {
1993+
if (HiveTableUtil.isTableTypeSet(origParams)) {
19941994
tbl.getParameters()
19951995
.put(InputFormatConfig.TABLE_SCHEMA, origParams.get(InputFormatConfig.TABLE_SCHEMA));
19961996
tbl.getParameters()
@@ -2147,10 +2147,10 @@ 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 (hmsTable.getMetaTable() != null || !hmsTable.getTTable().isSetId()) {
2150+
if (hmsTable.getMetaTable() != null) {
21512151
return false;
21522152
}
2153-
if (MetaStoreUtils.usesNativePartSpec(hmsTable.getTTable())) {
2153+
if (!HiveTableUtil.isRegistered(hmsTable) || HiveTableUtil.isIcebergView(hmsTable.getTTable())) {
21542154
return !hmsTable.getPartitionKeys().isEmpty();
21552155
}
21562156
Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable());
@@ -2295,10 +2295,10 @@ public boolean canPerformMetadataDelete(org.apache.hadoop.hive.ql.metadata.Table
22952295

22962296
@Override
22972297
public List<FieldSchema> getPartitionKeys(org.apache.hadoop.hive.ql.metadata.Table hmsTable) {
2298-
if (hmsTable.getMetaTable() != null || !hmsTable.getTTable().isSetId()) {
2298+
if (hmsTable.getMetaTable() != null) {
22992299
return Collections.emptyList();
23002300
}
2301-
if (MetaStoreUtils.usesNativePartSpec(hmsTable.getTTable())) {
2301+
if (!HiveTableUtil.isRegistered(hmsTable) || HiveTableUtil.isIcebergView(hmsTable.getTTable())) {
23022302
return hmsTable.getPartitionKeys();
23032303
}
23042304
Table icebergTable = IcebergTableUtil.getTable(conf, hmsTable.getTTable());

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.apache.hadoop.fs.Path;
4141
import org.apache.hadoop.fs.RemoteIterator;
4242
import org.apache.hadoop.hive.conf.HiveConf;
43+
import org.apache.hadoop.hive.metastore.HiveMetaHook;
44+
import org.apache.hadoop.hive.metastore.TableType;
4345
import org.apache.hadoop.hive.metastore.Warehouse;
4446
import org.apache.hadoop.hive.metastore.api.FieldSchema;
4547
import org.apache.hadoop.hive.metastore.api.MetaException;
@@ -380,4 +382,23 @@ public static boolean isCtas(Properties properties) {
380382
return Boolean.parseBoolean(properties.getProperty(hive_metastoreConstants.TABLE_IS_CTAS));
381383
}
382384

385+
public static boolean isTableTypeSet(Map<String, String> params) {
386+
return params != null &&
387+
HiveMetaHook.ICEBERG.equalsIgnoreCase(params.get(HiveMetaHook.TABLE_TYPE));
388+
}
389+
390+
public static boolean isIcebergView(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
391+
if (hmsTable == null ||
392+
hmsTable.getParameters() == null ||
393+
!TableType.VIRTUAL_VIEW.toString().equals(hmsTable.getTableType())) {
394+
return false;
395+
}
396+
String storageHandler = hmsTable.getParameters().get(hive_metastoreConstants.META_TABLE_STORAGE);
397+
return HiveMetaHook.HIVE_ICEBERG_STORAGE_HANDLER.equals(storageHandler);
398+
}
399+
400+
public static boolean isRegistered(org.apache.hadoop.hive.ql.metadata.Table hmsTable) {
401+
return hmsTable.getTTable().isSetId() && isTableTypeSet(hmsTable.getParameters());
402+
}
403+
383404
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,6 @@ 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-
public static boolean usesNativePartSpec(org.apache.hadoop.hive.metastore.api.Table table) {
314-
return isIcebergView(table) || !isIcebergTable(table.getParameters());
315-
}
316-
317303
public static boolean isIcebergTable(Properties params) {
318304
return HiveMetaHook.ICEBERG.equalsIgnoreCase((String) params.get(HiveMetaHook.TABLE_TYPE));
319305
}

0 commit comments

Comments
 (0)