Skip to content

Commit 94103ea

Browse files
pvaryrdblue
authored andcommitted
Hive: Fix Catalogs.hiveCatalog method for default catalogs (#3338)
1 parent 3291f77 commit 94103ea

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,15 @@ public static boolean dropTable(Configuration conf, Properties props) {
202202
*/
203203
public static boolean hiveCatalog(Configuration conf, Properties props) {
204204
String catalogName = props.getProperty(InputFormatConfig.CATALOG_NAME);
205-
return CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE.equalsIgnoreCase(getCatalogType(conf, catalogName));
205+
String catalogType = getCatalogType(conf, catalogName);
206+
if (catalogType != null) {
207+
return CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE.equalsIgnoreCase(catalogType);
208+
}
209+
catalogType = getCatalogType(conf, ICEBERG_DEFAULT_CATALOG_NAME);
210+
if (catalogType != null) {
211+
return CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE.equalsIgnoreCase(catalogType);
212+
}
213+
return getCatalogProperties(conf, catalogName, catalogType).get(CatalogProperties.CATALOG_IMPL) == null;
206214
}
207215

208216
@VisibleForTesting
@@ -279,9 +287,7 @@ private static String getCatalogType(Configuration conf, String catalogName) {
279287
}
280288
} else {
281289
String catalogType = conf.get(InputFormatConfig.CATALOG);
282-
if (catalogType == null) {
283-
return CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE;
284-
} else if (catalogType.equals(LOCATION)) {
290+
if (catalogType != null && catalogType.equals(LOCATION)) {
285291
return NO_CATALOG_TYPE;
286292
} else {
287293
return catalogType;

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public void testLegacyLoadCatalogDefault() {
197197
Optional<Catalog> defaultCatalog = Catalogs.loadCatalog(conf, null);
198198
Assert.assertTrue(defaultCatalog.isPresent());
199199
Assertions.assertThat(defaultCatalog.get()).isInstanceOf(HiveCatalog.class);
200+
Assert.assertTrue(Catalogs.hiveCatalog(conf, new Properties()));
200201
}
201202

202203
@Test
@@ -205,6 +206,7 @@ public void testLegacyLoadCatalogHive() {
205206
Optional<Catalog> hiveCatalog = Catalogs.loadCatalog(conf, null);
206207
Assert.assertTrue(hiveCatalog.isPresent());
207208
Assertions.assertThat(hiveCatalog.get()).isInstanceOf(HiveCatalog.class);
209+
Assert.assertTrue(Catalogs.hiveCatalog(conf, new Properties()));
208210
}
209211

210212
@Test
@@ -214,6 +216,7 @@ public void testLegacyLoadCatalogHadoop() {
214216
Optional<Catalog> hadoopCatalog = Catalogs.loadCatalog(conf, null);
215217
Assert.assertTrue(hadoopCatalog.isPresent());
216218
Assertions.assertThat(hadoopCatalog.get()).isInstanceOf(HadoopCatalog.class);
219+
Assert.assertFalse(Catalogs.hiveCatalog(conf, new Properties()));
217220
}
218221

219222
@Test
@@ -223,12 +226,14 @@ public void testLegacyLoadCatalogCustom() {
223226
Optional<Catalog> customHadoopCatalog = Catalogs.loadCatalog(conf, null);
224227
Assert.assertTrue(customHadoopCatalog.isPresent());
225228
Assertions.assertThat(customHadoopCatalog.get()).isInstanceOf(CustomHadoopCatalog.class);
229+
Assert.assertFalse(Catalogs.hiveCatalog(conf, new Properties()));
226230
}
227231

228232
@Test
229233
public void testLegacyLoadCatalogLocation() {
230234
conf.set(InputFormatConfig.CATALOG, Catalogs.LOCATION);
231235
Assert.assertFalse(Catalogs.loadCatalog(conf, null).isPresent());
236+
Assert.assertFalse(Catalogs.hiveCatalog(conf, new Properties()));
232237
}
233238

234239
@Test
@@ -241,9 +246,13 @@ public void testLegacyLoadCatalogUnknown() {
241246

242247
@Test
243248
public void testLoadCatalogDefault() {
244-
Optional<Catalog> defaultCatalog = Catalogs.loadCatalog(conf, "barCatalog");
249+
String catalogName = "barCatalog";
250+
Optional<Catalog> defaultCatalog = Catalogs.loadCatalog(conf, catalogName);
245251
Assert.assertTrue(defaultCatalog.isPresent());
246252
Assertions.assertThat(defaultCatalog.get()).isInstanceOf(HiveCatalog.class);
253+
Properties properties = new Properties();
254+
properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
255+
Assert.assertTrue(Catalogs.hiveCatalog(conf, properties));
247256
}
248257

249258
@Test
@@ -254,6 +263,9 @@ public void testLoadCatalogHive() {
254263
Optional<Catalog> hiveCatalog = Catalogs.loadCatalog(conf, catalogName);
255264
Assert.assertTrue(hiveCatalog.isPresent());
256265
Assertions.assertThat(hiveCatalog.get()).isInstanceOf(HiveCatalog.class);
266+
Properties properties = new Properties();
267+
properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
268+
Assert.assertTrue(Catalogs.hiveCatalog(conf, properties));
257269
}
258270

259271
@Test
@@ -267,6 +279,9 @@ public void testLoadCatalogHadoop() {
267279
Assert.assertTrue(hadoopCatalog.isPresent());
268280
Assertions.assertThat(hadoopCatalog.get()).isInstanceOf(HadoopCatalog.class);
269281
Assert.assertEquals("HadoopCatalog{name=barCatalog, location=/tmp/mylocation}", hadoopCatalog.get().toString());
282+
Properties properties = new Properties();
283+
properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
284+
Assert.assertFalse(Catalogs.hiveCatalog(conf, properties));
270285
}
271286

272287
@Test
@@ -279,6 +294,9 @@ public void testLoadCatalogHadoopWithLegacyWarehouseLocation() {
279294
Assert.assertTrue(hadoopCatalog.isPresent());
280295
Assertions.assertThat(hadoopCatalog.get()).isInstanceOf(HadoopCatalog.class);
281296
Assert.assertEquals("HadoopCatalog{name=barCatalog, location=/tmp/mylocation}", hadoopCatalog.get().toString());
297+
Properties properties = new Properties();
298+
properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
299+
Assert.assertFalse(Catalogs.hiveCatalog(conf, properties));
282300
}
283301

284302
@Test
@@ -291,6 +309,9 @@ public void testLoadCatalogCustom() {
291309
Optional<Catalog> customHadoopCatalog = Catalogs.loadCatalog(conf, catalogName);
292310
Assert.assertTrue(customHadoopCatalog.isPresent());
293311
Assertions.assertThat(customHadoopCatalog.get()).isInstanceOf(CustomHadoopCatalog.class);
312+
Properties properties = new Properties();
313+
properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
314+
Assert.assertFalse(Catalogs.hiveCatalog(conf, properties));
294315
}
295316

296317
@Test

0 commit comments

Comments
 (0)