简体   繁体   中英

R odbc Impala Change from Default Database in Select

I have successfully connected to Impala using R 's odbc package. When I created the connection using my Microsoft ODBC Administator tool, I set the default database to default . This is a database which exists in this Impala instance, but it isn't one which I really care about. I just wanted to connect to the instance and bounce around between databases when I need to.

With SQL Servers connected via odbc , I can do this. Let's say I set up an odbc connection to a MS SQL Server and have the default database as DB1 . If I wanted to query another database, say DB2 , I could do this as follows:

library(odbc)
#set up connection to MS SQL server
mssqlcon <- dbConnect(odbc(), "ms_sql_server")

#query DB2
my_table <- dbGetQuery(mssqlcon , "SELECT * FROM [DB2].[dbo].[mytable]) 

I don't know how to do the equivalent of this using an Impala ODBC connection. Let's say there is a table called imp_table1 on a database called imp_db2 in the Impala instance I've connected to. The tricks I would use for MS SQL Server aren't working. Things I have tried are:

#impala connection
impcon <- dbConnect(odbc(), "Test Impala")
my_table <- dbGetQuery(impcon , "SELECT * FROM [imp_table1]) 

This throws an error saying user does not have privileges to execute 'SELECT' on: default.imp_table1

If I try the USE statement as described here , I end up with a syntax error.

my_table <- dbGetQuery(impcon , "USE imp_db2; SELECT * FROM [imp_table1]) 

And finally, if I try to use syntax similar to what I use for SQL Server, I get the following error.

my_table <- dbGetQuery(impcon , "SELECT * FROM imp_db2.imp_table1) 

User  does not have privileges to execute 'SELECT' on: imp_db2.imp_table1

This error doesn't make sense because I can access this table using a web interface with my credentials and I can even use R Studio's Connection browser to preview columns in the data. I understand that it might be possible to change the connection setup in the MS ODBC Administrator so that I default to a different table, but I would prefer a single connection string that I can use to bounce around from database to database within the Impala instance.

Any help would be appreciated.

怎么样

my_table <- dbGetQuery(impcon , dbplyr::in_schema("imp_db2", "imp_table1")) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM