Repository navigation
Connect to Snowflake and Databricks from ggsql with Workbench managed credentials #17577
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
Merged
+1,193
−32
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7dedb00
Generate a ggsql line for Snowflake Workbench managed credentials
juliasilge b207dbd
Offer "Connect With" only for the languages a connection supports
juliasilge 71652f6
Generate a ggsql line for Databricks Workbench managed credentials
juliasilge 950faa0
Offer ggsql for Snowflake only when the settings give a line
juliasilge f45a05e
Offer ggsql for Databricks only with a ggsql that adds the token
juliasilge 2449c8f
Offer ggsql only where a connection can use it
juliasilge 5f46ba9
Keep the "Connect With" menu accurate while it waits for the driver
juliasilge 5cc84bb
Require ggsql 0.6.0 for the Databricks Workbench token
juliasilge 5020940
Oops, move the field above the constructor docstring
juliasilge b926fa2
Wait for the ggsql runtime before offering ggsql for Databricks
juliasilge 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (C) 2026 Posit Software, PBC. All rights reserved. | ||
| * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
|
|
||
| /** | ||
| * `ggsqlOdbc.ts` exists once per data connection driver that writes a ggsql ODBC line for Workbench | ||
| * managed credentials, because each extension compiles under its own tsconfig and cannot import from | ||
| * another. The copies have to stay in step: a fix to the line checks in one and not the other would | ||
| * let one driver write a line that connects with altered settings. The tests in the Snowflake | ||
| * extension's `ggsqlOdbc.vitest.ts` cover both copies. | ||
| */ | ||
| const COPIES = [ | ||
| 'positron-data-driver-snowflake/src/ggsqlOdbc.ts', | ||
| 'positron-data-driver-databricks/src/ggsqlOdbc.ts', | ||
| ] as const; | ||
|
|
||
| // `__dirname` is this file's own directory, so the paths hold wherever Vitest is started from. | ||
| function read(relativePath: string): string { | ||
| return fs.readFileSync(path.join(__dirname, relativePath), 'utf8'); | ||
| } | ||
|
|
||
| describe('ggsqlOdbc copies', () => { | ||
| it('keeps the Databricks copy identical to the Snowflake copy', () => { | ||
| const [snowflake, databricks] = COPIES; | ||
| expect(read(databricks)).toBe(read(snowflake)); | ||
| }); | ||
| }); |
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
85 changes: 85 additions & 0 deletions
85
extensions/positron-data-driver-databricks/src/ggsqlOdbc.ts
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,85 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (C) 2026 Posit Software, PBC. All rights reserved. | ||
| * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| // Builds ggsql `-- @connect: odbc://...` lines for connections whose credentials ggsql adds at | ||
| // connect time (Posit Workbench managed credentials). The line names the ODBC driver and where to | ||
| // connect, never a credential. It has no `vscode` import so Vitest can test it directly. | ||
|
|
||
| import { promises as fs } from 'fs'; | ||
|
|
||
| /** | ||
| * Where the Snowflake ODBC driver library is installed on Linux: the Posit Pro Drivers first, then | ||
| * Snowflake's own installer. The same paths R's `odbc::snowflake()` looks for. | ||
| */ | ||
| export const SNOWFLAKE_ODBC_DRIVER_PATHS: readonly string[] = [ | ||
| '/opt/rstudio-drivers/snowflake/bin/lib/libsnowflakeodbc_sb64.so', | ||
| '/usr/lib/snowflake/odbc/lib/libSnowflake.so', | ||
| ]; | ||
|
|
||
| /** | ||
| * Where a Databricks ODBC driver library is installed on Linux: the Posit Pro Drivers first, then the | ||
| * Databricks ODBC Driver (its library file name changed between versions), then the older Simba Spark | ||
| * driver. | ||
| */ | ||
| export const DATABRICKS_ODBC_DRIVER_PATHS: readonly string[] = [ | ||
| '/opt/rstudio-drivers/spark/bin/lib/libsparkodbc_sb64.so', | ||
| '/opt/databricks/databricksodbc/lib/64/libdatabricksodbc64.so', | ||
| '/opt/databricks/databricksodbc/lib/64/libdatabricksodbc_sb64.so', | ||
| '/opt/simba/spark/lib/64/libsparkodbc_sb64.so', | ||
| ]; | ||
|
|
||
| /** | ||
| * Characters that would break a ggsql connect line: ODBC's separators and braces, ggsql's own | ||
| * query separator (it splits the URI at the first `?`), and line breaks (ggsql reads only the first | ||
| * line). | ||
| */ | ||
| const LINE_BREAKING_CHARACTERS = /[;{}?\r\n]/; | ||
|
|
||
| /** Whether a file exists, without blocking the extension host. */ | ||
| async function fileExists(path: string): Promise<boolean> { | ||
| try { | ||
| await fs.access(path); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The value for an ODBC `Driver=` key: the first of `paths` that exists, or `fallbackName` (a driver | ||
| * registered in odbcinst.ini) when none does. A library path works whether or not the driver is | ||
| * registered. | ||
| * | ||
| * @param paths Library paths to try, in order. | ||
| * @param fallbackName The registered driver name to use when no path exists. | ||
| * @param exists Whether a path exists; the file system by default. | ||
| */ | ||
| export async function resolveOdbcDriver(paths: readonly string[], fallbackName: string, exists: (path: string) => Promise<boolean> = fileExists): Promise<string> { | ||
| for (const path of paths) { | ||
| if (await exists(path)) { | ||
| return path; | ||
| } | ||
| } | ||
| return fallbackName; | ||
| } | ||
|
|
||
| /** | ||
| * A ggsql `-- @connect: odbc://...` line from ODBC attributes, in the given order. Values are | ||
| * trimmed, and attributes with no value left are left out: ggsql trims the line it reports back, and | ||
| * Positron reuses a ggsql session only when that report matches this line exactly. Returns undefined | ||
| * when any value contains a character that would break the line, rather than a line that connects | ||
| * with altered settings. | ||
| * | ||
| * @param attributes ODBC `[key, value]` pairs. | ||
| */ | ||
| export function ggsqlOdbcConnectLine(attributes: ReadonlyArray<readonly [string, string | undefined]>): string | undefined { | ||
| const present = attributes | ||
| .map(([key, value]) => [key, value?.trim()] as const) | ||
| .filter((entry): entry is readonly [string, string] => !!entry[1]); | ||
| if (present.some(([, value]) => LINE_BREAKING_CHARACTERS.test(value))) { | ||
| return undefined; | ||
| } | ||
| return `-- @connect: odbc://${present.map(([key, value]) => `${key}=${value}`).join(';')}`; | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
undefinedhere covers two cases: ggsql isn't installed, or the ggsql extension is installed but hasn't registered its runtime yet.In the second case, someone with ggsql 0.5.2 who opens Connect With right after startup gets offered ggsql, and the line can't sign in. We could avoid this by waiting for discovery, but extensions have no API for that.
Could we use the ggsql extension being installed as the signal? Something like:
with
ggsqlExtensionInstalledbeing the result ofvscode.extensions.getExtension('ggsql.ggsql') !== undefined. During discovery it hides ggsql until the next menu open, and a truly missing ggsql still gets the Not Installed dialog.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thank you! I made this change in b926fa2. When the ggsql extension is installed but its runtime is not registered yet, the driver does not offer ggsql. Connect With asks the driver again each time it opens, so ggsql shows when the runtime registers. When no ggsql extension is installed, the driver still offers ggsql, so Connect shows the dialog that tells the user to install it.
I didn't use the extension version as the ggsql version since it is possible for the extension to run a ggsql kernel from
ggsql.kernelPath, a Jupyter kernelspec, the PATH, etc (so the runtime version can be different from the extension version).