relferreira / metabase-sparksql-databricks-driver

GNU Affero General Public License v3.0
30 stars 32 forks source link

Support databases other than `default` #5

Closed snarfed closed 2 years ago

snarfed commented 2 years ago

Cross posted from https://github.com/metabase/metabase/issues/10029#issuecomment-1220128324 : I can't get it to connect to any database other than default. It seems to ignore both the Database name field and the path in the jdbc:spark:// URI in the JDBC connection string. eg when I enter a JDBC connection URI that starts with jdbc:spark://adb-...1.azuredatabricks.net:443/benchmarks;..., it ignores the /benchmarks path and still uses the default database. Any idea how I can tell it the database name?

snarfed commented 2 years ago

Hi again @relferreira! Just checking in here. I'm guessing this might be straightforward, want me to see if I can fix it? Feel free to point me to anywhere specific in the code you think I should start looking!

relferreira commented 2 years ago

Hello, @snarfed. I'll take a look as soon as possible. Looking at this line:

https://github.com/relferreira/metabase-sparksql-databricks-driver/blob/3469d8d506137d59492fcd7e8d0a28f41bae2590/src/metabase/driver/sparksql_databricks.clj#L107

It should already support other databases, but I haven't debugged it yet.

snarfed commented 2 years ago

I've dug in a bit here, and I don't have a fix yet, but I have learned a couple things that might help.

First, in this line you mentioned:

https://github.com/relferreira/metabase-sparksql-databricks-driver/blob/3469d8d506137d59492fcd7e8d0a28f41bae2590/src/metabase/driver/sparksql_databricks.clj#L107

...should there be a separator between db and jdbc-flags? Right now it concatenates them directly, ie if db is foo and jdbc-flags is jdbc:spark://adb-123.azuredatabricks.net:443/..., then :subname here ends up something like //adb-123.azuredatabricks.net:443/foojdbc:spark://adb-123.azuredatabricks.net:443/..., which seems wrong.

snarfed commented 2 years ago

Second, looking at sql-jdbc.conn/connection-details->spec:

https://github.com/relferreira/metabase-sparksql-databricks-driver/blob/3469d8d506137d59492fcd7e8d0a28f41bae2590/src/metabase/driver/sparksql_databricks.clj#L110-L120

The -> seems to lose all of the keys in the map when it hits sparksql-databricks. After the (select-keys [:host :port :db :jdbc-flags :dbname]) line, it has values for :host :port :db :jdbc-flags, but after sparksql-databricks, it instead has :classname :subprotocol :subname. Is that expected?

relferreira commented 2 years ago

Hello @snarfed, unfortunately, I'm on vacation now, but I think that you are passing the full connection URL to the JDBC params. It should be something like Screenshot_20220914-095058.png

snarfed commented 2 years ago

Aha, that was the problem. User error, ugh. Apologies for the false alarm, thank you for the answer!

relferreira commented 2 years ago

Don't worry, it happens with all of us.😅 Maybe we can improve the docs in the future