UNPKG

@dpkit/table

Version:

Data Package implementation in TypeScript.

22 lines (17 loc) 645 B
import type { Field } from "@dpkit/core" import { col } from "nodejs-polars" import type { Table } from "../../table/index.ts" // TODO: Support schema.primaryKey and schema.uniqueKeys export function checkCellUnique(field: Field, errorTable: Table) { const unique = field.constraints?.unique if (unique) { const target = col(`target:${field.name}`) const errorName = `error:cell/unique:${field.name}` errorTable = errorTable .withColumn( target.isNotNull().and(target.isFirstDistinct().not()).alias(errorName), ) .withColumn(col("error").or(col(errorName)).alias("error")) } return errorTable }