Skip to content

Commit d6dd937

Browse files
committed
Fix test failures
1 parent 8d6463f commit d6dd937

8 files changed

Lines changed: 38 additions & 14 deletions

File tree

common/src/java/org/apache/hadoop/hive/conf/HiveConf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ public static enum ConfVars {
21292129
"If this is set to true, then all the data files being read should be withing the table location"),
21302130
HIVE_ICEBERG_MATERIALIZEDVIEW_METADATA_LOCATION("hive.iceberg.materializedview.metadata.location", "metastore",
21312131
new StringSet("metastore", "iceberg"),
2132-
"Location of materialized view matedata stored by iceberg"),
2132+
"Location of materialized view metadata stored by iceberg"),
21332133
HIVE_USE_EXPLICIT_RCFILE_HEADER("hive.exec.rcfile.use.explicit.header", true,
21342134
"If this is set the header for RCFiles will simply be RCF. If this is not\n" +
21352135
"set the header will be that borrowed from sequence files, e.g. SEQ- followed\n" +

iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/HiveOperationsBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ static void validateTableOrMVIsIceberg(Table table, String fullName) {
148148

149149
static void validateTableIsIcebergView(Table table, String fullName) {
150150
String tableTypeProp = table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP);
151+
151152
NoSuchIcebergViewException.check(
152153
(TableType.VIRTUAL_VIEW.name().equalsIgnoreCase(table.getTableType()) ||
153-
TableType.MATERIALIZED_VIEW.name().equalsIgnoreCase(table.getTableType()) ||
154154
TableType.EXTERNAL_MATERIALIZED_VIEW.name().equalsIgnoreCase(table.getTableType())) &&
155155
ICEBERG_VIEW_TYPE_VALUE.equalsIgnoreCase(tableTypeProp),
156156
"Not an iceberg view: %s (type=%s) (tableType=%s)",

iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.stream.Collectors;
2727
import org.apache.hadoop.conf.Configuration;
2828
import org.apache.hadoop.hive.common.StatsSetupConst;
29+
import org.apache.hadoop.hive.conf.HiveConf;
2930
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
3031
import org.apache.hadoop.hive.metastore.TableType;
3132
import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
@@ -118,8 +119,10 @@ protected void doRefresh() {
118119

119120
// Check if we are trying to load an Iceberg View as a Table
120121
HiveOperationsBase.validateIcebergViewNotLoadedAsIcebergTable(table, fullName);
121-
// Check if it is a valid Iceberg Table
122-
HiveOperationsBase.validateTableOrMVIsIceberg(table, fullName);
122+
123+
if ("iceberg".equals(HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_ICEBERG_MATERIALIZEDVIEW_METADATA_LOCATION))) {
124+
HiveOperationsBase.validateTableOrMVIsIceberg(table, fullName);
125+
}
123126

124127
metadataLocation = table.getParameters().get(METADATA_LOCATION_PROP);
125128

iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Set;
2727
import java.util.UUID;
2828
import org.apache.hadoop.conf.Configuration;
29+
import org.apache.hadoop.hive.conf.HiveConf;
2930
import org.apache.hadoop.hive.metastore.api.CreationMetadata;
3031
import org.apache.iceberg.CatalogUtil;
3132
import org.apache.iceberg.PartitionSpec;
@@ -306,10 +307,14 @@ public static MaterializedView createMaterializedView(
306307
Configuration conf, Properties props, String viewOriginalText, String viewExpandedText,
307308
CreationMetadata creationMetadata) {
308309

310+
boolean isExternalMaterializedView = "iceberg".equals(
311+
HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_ICEBERG_MATERIALIZEDVIEW_METADATA_LOCATION));
312+
309313
Schema schema = schema(props);
310314
PartitionSpec spec = spec(props, schema);
311315
String location = props.getProperty(LOCATION);
312-
String storageTableLocation = location + MATERIALIZED_VIEW_STORAGE_TABLE_IDENTIFIER_SUFFIX;
316+
String storageTableLocation = location +
317+
(isExternalMaterializedView ? MATERIALIZED_VIEW_STORAGE_TABLE_IDENTIFIER_SUFFIX : "");
313318
String catalogName = props.getProperty(InputFormatConfig.CATALOG_NAME);
314319

315320
Optional<Catalog> catalog = loadCatalog(conf, catalogName);
@@ -323,7 +328,8 @@ public static MaterializedView createMaterializedView(
323328
ViewCatalog viewCatalog = (ViewCatalog) catalog.get();
324329

325330
Map<String, String> map = filterIcebergTableProperties(props);
326-
String storageTableIdentifier = name + MATERIALIZED_VIEW_STORAGE_TABLE_IDENTIFIER_SUFFIX;
331+
String storageTableIdentifier = name +
332+
(isExternalMaterializedView ? MATERIALIZED_VIEW_STORAGE_TABLE_IDENTIFIER_SUFFIX : "");
327333
Table storageTable = catalog.get().buildTable(TableIdentifier.parse(storageTableIdentifier), schema)
328334
.withPartitionSpec(spec).withLocation(storageTableLocation).withProperties(map).withSortOrder(sortOrder)
329335
.create();

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
@@ -48,7 +48,6 @@
4848
import org.apache.hadoop.hive.ql.ddl.misc.sortoder.ZOrderFields;
4949
import org.apache.hadoop.hive.ql.util.NullOrdering;
5050
import org.apache.iceberg.BaseMetastoreTableOperations;
51-
import org.apache.iceberg.BaseTable;
5251
import org.apache.iceberg.NullOrder;
5352
import org.apache.iceberg.PartitionSpec;
5453
import org.apache.iceberg.PartitionSpecParser;
@@ -560,12 +559,12 @@ public void postGetTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
560559
case EXTERNAL_TABLE:
561560
case MATERIALIZED_VIEW:
562561
tbl = IcebergTableUtil.getTable(conf, hmsTable);
563-
formatVersion = String.valueOf(((BaseTable) tbl).operations().current().formatVersion());
562+
formatVersion = String.valueOf(TableUtil.formatVersion(tbl));
564563
break;
565564

566565
case EXTERNAL_MATERIALIZED_VIEW:
567566
Catalogs.MaterializedView mv = IcebergTableUtil.getMaterializedView(conf, hmsTable, false);
568-
formatVersion = String.valueOf(((BaseTable) mv.getStorageTable()).operations().current().formatVersion());
567+
formatVersion = String.valueOf(TableUtil.formatVersion(mv.getStorageTable()));
569568

570569
hmsTable.setViewOriginalText(mv.getView().properties().get(Catalogs.MATERIALIZED_VIEW_ORIGINAL_TEXT));
571570
hmsTable.setViewExpandedText(mv.getView().sqlFor("hive").sql());

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.hadoop.fs.FileSystem;
3838
import org.apache.hadoop.fs.Path;
3939
import org.apache.hadoop.hive.common.TableName;
40+
import org.apache.hadoop.hive.conf.HiveConf;
4041
import org.apache.hadoop.hive.metastore.HiveMetaHook;
4142
import org.apache.hadoop.hive.metastore.PartitionDropOptions;
4243
import org.apache.hadoop.hive.metastore.Warehouse;
@@ -194,8 +195,13 @@ public void commitCreateTable(org.apache.hadoop.hive.metastore.api.Table hmsTabl
194195
Table table;
195196
if (metadataLocation != null) {
196197
table = Catalogs.registerTable(conf, tableProperties, metadataLocation);
197-
} else if ("MATERIALIZED_VIEW".equals(hmsTable.getTableType()) ||
198-
"EXTERNAL_MATERIALIZED_VIEW".equals(hmsTable.getTableType())) {
198+
} else if (
199+
"iceberg".equals(HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_ICEBERG_MATERIALIZEDVIEW_METADATA_LOCATION)) &&
200+
(
201+
"MATERIALIZED_VIEW".equals(hmsTable.getTableType()) ||
202+
"EXTERNAL_MATERIALIZED_VIEW".equals(hmsTable.getTableType())
203+
)
204+
) {
199205
Catalogs.MaterializedView mv =
200206
Catalogs.createMaterializedView(
201207
conf,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ public static Table deserializeTable(Configuration config, String name) {
243243
config.getBoolean(hive_metastoreConstants.TABLE_IS_CTAS, false) &&
244244
StringUtils.isNotBlank(location)) {
245245
String type = config.get(InputFormatConfig.TABLE_TYPE);
246-
if (HiveOperationsBase.ICEBERG_VIEW_TYPE_VALUE.equals(type)) {
246+
if ("iceberg".equals(
247+
HiveConf.getVar(config, HiveConf.ConfVars.HIVE_ICEBERG_MATERIALIZEDVIEW_METADATA_LOCATION)
248+
) && HiveOperationsBase.ICEBERG_VIEW_TYPE_VALUE.equals(type)) {
249+
247250
location += Catalogs.MATERIALIZED_VIEW_STORAGE_TABLE_IDENTIFIER_SUFFIX;
248251
}
249252
table = readTableObjectFromFile(location, config);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ static Table getTable(Configuration configuration, org.apache.hadoop.hive.metast
162162
return v;
163163
});
164164

165-
if (TableType.MATERIALIZED_VIEW.name().equalsIgnoreCase(hmsTable.getTableType()) ||
166-
TableType.EXTERNAL_MATERIALIZED_VIEW.name().equalsIgnoreCase(hmsTable.getTableType())) {
165+
if (
166+
"iceberg".equals(
167+
HiveConf.getVar(configuration, HiveConf.ConfVars.HIVE_ICEBERG_MATERIALIZEDVIEW_METADATA_LOCATION)
168+
) &&
169+
(
170+
TableType.MATERIALIZED_VIEW.name().equalsIgnoreCase(hmsTable.getTableType()) ||
171+
TableType.EXTERNAL_MATERIALIZED_VIEW.name().equalsIgnoreCase(hmsTable.getTableType())
172+
)
173+
) {
167174
return getMaterializedView(configuration, hmsTable, skipCache).getStorageTable();
168175
}
169176

0 commit comments

Comments
 (0)