Skip to content

Commit 27f91dc

Browse files
author
Laszlo Pinter
committed
Review changes 2.
1 parent b7846f8 commit 27f91dc

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

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

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -194,36 +194,14 @@ public static boolean dropTable(Configuration conf, Properties props) {
194194
*/
195195
public static boolean hiveCatalog(Configuration conf, Properties props) {
196196
String catalogName = props.getProperty(InputFormatConfig.TABLE_CATALOG);
197-
if (catalogName != null) {
198-
return HIVE.equalsIgnoreCase(conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, catalogName)));
199-
} else {
200-
if (HIVE.equalsIgnoreCase(conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, DEFAULT_CATALOG)))) {
201-
return true;
202-
} else {
203-
return HIVE.equalsIgnoreCase(conf.get(InputFormatConfig.CATALOG));
204-
}
205-
}
197+
return HIVE.equalsIgnoreCase(getCatalogType(conf, catalogName));
206198
}
207199

208200
@VisibleForTesting
209201
static Optional<Catalog> loadCatalog(Configuration conf, String catalogName) {
210-
String catalogType;
211202
String name = catalogName == null ? DEFAULT_CATALOG : catalogName;
212-
catalogType = conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, name));
213-
214-
// keep both catalog configuration methods for seamless transition
215-
if (catalogType != null) {
216-
// new logic
217-
LOG.debug("Using catalog configuration from table properties.");
218-
return loadCatalog(conf, name, catalogType);
219-
} else {
220-
// old logic
221-
// use catalog {@link InputFormatConfig.CATALOG} stored in global hive config if table specific catalog
222-
// configuration or default catalog definition is missing
223-
LOG.debug("Using catalog configuration from global configuration.");
224-
catalogType = conf.get(InputFormatConfig.CATALOG);
225-
return loadCatalog(conf, name, catalogType);
226-
}
203+
String catalogType = getCatalogType(conf, name);
204+
return loadCatalog(conf, name, catalogType);
227205
}
228206

229207
private static Optional<Catalog> loadCatalog(Configuration conf, String catalogName, String catalogType) {
@@ -237,8 +215,7 @@ private static Optional<Catalog> loadCatalog(Configuration conf, String catalogN
237215
switch (catalogType.toLowerCase()) {
238216
case HADOOP:
239217
if (properties.containsKey(CatalogProperties.WAREHOUSE_LOCATION)) {
240-
catalog = CatalogUtil.loadCatalog(HadoopCatalog.class.getName(), catalogName,
241-
getCatalogProperties(conf, catalogName), conf);
218+
catalog = CatalogUtil.loadCatalog(HadoopCatalog.class.getName(), catalogName, properties, conf);
242219
} else {
243220
String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION);
244221
catalog = (warehouseLocation != null) ? new HadoopCatalog(conf, warehouseLocation) : new HadoopCatalog(conf);
@@ -282,4 +259,17 @@ private static Map<String, String> getCatalogProperties(Configuration conf, Stri
282259
});
283260
return properties;
284261
}
262+
263+
private static String getCatalogType(Configuration conf, String catalogName) {
264+
String name = catalogName == null ? DEFAULT_CATALOG : catalogName;
265+
String catalogType = conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, name));
266+
// keep both catalog configuration methods for seamless transition
267+
if (catalogType != null) {
268+
LOG.debug("Using catalog configuration from table properties.");
269+
return catalogType;
270+
} else {
271+
LOG.debug("Using catalog configuration from global configuration.");
272+
return conf.get(InputFormatConfig.CATALOG);
273+
}
274+
}
285275
}

mr/src/test/java/org/apache/iceberg/mr/TestCatalogs.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ public void testLoadTableFromLocation() throws IOException {
7979
public void testLoadTableFromCatalog() throws IOException {
8080
String defaultCatalogName = "default";
8181
String warehouseLocation = temp.newFolder("hadoop", "warehouse").toString();
82-
conf.set(String.format(InputFormatConfig.CATALOG_WAREHOUSE_TEMPLATE, defaultCatalogName), warehouseLocation);
83-
conf.set(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, defaultCatalogName), Catalogs.CUSTOM);
84-
conf.set(String.format(InputFormatConfig.CATALOG_CLASS_TEMPLATE, defaultCatalogName),
85-
CustomHadoopCatalog.class.getName());
82+
setCustomCatalogProperties(defaultCatalogName, warehouseLocation);
8683

8784
AssertHelpers.assertThrows(
8885
"Should complain about table identifier not set", IllegalArgumentException.class,
@@ -145,10 +142,7 @@ public void testCreateDropTableToCatalog() throws IOException {
145142
String defaultCatalogName = "default";
146143
String warehouseLocation = temp.newFolder("hadoop", "warehouse").toString();
147144

148-
conf.set(String.format(InputFormatConfig.CATALOG_WAREHOUSE_TEMPLATE, defaultCatalogName), warehouseLocation);
149-
conf.set(String.format(InputFormatConfig.CATALOG_CLASS_TEMPLATE, defaultCatalogName),
150-
CustomHadoopCatalog.class.getName());
151-
conf.set(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, defaultCatalogName), Catalogs.CUSTOM);
145+
setCustomCatalogProperties(defaultCatalogName, warehouseLocation);
152146

153147
Properties missingSchema = new Properties();
154148
missingSchema.put("name", identifier.toString());
@@ -298,4 +292,10 @@ public Catalog load(Configuration conf) {
298292
return new CustomHadoopCatalog(conf);
299293
}
300294
}
295+
296+
private void setCustomCatalogProperties(String catalogName, String warehouseLocation) {
297+
conf.set(String.format(InputFormatConfig.CATALOG_WAREHOUSE_TEMPLATE, catalogName), warehouseLocation);
298+
conf.set(String.format(InputFormatConfig.CATALOG_CLASS_TEMPLATE, catalogName), CustomHadoopCatalog.class.getName());
299+
conf.set(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, catalogName), Catalogs.CUSTOM);
300+
}
301301
}

0 commit comments

Comments
 (0)