Skip to content
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

Snowflake JDBC - guidance to help add support #152

Open
mbarton98 opened this issue Apr 23, 2021 · 7 comments
Open

Snowflake JDBC - guidance to help add support #152

mbarton98 opened this issue Apr 23, 2021 · 7 comments

Comments

@mbarton98
Copy link

This was the only Emacs solution that I found that works with Snowflake. I would love to help test or with some guidance add some additional support for completion. The show tables function errors out with a bad query, but describe table at point works. So for now to get completion of fields, I use C-h t to open a buffer describing the table and expansion will use that buffer as a source when editing the SQL.

If nothing else, I could share the config if you wanted to add to the readme.

@daniel2501
Copy link

What config did you use to get connected to Snowflake? I've been trying, but getting a timeout.

@mbarton98
Copy link
Author

mbarton98 commented Aug 23, 2021 via email

@cfclrk
Copy link

cfclrk commented Apr 1, 2023

Just to document another example, here's the config that ended up working for me:

(ejc-create-connection
 "snowflake"
 :dependencies [[net.snowflake/snowflake-jdbc "3.13.27"]
                [net.java.dev.jna/jna "5.13.0"]]
 :connection-uri (concat "jdbc:snowflake://my-db.snowflakecomputing.com:443"
                         "?user="my-email@myjob.com"
                         "&warehouse=my-warehouse"
                         "&role=my-role"
                         "&db=my-db"
                         "&authenticator=externalbrowser"
                         "&JDBC_QUERY_RESULT_FORMAT=JSON"))

The authenticator=externalbrowser is because we use SSO for authentication, so you may need a different value for this option (refer to snowflake's JDBC Driver Connection Parameter Reference).

The JDBC_QUERY_RESULT_FORMAT=JSON was really important for me to set. Without it, I kept getting the error:

Error: JDBC driver internal error: exception creating result java.lang.ExceptionInInitializerError at net.snowflake.client.jdbc.internal.apache.arrow.memory.UnsafeAllocationManager.<clinit>(UnsafeAllocationManager.java:27).

I'm able to execute SQL queries and a couple of the interactive ejc commands, like ejc-describe-table.

The setup isn't perfect yet, as I'm getting an error running M-x show-views-list or M-x show-tables-list (and probably other things... today is my first day with ejc-sql):

Error: SQL compilation error:
syntax error line 1 at position 0 unexpected 'nil'.

@kostafey
Copy link
Owner

kostafey commented Apr 2, 2023

@mbarton98, @cfclrk, I've added Snowflake connection example to README, from the example you provided.
If you want to better completions for tables, rows and other database objects, as well as views- and tables- lists, please provide a related queries. You can do it here in the comments or feel free to create pull request.

Here is an example for Oracle database: https://github.com/kostafey/ejc-sql/blob/master/src/ejc_sql/structure.clj#L119

@Lenbok
Copy link

Lenbok commented May 3, 2023

I've managed to use this information to connect to snowflake. However every time I execute a query, it is doing the externalbrowser authentication - is a new connection being established for every query? (I would expect that the connection would be kept open, so the authentication would only happen when making making the initial ejc-connect)

@mbarton98
Copy link
Author

mbarton98 commented May 3, 2023 via email

@Lenbok
Copy link

Lenbok commented May 3, 2023

I got our admin to enable that, but it turns out that credential caching is not supported on linux so I'm out of luck. Which leaves my other question of why the connection isn't kept open, removing the need to re-connect for every query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants