diff --git a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts index 052b2a00c3..394a10f8d8 100644 --- a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts +++ b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts @@ -60,6 +60,8 @@ describe("command surface", () => { "warehouse status", "warehouse tables", "warehouse tables get", + "warehouse tables layout", + "warehouse tables layout get", "warehouse tables list", "warehouse teardowns", "warehouse teardowns get", diff --git a/apps/cli/src/commands/api/api-command-bindings.integration.test.ts b/apps/cli/src/commands/api/api-command-bindings.integration.test.ts index 40165faa4b..224bae2207 100644 --- a/apps/cli/src/commands/api/api-command-bindings.integration.test.ts +++ b/apps/cli/src/commands/api/api-command-bindings.integration.test.ts @@ -81,13 +81,19 @@ const operationOf = (operationId: string): SpecOperation => { throw new Error(`${operationId} is not in openapi.json`); }; -/** The JSON Schema types of a node, with OpenAPI 3.0 `nullable` folded in as a `null` type. */ +/** + * The JSON Schema types of a node, with OpenAPI 3.0 `nullable` and a `null` union branch folded in + * as a `null` type. + */ const typesOf = (node: Json): ReadonlyArray => { const declared = node["type"]; const types = (Array.isArray(declared) ? declared : declared === undefined ? [] : [declared]).map( String, ); - return (node["nullable"] === true ? [...types, "null"] : types) + const nullable = + node["nullable"] === true || + asList(node["anyOf"]).some((branch) => asRecord(branch)["type"] === "null"); + return (nullable ? [...types, "null"] : types) .filter((type, index, all) => all.indexOf(type) === index) .toSorted((a, b) => a.localeCompare(b)); }; diff --git a/apps/cli/src/commands/api/api-command-policy.ts b/apps/cli/src/commands/api/api-command-policy.ts index 9d00ea8806..dfb73fa48e 100644 --- a/apps/cli/src/commands/api/api-command-policy.ts +++ b/apps/cli/src/commands/api/api-command-policy.ts @@ -38,6 +38,7 @@ export const generatedOperations: ReadonlyArray = [ "v2-get-warehouse-teardown", "v2-list-warehouse-tables", "v2-get-warehouse-table", + "v2-get-warehouse-table-layout", ]; export const nouns = { @@ -46,6 +47,7 @@ export const nouns = { feature: "warehouse", groups: { tables: "Inspect tables replicated to Warehouse", + "tables.layout": "Inspect the layout of tables replicated to Warehouse", teardowns: "Inspect Warehouse cleanup operations", }, }, diff --git a/apps/cli/src/commands/api/api-commands.integration.test.ts b/apps/cli/src/commands/api/api-commands.integration.test.ts index 2386d39f88..4d9740021a 100644 --- a/apps/cli/src/commands/api/api-commands.integration.test.ts +++ b/apps/cli/src/commands/api/api-commands.integration.test.ts @@ -480,6 +480,46 @@ describe("generated warehouse commands", () => { }, ); }); + describe("warehouse tables layout get", () => { + const layoutPath = `/v2/projects/${VALID_REF}/warehouse/tables/16385/layout`; + const body = { + data: { + id: "16385", + type: "warehouse_table_layout", + attributes: { + schema: "public", + name: "events", + desired: { + sort_by: null, + partition_by: [{ column: "account_id", transform: { kind: "bucket", count: 16 } }], + }, + observation_status: "observed", + observed: { + sort_by: [{ expression: '"created_at"', direction: "DESC", nulls: "NULLS_LAST" }], + partition_by: [{ column: "account_id", transform: "bucket(16)" }], + observed_at: "2026-11-18T09:30:00.123456Z", + }, + }, + }, + }; + + it.effect("renders unmanaged desired sorting beside the observed catalog layout", () => { + const { out, sent, run } = setup(["warehouse", "tables", "layout", "get", "16385"], { + route: ok(body), + stdoutIsTty: true, + }); + return Effect.gen(function* () { + yield* run; + expect(sent).toEqual([{ method: "GET", path: layoutPath, search: "", body: undefined }]); + expect(out.stdoutText).toMatch(/^Warehouse table layout\n/); + expect(out.stdoutText).toMatch(/Desired\n\s+Sort by\s+-\n/); + expect(out.stdoutText).toMatch(/account_id \| \{"kind":"bucket","count":16\}/); + expect(out.stdoutText).toMatch(/Observation status\s+observed/); + expect(out.stdoutText).toMatch(/account_id \| bucket\(16\)/); + expect(out.stdoutText).toMatch(/Observed at\s+2026-11-18T09:30:00\.123456Z/); + }); + }); + }); describe("warehouse connection", () => { const connectionPath = `/v2/projects/${VALID_REF}/warehouse/connection`; const host = `${VALID_REF}.warehouse.example.invalid`; diff --git a/apps/cli/src/commands/api/generated.md b/apps/cli/src/commands/api/generated.md index 9a1bb54ab3..e010aa47b3 100644 --- a/apps/cli/src/commands/api/generated.md +++ b/apps/cli/src/commands/api/generated.md @@ -88,6 +88,17 @@ Returns one source table selected for Warehouse replication by its source OID, f - Request: `GET /v2/projects/{ref}/warehouse/tables/{table_id}` (`v2-get-warehouse-table`), success 200 json. - Positional argument ``, bound to path parameter `table_id`. +## `supabase warehouse tables layout get` + +Get the layout of a table replicated to Warehouse + +Returns the sorting and partitioning rules saved for one replicated table, by source OID, beside the layout the DuckLake catalog records for it. The two are reported separately and can differ: the replicator applies saved rules when it starts and then hourly, and a stopped pipeline applies them on its next start. observation_status reports whether the catalog was read; desired rules are returned even when it was not. A catalog layout governs files written after it changes and does not establish that existing files are sorted or partitioned. Returns 404 when the table is not replicated, including when Warehouse is not set up, is being disabled or failed to clean up. + +- Access: read-only, no consent. +- Feature: `warehouse`. +- Request: `GET /v2/projects/{ref}/warehouse/tables/{table_id}/layout` (`v2-get-warehouse-table-layout`), success 200 json. +- Positional argument ``, bound to path parameter `table_id`. + ## `supabase warehouse tables list` List tables replicated to Warehouse diff --git a/apps/cli/src/commands/api/generated.schemas.ts b/apps/cli/src/commands/api/generated.schemas.ts index 4cbcade337..334a34bed9 100644 --- a/apps/cli/src/commands/api/generated.schemas.ts +++ b/apps/cli/src/commands/api/generated.schemas.ts @@ -1201,6 +1201,264 @@ export const apiCommandSchemas = { type: "object", }, }, + "v2-get-warehouse-table-layout": { + result: { + $schema: "https://json-schema.org/draft/2020-12/schema", + properties: { + data: { + properties: { + attributes: { + properties: { + desired: { + description: + "Saved layout rules. The replicator applies them on start and hourly, so they can differ from the observed layout.", + properties: { + partition_by: { + description: + "Configured partition keys in order. An empty list explicitly clears partitioning; null leaves it unmanaged.", + items: { + properties: { + column: { + description: "Source column name.", + type: "string", + }, + transform: { + oneOf: [ + { + properties: { + kind: { + enum: ["identity"], + type: "string", + }, + }, + required: ["kind"], + type: "object", + }, + { + properties: { + kind: { + enum: ["year"], + type: "string", + }, + }, + required: ["kind"], + type: "object", + }, + { + properties: { + kind: { + enum: ["month"], + type: "string", + }, + }, + required: ["kind"], + type: "object", + }, + { + properties: { + kind: { + enum: ["day"], + type: "string", + }, + }, + required: ["kind"], + type: "object", + }, + { + properties: { + kind: { + enum: ["hour"], + type: "string", + }, + }, + required: ["kind"], + type: "object", + }, + { + properties: { + count: { + description: "Number of hash buckets.", + maximum: 2147483647, + type: "integer", + exclusiveMinimum: 0, + }, + kind: { + enum: ["bucket"], + type: "string", + }, + }, + required: ["count", "kind"], + type: "object", + }, + ], + }, + }, + required: ["column", "transform"], + type: "object", + }, + type: ["array", "null"], + }, + sort_by: { + anyOf: [ + { + description: + "Configured sort order. none explicitly clears sorting, primary_key sorts by the source primary-key columns in key order, and columns lists them. Null leaves sorting unmanaged.", + oneOf: [ + { + properties: { + kind: { + enum: ["none"], + type: "string", + }, + }, + required: ["kind"], + type: "object", + }, + { + properties: { + kind: { + enum: ["primary_key"], + type: "string", + }, + }, + required: ["kind"], + type: "object", + }, + { + properties: { + columns: { + items: { + properties: { + direction: { + enum: ["asc", "desc"], + type: "string", + }, + name: { + description: "Source column name.", + type: "string", + }, + nulls: { + description: + "Null placement. Null uses DuckLake's default placement.", + enum: ["first", "last", null], + type: ["string", "null"], + }, + }, + required: ["direction", "name", "nulls"], + type: "object", + }, + type: "array", + }, + kind: { + enum: ["columns"], + type: "string", + }, + }, + required: ["columns", "kind"], + type: "object", + }, + ], + }, + { + type: "null", + }, + ], + }, + }, + required: ["partition_by", "sort_by"], + type: "object", + }, + name: { + description: "Source PostgreSQL table name.", + type: "string", + }, + observation_status: { + description: + "observed when the DuckLake catalog was read, table_missing when the catalog has no table for it yet, and unavailable when the catalog could not be read.", + enum: ["observed", "table_missing", "unavailable"], + type: "string", + }, + observed: { + description: + "Layout recorded in the DuckLake catalog, null unless observation_status is observed. Catalog metadata governs files written after it changes and does not establish that existing files are sorted or partitioned.", + properties: { + observed_at: { + description: "Time the catalog metadata was read.", + format: "date-time", + pattern: + "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$", + type: "string", + }, + partition_by: { + description: + "Active partition keys in key order, with transforms as the catalog reports them, for example bucket(16).", + items: { + properties: { + column: { + type: "string", + }, + transform: { + type: "string", + }, + }, + required: ["column", "transform"], + type: "object", + }, + type: "array", + }, + sort_by: { + description: + "Active sort expressions in key order, as the catalog reports them.", + items: { + properties: { + direction: { + type: "string", + }, + expression: { + type: "string", + }, + nulls: { + type: "string", + }, + }, + required: ["direction", "expression", "nulls"], + type: "object", + }, + type: "array", + }, + }, + required: ["observed_at", "partition_by", "sort_by"], + type: ["object", "null"], + }, + schema: { + description: "Source PostgreSQL schema of the table.", + type: "string", + }, + }, + required: ["desired", "name", "observation_status", "observed", "schema"], + type: "object", + }, + id: { + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + maxLength: 10, + pattern: "^[1-9]\\d*$", + type: "string", + examples: ["16385"], + }, + type: { + description: "Resource type.", + enum: ["warehouse_table_layout"], + type: "string", + }, + }, + required: ["attributes", "id", "type"], + type: "object", + }, + }, + required: ["data"], + type: "object", + }, + }, "v2-get-warehouse-teardown": { result: { $schema: "https://json-schema.org/draft/2020-12/schema", diff --git a/apps/cli/src/commands/api/generated.ts b/apps/cli/src/commands/api/generated.ts index d6b37b1b13..52f0e35045 100644 --- a/apps/cli/src/commands/api/generated.ts +++ b/apps/cli/src/commands/api/generated.ts @@ -248,6 +248,40 @@ export const apiCommands = [ }, ], }, + { + command: ["warehouse", "tables", "layout", "get"], + operationId: "v2-get-warehouse-table-layout", + definition: "v2GetWarehouseTableLayout", + method: "GET", + apiPath: "/v2/projects/{ref}/warehouse/tables/{table_id}/layout", + summary: "Get the layout of a table replicated to Warehouse", + description: + "Returns the sorting and partitioning rules saved for one replicated table, by source OID, beside the layout the DuckLake catalog records for it. The two are reported separately and can differ: the replicator applies saved rules when it starts and then hourly, and a stopped pipeline applies them on its next start. observation_status reports whether the catalog was read; desired rules are returned even when it was not. A catalog layout governs files written after it changes and does not establish that existing files are sorted or partitioned. Returns 404 when the table is not replicated, including when Warehouse is not set up, is being disabled or failed to clean up.", + readOnly: true, + feature: "warehouse", + response: { + status: 200, + kind: "json", + }, + argument: { + name: "table-id", + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + }, + flags: [], + bindings: [ + { + location: "path", + name: "ref", + source: "target", + }, + { + location: "path", + name: "table_id", + source: "argument", + argument: "table-id", + }, + ], + }, { command: ["warehouse", "tables", "list"], operationId: "v2-list-warehouse-tables", diff --git a/packages/api/scripts/generate.ts b/packages/api/scripts/generate.ts index db22bc75ba..8678ee9534 100644 --- a/packages/api/scripts/generate.ts +++ b/packages/api/scripts/generate.ts @@ -332,14 +332,15 @@ export function sanitizeOpenApiSchema( delete sanitized.pattern; } - if ( - sanitized.nullable === true && - sanitized.type === undefined && - Array.isArray(sanitized.anyOf) - ) { + const union = Array.isArray(sanitized.anyOf) + ? "anyOf" + : Array.isArray(sanitized.oneOf) + ? "oneOf" + : undefined; + if (sanitized.nullable === true && sanitized.type === undefined && union !== undefined) { const normalized = { ...sanitized, - anyOf: [...sanitized.anyOf, { type: "null" }], + [union]: [...(sanitized[union] ?? []), { type: "null" }], }; delete normalized.nullable; return normalized; diff --git a/packages/api/scripts/generate.unit.test.ts b/packages/api/scripts/generate.unit.test.ts index 278fd316a5..6e361ec65f 100644 --- a/packages/api/scripts/generate.unit.test.ts +++ b/packages/api/scripts/generate.unit.test.ts @@ -275,6 +275,15 @@ describe("generate", () => { ).toBe("Schema.Union([Schema.String, Schema.Finite, Schema.Boolean, Schema.Null])"); }); + test("preserves null in nullable oneOf variants without an explicit type", () => { + expect( + renderOpenApiSchema({ + oneOf: [{ type: "string", enum: ["none"] }, { type: "integer" }], + nullable: true, + }), + ).toBe('Schema.Union([Schema.Literal("none"), Schema.Int, Schema.Null], { mode: "oneOf" })'); + }); + test("accepts booleans for string-encoded boolean query parameters", () => { expect( normalizeQueryParameterSchema( diff --git a/packages/api/scripts/openapi-overrides.json b/packages/api/scripts/openapi-overrides.json index d36f9c98c3..8e26f033d3 100644 --- a/packages/api/scripts/openapi-overrides.json +++ b/packages/api/scripts/openapi-overrides.json @@ -1472,6 +1472,380 @@ }, "$comment": "The Warehouse table inspection contract is not yet in the deployed Management API specification." }, + { + "op": "add", + "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1tables~1{table_id}~1layout", + "value": { + "get": { + "description": "Returns the sorting and partitioning rules saved for one replicated table, by source OID, beside the layout the DuckLake catalog records for it. The two are reported separately and can differ: the replicator applies saved rules when it starts and then hourly, and a stopped pipeline applies them on its next start. observation_status reports whether the catalog was read; desired rules are returned even when it was not. A catalog layout governs files written after it changes and does not establish that existing files are sorted or partitioned. Returns 404 when the table is not replicated, including when Warehouse is not set up, is being disabled or failed to clean up.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-get-warehouse-table-layout", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + }, + { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "in": "path", + "name": "table_id", + "required": true, + "schema": { + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTableLayoutResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Table not replicated to Warehouse" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table layout unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "Get the layout of a table replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables.layout", + "method": "get" + }, + "x-scalar-stability": "experimental" + } + }, + "$comment": "The Warehouse table layout contract is not yet in the deployed Management API specification." + }, + { + "op": "add", + "path": "/components/schemas/V2WarehouseTableLayoutResponse_Output", + "value": { + "properties": { + "data": { + "properties": { + "attributes": { + "properties": { + "desired": { + "description": "Saved layout rules. The replicator applies them on start and hourly, so they can differ from the observed layout.", + "properties": { + "partition_by": { + "description": "Configured partition keys in order. An empty list explicitly clears partitioning; null leaves it unmanaged.", + "items": { + "properties": { + "column": { + "description": "Source column name.", + "type": "string" + }, + "transform": { + "oneOf": [ + { + "properties": { + "kind": { + "enum": ["identity"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["year"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["month"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["day"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["hour"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "count": { + "description": "Number of hash buckets.", + "exclusiveMinimum": true, + "maximum": 2147483647, + "minimum": 0, + "type": "integer" + }, + "kind": { + "enum": ["bucket"], + "type": "string" + } + }, + "required": ["count", "kind"], + "type": "object" + } + ] + } + }, + "required": ["column", "transform"], + "type": "object" + }, + "nullable": true, + "type": "array" + }, + "sort_by": { + "description": "Configured sort order. none explicitly clears sorting, primary_key sorts by the source primary-key columns in key order, and columns lists them. Null leaves sorting unmanaged.", + "nullable": true, + "oneOf": [ + { + "properties": { + "kind": { + "enum": ["none"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["primary_key"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "columns": { + "items": { + "properties": { + "direction": { + "enum": ["asc", "desc"], + "type": "string" + }, + "name": { + "description": "Source column name.", + "type": "string" + }, + "nulls": { + "description": "Null placement. Null uses DuckLake's default placement.", + "enum": ["first", "last", null], + "nullable": true, + "type": "string" + } + }, + "required": ["direction", "name", "nulls"], + "type": "object" + }, + "type": "array" + }, + "kind": { + "enum": ["columns"], + "type": "string" + } + }, + "required": ["columns", "kind"], + "type": "object" + } + ] + } + }, + "required": ["partition_by", "sort_by"], + "type": "object" + }, + "name": { + "description": "Source PostgreSQL table name.", + "type": "string" + }, + "observation_status": { + "description": "observed when the DuckLake catalog was read, table_missing when the catalog has no table for it yet, and unavailable when the catalog could not be read.", + "enum": ["observed", "table_missing", "unavailable"], + "type": "string" + }, + "observed": { + "description": "Layout recorded in the DuckLake catalog, null unless observation_status is observed. Catalog metadata governs files written after it changes and does not establish that existing files are sorted or partitioned.", + "nullable": true, + "properties": { + "observed_at": { + "description": "Time the catalog metadata was read.", + "format": "date-time", + "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$", + "type": "string" + }, + "partition_by": { + "description": "Active partition keys in key order, with transforms as the catalog reports them, for example bucket(16).", + "items": { + "properties": { + "column": { + "type": "string" + }, + "transform": { + "type": "string" + } + }, + "required": ["column", "transform"], + "type": "object" + }, + "type": "array" + }, + "sort_by": { + "description": "Active sort expressions in key order, as the catalog reports them.", + "items": { + "properties": { + "direction": { + "type": "string" + }, + "expression": { + "type": "string" + }, + "nulls": { + "type": "string" + } + }, + "required": ["direction", "expression", "nulls"], + "type": "object" + }, + "type": "array" + } + }, + "required": ["observed_at", "partition_by", "sort_by"], + "type": "object" + }, + "schema": { + "description": "Source PostgreSQL schema of the table.", + "type": "string" + } + }, + "required": ["desired", "name", "observation_status", "observed", "schema"], + "type": "object" + }, + "id": { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table_layout"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + } + }, + "required": ["data"], + "type": "object" + }, + "$comment": "The Warehouse table layout contract is not yet in the deployed Management API specification." + }, { "op": "test", "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1setups~1current/get/x-operation", diff --git a/packages/api/src/generated/contracts.ts b/packages/api/src/generated/contracts.ts index b5a6a4c5c8..07acba934a 100644 --- a/packages/api/src/generated/contracts.ts +++ b/packages/api/src/generated/contracts.ts @@ -15191,6 +15191,145 @@ export const V2GetWarehouseTableOutput = Schema.Struct({ type: Schema.Literal("warehouse_table").annotate({ description: "Resource type." }), }), }); +export const V2GetWarehouseTableLayoutInput = Schema.Struct({ + ref: Schema.String.check( + Schema.isMinCodePoints(20).annotate({ expected: "a string with at least 20 code points" }), + ) + .check( + Schema.isMaxCodePoints(20).annotate({ expected: "a string with at most 20 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[a-z]+$", "u")).annotate({ + expected: "a string matching the RegExp ^[a-z]+$", + }), + ), + table_id: Schema.String.check( + Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), + ).check( + Schema.isPattern(new RegExp("^[1-9]\\d*$", "u")).annotate({ + expected: "a string matching the RegExp ^[1-9]\\d*$", + }), + ), +}); +export const V2GetWarehouseTableLayoutOutput = Schema.Struct({ + data: Schema.Struct({ + attributes: Schema.Struct({ + desired: Schema.Struct({ + partition_by: Schema.Union([ + Schema.Array( + Schema.Struct({ + column: Schema.String.annotate({ description: "Source column name." }), + transform: Schema.Union( + [ + Schema.Struct({ kind: Schema.Literal("identity") }), + Schema.Struct({ kind: Schema.Literal("year") }), + Schema.Struct({ kind: Schema.Literal("month") }), + Schema.Struct({ kind: Schema.Literal("day") }), + Schema.Struct({ kind: Schema.Literal("hour") }), + Schema.Struct({ + count: Schema.Number.annotate({ description: "Number of hash buckets." }) + .check(Schema.isInt().annotate({ expected: "an integer" })) + .check( + Schema.isLessThanOrEqualTo(2147483647).annotate({ + expected: "a value less than or equal to 2147483647", + }), + ) + .check( + Schema.isGreaterThan(0).annotate({ expected: "a value greater than 0" }), + ), + kind: Schema.Literal("bucket"), + }), + ], + { mode: "oneOf" }, + ), + }), + ).annotate({ + description: + "Configured partition keys in order. An empty list explicitly clears partitioning; null leaves it unmanaged.", + }), + Schema.Null, + ]), + sort_by: Schema.Union( + [ + Schema.Struct({ kind: Schema.Literal("none") }), + Schema.Struct({ kind: Schema.Literal("primary_key") }), + Schema.Struct({ + columns: Schema.Array( + Schema.Struct({ + direction: Schema.Union([Schema.Literals(["asc", "desc"]), OpenString]), + name: Schema.String.annotate({ description: "Source column name." }), + nulls: Schema.Union([ + Schema.Union([Schema.Literals(["first", "last"]), Schema.Null]).annotate({ + description: "Null placement. Null uses DuckLake's default placement.", + }), + OpenString, + ]), + }), + ), + kind: Schema.Literal("columns"), + }), + Schema.Null, + ], + { mode: "oneOf" }, + ).annotate({ + description: + "Configured sort order. none explicitly clears sorting, primary_key sorts by the source primary-key columns in key order, and columns lists them. Null leaves sorting unmanaged.", + }), + }).annotate({ + description: + "Saved layout rules. The replicator applies them on start and hourly, so they can differ from the observed layout.", + }), + name: Schema.String.annotate({ description: "Source PostgreSQL table name." }), + observation_status: Schema.Union([ + Schema.Literals(["observed", "table_missing", "unavailable"]).annotate({ + description: + "observed when the DuckLake catalog was read, table_missing when the catalog has no table for it yet, and unavailable when the catalog could not be read.", + }), + OpenString, + ]), + observed: Schema.Union([ + Schema.Struct({ + observed_at: Schema.String.annotate({ + description: "Time the catalog metadata was read.", + format: "date-time", + }), + partition_by: Schema.Array( + Schema.Struct({ column: Schema.String, transform: Schema.String }), + ).annotate({ + description: + "Active partition keys in key order, with transforms as the catalog reports them, for example bucket(16).", + }), + sort_by: Schema.Array( + Schema.Struct({ + direction: Schema.String, + expression: Schema.String, + nulls: Schema.String, + }), + ).annotate({ + description: "Active sort expressions in key order, as the catalog reports them.", + }), + }).annotate({ + description: + "Layout recorded in the DuckLake catalog, null unless observation_status is observed. Catalog metadata governs files written after it changes and does not establish that existing files are sorted or partitioned.", + }), + Schema.Null, + ]), + schema: Schema.String.annotate({ description: "Source PostgreSQL schema of the table." }), + }), + id: Schema.String.annotate({ + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + }) + .check( + Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[1-9]\\d*$", "u")).annotate({ + expected: "a string matching the RegExp ^[1-9]\\d*$", + }), + ), + type: Schema.Literal("warehouse_table_layout").annotate({ description: "Resource type." }), + }), +}); export const V2GetWarehouseTeardownInput = Schema.Struct({ ref: Schema.String.check( Schema.isMinCodePoints(20).annotate({ expected: "a string with at least 20 code points" }), @@ -20398,6 +20537,7 @@ export const openApiOperationIdMap = { "v2-get-warehouse-setup": "v2GetWarehouseSetup", "v2-get-warehouse-status": "v2GetWarehouseStatus", "v2-get-warehouse-table": "v2GetWarehouseTable", + "v2-get-warehouse-table-layout": "v2GetWarehouseTableLayout", "v2-get-warehouse-teardown": "v2GetWarehouseTeardown", "v2-list-all-compute-instances": "v2ListAllComputeInstances", "v2-list-log-drains": "v2ListLogDrains", @@ -23628,6 +23768,20 @@ export const operationDefinitions = { inputSchema: V2GetWarehouseTableInput, outputSchema: V2GetWarehouseTableOutput, }, + v2GetWarehouseTableLayout: { + id: "v2GetWarehouseTableLayout", + description: + "Returns the sorting and partitioning rules saved for one replicated table, by source OID, beside the layout the DuckLake catalog records for it. The two are reported separately and can differ: the replicator applies saved rules when it starts and then hourly, and a stopped pipeline applies them on its next start. observation_status reports whether the catalog was read; desired rules are returned even when it was not. A catalog layout governs files written after it changes and does not establish that existing files are sorted or partitioned. Returns 404 when the table is not replicated, including when Warehouse is not set up, is being disabled or failed to clean up.\n\nThis endpoint is currently in its **Alpha** stage.", + method: "GET", + path: "/v2/projects/{ref}/warehouse/tables/{table_id}/layout", + pathParams: ["ref", "table_id"], + queryParams: [], + headerParams: [], + requestBody: { kind: "none" }, + response: { kind: "json" }, + inputSchema: V2GetWarehouseTableLayoutInput, + outputSchema: V2GetWarehouseTableLayoutOutput, + }, v2GetWarehouseTeardown: { id: "v2GetWarehouseTeardown", description: diff --git a/packages/api/src/generated/effect-client.ts b/packages/api/src/generated/effect-client.ts index dfcad4c47e..d8832c0141 100644 --- a/packages/api/src/generated/effect-client.ts +++ b/packages/api/src/generated/effect-client.ts @@ -3156,6 +3156,22 @@ export const versionedEffectOperations = { options, ); }), + getWarehouseTableLayout: ( + input: typeof operationDefinitions.v2GetWarehouseTableLayout.inputSchema.Type, + options?: SupabaseApiRequestOptions, + ): Effect.Effect< + typeof operationDefinitions.v2GetWarehouseTableLayout.outputSchema.Type, + SupabaseApiError, + SupabaseApiClient + > => + Effect.gen(function* () { + const client = yield* SupabaseApiClient; + return yield* client.execute<"v2GetWarehouseTableLayout">( + operationDefinitions.v2GetWarehouseTableLayout, + input, + options, + ); + }), getWarehouseTeardown: ( input: typeof operationDefinitions.v2GetWarehouseTeardown.inputSchema.Type, options?: SupabaseApiRequestOptions, diff --git a/packages/api/src/generated/openapi.json b/packages/api/src/generated/openapi.json index a47c989ec1..66f86343b5 100644 --- a/packages/api/src/generated/openapi.json +++ b/packages/api/src/generated/openapi.json @@ -33086,6 +33086,126 @@ }, "x-scalar-stability": "experimental" } + }, + "/v2/projects/{ref}/warehouse/tables/{table_id}/layout": { + "get": { + "description": "Returns the sorting and partitioning rules saved for one replicated table, by source OID, beside the layout the DuckLake catalog records for it. The two are reported separately and can differ: the replicator applies saved rules when it starts and then hourly, and a stopped pipeline applies them on its next start. observation_status reports whether the catalog was read; desired rules are returned even when it was not. A catalog layout governs files written after it changes and does not establish that existing files are sorted or partitioned. Returns 404 when the table is not replicated, including when Warehouse is not set up, is being disabled or failed to clean up.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-get-warehouse-table-layout", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + }, + { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "in": "path", + "name": "table_id", + "required": true, + "schema": { + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTableLayoutResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Table not replicated to Warehouse" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table layout unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "Get the layout of a table replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables.layout", + "method": "get" + }, + "x-scalar-stability": "experimental" + } } }, "components": { @@ -49290,6 +49410,250 @@ }, "required": ["data"], "type": "object" + }, + "V2WarehouseTableLayoutResponse_Output": { + "properties": { + "data": { + "properties": { + "attributes": { + "properties": { + "desired": { + "description": "Saved layout rules. The replicator applies them on start and hourly, so they can differ from the observed layout.", + "properties": { + "partition_by": { + "description": "Configured partition keys in order. An empty list explicitly clears partitioning; null leaves it unmanaged.", + "items": { + "properties": { + "column": { + "description": "Source column name.", + "type": "string" + }, + "transform": { + "oneOf": [ + { + "properties": { + "kind": { + "enum": ["identity"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["year"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["month"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["day"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["hour"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "count": { + "description": "Number of hash buckets.", + "exclusiveMinimum": true, + "maximum": 2147483647, + "minimum": 0, + "type": "integer" + }, + "kind": { + "enum": ["bucket"], + "type": "string" + } + }, + "required": ["count", "kind"], + "type": "object" + } + ] + } + }, + "required": ["column", "transform"], + "type": "object" + }, + "nullable": true, + "type": "array" + }, + "sort_by": { + "description": "Configured sort order. none explicitly clears sorting, primary_key sorts by the source primary-key columns in key order, and columns lists them. Null leaves sorting unmanaged.", + "nullable": true, + "oneOf": [ + { + "properties": { + "kind": { + "enum": ["none"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "kind": { + "enum": ["primary_key"], + "type": "string" + } + }, + "required": ["kind"], + "type": "object" + }, + { + "properties": { + "columns": { + "items": { + "properties": { + "direction": { + "enum": ["asc", "desc"], + "type": "string" + }, + "name": { + "description": "Source column name.", + "type": "string" + }, + "nulls": { + "description": "Null placement. Null uses DuckLake's default placement.", + "enum": ["first", "last", null], + "nullable": true, + "type": "string" + } + }, + "required": ["direction", "name", "nulls"], + "type": "object" + }, + "type": "array" + }, + "kind": { + "enum": ["columns"], + "type": "string" + } + }, + "required": ["columns", "kind"], + "type": "object" + } + ] + } + }, + "required": ["partition_by", "sort_by"], + "type": "object" + }, + "name": { + "description": "Source PostgreSQL table name.", + "type": "string" + }, + "observation_status": { + "description": "observed when the DuckLake catalog was read, table_missing when the catalog has no table for it yet, and unavailable when the catalog could not be read.", + "enum": ["observed", "table_missing", "unavailable"], + "type": "string" + }, + "observed": { + "description": "Layout recorded in the DuckLake catalog, null unless observation_status is observed. Catalog metadata governs files written after it changes and does not establish that existing files are sorted or partitioned.", + "nullable": true, + "properties": { + "observed_at": { + "description": "Time the catalog metadata was read.", + "format": "date-time", + "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$", + "type": "string" + }, + "partition_by": { + "description": "Active partition keys in key order, with transforms as the catalog reports them, for example bucket(16).", + "items": { + "properties": { + "column": { + "type": "string" + }, + "transform": { + "type": "string" + } + }, + "required": ["column", "transform"], + "type": "object" + }, + "type": "array" + }, + "sort_by": { + "description": "Active sort expressions in key order, as the catalog reports them.", + "items": { + "properties": { + "direction": { + "type": "string" + }, + "expression": { + "type": "string" + }, + "nulls": { + "type": "string" + } + }, + "required": ["direction", "expression", "nulls"], + "type": "object" + }, + "type": "array" + } + }, + "required": ["observed_at", "partition_by", "sort_by"], + "type": "object" + }, + "schema": { + "description": "Source PostgreSQL schema of the table.", + "type": "string" + } + }, + "required": ["desired", "name", "observation_status", "observed", "schema"], + "type": "object" + }, + "id": { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table_layout"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + } + }, + "required": ["data"], + "type": "object" } } } diff --git a/packages/api/src/generated/permissions.ts b/packages/api/src/generated/permissions.ts index d074d62edf..85ddcad1f1 100644 --- a/packages/api/src/generated/permissions.ts +++ b/packages/api/src/generated/permissions.ts @@ -452,4 +452,5 @@ export const operationPermissions: Readonly "v2-get-warehouse-connection": { fga: [["database_read"]], oauthScope: "database:read" }, "v2-list-warehouse-tables": { fga: [["database_read"]], oauthScope: "database:read" }, "v2-get-warehouse-table": { fga: [["database_read"]], oauthScope: "database:read" }, + "v2-get-warehouse-table-layout": { fga: [["database_read"]], oauthScope: "database:read" }, };