From ee96d2f7a7223d88951488fc6bc94a73e53eedb7 Mon Sep 17 00:00:00 2001 From: Gabe Gorelick Date: Mon, 28 Oct 2024 11:45:40 -0400 Subject: [PATCH] Add support for `describeOnly` Fixes #940 --- index.d.ts | 6 ++++++ lib/connection/statement.js | 16 ++++++++++++++++ lib/constants/error_messages.js | 1 + lib/errors.js | 1 + test/unit/connection/statement_test.js | 12 +++++++++++- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index e2c56ecb4..0d4e17bea 100644 --- a/index.d.ts +++ b/index.d.ts @@ -131,6 +131,7 @@ declare module 'snowflake-sdk' { ERR_CONN_EXEC_STMT_INVALID_FETCH_AS_STRING_VALUES = 409012, ERR_CONN_EXEC_STMT_INVALID_REQUEST_ID = 409013, ERR_CONN_EXEC_STMT_INVALID_ASYNC_EXEC = 409014, + ERR_CONN_EXEC_STMT_INVALID_DESCRIBE_ONLY = 409015, // 410001 ERR_CONN_FETCH_RESULT_MISSING_OPTIONS = 410001, @@ -652,6 +653,11 @@ declare module 'snowflake-sdk' { * that is different from the connector directory. */ cwd?: string; + + /** + * `true` to enable a describe only query. + */ + describeOnly?: boolean; } export interface RowStatement { diff --git a/lib/connection/statement.js b/lib/connection/statement.js index fef7b2cbb..b67f81357 100644 --- a/lib/connection/statement.js +++ b/lib/connection/statement.js @@ -353,6 +353,12 @@ function createContextPreExec( ErrorCodes.ERR_CONN_EXEC_STMT_INVALID_ASYNC_EXEC); } + // if a describeOnly flag is specified, make sure it's boolean + if (Util.exists(statementOptions.describeOnly)) { + Errors.checkArgumentValid(Util.isBoolean(statementOptions.describeOnly), + ErrorCodes.ERR_CONN_EXEC_STMT_INVALID_DESCRIBE_ONLY); + } + // create a statement context const statementContext = createStatementContext(); @@ -384,6 +390,11 @@ function createContextPreExec( statementContext.cwd = statementOptions.cwd; } + // if the describeOnly flag is specified, add it to the statement context + if (Util.exists(statementOptions.describeOnly)) { + statementContext.describeOnly = statementOptions.describeOnly; + } + // validate non-user-specified arguments Errors.assertInternal(Util.isObject(services)); Errors.assertInternal(Util.isObject(connectionConfig)); @@ -1244,6 +1255,11 @@ function sendRequestPreExec(statementContext, onResultAvailable) { json.asyncExec = statementContext.asyncExec; } + // include describeOnly flag if a value was specified + if (Util.exists(statementContext.describeOnly)) { + json.describeOnly = statementContext.describeOnly; + } + // use the snowflake service to issue the request sendSfRequest(statementContext, { diff --git a/lib/constants/error_messages.js b/lib/constants/error_messages.js index 4a1c34145..2effda456 100644 --- a/lib/constants/error_messages.js +++ b/lib/constants/error_messages.js @@ -126,6 +126,7 @@ exports[409011] = 'Invalid fetchAsString value. The specified value must be an A exports[409012] = 'Invalid fetchAsString type: %s. The supported types are: String, Boolean, Number, Date, Buffer, and JSON.'; exports[409013] = 'Invalid requestId. The specified value must be a string.'; exports[409014] = 'Invalid asyncExec. The specified value must be a boolean.'; +exports[409015] = 'Invalid describeOnly. The specified value must be a boolean.'; // 410001 exports[410001] = 'Fetch-result options must be specified.'; diff --git a/lib/errors.js b/lib/errors.js index b57e4dc39..6a00ad982 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -130,6 +130,7 @@ codes.ERR_CONN_EXEC_STMT_INVALID_FETCH_AS_STRING = 409011; codes.ERR_CONN_EXEC_STMT_INVALID_FETCH_AS_STRING_VALUES = 409012; codes.ERR_CONN_EXEC_STMT_INVALID_REQUEST_ID = 409013; codes.ERR_CONN_EXEC_STMT_INVALID_ASYNC_EXEC = 409014; +codes.ERR_CONN_EXEC_STMT_INVALID_DESCRIBE_ONLY = 409015; // 410001 codes.ERR_CONN_FETCH_RESULT_MISSING_OPTIONS = 410001; diff --git a/test/unit/connection/statement_test.js b/test/unit/connection/statement_test.js index eaba007bf..7405b64af 100644 --- a/test/unit/connection/statement_test.js +++ b/test/unit/connection/statement_test.js @@ -205,6 +205,16 @@ describe('Statement.execute()', function () { connectionConfig: null }, errorCode: ErrorCodes.ERR_CONN_EXEC_STMT_MISSING_SQL_TEXT + }, + { + name: 'execute() invalid describeOnly', + options: { + statementOptions: { + sqlText: '', + describeOnly: 1, + }, + }, + errorCode: ErrorCodes.ERR_CONN_EXEC_STMT_INVALID_DESCRIBE_ONLY } ]; @@ -404,4 +414,4 @@ describe('Statement.fetchResult()', function () { testCase = testCases[index]; it(testCase.name, createItCallback(testCase)); } -}); \ No newline at end of file +});