Skip to content

Commit b73d751

Browse files
author
Laszlo Pinter
committed
Review changes 6.
1 parent 2a423c9 commit b73d751

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,13 @@ static Optional<Catalog> loadCatalog(Configuration conf, String catalogName) {
202202
if (catalogType == null) {
203203
throw new NoSuchNamespaceException("Catalog definition for %s is not found.", catalogName);
204204
}
205-
String name = catalogName == null ? ICEBERG_DEFAULT_CATALOG_NAME : catalogName;
206205

207-
switch (catalogType.toLowerCase()) {
208-
case NO_CATALOG_TYPE:
209-
return Optional.empty();
210-
default:
211-
return Optional.of(CatalogUtil.buildIcebergCatalog(name,
212-
getCatalogProperties(conf, name, catalogType), conf));
206+
if (NO_CATALOG_TYPE.equalsIgnoreCase(catalogType)) {
207+
return Optional.empty();
208+
} else {
209+
String name = catalogName == null ? ICEBERG_DEFAULT_CATALOG_NAME : catalogName;
210+
return Optional.of(CatalogUtil.buildIcebergCatalog(name,
211+
getCatalogProperties(conf, name, catalogType), conf));
213212
}
214213
}
215214

@@ -267,18 +266,18 @@ private static Map<String, String> addCatalogPropertiesIfMissing(Configuration c
267266
* @return type of the catalog, can be null
268267
*/
269268
private static String getCatalogType(Configuration conf, String catalogName) {
270-
if (catalogName == null) {
271-
String catalogType = conf.get(InputFormatConfig.CATALOG);
272-
if (catalogType == null) {
273-
return HIVE_CATALOG_TYPE;
274-
} else if (catalogType.equals(LOCATION)) {
269+
if (catalogName != null) {
270+
String catalogType = conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, catalogName));
271+
if (catalogName.equals(ICEBERG_HADOOP_TABLE_NAME) || catalogType == null) {
275272
return NO_CATALOG_TYPE;
276273
} else {
277-
return conf.get(InputFormatConfig.CATALOG);
274+
return catalogType;
278275
}
279276
} else {
280-
String catalogType = conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, catalogName));
281-
if (catalogName.equals(ICEBERG_HADOOP_TABLE_NAME) || catalogType == null) {
277+
String catalogType = conf.get(InputFormatConfig.CATALOG);
278+
if (catalogType == null) {
279+
return HIVE_CATALOG_TYPE;
280+
} else if (catalogType.equals(LOCATION)) {
282281
return NO_CATALOG_TYPE;
283282
} else {
284283
return catalogType;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ public void configureJobConf(TableDesc tableDesc, JobConf jobConf) {
121121
String tables = jobConf.get(InputFormatConfig.OUTPUT_TABLES);
122122
String catalogName = tableDesc.getProperties().getProperty(InputFormatConfig.CATALOG_NAME);
123123
if (catalogName != null) {
124-
tables = tables == null ? catalogName + CATALOG_NAME_SEPARATOR + tableDesc.getTableName() :
125-
tables + TABLE_NAME_SEPARATOR + catalogName + CATALOG_NAME_SEPARATOR + tableDesc.getTableName();
124+
String tableWithCatalogName = catalogName + CATALOG_NAME_SEPARATOR + tableDesc.getTableName();
125+
tables = tables == null ? tableWithCatalogName : tables + TABLE_NAME_SEPARATOR + tableWithCatalogName;
126126
} else {
127127
tables = tables == null ? tableDesc.getTableName() : tables + TABLE_NAME_SEPARATOR + tableDesc.getTableName();
128128
}
@@ -174,7 +174,7 @@ public static Table table(Configuration config, String name) {
174174
/**
175175
* Returns the names of the output tables stored in the configuration.
176176
* @param config The configuration used to get the data from
177-
* @return The collection of the table names as returned by TableDesc.getTableName()
177+
* @return The collection of catalog name - table name pairs.
178178
*/
179179
public static Collection<Pair<String, String>> outputTables(Configuration config) {
180180
Collection<String> tables = TABLE_NAME_SPLITTER.splitToList(config.get(InputFormatConfig.OUTPUT_TABLES));

mr/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandlerTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static TestHiveShell shell(Map<String, String> configs) {
6868
TestHiveShell shell = new TestHiveShell();
6969
shell.setHiveConfValue("hive.notification.event.poll.interval", "-1");
7070
shell.setHiveConfValue("hive.tez.exec.print.summary", "true");
71-
configs.entrySet().forEach(e -> shell.setHiveConfValue(e.getKey(), e.getValue()));
71+
configs.forEach((k, v) -> shell.setHiveConfValue(k, v));
7272
// We would like to make sure that ORC reading overrides this config, so reading Iceberg tables could work in
7373
// systems (like Hive 3.2 and higher) where this value is set to true explicitly.
7474
shell.setHiveConfValue(OrcConf.FORCE_POSITIONAL_EVOLUTION.getHiveConfName(), "true");

mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ public void testCreateTableAboveExistingTable() throws IOException {
361361
Collections.emptyList());
362362

363363
if (testTableType == TestTables.TestTableType.HIVE_CATALOG) {
364-
365364
// In HiveCatalog we just expect an exception since the table is already exists
366365
AssertHelpers.assertThrows("should throw exception", IllegalArgumentException.class,
367366
"customers already exists", () -> {

0 commit comments

Comments
 (0)