I'm using (NodeJs Snowflake Driver lib) - snowflake-sdk and wanted to ask:
is there a way to execute Snowflake statements in async manner so that after starting a heavy procedure I would be able to monitor its status using snowflake's query_history() calls?
Looks like snowflake-connector-nodejs doesn't allow to set async
execution parameter to the inner SnowFlake API call on statement execution…
In general Snowflake REST API allows to execute sql statement in async
mode using async:true
(see here) - this is an url parameter but it’s not allowed in NodeJs snowflake driver library.
This is the snippet from my code:
async executeStatement(params: ExecuteProcedureParams, connection: sf.Connection): Promise<ExecutionResult> {
const procedureCommand = `${params.sqlCommandText};`;
return new Promise((resolve, reject) => {
try {
connection.execute({
sqlText: procedureCommand,
binds: params.sqlCommandParams ?? undefined,
complete: (err: Error, stmt: sf.Statement, rows: any) => {
if (err) {
reject(err);
} else {
console.log('Number of rows produced: ' + rows?.length);
resolve({
requestId: stmt.getRequestId(),
executedSqlText: stmt.getSqlText(),
rows,
});
}
},
});
} catch (err) {
console.log(err);
}
});
}
I would like executeStatement
to be non-blocking for heavy statements if I choose to run connection.execute({...});
in async
mode.
And I believe this is the place where we should be able to set async param:
url: Url.format(
{
pathname: '/queries/v1/query-request',
search: QueryString.stringify(
{
requestId: statementContext.requestId,
async: statementContext.async // <--- NEW LINE THAT DOESN'T EXIST AT THE MOMENT
})
}),
source code is here
Maybe someone could recommend an approach to achieve this asynchronous behavior?