chdb-node
chdb-node copied to clipboard
Question: Do we need a result CREATE FUNCTION query
Hello @auxten
I have been adding a few UDFs to my application/playground.
I found that CREATE FUNCTION returns an empty response even when I instruct CHDB that I would like to get the result in JSON.
Example script:
const { query, Session } = require("chdb");
var ret;
// Test standalone query
ret = query("SELECT version(), 'Hello chDB', chdb()", "CSV");
console.log("Standalone Query Result:", ret);
// Test session query
// Create a new session instance
const session = new Session("./udf_create_response");
try {
const resJson = session.query(`CREATE FUNCTION IF NOT EXISTS to_varchar_json_resp AS (x) -> toString(x);`, "JSON");
console.log("JSON resp:", resJson);
} catch (e) {
console.log(e)
}
try {
const resCsv = session.query(`CREATE FUNCTION IF NOT EXISTS to_varchar_json_resp AS (x) -> toString(x);`);
console.log("CSV resp:", resCsv);
} catch (e) {
console.log(e)
}
session.cleanup();
Console output:
Standalone Query Result: "24.5.1.1","Hello chDB","2.0.2"
JSON resp:
CSV resp:
I see similar behavior when I use the play function of ClickHouse where the browser receives an empty response when things are Ok.
Not sure if this is a bug or if it can be classified and a serious problem.
I suppose the confusing part was when I expected JSON output but got an empty string. In my code I am treading the results like: JSON.parse(session.query(sql, "JSON"));
and I just got a JSON parse error.