Skip to content

Commit e2e9c2a

Browse files
committed
HIVE-27472: Iceberg: Disallow creation of temporary tables
1 parent 24092d1 commit e2e9c2a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ public HiveIcebergMetaHook(Configuration conf) {
165165

166166
@Override
167167
public void preCreateTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
168+
if (hmsTable.isTemporary()) {
169+
throw new UnsupportedOperationException("Creation of iceberg temporary tables is not supported.");
170+
}
168171
this.catalogProperties = getCatalogProperties(hmsTable);
169172

170173
// Set the table type even for non HiveCatalog based tables
@@ -173,7 +176,7 @@ public void preCreateTable(org.apache.hadoop.hive.metastore.api.Table hmsTable)
173176

174177
if (!Catalogs.hiveCatalog(conf, catalogProperties)) {
175178
if (Boolean.parseBoolean(this.catalogProperties.getProperty(hive_metastoreConstants.TABLE_IS_CTLT))) {
176-
throw new RuntimeException("CTLT target table must be a HiveCatalog table.");
179+
throw new UnsupportedOperationException("CTLT target table must be a HiveCatalog table.");
177180
}
178181
// For non-HiveCatalog tables too, we should set the input and output format
179182
// so that the table can be read by other engines like Impala

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,13 +1659,27 @@ public void testCTLTHiveCatalogValidation() throws TException, InterruptedExcept
16591659

16601660
// Run a CTLT query.
16611661
AssertHelpers.assertThrows("should throw exception", IllegalArgumentException.class,
1662-
" CTLT target table must be a HiveCatalog table", () -> {
1662+
"CTLT target table must be a HiveCatalog table", () -> {
16631663
shell.executeStatement(String.format("CREATE TABLE dest LIKE source STORED BY ICEBERG %s %s",
16641664
testTables.locationForCreateTableSQL(TableIdentifier.of("default", "dest")),
16651665
testTables.propertiesForCreateTableSQL(ImmutableMap.of())));
16661666
});
16671667
}
16681668

1669+
@Test
1670+
public void testCreateTemporaryTable() {
1671+
TableIdentifier identifier = TableIdentifier.of("default", "customers");
1672+
String query = String.format("CREATE temporary TABLE customers (customer_id BIGINT, first_name STRING, last_name " +
1673+
"STRING) STORED BY iceberg %s %s",
1674+
testTables.locationForCreateTableSQL(identifier),
1675+
testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
1676+
1677+
AssertHelpers.assertThrows("should throw exception", IllegalArgumentException.class,
1678+
"Creation of iceberg temporary tables is not supported", () -> {
1679+
shell.executeStatement(query);
1680+
});
1681+
}
1682+
16691683
@Test
16701684
public void testParquetHiveCatalogValidation() throws TException, InterruptedException, IOException {
16711685

0 commit comments

Comments
 (0)