duckdb / duckdb-node

MIT License
57 stars 27 forks source link

Inserting data via Arrow fails in DuckDB 1.1.0 #120

Closed marvold-mw closed 1 month ago

marvold-mw commented 2 months ago

Using the following code (basically the sample code from https://duckdb.org/docs/api/nodejs/overview.html#inserting-data-via-arrow), DuckDB 1.1.0 failed to register an Arrow buffer via the Node bindings:

const arrow = require("apache-arrow");
const duckdb = require("duckdb");
const db = new duckdb.Database(":memory:");

const jsonData = [
  { userId: 1, id: 1, title: "delectus aut autem", completed: false },
  {
    userId: 1,
    id: 2,
    title: "quis ut nam facilis et officia qui",
    completed: false,
  },
];

// note; doesn't work on Windows yet
db.exec(`INSTALL arrow; LOAD arrow;`, (err) => {
  if (err) {
    console.warn(err);
    return;
  }

  const arrowTable = arrow.tableFromJSON(jsonData);
  db.register_buffer(
    "jsonDataTable",
    [arrow.tableToIPC(arrowTable)],
    true,
    (err, res) => {
      if (err) {
        console.warn(err);
        return;
      }

      // `SELECT * FROM jsonDataTable` would return the entries in `jsonData`
    }
  );
});
$ node ./test.js
[Error: Binder Error: No function matches the given name and argument types 'scan_arrow_ipc(STRUCT(ptr BIGINT, size INTEGER)[])'. You might need to add explicit type casts.
    Candidate functions:
    scan_arrow_ipc(STRUCT(ptr UBIGINT, size UBIGINT)[])

LINE 1: ...RY VIEW jsonDataTable AS SELECT * FROM scan_arrow_ipc([{'ptr': 5099265536, 'si...
                                                  ^] {
  errno: -1,
  code: 'DUCKDB_NODEJS_ERROR',
  errorType: 'Binder'
}

This code failed with NPM packages apache-arrow 17.0.0 and duckdb 1.1.0, but succeeded with apache-arrow 17.0.0 and duckdb 1.0.0.

marvold-mw commented 2 months ago

(I should note that this was on an Apple Silicon Mac running macOS Sequoia and Node 20.17.0, in case that proves relevant. This also happened with slightly different code on a GitHub runner running Ubuntu 22.04 and Node 20.17.0; I suspect it's a general issue, but I ought to mention as much as I can.)

SanYann commented 2 months ago

Same issue here

nshiab commented 2 months ago

I have the same problem.

carlopi commented 1 month ago

https://github.com/duckdb/duckdb-node/pull/125 should fix the issue here, please reopen if that's not the case and I missed something.

marvold-mw commented 1 month ago

I was worried it wasn't fixed for a moment, but realized my real scenario is using duckdb-async which is bringing in the old version on its own. Running with the simple repro above, everything now works. Thanks, looking forward to seeing this released!