Skip to content

Commit

Permalink
feat(databricks-jdbc): jdbc (jar) driver update (#5612)
Browse files Browse the repository at this point in the history
  • Loading branch information
buntarb committed Nov 15, 2022
1 parent 23ed416 commit 372ed71
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/content/Configuration/Databases/Databricks-JDBC.mdx
Expand Up @@ -20,7 +20,7 @@ CUBEJS_DB_TYPE=databricks-jdbc
# CUBEJS_DB_NAME is optional
CUBEJS_DB_NAME=default
# You can find this inside the cluster's configuration
CUBEJS_DB_DATABRICKS_URL=jdbc:spark://dbc-XXXXXXX-XXXX.cloud.databricks.com:443/default;transportMode=http;ssl=1;httpPath=sql/protocolv1/o/XXXXX/XXXXX;AuthMech=3;UID=token
CUBEJS_DB_DATABRICKS_URL=jdbc:databricks://dbc-XXXXXXX-XXXX.cloud.databricks.com:443/default;transportMode=http;ssl=1;httpPath=sql/protocolv1/o/XXXXX/XXXXX;AuthMech=3;UID=token
# You can specify the personal access token separately from `CUBEJS_DB_DATABRICKS_URL` by doing this:
CUBEJS_DB_DATABRICKS_TOKEN=XXXXX
```
Expand Down
36 changes: 28 additions & 8 deletions packages/cubejs-databricks-jdbc-driver/src/DatabricksDriver.ts
Expand Up @@ -79,16 +79,16 @@ const DatabricksToGenericType: Record<string, string> = {

async function resolveJDBCDriver(): Promise<string> {
return fileExistsOr(
path.join(process.cwd(), 'SparkJDBC42.jar'),
path.join(process.cwd(), 'DatabricksJDBC42.jar'),
async () => fileExistsOr(
path.join(__dirname, '..', 'download', 'SparkJDBC42.jar'),
path.join(__dirname, '..', 'download', 'DatabricksJDBC42.jar'),
async () => {
const pathOrNull = await downloadJDBCDriver();
if (pathOrNull) {
return pathOrNull;
}
throw new Error(
'Please download and place SparkJDBC42.jar inside your ' +
'Please download and place DatabricksJDBC42.jar inside your ' +
'project directory'
);
}
Expand All @@ -100,6 +100,8 @@ async function resolveJDBCDriver(): Promise<string> {
* Databricks driver class.
*/
export class DatabricksDriver extends JDBCDriver {
private showSparkProtocolWarn: boolean;

protected readonly config: DatabricksDriverConfiguration;

public static dialectClass() {
Expand Down Expand Up @@ -133,10 +135,17 @@ export class DatabricksDriver extends JDBCDriver {
conf.dataSource ||
assertDataSource('default');

let showSparkProtocolWarn = false;
let url: string = getEnv('databrickUrl', { dataSource });
if (url.indexOf('jdbc:spark://') !== -1) {
showSparkProtocolWarn = true;
url = url.replace('jdbc:spark://', 'jdbc:databricks://');
}

const config: DatabricksDriverConfiguration = {
...conf,
dbType: 'databricks',
drivername: 'com.simba.spark.jdbc.Driver',
drivername: 'com.databricks.client.jdbc.Driver',
customClassPath: undefined,
properties: {
// PWD-parameter passed to the connection string has higher priority,
Expand All @@ -145,7 +154,7 @@ export class DatabricksDriver extends JDBCDriver {
UserAgentEntry: `CubeDev+Cube/${version} (Databricks)`,
},
database: getEnv('dbName', { required: false, dataSource }),
url: getEnv('databrickUrl', { dataSource }),
url,
// common export bucket config
bucketType:
conf?.bucketType ||
Expand Down Expand Up @@ -178,6 +187,7 @@ export class DatabricksDriver extends JDBCDriver {
};
super(config);
this.config = config;
this.showSparkProtocolWarn = showSparkProtocolWarn;
}

public readOnly() {
Expand All @@ -186,10 +196,10 @@ export class DatabricksDriver extends JDBCDriver {

public setLogger(logger: any) {
super.setLogger(logger);
this.showUrlTokenDeprecation();
this.showDeprecations();
}

public showUrlTokenDeprecation() {
public showDeprecations() {
if (this.config.url) {
const result = this.config.url
.split(';')
Expand All @@ -198,10 +208,20 @@ export class DatabricksDriver extends JDBCDriver {

if (result) {
this.logger('PWD Parameter Deprecation in connection string', {
warning: 'PWD parameter is deprecated and will be ignored in future releases. Please migrate to the CUBEJS_DB_DATABRICKS_TOKEN environment variable.'
warning:
'PWD parameter is deprecated and will be ignored in future releases. ' +
'Please migrate to the CUBEJS_DB_DATABRICKS_TOKEN environment variable.'
});
}
}
if (this.showSparkProtocolWarn) {
this.logger('jdbc:spark protocol deprecation', {
warning:
'The `jdbc:spark` protocol is deprecated and will be ignored in future releases. ' +
'Please migrate your CUBEJS_DB_DATABRICKS_URL environment variable to the ' +
'`jdbc:databricks` protocol.'
});
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/cubejs-databricks-jdbc-driver/src/installer.ts
Expand Up @@ -19,19 +19,19 @@ export async function downloadJDBCDriver(): Promise<string | null> {
const driverAccepted = acceptedByEnv();

if (driverAccepted) {
console.log('Downloading SimbaSparkJDBC42-2.6.17.1021');
console.log('Downloading DatabricksJDBC42-2.6.29.1051');

await downloadAndExtractFile(
'https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/jdbc/2.6.17/SimbaSparkJDBC42-2.6.17.1021.zip',
'https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/jdbc/2.6.29/DatabricksJDBC42-2.6.29.1051.zip',
{
showProgress: true,
cwd: path.resolve(path.join(__dirname, '..', 'download')),
}
);

console.log('Release notes: https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/jdbc/2.6.17/docs/release-notes.txt');
console.log('Release notes: https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/jdbc/2.6.29/docs/release-notes.txt');

return path.resolve(path.join(__dirname, '..', 'download', 'SparkJDBC42.jar'));
return path.resolve(path.join(__dirname, '..', 'download', 'DatabricksJDBC42.jar'));
}

return null;
Expand Down

0 comments on commit 372ed71

Please sign in to comment.