Repository navigation
feat: report hasResultSet in result metadata #584
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
Open
vuanhphung
wants to merge
4
commits into
main
Choose a base branch
from
feat/issue-309-has-result-set
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4e4e85b
feat: report hasResultSet in result metadata
vuanhphung f171c1c
test: always restore the getConfig stub in the result-set e2e spec
vuanhphung 76a3bcf
fix: honor an explicit hasResultSet=false from the Thrift server
vuanhphung 8381b44
chore: log Arrow schema decode failures at debug level
vuanhphung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { expect } from 'chai'; | ||
| import sinon from 'sinon'; | ||
| import { DBSQLClient } from '../../lib'; | ||
| import { ConnectionOptions } from '../../lib/contracts/IDBSQLClient'; | ||
| import { ClientConfig } from '../../lib/contracts/IClientContext'; | ||
| import { InternalConnectionOptions } from '../../lib/contracts/InternalConnectionOptions'; | ||
| import IDBSQLSession from '../../lib/contracts/IDBSQLSession'; | ||
| import { tryGetKernelNative } from '../../lib/kernel/KernelNativeLoader'; | ||
| import config from './utils/config'; | ||
|
|
||
| async function openSession(useKernel: boolean, customConfig: Partial<ClientConfig> = {}) { | ||
| const client = new DBSQLClient(); | ||
| if (Object.keys(customConfig).length > 0) { | ||
| const clientConfig = client.getConfig(); | ||
| sinon.stub(client, 'getConfig').returns({ ...clientConfig, ...customConfig }); | ||
| } | ||
| await client.connect({ | ||
| host: config.host, | ||
| path: config.path, | ||
| token: config.token, | ||
| useKernel, | ||
| } as ConnectionOptions & InternalConnectionOptions); | ||
| const session = await client.openSession({ initialCatalog: config.catalog, initialSchema: config.schema }); | ||
| return { client, session }; | ||
| } | ||
|
|
||
| async function hasResultSet(session: IDBSQLSession, statement: string) { | ||
| const operation = await session.executeStatement(statement); | ||
| try { | ||
| const { hasResultSet: value } = await operation.getResultMetadata(); | ||
| await operation.fetchAll(); | ||
| return value; | ||
| } finally { | ||
| await operation.close(); | ||
| } | ||
| } | ||
|
|
||
| const backends = [ | ||
| { name: 'Thrift', useKernel: false }, | ||
| { name: 'kernel', useKernel: true, skip: tryGetKernelNative() === undefined }, | ||
| ]; | ||
|
|
||
| backends.forEach(({ name, useKernel, skip }) => { | ||
| describe(`getResultMetadata().hasResultSet (${name})`, () => { | ||
| const table = `${config.catalog}.${config.schema}.result_set_presence_${config.tableSuffix}_${name}`; | ||
| let client: DBSQLClient; | ||
| let session: IDBSQLSession; | ||
|
|
||
| before(async function setup() { | ||
| if (skip) { | ||
| // eslint-disable-next-line no-invalid-this | ||
| this.skip(); | ||
| } | ||
| ({ client, session } = await openSession(useKernel)); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| try { | ||
| if (session) { | ||
| await hasResultSet(session, `DROP TABLE IF EXISTS ${table}`); | ||
| await session.close(); | ||
| } | ||
| } finally { | ||
| await client?.close(); | ||
| } | ||
| }); | ||
|
|
||
| afterEach(() => sinon.restore()); | ||
|
|
||
| it('is false for DDL and true for an empty SELECT', async () => { | ||
| expect(await hasResultSet(session, `CREATE TABLE IF NOT EXISTS ${table} (col1 INT)`)).to.be.false; | ||
| expect(await hasResultSet(session, `SELECT 'sample' AS Result WHERE 1 = 0`)).to.be.true; | ||
| expect(await hasResultSet(session, 'SELECT 1 AS one')).to.be.true; | ||
| expect(await hasResultSet(session, `INSERT INTO ${table} VALUES (1)`)).to.be.true; | ||
| expect(await hasResultSet(session, `USE SCHEMA ${config.schema}`)).to.be.false; | ||
| }); | ||
|
|
||
| it('is true for catalog operations', async () => { | ||
| const operation = await session.getTables({ catalogName: config.catalog, schemaName: config.schema }); | ||
| try { | ||
| expect((await operation.getResultMetadata()).hasResultSet).to.be.true; | ||
| } finally { | ||
| await operation.close(); | ||
| } | ||
| }); | ||
|
|
||
| if (!useKernel) { | ||
| it('is undefined when Arrow results are disabled', async () => { | ||
| const columnar = await openSession(false, { arrowEnabled: false }); | ||
| try { | ||
| expect(await hasResultSet(columnar.session, `SELECT 'sample' AS Result WHERE 1 = 0`)).to.be.undefined; | ||
| } finally { | ||
| await columnar.session.close(); | ||
| await columnar.client.close(); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.