Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Double primative for JSON Schema "number" type #111

Merged

Conversation

mpotter
Copy link

@mpotter mpotter commented Jan 11, 2024

Problem

The JSON Schema stipulates that a "number" type can be an integer, floating point, or exponential notation. Currently, the "number" type is treated the same as an integer when instantiating fromJSONSchema. In those cases, providing a float value of e.g. 2.5 will fail because it can't be converted into a BigInt.

Solution

I changed the primitive to Double for "number" types when creating a schema from JSON.

Change summary:

Steps to Verify:

Note: This is the example from the README.

import * as parquet from "@dsnp/parquetjs";

var schema = parquet.ParquetSchema.fromJsonSchema({
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "quantity": {
      "type": "integer"
    },
    "price": {
      "type": "number"
    },
    "date": {
      "type": "string",
      "format": "date-time"
    },
    "in_stock": {
      "type": "boolean"
    }
  },
  "required": ["name", "quantity", "price", "date", "in_stock"]
});

var writer = await parquet.ParquetWriter.openFile(schema, 'fruits.parquet');

await writer.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
await writer.appendRow({name: 'oranges', quantity: 10, price: 2.5, date: new Date(), in_stock: true});

await writer.close();

Expected behavior is that the file will be successfully written. Current behavior results in RangeError: The number 2.5 cannot be converted to a BigInt because it is not an integer.

@noxify
Copy link

noxify commented Jan 11, 2024

LGTM

@noxify
Copy link

noxify commented Jan 11, 2024

should we update the tests, too?

Edit: We have to - CI tests are failing 🙈

Copy link
Member

@wilwade wilwade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just a matter of updating the tests.

@mpotter
Copy link
Author

mpotter commented Jan 11, 2024

@wilwade tests updated

Copy link
Member

@wilwade wilwade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Copy link
Collaborator

@shannonwells shannonwells left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, thank you!

@shannonwells shannonwells merged commit 0a42955 into LibertyDSNP:main Jan 11, 2024
1 check passed
@wilwade
Copy link
Member

wilwade commented Jan 11, 2024

Published as part of v1.4.0! Thanks again!

@mpotter
Copy link
Author

mpotter commented Jan 11, 2024

Awesome, thank you for the fast turnaround 🙏

@mpotter mpotter deleted the patch-json-schema-number-as-double branch January 11, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants