Skip to content

Commit

Permalink
Add support for describeOnly
Browse files Browse the repository at this point in the history
Fixes #940
  • Loading branch information
gabegorelick authored and sfc-gh-pmotacki committed Nov 6, 2024
1 parent 5175843 commit ee96d2f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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,
{
Expand Down
1 change: 1 addition & 0 deletions lib/constants/error_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
1 change: 1 addition & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion test/unit/connection/statement_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
];

Expand Down Expand Up @@ -404,4 +414,4 @@ describe('Statement.fetchResult()', function () {
testCase = testCases[index];
it(testCase.name, createItCallback(testCase));
}
});
});

0 comments on commit ee96d2f

Please sign in to comment.