Skip to content

Commit 7fb95ec

Browse files
committed
HIVE-27472: Iceberg: Disallow creation of temporary tables
1 parent 462a6e0 commit 7fb95ec

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,22 @@ public void testCTLTHiveCatalogValidation() throws TException, InterruptedExcept
16931693
testTables.propertiesForCreateTableSQL(ImmutableMap.of())));
16941694
})
16951695
.isInstanceOf(IllegalArgumentException.class)
1696-
.hasMessageContaining(" CTLT target table must be a HiveCatalog table");
1696+
.hasMessageContaining("CTLT target table must be a HiveCatalog table");
1697+
}
1698+
1699+
@Test
1700+
public void testCreateTemporaryTable() {
1701+
TableIdentifier identifier = TableIdentifier.of("default", "customers");
1702+
String query = String.format("CREATE temporary TABLE customers (customer_id BIGINT, first_name STRING, last_name " +
1703+
"STRING) STORED BY iceberg %s %s",
1704+
testTables.locationForCreateTableSQL(identifier),
1705+
testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
1706+
1707+
Assertions.assertThatThrownBy(() -> {
1708+
shell.executeStatement(query);
1709+
})
1710+
.isInstanceOf(IllegalArgumentException.class)
1711+
.hasMessageContaining("Creation of iceberg temporary tables is not supported");
16971712
}
16981713

16991714
@Test

0 commit comments

Comments
 (0)