From c912450a296ed2eb0d053d6244a2b82bc1ceaea4 Mon Sep 17 00:00:00 2001 From: roll Date: Wed, 8 Oct 2025 11:16:42 +0100 Subject: [PATCH 1/3] Rebased from legacy df.select signature --- table/table/denormalize.ts | 2 +- table/table/helpers.ts | 2 +- table/table/normalize.ts | 2 +- table/table/validate.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/table/table/denormalize.ts b/table/table/denormalize.ts index 2f724b5c..29ffa762 100644 --- a/table/table/denormalize.ts +++ b/table/table/denormalize.ts @@ -21,7 +21,7 @@ export async function denormalizeTable( const polarsSchema = getPolarsSchema(head.schema) return table.select( - Object.values(denormalizeFields(schema, polarsSchema, options)), + ...Object.values(denormalizeFields(schema, polarsSchema, options)), ) } diff --git a/table/table/helpers.ts b/table/table/helpers.ts index a7638d24..b52fb979 100644 --- a/table/table/helpers.ts +++ b/table/table/helpers.ts @@ -19,7 +19,7 @@ export async function joinHeaderRows( .withRowCount() .withColumn(col("row_nr").add(1)) .filter(col("row_nr").add(headerOffset).isIn(headerRows)) - .select(table.columns.map(name => col(name).str.concat(headerJoin))) + .select(...table.columns.map(name => col(name).str.concat(headerJoin))) .collect() const labels = table.columns diff --git a/table/table/normalize.ts b/table/table/normalize.ts index a5ead8e8..2121af3d 100644 --- a/table/table/normalize.ts +++ b/table/table/normalize.ts @@ -23,7 +23,7 @@ export async function normalizeTable( const polarsSchema = getPolarsSchema(head.schema) return table.select( - Object.values(normalizeFields(schema, polarsSchema, { noParse })), + ...Object.values(normalizeFields(schema, polarsSchema, { noParse })), ) } diff --git a/table/table/validate.ts b/table/table/validate.ts index 5e48ebd1..87230787 100644 --- a/table/table/validate.ts +++ b/table/table/validate.ts @@ -147,12 +147,12 @@ async function validateFields( let errorTable = table .withRowCount() - .select([ + .select( col("row_nr").add(1), lit(false).alias("error"), ...sources, ...targets, - ]) + ) for (const [index, field] of schema.fields.entries()) { const polarsField = matchField(index, field, schema, polarsSchema) From 656aa8e9e664b838b22aafa29a3cf02195f84d55 Mon Sep 17 00:00:00 2001 From: roll Date: Wed, 8 Oct 2025 13:00:36 +0100 Subject: [PATCH 2/3] Updated implementation --- table/table/validate.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/table/table/validate.ts b/table/table/validate.ts index 87230787..8cfd7179 100644 --- a/table/table/validate.ts +++ b/table/table/validate.ts @@ -54,11 +54,16 @@ function validateFieldsMatch(props: { const names = fields.map(field => field.name) const polarsNames = polarsFields.map(field => field.name) + const requiredNames = fields + .filter(field => field.constraints?.required) + .map(field => field.name) + const extraFields = polarsFields.length - fields.length const missingFields = fields.length - polarsFields.length const extraNames = arrayDiff(polarsNames, names) const missingNames = arrayDiff(names, polarsNames) + const missingRequiredNames = arrayDiff(requiredNames, polarsNames) if (fieldsMatch === "exact") { if (extraFields > 0) { @@ -84,19 +89,19 @@ function validateFieldsMatch(props: { }) } - if (missingNames.length > 0) { + if (missingRequiredNames.length > 0) { errors.push({ type: "fields/missing", - fieldNames: missingNames, + fieldNames: missingRequiredNames, }) } } if (fieldsMatch === "subset") { - if (missingNames.length > 0) { + if (missingRequiredNames.length > 0) { errors.push({ type: "fields/missing", - fieldNames: missingNames, + fieldNames: missingRequiredNames, }) } } From 851635022543e3b10b70f64bac1a47aa95752cbe Mon Sep 17 00:00:00 2001 From: roll Date: Wed, 8 Oct 2025 13:07:02 +0100 Subject: [PATCH 3/3] Updated tests --- table/table/validate.spec.ts | 46 ++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/table/table/validate.spec.ts b/table/table/validate.spec.ts index a114d73d..a9756e71 100644 --- a/table/table/validate.spec.ts +++ b/table/table/validate.spec.ts @@ -138,7 +138,11 @@ describe("validateTable", () => { fieldsMatch: "equal", fields: [ { name: "id", type: "number" }, - { name: "name", type: "string" }, + { + name: "name", + type: "string", + constraints: { required: true }, + }, ], } @@ -148,6 +152,23 @@ describe("validateTable", () => { fieldNames: ["name"], }) }) + + it("should pass when non-required fields are missing", async () => { + const table = DataFrame({ + id: [1, 2], + }).lazy() + + const schema: Schema = { + fieldsMatch: "equal", + fields: [ + { name: "id", type: "number" }, + { name: "name", type: "string" }, + ], + } + + const { errors } = await validateTable(table, { schema }) + expect(errors).toEqual([]) + }) }) describe("fields validation with fieldsMatch='subset'", () => { @@ -197,7 +218,11 @@ describe("validateTable", () => { fieldsMatch: "subset", fields: [ { name: "id", type: "number" }, - { name: "name", type: "string" }, + { + name: "name", + type: "string", + constraints: { required: true }, + }, ], } @@ -207,6 +232,23 @@ describe("validateTable", () => { fieldNames: ["name"], }) }) + + it("should pass when non-required fields are missing", async () => { + const table = DataFrame({ + id: [1, 2], + }).lazy() + + const schema: Schema = { + fieldsMatch: "subset", + fields: [ + { name: "id", type: "number" }, + { name: "name", type: "string" }, + ], + } + + const { errors } = await validateTable(table, { schema }) + expect(errors).toEqual([]) + }) }) describe("fields validation with fieldsMatch='superset'", () => {