@@ -3,6 +3,7 @@ import { AuthenticatedRequest } from '../../types'
3
3
import { FromSchema } from 'json-schema-to-ts'
4
4
import { ERRORS } from '@internal/errors'
5
5
import { CreateTableRequest } from '@storage/protocols/iceberg/catalog/rest-catalog-client'
6
+ import { ROUTE_OPERATIONS } from '../operations'
6
7
7
8
const createTableSchema = {
8
9
body : {
@@ -191,6 +192,14 @@ const dropTableSchema = {
191
192
type : 'object' ,
192
193
querystring : {
193
194
type : 'object' ,
195
+ properties : {
196
+ purgeRequested : {
197
+ type : 'string' ,
198
+ enum : [ 'true' , 'false' , 'True' , 'False' ] ,
199
+ default : 'false' ,
200
+ description : 'If true, the table will be permanently deleted' ,
201
+ } ,
202
+ } ,
194
203
} ,
195
204
params : {
196
205
type : 'object' ,
@@ -300,14 +309,9 @@ export default async function routes(fastify: FastifyInstance) {
300
309
throw ERRORS . FeatureNotEnabled ( 'icebergCatalog' , 'iceberg_catalog' )
301
310
}
302
311
303
- const bucket = await request . icebergCatalog . findCatalogById ( {
304
- tenantId : request . tenantId ,
305
- id : request . params . prefix ,
306
- } )
307
-
308
- const result = await request . icebergCatalog ?. createTable ( {
312
+ const result = await request . icebergCatalog . createTable ( {
309
313
...( request . body as unknown as CreateTableRequest ) ,
310
- warehouse : bucket . id ,
314
+ warehouse : request . params . prefix ,
311
315
namespace : request . params . namespace ,
312
316
} )
313
317
@@ -318,19 +322,18 @@ export default async function routes(fastify: FastifyInstance) {
318
322
fastify . get < listTableSchemaRequest > (
319
323
'/:prefix/namespaces/:namespace/tables' ,
320
324
{
325
+ config : {
326
+ operation : { type : ROUTE_OPERATIONS . ICEBERG_LIST_TABLES } ,
327
+ } ,
321
328
schema : { ...listTableSchema , tags : [ 'iceberg' ] } ,
322
329
} ,
323
330
async ( request , response ) => {
324
331
if ( ! request . icebergCatalog ) {
325
332
throw ERRORS . FeatureNotEnabled ( 'icebergCatalog' , 'iceberg_catalog' )
326
333
}
327
334
328
- await request . icebergCatalog . findCatalogById ( {
329
- tenantId : request . tenantId ,
330
- id : request . params . prefix ,
331
- } )
332
-
333
- const result = await request . icebergCatalog ?. listTables ( {
335
+ const result = await request . icebergCatalog . listTables ( {
336
+ warehouse : request . params . prefix ,
334
337
namespace : request . params . namespace ,
335
338
pageSize : request . query . pageSize ,
336
339
pageToken : request . query . pageToken ,
@@ -343,6 +346,9 @@ export default async function routes(fastify: FastifyInstance) {
343
346
fastify . get < loadTableRequest > (
344
347
'/:prefix/namespaces/:namespace/tables/:table' ,
345
348
{
349
+ config : {
350
+ operation : { type : ROUTE_OPERATIONS . ICEBERG_LOAD_TABLE } ,
351
+ } ,
346
352
schema : { ...loadTableSchema , tags : [ 'iceberg' ] } ,
347
353
exposeHeadRoute : false ,
348
354
} ,
@@ -351,13 +357,8 @@ export default async function routes(fastify: FastifyInstance) {
351
357
throw ERRORS . FeatureNotEnabled ( 'icebergCatalog' , 'iceberg_catalog' )
352
358
}
353
359
354
- const bucket = await request . icebergCatalog . findCatalogById ( {
355
- tenantId : request . tenantId ,
356
- id : request . params . prefix ,
357
- } )
358
-
359
- const result = await request . icebergCatalog ?. loadTable ( {
360
- warehouse : bucket . id ,
360
+ const result = await request . icebergCatalog . loadTable ( {
361
+ warehouse : request . params . prefix ,
361
362
namespace : request . params . namespace ,
362
363
table : request . params . table ,
363
364
} )
@@ -369,19 +370,18 @@ export default async function routes(fastify: FastifyInstance) {
369
370
fastify . head < loadTableRequest > (
370
371
'/:prefix/namespaces/:namespace/tables/:table' ,
371
372
{
373
+ config : {
374
+ operation : { type : ROUTE_OPERATIONS . ICEBERG_TABLE_EXISTS } ,
375
+ } ,
372
376
schema : { ...loadTableSchema , tags : [ 'iceberg' ] } ,
373
377
} ,
374
378
async ( request , response ) => {
375
379
if ( ! request . icebergCatalog ) {
376
380
throw ERRORS . FeatureNotEnabled ( 'icebergCatalog' , 'iceberg_catalog' )
377
381
}
378
382
379
- await request . icebergCatalog . findCatalogById ( {
380
- tenantId : request . tenantId ,
381
- id : request . params . prefix ,
382
- } )
383
-
384
- const result = await request . icebergCatalog ?. tableExists ( {
383
+ const result = await request . icebergCatalog . tableExists ( {
384
+ warehouse : request . params . prefix ,
385
385
namespace : request . params . namespace ,
386
386
table : request . params . table ,
387
387
} )
@@ -402,21 +402,21 @@ export default async function routes(fastify: FastifyInstance) {
402
402
fastify . delete < dropTableSchemaRequest > (
403
403
'/:prefix/namespaces/:namespace/tables/:table' ,
404
404
{
405
+ config : {
406
+ operation : { type : ROUTE_OPERATIONS . ICEBERG_DROP_TABLE } ,
407
+ } ,
405
408
schema : { ...dropTableSchema , tags : [ 'iceberg' ] } ,
406
409
} ,
407
410
async ( request , response ) => {
408
411
if ( ! request . icebergCatalog ) {
409
412
throw ERRORS . FeatureNotEnabled ( 'icebergCatalog' , 'iceberg_catalog' )
410
413
}
411
414
412
- await request . icebergCatalog . findCatalogById ( {
413
- tenantId : request . tenantId ,
414
- id : request . params . prefix ,
415
- } )
416
-
417
- const result = await request . icebergCatalog ?. dropTable ( {
415
+ const result = await request . icebergCatalog . dropTable ( {
418
416
namespace : request . params . namespace ,
419
417
table : request . params . table ,
418
+ warehouse : request . params . prefix ,
419
+ purgeRequested : request . query . purgeRequested ?. toLowerCase ( ) === 'true' ,
420
420
} )
421
421
422
422
return response . status ( 204 ) . send ( result )
@@ -427,22 +427,21 @@ export default async function routes(fastify: FastifyInstance) {
427
427
fastify . post < commitTableRequest > (
428
428
'/:prefix/namespaces/:namespace/tables/:table' ,
429
429
{
430
+ config : {
431
+ operation : { type : ROUTE_OPERATIONS . ICEBERG_COMMIT_TABLE } ,
432
+ } ,
430
433
schema : { ...commitTransactionSchema , tags : [ 'iceberg' ] } ,
431
434
} ,
432
435
async ( request , response ) => {
433
436
if ( ! request . icebergCatalog ) {
434
437
throw ERRORS . FeatureNotEnabled ( 'icebergCatalog' , 'iceberg_catalog' )
435
438
}
436
439
437
- await request . icebergCatalog . findCatalogById ( {
438
- tenantId : request . tenantId ,
439
- id : request . params . prefix ,
440
- } )
441
-
442
- const result = await request . icebergCatalog ?. updateTable ( {
440
+ const result = await request . icebergCatalog . updateTable ( {
443
441
...request . body ,
444
442
namespace : request . params . namespace ,
445
443
table : request . params . table ,
444
+ warehouse : request . params . prefix ,
446
445
} )
447
446
448
447
return response . send ( result )
0 commit comments