-
Notifications
You must be signed in to change notification settings - Fork 132
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
SNOW-1532645: getResultsFromQueryId ran into unhandled error #869
Comments
hi - thank you for pointing this out and the example , we'll take a look |
@sfc-gh-dszmolka also the type of |
https://www.npmjs.com/package/@types/snowflake-sdk is not from Snowflake, so it is entirely up to you whether you install it or not. will update this Issue once i had a chance to actually look into it. thank you for bearing with us ! |
so i took an initial look using a queryId which is a valid connection.execute({
sqlText: 'select top 10 * from snowflake_sample_data.tpch_sf1.customer',
asyncExec: true,
complete: async function (err, stmt, rows)
{
let queryId = stmt.getQueryId();
console.log(`==> queryId: ${queryId}`);
let wrongQueryId = "01b599c2-0302-d469-0000-6b0983867cf1";
// 2. Get results using the query ID
connection.getResultsFromQueryId({
//queryId: queryId,
queryId: wrongQueryId,
complete: async function (err, _stmt, rows)
{
console.log(rows);
}
});
}
}); ends up polling
by 'error handling', what would be the expected behaviour here? Would this |
@sfc-gh-dszmolka How do you catch that error? none of these two will work: try {
connection.getResultsFromQueryId({
// queryId: queryId,
queryId: wrongQueryId,
complete: async function (err, _stmt, rows) {
if (err) {
console.log('err1')
}
},
})
} catch (e) {
console.log('err2')
} |
i was wrong, this is indeed not easily manageable with a simple try/catch block. we'll see what can be done here and i'll update this thread once there's any new info available. |
so using Snowflake documentation for Executing queries asynchronously and this blog from Ian Segers which I found very helpful in addressing this particular problem; i took a stab at addressing the issue that the Error is thrown from inside an async function ( Using below script, I was either able to get the query result for a valid query, or handle the error for an invalid/bad queryId which would throw from inside Disclaimer: below approach is more like intended as an inspiration, definitely not an official, proper solution from 'Snowflake' which would be ready to be implemented in production. Script: # cat async_test.js
var snowflake = require('snowflake-sdk');
//snowflake.configure({ logLevel : 'trace'});
async function run() {
// Create connection with parameters
var connection = snowflake.createConnection({
account: process.env.SFACCOUNT,
username: process.env.SFUSER,
password: process.env.SFPASS,
warehouse: process.env.SFWH,
});
await new Promise((resolve, reject) => {
connection.connect(
function(err, conn) {
if (err) {
console.error('Unable to connect: ' + err.message);
} else {
console.log('Successfully connected to Snowflake.');
resolve(conn);
}
}
)
});
let queryId;
let query = 'select top 10 c_custkey from snowflake_sample_data.tpch_sf1.customer;'
// 1. Execute query with asyncExec set to true
await new Promise((resolve) => {
console.log(`==> Launching query ${query}`);
connection.execute({
sqlText: query,
asyncExec: true,
complete: async function(err, stmt, rows) {
queryId = stmt.getQueryId(); // Get the query ID
console.log(`==> queryId: ${queryId}`);
resolve();
}
});
});
let invalidQueryId = 'this_is_invalid';
let validButBadQueryId = '01b599c2-0302-d469-0000-6b0983867cf1';
let queryIdToGet = validButBadQueryId;
// 2. Get results using the query ID
async function tryGetResultsFromQueryId(connection) {
try {
console.log(`==> Trying to get the query status for ${queryIdToGet}`);
let result = await connection.getResultsFromQueryId({
queryId: queryIdToGet
});
return result
} catch (e) {
console.error(`==> Something bad happened: ${e}`);
return
}
}
await new Promise((resolve, reject) => {
tryGetResultsFromQueryId(connection)
.then((statement) => {
var stream = statement.streamRows();
stream.on('error', function(err) {
reject(err);
});
stream.on('data', function(row) {
console.log(row);
});
stream.on('end', function() {
resolve();
});
})
.catch((error) => {
console.log(`==> Well this is another error: ${error}`)
});
});
}
run(); Run with good queryId (letting it come from the actual query executed:
Run with invalid or bad queryId:
Would this be something which helps you in implementing error handling ? |
@sfc-gh-dszmolka Thank you, statement stream is actually usful in my case. |
all right; thank you for the feedback, good to hear you found the workaround helpful! |
we will add an enhancement at #882 for this corner case where the queryid is syntactically valid, but does not exist. Now the driver will fail much faster (instantly) instead retrying it for 20+ times for 2+ minutes, if the server response is indicating no data is available for the particular query. |
the above improvement (to not retry 20+ times for 2+ minutes, if we know the queryId doesn't exist on the server) has been merged and will be part of the next upcoming release |
released with snowflake-sdk v1.13.0 in August 2024 release cycle |
node:
v18.17.1
npm:
9.6.7
snowflake-sdk:
"^1.11.0"
Macos
The
getResultsFromQueryId
method does not handle or provide a way to handle errors, let's say we want to rungetResultsFromQueryId
withcomplete
to avoid dealing with stream etc.And assume we are using it like:
and in this case
01b599c2-0302-d469-0000-6b0983867cf1
is a incorrect value/id, it will ran into unhandled error and wont be caught inside the complete witherror
The text was updated successfully, but these errors were encountered: