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

Problem with parsing int64 values? #69

Closed
imirosedi opened this issue Dec 16, 2024 · 8 comments · Fixed by oven-sh/bun#15804
Closed

Problem with parsing int64 values? #69

imirosedi opened this issue Dec 16, 2024 · 8 comments · Fixed by oven-sh/bun#15804
Assignees

Comments

@imirosedi
Copy link

imirosedi commented Dec 16, 2024

When I'm trying to insert BigInt and Timestamp values, I get errors, both with prepared statements and appenders. I'm not sure if it's a bug or me doing something wrong, because there are no mentions of BigInts and Timestamps in the documentations for now.

How to Reproduce the Problem

Here is a minimal test case:

import { DuckDBInstance, DuckDBTimestampValue } from '@duckdb/node-api';

const db = await DuckDBInstance.create(':memory:');
const connection = await db.connect();

await connection.run(`
  CREATE TABLE IF NOT EXISTS test (
    id BIGINT PRIMARY KEY,
    value INTEGER NOT NULL,
    timestamp TIMESTAMPTZ NOT NULL
  );
`);


const query = await connection.prepare(
  'INSERT INTO test (id, value, timestamp) VALUES ($1, $2, $3);',
);
// throws "bigint out of int64 range"
query.bindBigInt(1, BigInt(1));
// Works as expected
query.bindInteger(2, 100);
// throws "micros out of int64 range"
query.bindTimestamp(3, new DuckDBTimestampValue(BigInt(Date.now()) * 1000n));

await query.run();


const appender = await connection.createAppender('main', 'test');

// throws "bigint out of int64 range"
appender.appendBigInt(BigInt(2));
// Works as expected
appender.appendInteger(200);
// throws "Unimplemented type for cast (INT64 -> INT32)""
appender.appendTimestamp(new DuckDBTimestampValue(BigInt(Date.now()) * 1000n));
appender.endRow();

appender.close();

Specifications

  • Version: 1.1.3-alpha.7
  • Platform: Bun 1.1.38
  • OS: Manjaro Linux, kernel 6.6.63-1-MANJARO
@jraymakers
Copy link
Contributor

Interesting. I tested the above on Node v20.14.0 and it works fine. Perhaps this is something specific to Bun?

@jraymakers
Copy link
Contributor

Sure enough, I ran the exact same script on the same machine using Bun, and it failed in the ways you describe. Could be a bug in Bun's implementation of the Node Addon API.

@jraymakers
Copy link
Contributor

Yup, there's a TODO in the Bun code regarding the lossless parameter of napi_get_value_bigint_int64 (and similar functions). This could definitely lead to some of the errors mentioned.

@jraymakers
Copy link
Contributor

Asked about this in the relevant Bun issue.

@190n
Copy link

190n commented Dec 16, 2024

Bun bug: oven-sh/bun#15797

@190n
Copy link

190n commented Dec 18, 2024

Should be fixed in Bun v1.1.40.

@imirosedi
Copy link
Author

Yes, it seems to be working as expected now. Thank you!

@jraymakers
Copy link
Contributor

Thanks for the quick fix @190n!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants