diff --git a/src/catalog/IcebergRestCatalog.ts b/src/catalog/IcebergRestCatalog.ts index 5ac4c95..725d909 100644 --- a/src/catalog/IcebergRestCatalog.ts +++ b/src/catalog/IcebergRestCatalog.ts @@ -9,6 +9,7 @@ import type { TableIdentifier, TableMetadata, UpdateTableRequest, + DropTableRequest, } from './types' /** @@ -254,8 +255,8 @@ export class IcebergRestCatalog { * await catalog.dropTable({ namespace: ['analytics'], name: 'events' }); * ``` */ - async dropTable(id: TableIdentifier): Promise { - await this.tableOps.dropTable(id) + async dropTable(id: TableIdentifier, options?: DropTableRequest): Promise { + await this.tableOps.dropTable(id, options) } /** diff --git a/src/catalog/tables.ts b/src/catalog/tables.ts index 8977de4..1f07157 100644 --- a/src/catalog/tables.ts +++ b/src/catalog/tables.ts @@ -7,6 +7,7 @@ import type { TableIdentifier, TableMetadata, UpdateTableRequest, + DropTableRequest, } from './types' function namespaceToPath(namespace: string[]): string { @@ -58,10 +59,11 @@ export class TableOperations { return response.data.metadata } - async dropTable(id: TableIdentifier): Promise { + async dropTable(id: TableIdentifier, options?: DropTableRequest): Promise { await this.client.request({ method: 'DELETE', path: `${this.prefix}/namespaces/${namespaceToPath(id.namespace)}/tables/${id.name}`, + query: { purgeRequested: String(options?.purge ?? false) }, }) } diff --git a/src/catalog/types.ts b/src/catalog/types.ts index d70111c..858c64a 100644 --- a/src/catalog/types.ts +++ b/src/catalog/types.ts @@ -81,6 +81,10 @@ export interface UpdateTableRequest { properties?: Record } +export interface DropTableRequest { + purge?: boolean +} + export interface TableMetadata { name?: string location: string diff --git a/test/catalog/tables.test.ts b/test/catalog/tables.test.ts index 94b5181..bba7628 100644 --- a/test/catalog/tables.test.ts +++ b/test/catalog/tables.test.ts @@ -352,6 +352,25 @@ describe('TableOperations', () => { expect(mockClient.request).toHaveBeenCalledWith({ method: 'DELETE', path: '/v1/namespaces/analytics/tables/events', + query: {purgeRequested: "false"} + }) + }) + + it('should drop a table with purge set to true', async () => { + const mockClient = createMockClient() + vi.mocked(mockClient.request).mockResolvedValue({ + status: 204, + headers: new Headers(), + data: undefined, + }) + + const ops = new TableOperations(mockClient, '/v1') + await ops.dropTable({ namespace: ['analytics'], name: 'events' }, {purge: true}) + + expect(mockClient.request).toHaveBeenCalledWith({ + method: 'DELETE', + path: '/v1/namespaces/analytics/tables/events', + query: {purgeRequested: "true"} }) }) @@ -369,6 +388,7 @@ describe('TableOperations', () => { expect(mockClient.request).toHaveBeenCalledWith({ method: 'DELETE', path: '/v1/namespaces/analytics\x1Fprod/tables/events', + query: {purgeRequested: "false"} }) }) })