xo / usql

Universal command-line interface for SQL databases
MIT License
8.94k stars 352 forks source link

Athena driver #332

Closed forbesmyester closed 2 years ago

forbesmyester commented 2 years ago

Hi, thanks for usql, I really quite enjoy using it and is the only SQL tool that makes me think about leaving psql by choice (I also have to use SQLite and Athena).

On the Athena though, I am trying to connect via usql 'athena://____:____@athena.eu-west-2.amazonaws.com/dev-databasing?s3_staging_dir=s3%3A%2F%2Fmy-bucket-%2F' which is the best I've been able to figure out, but it's giving the error:

error: athena: sql: unknown driver "athena" (forgotten import?)

However if I do \drivers I get

$ usql
Pager usage is off.
Null display is "·".
Type "help" for help.

(not connected)=> \drivers
Available Drivers:
  athena [s3, aws]
  avatica [av, phoenix]
  bigquery [bq]
  --- SNIP ---

It could well be user error, but I'm a bit flumoxed... help would be appreciated.

forbesmyester commented 2 years ago
$ usql --version
usql 0.10.0
kenshaw commented 2 years ago

@forbesmyester I just pushed a change (I have not tagged it, and am not planning on doing a release until I can verify the change works) that should fix this. I'm not sure if they changed the driver name, or if I never properly vetted this when I added it. Apologies. Over the weekend I should have time to verify this against an actual Athena instance. Please note that URLs for Athena will need to look something like this:

s3://myqueryresults?WGRemoteCreation=true&accessID=DummyAccessID&db=default&missingAsEmptyString=true&region=us-east-2&secretAccessKey=DummySecretAccessKey

(the driver that's being used here is decidedly non-idiomatic Go, and "requires" use of the driver's APIs to generate a DSN ... I'll look at this closer over the weekend)

I'd appreciate it if you could checkout usql from the latest source, build it (I'd suggest using the ./most.sh script) and see if you're able to connect to an Athena instance.

Thank you for bringing this to my attention, and I appreciate your understanding that it's difficult to track all the different drivers/databases.

kenshaw commented 2 years ago

@forbesmyester can you check if the latest version of usql fixes this issue? Thanks.

forbesmyester commented 2 years ago

Hi @kenshaw

I have:

$ usql 's3://__S3_STAGING_DIR_NOT_URL_ENCODE_WITH_TRAILING_FORWARDSLASH_ALSO_NOT_ENCODED?WGRemoteCreation=true&accessID=__THE_ACCESS_KEY__&db=__DATABASE_NAME_PROBABLY_URLENCODED_&missingAsEmptyString=true&region=eu-west-2&secretAccessKey=__THE_SECRET_URLENCODED__'

Which does work / can query, though \d does not (not supported by awsathena driver).

$ usql --version
usql 0.12.13
nineinchnick commented 2 years ago

Can you open another issue about implementing metadata introspection for Athena, so that the \d commands and completion would work?

Looks like the issue reported here is resolved and you could close this one.

forbesmyester commented 2 years ago

Sure, new ticket opened - https://github.com/xo/usql/issues/375