forked from briefercloud/briefer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ceab2e
commit 7ba1eb5
Showing
27 changed files
with
1,374 additions
and
101 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,43 @@ | ||
import { config } from '../config/index.js' | ||
import prisma, { DatabricksSQLDataSource } from '@briefer/database' | ||
import { DataSourceStatus } from './index.js' | ||
import { pingDatabricksSQL } from '../python/query/databrickssql.js' | ||
|
||
export async function ping(ds: DatabricksSQLDataSource): Promise<DatabricksSQLDataSource> { | ||
const lastConnection = new Date() | ||
const err = await pingDatabricksSQL(ds, config().DATASOURCES_ENCRYPTION_KEY) | ||
|
||
if (!err) { | ||
return updateConnStatus(ds, { | ||
connStatus: 'online', | ||
lastConnection, | ||
}) | ||
} | ||
|
||
return updateConnStatus(ds, { connStatus: 'offline', connError: err }) | ||
} | ||
|
||
export async function updateConnStatus( | ||
ds: DatabricksSQLDataSource, | ||
status: DataSourceStatus | ||
): Promise<DatabricksSQLDataSource> { | ||
const newDs = await prisma().databricksSQLDataSource.update({ | ||
where: { id: ds.id }, | ||
data: { | ||
connStatus: status.connStatus, | ||
lastConnection: | ||
status.connStatus === 'online' ? status.lastConnection : undefined, | ||
connError: | ||
status.connStatus === 'offline' | ||
? JSON.stringify(status.connError) | ||
: undefined, | ||
}, | ||
}) | ||
|
||
return { | ||
...ds, | ||
connStatus: newDs.connStatus, | ||
lastConnection: newDs.lastConnection?.toISOString() ?? null, | ||
connError: newDs.connError, | ||
} | ||
} |
This file contains 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 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 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,64 @@ | ||
import { v4 as uuidv4 } from 'uuid' | ||
import { DatabricksSQLDataSource, getDatabaseURL } from '@briefer/database' | ||
import { RunQueryResult, SuccessRunQueryResult } from '@briefer/types' | ||
import { | ||
getSQLAlchemySchema, | ||
makeSQLAlchemyQuery, | ||
pingSQLAlchemy, | ||
} from './sqlalchemy.js' | ||
import { OnTable } from '../../datasources/structure.js' | ||
|
||
export async function makeDatabricksSQLQuery( | ||
workspaceId: string, | ||
sessionId: string, | ||
queryId: string, | ||
dataframeName: string, | ||
datasource: DatabricksSQLDataSource, | ||
encryptionKey: string, | ||
sql: string, | ||
onProgress: (result: SuccessRunQueryResult) => void | ||
): Promise<[Promise<RunQueryResult>, () => Promise<void>]> { | ||
const databaseUrl = await getDatabaseURL( | ||
{ type: 'databrickssql', data: datasource }, | ||
encryptionKey | ||
) | ||
|
||
const jobId = uuidv4() | ||
const query = `${sql} -- Briefer jobId: ${jobId}` | ||
|
||
return makeSQLAlchemyQuery( | ||
workspaceId, | ||
sessionId, | ||
dataframeName, | ||
databaseUrl, | ||
'databrickssql', | ||
jobId, | ||
query, | ||
queryId, | ||
onProgress | ||
) | ||
} | ||
|
||
export function pingDatabricksSQL( | ||
ds: DatabricksSQLDataSource, | ||
encryptionKey: string | ||
): Promise<null | Error> { | ||
return pingSQLAlchemy( | ||
{ type: 'databrickssql', data: ds }, | ||
encryptionKey, | ||
null | ||
) | ||
} | ||
|
||
export function getDatabricksSQLSchema( | ||
ds: DatabricksSQLDataSource, | ||
encryptionKey: string, | ||
onTable: OnTable | ||
): Promise<void> { | ||
return getSQLAlchemySchema( | ||
{ type: 'databrickssql', data: ds }, | ||
encryptionKey, | ||
null, | ||
onTable | ||
) | ||
} |
This file contains 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 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 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 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.