-
Notifications
You must be signed in to change notification settings - Fork 9
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
Appender with array #182
Comments
The DuckDB type for Note that |
Thanks for the help. With these pointers I managed to get it to work the following, but it's quite the set or arcane incantations.. import { DuckDBInstance, FLOAT, ARRAY, DuckDBArrayValue } from '@duckdb/node-api';
const instance = await DuckDBInstance.create(':memory:');
const connection = await instance.connect();
await connection.run(` CREATE TABLE IF NOT EXISTS test ( name TEXT, fl_array FLOAT[2], ); `);
const appender = await connection.createAppender('test');
appender.appendVarchar('test');
appender.appendArray(new DuckDBArrayValue([1.01, 2.0]), ARRAY(FLOAT, 2));
appender.endRow();
appender.close();
const results = await connection.runAndReadAll(` SELECT * FROM test`);
console.log(results.getRows());
connection.close(); |
Glad you got it to work! I'm curious which parts you found the most cumbersome. (I'm always looking for opportunities to improve the API.) Note that you can use the slightly more concise helper Also, there's an alternate way to use the appender. You can create a data chunk, set the data in that chunk, and then append the chunk. There are convenience methods to set the data in a chunk all at once, such as |
I imagine the goal here is to keep close to the underlying C api, but a external user like me expect a slight higher level of abstraction. appender.appendArray(new DuckDBArrayValue([1.01, 2.0]), ARRAY(FLOAT, 2)); and I feel like the following has the same information: appender.appendFloat([1.1, 2.2]) Also, the discoverability of I did see the const chunk = DuckDBDataChunk.create([VARCHAR, ARRAY(FLOAT, 2)]);
chunk.setRows([
['duck', new DuckDBArrayValue([1,2])],
['mallard', new DuckDBArrayValue([3.1,4.5])],
['goose', new DuckDBArrayValue([1.21,2.324])],
]);
appender.appendDataChunk(chunk); Again, I wish I could pass normal arrays instead of |
Thanks for the feedback. I agree many parts could be documented better. Regarding the need for |
I can't seem to figure out how to use an appender with with a column of type
float[2]
gives me
TypeError: A number was expected
I thought maybe
but that gives me
error: Failed to cast value: Unimplemented type for cast (FLOAT -> FLOAT[2])
which now feels circular. I can't really find any example, tests or documentation.The text was updated successfully, but these errors were encountered: