@@ -218,16 +218,22 @@ func (c *Catalog) deleteTableSpecByName(name string) error {
218
218
return fmt .Errorf ("failed to find table spec from map by %s" , name )
219
219
}
220
220
tables := make ([]* TableSpec , 0 , len (c .tables ))
221
+ specName := strings .Join (spec .NamePath , "_" )
221
222
for _ , table := range c .tables {
222
- if spec == table {
223
+ if specName == strings . Join ( table . NamePath , "_" ) {
223
224
continue
224
225
}
225
226
tables = append (tables , table )
226
227
}
227
- c .tables = tables
228
- delete (c .tableMap , name )
229
- if err := c .resetCatalogs (); err != nil {
230
- return fmt .Errorf ("failed to reset catalogs: %w" , err )
228
+
229
+ c .defaultCatalog = newSimpleCatalog (defaultCatalogName )
230
+ c .pathToCatalogMap = map [string ]* types.SimpleCatalog {}
231
+ c .tables = []* TableSpec {}
232
+ c .tableMap = map [string ]* TableSpec {}
233
+ for _ , spec := range tables {
234
+ if err := c .addTableSpec (spec ); err != nil {
235
+ return err
236
+ }
231
237
}
232
238
return nil
233
239
}
@@ -238,28 +244,18 @@ func (c *Catalog) deleteFunctionSpecByName(name string) error {
238
244
return fmt .Errorf ("failed to find function spec from map by %s" , name )
239
245
}
240
246
functions := make ([]* FunctionSpec , 0 , len (c .functions ))
247
+ specName := strings .Join (spec .NamePath , "_" )
241
248
for _ , function := range c .functions {
242
- if spec == function {
249
+ if specName == strings . Join ( function . NamePath , "_" ) {
243
250
continue
244
251
}
245
252
functions = append (functions , function )
246
253
}
247
- c .functions = functions
248
- delete (c .funcMap , name )
249
- if err := c .resetCatalogs (); err != nil {
250
- return fmt .Errorf ("failed to reset catalogs: %w" , err )
251
- }
252
- return nil
253
- }
254
254
255
- func (c * Catalog ) resetCatalogs () error {
256
255
c .defaultCatalog = newSimpleCatalog (defaultCatalogName )
257
256
c .pathToCatalogMap = map [string ]* types.SimpleCatalog {}
258
- for _ , spec := range c .tables {
259
- if err := c .addTableSpec (spec ); err != nil {
260
- return err
261
- }
262
- }
257
+ c .functions = []* FunctionSpec {}
258
+ c .funcMap = map [string ]* FunctionSpec {}
263
259
for _ , spec := range c .functions {
264
260
if err := c .addFunctionSpec (spec ); err != nil {
265
261
return err
@@ -353,13 +349,15 @@ func (c *Catalog) addFunctionSpec(spec *FunctionSpec) error {
353
349
c .functions = append (c .functions , spec )
354
350
c .funcMap [funcName ] = spec
355
351
catalogMapKey := c .pathToCatalogMapKey (c .trimmedLastPath (spec .NamePath ))
356
- cat , exists := c .pathToCatalogMap [catalogMapKey ]
357
- if ! exists {
358
- cat = newSimpleCatalog (defaultCatalogName )
359
- c .pathToCatalogMap [catalogMapKey ] = cat
360
- }
361
- if err := c .addFunctionSpecRecursive (cat , spec ); err != nil {
362
- return err
352
+ if catalogMapKey != "" {
353
+ cat , exists := c .pathToCatalogMap [catalogMapKey ]
354
+ if ! exists {
355
+ cat = newSimpleCatalog (defaultCatalogName )
356
+ c .pathToCatalogMap [catalogMapKey ] = cat
357
+ }
358
+ if err := c .addFunctionSpecRecursive (cat , spec ); err != nil {
359
+ return err
360
+ }
363
361
}
364
362
if err := c .addFunctionSpecRecursive (c .defaultCatalog , spec ); err != nil {
365
363
return err
@@ -376,13 +374,15 @@ func (c *Catalog) addTableSpec(spec *TableSpec) error {
376
374
c .tables = append (c .tables , spec )
377
375
c .tableMap [tableName ] = spec
378
376
catalogMapKey := c .pathToCatalogMapKey (c .trimmedLastPath (spec .NamePath ))
379
- cat , exists := c .pathToCatalogMap [catalogMapKey ]
380
- if ! exists {
381
- cat = newSimpleCatalog (defaultCatalogName )
382
- c .pathToCatalogMap [catalogMapKey ] = cat
383
- }
384
- if err := c .addTableSpecRecursive (cat , spec ); err != nil {
385
- return err
377
+ if catalogMapKey != "" {
378
+ cat , exists := c .pathToCatalogMap [catalogMapKey ]
379
+ if ! exists {
380
+ cat = newSimpleCatalog (defaultCatalogName )
381
+ c .pathToCatalogMap [catalogMapKey ] = cat
382
+ }
383
+ if err := c .addTableSpecRecursive (cat , spec ); err != nil {
384
+ return err
385
+ }
386
386
}
387
387
if err := c .addTableSpecRecursive (c .defaultCatalog , spec ); err != nil {
388
388
return err
0 commit comments