Revanth14 commented on code in PR #1285:
URL: https://github.com/apache/iceberg-go/pull/1285#discussion_r3470681798
##########
catalog/hive/hive_test.go:
##########
@@ -523,6 +530,114 @@ func TestHiveDropTable(t *testing.T) {
mockClient.AssertExpectations(t)
}
+func TestHivePurgeTable(t *testing.T) {
+ assert := require.New(t)
+ ctx := context.Background()
+ tableLocation := filepath.Join(t.TempDir(), "warehouse",
"test_database", "test_table")
+ metadataLocation, dataFile := writeHivePurgeTableFiles(t, tableLocation)
+ hiveTable := hivePurgeTable(metadataLocation, tableLocation)
+
+ mockClient := &mockHiveClient{}
+ mockClient.On("GetTable", mock.Anything, "test_database", "test_table").
+ Return(hiveTable, nil).Twice()
+ mockClient.On("DropTable", mock.Anything, "test_database",
"test_table", false).
+ Return(nil).Once()
+
+ hiveCatalog := NewCatalogWithClient(mockClient, iceberg.Properties{})
+
+ assert.NoError(hiveCatalog.PurgeTable(ctx,
TableIdentifier("test_database", "test_table")))
+ assert.NoFileExists(metadataLocation)
+ assert.NoFileExists(dataFile)
+ mockClient.AssertExpectations(t)
+}
+
+func TestHivePurgeTableSwallowsPurgeFilesError(t *testing.T) {
+ assert := require.New(t)
+ ctx := context.Background()
+ const scheme = "hivepurgefail"
+ failingFS := failRemoveIO{MemFS: iceio.NewMemFS(), err:
errHivePurgeRemove}
+ iceio.Register(scheme, func(context.Context, *url.URL,
map[string]string) (iceio.IO, error) {
+ return failingFS, nil
+ })
+ t.Cleanup(func() { iceio.Unregister(scheme) })
+
+ tableLocation := scheme + "://bucket/test_database/test_table"
+ metadataLocation := tableLocation + "/metadata/v1.metadata.json"
+ dataFile := tableLocation + "/data/file.parquet"
+ writeHivePurgeTableMetadata(t, failingFS, tableLocation,
metadataLocation)
+ require.NoError(t, failingFS.WriteFile(dataFile, []byte("data")))
+ hiveTable := hivePurgeTable(metadataLocation, tableLocation)
+
+ mockClient := &mockHiveClient{}
+ mockClient.On("GetTable", mock.Anything, "test_database", "test_table").
+ Return(hiveTable, nil).Twice()
+ mockClient.On("DropTable", mock.Anything, "test_database",
"test_table", false).
+ Return(nil).Once()
+
+ var logs bytes.Buffer
+ originalLogOutput := log.Writer()
+ log.SetOutput(&logs)
+ t.Cleanup(func() { log.SetOutput(originalLogOutput) })
+
+ hiveCatalog := NewCatalogWithClient(mockClient, iceberg.Properties{})
+
+ assert.NoError(hiveCatalog.PurgeTable(ctx,
TableIdentifier("test_database", "test_table")))
+ assert.Contains(logs.String(), "failed to purge files")
+ assert.Contains(logs.String(), errHivePurgeRemove.Error())
+ file, err := failingFS.Open(dataFile)
+ assert.NoError(err, "data file should remain when FileIO remove fails")
+ assert.NoError(file.Close())
+ mockClient.AssertExpectations(t)
+}
+
+type failRemoveIO struct {
+ *iceio.MemFS
+ err error
+}
+
+func (f failRemoveIO) Remove(string) error {
+ return f.err
+}
+
+func hivePurgeTable(metadataLocation, tableLocation string)
*hive_metastore.Table {
+ return &hive_metastore.Table{
+ TableName: "test_table",
+ DbName: "test_database",
+ TableType: TableTypeExternalTable,
+ Parameters: map[string]string{
Review Comment:
Agreed. Added both `EXTERNAL=TRUE` and `storage_handler` to the Hive purge
fixture so it matches the table shape produced by the Hive catalog.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]