Skip to content
Open
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
36 changes: 36 additions & 0 deletions console/src/api/catalog/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
LoadTableResult,
LoadGenericTableResponse,
GenericTableIdentifier,
SchemaField,
} from "@/types/api"

/**
Expand Down Expand Up @@ -130,6 +131,41 @@ export const tablesApi = {
await apiClient.getCatalogClient().post(`/${encodeURIComponent(prefix)}/tables/rename`, payload)
},

/**
* Update table schema using the commit API.
* Sends add-schema + set-current-schema updates with an assert-current-schema-id requirement.
*/
updateSchema: async (
prefix: string,
namespace: string[],
tableName: string,
newSchemaFields: SchemaField[],
currentSchemaId: number,
identifierFieldIds?: number[]
): Promise<void> => {
const namespaceStr = encodeNamespace(namespace)
const schema: Record<string, unknown> = {
type: "struct",
fields: newSchemaFields,
}
if (identifierFieldIds && identifierFieldIds.length > 0) {
schema["identifier-field-ids"] = identifierFieldIds
}
const body = {
requirements: [{ type: "assert-current-schema-id", "current-schema-id": currentSchemaId }],
updates: [
{ action: "add-schema", schema },
{ action: "set-current-schema", "schema-id": -1 },
],
}
await apiClient
.getCatalogClient()
.post(
`/${encodeURIComponent(prefix)}/namespaces/${encodeURIComponent(namespaceStr)}/tables/${encodeURIComponent(tableName)}`,
body
)
},

/**
* Update table properties using commit API.
* Sends set-properties and/or remove-properties updates.
Expand Down
Loading
Loading