-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparquet.spec.ts
48 lines (38 loc) · 1.39 KB
/
parquet.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import fs from "fs";
import { ParquetWriter, ParquetReader, ParquetSchema } from "@dsnp/parquetjs";
import { fromDSNPSchema } from "./parquet.js";
import { AnnouncementType, descriptorForAnnouncementType } from "./index.js";
describe("DSNP Schema Conversion Test File", () => {
const [parquetSchema, writerOptions] = fromDSNPSchema(
descriptorForAnnouncementType(AnnouncementType.Broadcast).parquetSchema,
);
const row1 = {
announcementType: AnnouncementType.Broadcast,
contentHash: "bciqdnu347gcfmxzbkhgoubiobphm6readngitfywktdtbdocgogop2q",
fromId: 12n,
url: "https://github.com/LibertyDSNP/parquetjs/",
};
const path = "./dsnp-schema-test-file.parquet";
let reader: ParquetReader;
beforeAll(async () => {
const writer = await ParquetWriter.openFile(new ParquetSchema(parquetSchema), path, writerOptions);
writer.appendRow(row1);
await writer.close();
reader = await ParquetReader.openFile(path);
});
afterAll(async () => {
await reader.close();
fs.rmSync(path);
});
it("schema is generated correctly", () => {
expect(new ParquetSchema(parquetSchema)).toMatchSnapshot();
});
it("schema is encoded correctly", () => {
expect(reader.metadata?.schema).toMatchSnapshot();
});
it("output matches input", async () => {
const cursor = reader.getCursor();
const row = await cursor.next();
expect(row).toEqual(row1);
});
});