Skip to content

Commit f886a24

Browse files
authored
fix(catalog/sql): handle error for metadata location while dropping view (#648)
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent 97e3329 commit f886a24

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

catalog/sql/sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ func (c *Catalog) DropView(ctx context.Context, identifier table.Identifier) err
983983
if metadataLocation != "" {
984984
fs, err := io.LoadFS(ctx, c.props, metadataLocation)
985985
if err != nil {
986-
return nil
986+
return err
987987
}
988988

989989
_ = fs.Remove(metadataLocation)

catalog/sql/sql_test.go

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ func (s *SqliteCatalogTestSuite) TestCreationOneTableExists() {
278278
s.confirmNoTables(sqldb)
279279

280280
_, err := sqldb.Exec(`CREATE TABLE "iceberg_tables" (
281-
"catalog_name" VARCHAR NOT NULL,
282-
"table_namespace" VARCHAR NOT NULL,
281+
"catalog_name" VARCHAR NOT NULL,
282+
"table_namespace" VARCHAR NOT NULL,
283283
"table_name" VARCHAR NOT NULL,
284284
"iceberg_type" VARCHAR NOT NULL DEFAULT 'TABLE',
285-
"metadata_location" VARCHAR,
286-
"previous_metadata_location" VARCHAR,
285+
"metadata_location" VARCHAR,
286+
"previous_metadata_location" VARCHAR,
287287
PRIMARY KEY ("catalog_name", "table_namespace", "table_name"))`)
288288
s.Require().NoError(err)
289289

@@ -297,20 +297,20 @@ func (s *SqliteCatalogTestSuite) TestCreationAllTablesExist() {
297297
s.confirmNoTables(sqldb)
298298

299299
_, err := sqldb.Exec(`CREATE TABLE "iceberg_tables" (
300-
"catalog_name" VARCHAR NOT NULL,
301-
"table_namespace" VARCHAR NOT NULL,
300+
"catalog_name" VARCHAR NOT NULL,
301+
"table_namespace" VARCHAR NOT NULL,
302302
"table_name" VARCHAR NOT NULL,
303303
"iceberg_type" VARCHAR,
304-
"metadata_location" VARCHAR,
305-
"previous_metadata_location" VARCHAR,
304+
"metadata_location" VARCHAR,
305+
"previous_metadata_location" VARCHAR,
306306
PRIMARY KEY ("catalog_name", "table_namespace", "table_name"))`)
307307
s.Require().NoError(err)
308308

309309
_, err = sqldb.Exec(`CREATE TABLE "iceberg_namespace_properties" (
310-
"catalog_name" VARCHAR NOT NULL,
311-
"namespace" VARCHAR NOT NULL,
312-
"property_key" VARCHAR NOT NULL,
313-
"property_value" VARCHAR,
310+
"catalog_name" VARCHAR NOT NULL,
311+
"namespace" VARCHAR NOT NULL,
312+
"property_key" VARCHAR NOT NULL,
313+
"property_value" VARCHAR,
314314
PRIMARY KEY ("catalog_name", "namespace", "property_key"))`)
315315
s.Require().NoError(err)
316316

@@ -1097,6 +1097,38 @@ func (s *SqliteCatalogTestSuite) TestDropView() {
10971097
s.ErrorIs(err, catalog.ErrNoSuchView)
10981098
}
10991099

1100+
func (s *SqliteCatalogTestSuite) TestDropViewWithInvalidMetadataLocation() {
1101+
db := s.getCatalogSqlite()
1102+
s.Require().NoError(db.CreateSQLTables(context.Background()))
1103+
1104+
nsName := databaseName()
1105+
viewName := tableName()
1106+
s.Require().NoError(db.CreateNamespace(context.Background(), []string{nsName}, nil))
1107+
1108+
viewSQL := "SELECT * FROM test_table"
1109+
schema := iceberg.NewSchema(1, iceberg.NestedField{
1110+
ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int32, Required: true,
1111+
})
1112+
s.Require().NoError(db.CreateView(context.Background(), []string{nsName, viewName}, schema, viewSQL, nil))
1113+
1114+
// Manually update the metadata location to a URL with an unsupported scheme
1115+
// This will cause io.LoadFS to fail with "IO for file '...' not implemented"
1116+
sqldb := s.getDB()
1117+
defer sqldb.Close()
1118+
1119+
_, err := sqldb.Exec(
1120+
"UPDATE iceberg_tables SET metadata_location = ? WHERE table_namespace = ? AND table_name = ?",
1121+
"unsupported-scheme://bucket/metadata.json",
1122+
nsName,
1123+
viewName,
1124+
)
1125+
s.Require().NoError(err)
1126+
1127+
// DropView should return an error when io.LoadFS fails
1128+
err = db.DropView(context.Background(), []string{nsName, viewName})
1129+
s.Error(err, "DropView should return an error when LoadFS fails for invalid metadata location")
1130+
}
1131+
11001132
func (s *SqliteCatalogTestSuite) TestCheckViewExists() {
11011133
db := s.getCatalogSqlite()
11021134
s.Require().NoError(db.CreateSQLTables(context.Background()))

0 commit comments

Comments
 (0)