Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/catalog/IcebergRestCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
TableIdentifier,
TableMetadata,
UpdateTableRequest,
DropTableRequest,
} from './types'

/**
Expand Down Expand Up @@ -254,8 +255,8 @@ export class IcebergRestCatalog {
* await catalog.dropTable({ namespace: ['analytics'], name: 'events' });
* ```
*/
async dropTable(id: TableIdentifier): Promise<void> {
await this.tableOps.dropTable(id)
async dropTable(id: TableIdentifier, options?: DropTableRequest): Promise<void> {
await this.tableOps.dropTable(id, options)
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/catalog/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
TableIdentifier,
TableMetadata,
UpdateTableRequest,
DropTableRequest,
} from './types'

function namespaceToPath(namespace: string[]): string {
Expand Down Expand Up @@ -58,10 +59,11 @@ export class TableOperations {
return response.data.metadata
}

async dropTable(id: TableIdentifier): Promise<void> {
async dropTable(id: TableIdentifier, options?: DropTableRequest): Promise<void> {
await this.client.request<void>({
method: 'DELETE',
path: `${this.prefix}/namespaces/${namespaceToPath(id.namespace)}/tables/${id.name}`,
query: { purgeRequested: String(options?.purge ?? false) },
})
}

Expand Down
4 changes: 4 additions & 0 deletions src/catalog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export interface UpdateTableRequest {
properties?: Record<string, string>
}

export interface DropTableRequest {
purge?: boolean
}

export interface TableMetadata {
name?: string
location: string
Expand Down
20 changes: 20 additions & 0 deletions test/catalog/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
})
})

Expand All @@ -369,6 +388,7 @@ describe('TableOperations', () => {
expect(mockClient.request).toHaveBeenCalledWith({
method: 'DELETE',
path: '/v1/namespaces/analytics\x1Fprod/tables/events',
query: {purgeRequested: "false"}
})
})
})
Expand Down