-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Rework chdb-node api #23
base: main
Are you sure you want to change the base?
Conversation
This commit includes the new LocalChdb api using connect / chdb_conn to offer stateful query with long live clickhouse engine instance bind with connection. It also include a new NApi wrapper around local_result_v2 to prevent unnecessary copy and direct access to byte array (in case you want to use binary format and nodejs as a passhrough process). Thanks to `Napi::ObjectWrap`, nodejs is correctly calling free when needed (ie: the result isn't referenced anymore, thus garbage collected)
Wow, thank you so much @mgrenonville. |
Thank you ! |
I noticed that chDB v3.0.0 was released 2 weeks ago: https://github.com/chdb-io/chdb/releases/tag/v3.0.0 Do we need to bump something in this MR in order to use chDB v3.0.0 ? Auxten, also do we know if this MR will address the issues reported in #18 ? I recall that the issues were caused due to the way how Sessions were handled in older versions of chDB. |
in chdb v3.0, there could be only 1 session in the process.
|
Hello @auxten I would like to ask again part of my question that wasn't covered by your comment:
|
The old stateless query function cannot coexist with the new stateful one in the same process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, there are some issues to be addressed:
We need to re-impl the Query, QuerySession classes the Conn based API. The old impl of query and the new one can not co-exist in one process. As the new one need to keep some global stuff, but the old one tend to cleanup everything on finished.
It's a little bit complex for first time contributor. If you don't mind, I will take over this PR @mgrenonville
index.js
Outdated
@@ -30,10 +87,17 @@ class Session { | |||
return chdbNode.QuerySession(query, format, this.path); | |||
} | |||
|
|||
queryBuffer(query, format = "CSV") { | |||
if (!query) return ""; | |||
return chdbNode.QuerySessionBuffer(query, format, this.path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the QuerySessionBuffer seems not defined
index.js
Outdated
if (!query) { | ||
return ""; | ||
} | ||
return chdbNode.QueryBuffer(query, format); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the chdbNode.QueryBuffer seems not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Your right, I've not cleaned up this code :(
index.js
Outdated
return chdbNode.QueryBuffer(query, format); | ||
} | ||
|
||
class LocalChDB { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to the libchdb function called here, Connect is a better name than LocalChDB
@@ -121,6 +98,34 @@ Napi::String QueryWrapper(const Napi::CallbackInfo &info) { | |||
return Napi::String::New(env, result); | |||
} | |||
|
|||
// QuerySession function will save the session to the path | |||
char *QuerySession(const char *query, const char *format, const char *path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old impl of queryStable and the new one can not co-exist in one process.
As the new one need to keep some global stuff, but the old one tend to cleanup everything on finished.
We should use the Connection base queryConn here instead.
And the Query should also use the the Connection base queryConn
See also: https://github.com/chdb-io/chdb/blob/d26d2ce84190e9f9e2dbbde024ac09e9739198eb/chdb/__init__.py#L75
I think I understand what needs to be done, I think I will dig in chdb python wrapper to understand how. This is basically only for retro-compatibility purpose ? What do you think of removing Query and QuerySession since it's a subset of what can be done with Conn based API, by bumping chdb-node to a new major version ? I've run some experimentation I made with chdb v3.0.0 and, with connect api, it continues to work 🎉 |
This commit includes the new LocalChdb api using connect / chdb_conn to offer stateful query with long live clickhouse engine instance bind with connection.
It also include a new NApi wrapper around local_result_v2 to prevent unnecessary copy and direct access to byte array (in case you want to use binary format and nodejs as a passhrough process).
Thanks to
Napi::ObjectWrap
, nodejs is correctly calling free when needed (ie: the result isn't referenced anymore, thus garbage collected)