rdblue commented on a change in pull request #1495:
URL: https://github.com/apache/iceberg/pull/1495#discussion_r497840757
##########
File path:
mr/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandlerBaseTest.java
##########
@@ -157,6 +177,282 @@ public void testJoinTables() throws IOException {
Assert.assertArrayEquals(new Object[] {1L, "Bob", 102L, 33.33d},
rows.get(2));
}
+ @Test
+ public void testCreateDropTable() throws TException, IOException {
+ // We need the location for HadoopTable based tests only
+ String location = locationForCreateTable(temp.getRoot().getPath(),
"customers");
+ shell.executeStatement("CREATE EXTERNAL TABLE customers " +
+ "STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' " +
+ (location != null ? "LOCATION '" + location + "' " : "") +
+ "TBLPROPERTIES ('" + InputFormatConfig.TABLE_SCHEMA + "'='" +
SchemaParser.toJson(CUSTOMER_SCHEMA) + "', " +
+ "'" + InputFormatConfig.PARTITION_SPEC + "'='" +
PartitionSpecParser.toJson(IDENTITY_SPEC) + "', " +
+ "'dummy'='test')");
+
+ Properties properties = new Properties();
+ properties.put(Catalogs.NAME, TableIdentifier.of("default",
"customers").toString());
+ if (location != null) {
+ properties.put(Catalogs.LOCATION, location);
+ }
+
+ // Check the Iceberg table data
+ org.apache.iceberg.Table icebergTable =
Catalogs.loadTable(shell.getHiveConf(), properties);
+ Assert.assertEquals(SchemaParser.toJson(CUSTOMER_SCHEMA),
SchemaParser.toJson(icebergTable.schema()));
+ Assert.assertEquals(PartitionSpecParser.toJson(IDENTITY_SPEC),
PartitionSpecParser.toJson(icebergTable.spec()));
+ Assert.assertEquals(Collections.singletonMap("dummy", "test"),
icebergTable.properties());
+
+ // Check the HMS table parameters
+ IMetaStoreClient client = null;
+ org.apache.hadoop.hive.metastore.api.Table hmsTable;
+ try {
+ client = new HiveMetaStoreClient(metastore.hiveConf());
+ hmsTable = client.getTable("default", "customers");
+ } finally {
+ if (client != null) {
+ client.close();
+ }
+ }
+
+ Map<String, String> hmsParams = hmsTable.getParameters();
+
+ // This is only set for HiveCatalog based tables. Check the value, then
remove it so the other checks can be general
+ if (needToCheckSnapshotLocation()) {
+
Assert.assertTrue(hmsParams.get(BaseMetastoreTableOperations.METADATA_LOCATION_PROP)
+ .startsWith(icebergTable.location()));
+ hmsParams.remove(BaseMetastoreTableOperations.METADATA_LOCATION_PROP);
+ }
+
+ // General metadata checks
+ Assert.assertEquals(6, hmsParams.size());
+ Assert.assertEquals("test", hmsParams.get("dummy"));
+ Assert.assertEquals("TRUE",
hmsParams.get(InputFormatConfig.EXTERNAL_TABLE_PURGE));
+ Assert.assertEquals("TRUE", hmsParams.get("EXTERNAL"));
+ Assert.assertNotNull(hmsParams.get(hive_metastoreConstants.DDL_TIME));
+ Assert.assertEquals(HiveIcebergStorageHandler.class.getName(),
+
hmsTable.getParameters().get(hive_metastoreConstants.META_TABLE_STORAGE));
+
Assert.assertEquals(BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE.toUpperCase(),
+
hmsTable.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP));
+
+ if (Catalogs.canWorkWithoutHive(shell.getHiveConf())) {
+ shell.executeStatement("DROP TABLE customers");
+
+ // Check if the table was really dropped even from the Catalog
+ AssertHelpers.assertThrows("should throw exception",
NoSuchTableException.class,
+ "Table does not exist", () -> {
+ Catalogs.loadTable(shell.getHiveConf(), properties);
+ }
+ );
+ } else {
+ // Check the HMS table parameters
+ Path hmsTableLocation;
+ try {
+ client = new HiveMetaStoreClient(metastore.hiveConf());
+ hmsTableLocation = new Path(client.getTable("default",
"customers").getSd().getLocation());
+ } finally {
+ if (client != null) {
+ client.close();
+ }
+ }
+
+ // Drop the table
+ shell.executeStatement("DROP TABLE customers");
+
+ // Check if we drop an exception when trying to drop the table
+ AssertHelpers.assertThrows("should throw exception",
NoSuchTableException.class,
+ "Table does not exist", () -> {
+ Catalogs.loadTable(shell.getHiveConf(), properties);
+ }
+ );
+
+ // Check if the files are kept
+ FileSystem fs = Util.getFs(hmsTableLocation, shell.getHiveConf());
Review comment:
Should this be done in the case where the table can work without Hive?
The if statement seems backward to me.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]