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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ This repository documents what is specific to the PostgreSQL backend:

<!-- antelopejs-docs-compat:start -->

| Package | Supported | Tested with |
| ---------------------------------------- | ---------------- | ----------- |
| `@antelopejs/interface-core` | `>=0.5.0 <0.6.0` | `0.5.1` |
| `@antelopejs/interface-database` | `>=0.4.1 <0.5.0` | `0.4.1` |
| `@antelopejs/interface-database-catalog` | `>=0.1.0 <0.2.0` | `0.1.0` |
| Package | Supported | Tested with |
| ---------------------------------------- | ------------------------ | ------------------------ |
| `@antelopejs/interface-core` | `>=0.5.0 <0.6.0` | `0.5.1` |
| `@antelopejs/interface-database` | `>=0.4.1 <0.5.0` | `0.4.1` |
| `@antelopejs/interface-database-catalog` | `0.1.1-next.44.gee21aa3` | `0.1.1-next.44.gee21aa3` |

<!-- antelopejs-docs-compat:end -->

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"@antelopejs/interface-core": ">=0.5.0 <0.6.0",
"@antelopejs/interface-database": ">=0.4.1 <0.5.0",
"@antelopejs/interface-database-catalog": ">=0.1.0 <0.2.0",
"@antelopejs/interface-database-catalog": "0.1.1-next.44.gee21aa3",
"pg": "^8.22.0",
"pg-connection-string": "^2.14.0"
},
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 47 additions & 9 deletions src/test-external/ranges.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,75 @@
import { expect } from "chai";
import { z } from "zod";
import {
type ColumnProfile,
Profile,
type RelationProfile,
} from "@antelopejs/interface-database-catalog";
import {
AssertNoRareValue,
type FixtureCount,
type ResultValue,
} from "@antelopejs/interface-database-catalog/testing";

import { Received } from "./received";

/** The labels of `sales.grade` as the relation's description reads them from `pg_enum`. */
const DECLARED_GRADES = '["bronze","silver","gold","platinum"]';

/** The rows of `sales.grades` that hold each value of its `grade` and `level` columns. */
const GRADE_COUNTS = {
grade: [
{ value: "bronze", rows: 4 },
{ value: "silver", rows: 5 },
{ value: "gold", rows: 8 },
{ value: "platinum", rows: 1 },
],
level: [
{ value: 7001, rows: 4 },
{ value: 7002, rows: 5 },
{ value: 7008, rows: 5 },
{ value: 7009, rows: 4 },
],
} satisfies Record<string, FixtureCount[]>;

async function ProfiledColumn(
column: string,
relation = "sales.grades",
): Promise<{ profile: ColumnProfile | undefined; results: string }> {
): Promise<{
profile: ColumnProfile | undefined;
relationProfile: RelationProfile;
results: string;
received: ResultValue[];
}> {
const { answer, results } = await Received(() =>
Profile({ relation, columns: [column] }),
);
return {
profile: answer.columns.find((profiled) => profiled.name === column),
relationProfile: answer,
results: results.join("\n"),
received: results
.filter((result) => !result.includes(DECLARED_GRADES))
.map((result): ResultValue => z.json().parse(JSON.parse(result))),
};
}

describe("the range of an external column", function () {
this.timeout(120_000);

it("ends an enum column at labels seen at least 5 times, so no result set holds a rarer one but the declared labels", async () => {
const { profile, results } = await ProfiledColumn("grade");
const { profile, results, relationProfile, received } =
await ProfiledColumn("grade");
expect(profile?.range).to.deep.equal({
status: "ok",
value: { min: "silver", max: "gold" },
});
expect(results).to.include(DECLARED_GRADES);
const measured = results.replaceAll(DECLARED_GRADES, "");
expect(measured).to.include('"silver"');
expect(measured).to.not.include("bronze");
expect(measured).to.not.include("platinum");
AssertNoRareValue({
profile: relationProfile,
results: received,
counts: GRADE_COUNTS,
});
});

it("ends a column typed as a domain over an enum like an enum column, and counts its nulls", async () => {
Expand All @@ -48,14 +82,18 @@ describe("the range of an external column", function () {
});

it("ends an integer column at values seen 5 times, past values seen 4 times", async () => {
const { profile, results } = await ProfiledColumn("level");
const { profile, results, relationProfile, received } =
await ProfiledColumn("level");
expect(profile?.range).to.deep.equal({
status: "ok",
value: { min: 7002, max: 7008 },
});
expect(results).to.include("7002");
expect(results).to.not.include("7001");
expect(results).to.not.include("7009");
AssertNoRareValue({
profile: relationProfile,
results: received,
counts: GRADE_COUNTS,
});
});

it("answers empty for an integer column whose every value is seen once", async () => {
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"noImplicitAny": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"paths": {
"@antelopejs/interface-database-catalog/testing": [
"./node_modules/@antelopejs/interface-database-catalog/dist/testing.d.ts"
]
},
"removeComments": true,
"preserveConstEnums": true,
"experimentalDecorators": true,
Expand Down
Loading