duckdb / duckdb-wasm

WebAssembly version of DuckDB
https://shell.duckdb.org
MIT License
1.02k stars 110 forks source link

UDF String returned results always \x00... #1720

Open seeya opened 2 months ago

seeya commented 2 months ago

What happens?

The returned results of a UDF is always "\x00\x00..." when the returned type is a String.

To Reproduce

Created a sandbox here: https://codesandbox.io/p/sandbox/small-feather-n3p688?file=%2Fsrc%2FDuckDb.js

Basically create a UDF that returns the exact value. The results will all turn into \x00...

  await c.createScalarFunction('base64', new Utf8(), (a) => {
    console.log(a) // Mark
    return a
  });
  await c.query(`CREATE TABLE people(id INTEGER, name VARCHAR);`);
  await c.query(`INSERT INTO people VALUES (6, 'Mark');`);
  let r = await c.query(`SELECT id, name, base64(name)::VARCHAR as base64 FROM people;`);

  let array = r.toArray().map((row) => row.toJSON());
  console.log(array) // {id: 6, name: 'Mark', base64: '\x00\x00\x00\x00'}

Browser/Environment:

Chrome 124.0.6367.79

Device:

macOS

DuckDB-Wasm Version:

1.28.0

DuckDB-Wasm Deployment:

browser

Full Name:

seeya

Affiliation:

None