diff --git a/README.md b/README.md index 4d55321..69e3749 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![minzipped](https://img.shields.io/bundlephobia/minzip/hyparquet-writer)](https://www.npmjs.com/package/hyparquet-writer) [![workflow status](https://github.com/hyparam/hyparquet-writer/actions/workflows/ci.yml/badge.svg)](https://github.com/hyparam/hyparquet-writer/actions) [![mit license](https://img.shields.io/badge/License-MIT-orange.svg)](https://opensource.org/licenses/MIT) -![coverage](https://img.shields.io/badge/Coverage-95-darkred) +![coverage](https://img.shields.io/badge/Coverage-96-darkred) [![dependencies](https://img.shields.io/badge/Dependencies-1-blueviolet)](https://www.npmjs.com/package/hyparquet-writer?activeTab=dependencies) Hyparquet Writer is a JavaScript library for writing [Apache Parquet](https://parquet.apache.org) files. It is designed to be lightweight, fast and store data very efficiently. It is a companion to the [hyparquet](https://github.com/hyparam/hyparquet) library, which is a JavaScript library for reading parquet files. diff --git a/eslint.config.js b/eslint.config.js index becee16..19ce990 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -43,7 +43,7 @@ export default [ 'jsdoc/require-returns-type': 'error', 'jsdoc/sort-tags': 'error', 'no-constant-condition': 'off', - 'no-extra-parens': 'error', + 'no-extra-parens': 'warn', 'no-multi-spaces': 'error', 'no-trailing-spaces': 'error', 'no-undef': 'error', diff --git a/test/files/fixed_length_decimal.parquet b/test/files/fixed_length_decimal.parquet new file mode 100644 index 0000000..69fce53 Binary files /dev/null and b/test/files/fixed_length_decimal.parquet differ diff --git a/test/files/signs.parquet b/test/files/signs.parquet new file mode 100644 index 0000000..100e64d Binary files /dev/null and b/test/files/signs.parquet differ diff --git a/test/write.roundtrip.test.js b/test/write.roundtrip.test.js new file mode 100644 index 0000000..9d947ca --- /dev/null +++ b/test/write.roundtrip.test.js @@ -0,0 +1,34 @@ +import fs from 'fs' +import { asyncBufferFromFile, parquetMetadataAsync, parquetReadObjects, parquetSchema } from 'hyparquet' +import { describe, expect, it } from 'vitest' +import { parquetWriteBuffer } from '../src/index.js' + +describe('parquetWrite round-trip', () => { + const files = fs.readdirSync('test/files').filter(f => f.endsWith('.parquet')) + + files.forEach(filename => { + it(`round-trips data from ${filename}`, async () => { + const file = await asyncBufferFromFile(`test/files/${filename}`) + const metadata = await parquetMetadataAsync(file) + const rows = await parquetReadObjects({ file }) + + // transpose the row data + const schema = parquetSchema(metadata) + const columnData = schema.children.map(({ element }) => ({ + ...element, + data: /** @type {any[]} */ ([]), + })) + for (const row of rows) { + for (const { name, data } of columnData) { + data.push(row[name]) + } + } + + const buffer = parquetWriteBuffer({ columnData }) + const output = await parquetReadObjects({ file: buffer }) + + expect(output.length).toBe(rows.length) + expect(output).toEqual(rows) + }) + }) +})