Problems connecting R to Hadoop using Phoenix - r

I'm trying to connect R to Hadoop using Phoenix but I get the following error:
Error in .jcall(drv#jdrv, "Ljava/sql/Connection;", "connect",
as.character(url)[1], : java.sql.SQLException:
java.lang.IllegalArgumentException: Can't get Kerberos realm
Below you can find my R code. Anyone knows how to correct this to be able to connect without errors?
library(RJDBC)
library(rJava)
library(DBI)
Sys.setenv(JAVA_TOOL_OPTIONS="-Djava.security.krb5.conf=/path/to/krb5.conf")
.jinit(,"-Djavax.security.auth.useSubjectCredsOnly=false")
.jaddClassPath(Sys.glob("/path/to/site-xml"))
# this folder contains core-site.xml, hbase-site.xml and hdfs-site.xml
drv <- JDBC("org.apache.phoenix.jdbc.PhoenixDriver",
"/path/to/phoenix-4.4.0.2.3.2.0-2950-client.jar",
identifier.quote = "'"
)
conn <- dbConnect(
drv,
"jdbc:phoenix:IP1,IP2,IP3:2181:/hbase-secure:USER#HADOOP.COM:/path/to/keytab/file.keytab",
"",
""
)
result <- dbGetQuery(conn, "select * from \"TABLE_NAME\"")
print(result)

Related

RPostgreSQL - SCRAM error when trying to connect to local database

I am trying to connect to my localhost postgres DB and I get the following error.
library("RPostgreSQL")
drv <- dbDriver("PostgreSQL")
connec <- dbConnect(drv, dbname = "dbnamehere", port = 5432,user = "some_username", password = "somepassword")
Error in postgresqlNewConnection(drv, ...) :
RPosgreSQL error: could not connect admin_sci4i#localhost:5432 on dbname "website": SCRAM authentication requires libpq version 10 or above
It seems related to authentication security but I am having a local DB.. Is there any way to do anything in pgAdmin 4 and avoid this error (even if it is less secure)?
Surprisingly I managed to connect using other packages
library("RODBC")
library("odbc")
library("RPostgres")
con <- dbCanConnect(RPostgres::Postgres(),dbname="dbnamehere",port = 5432,user = "some_username", password = "somepassword")
con # Checks connection is working
con1 = dbConnect(RPostgres::Postgres(),dbname="dbnamehere",port = 5432,user = "some_username", password = "somepassword")
con1 # Checks connect
dbListTables(con1) # See tables
A nice explanation and walkthrough here.

Error in .local(drv, ...) : Failed to connect to database: Error: Can't connect to MySQL server on 'xx.143.13.xxx' (0)

I am getting erro in .local(drv,...).
I have no idea how to fix this issue.
Can anyone help me out why showing such a error and how to fix this error?
code:
library(RMySQL)
mydb = dbConnect(MySQL(), user='XXXXXXX',
password='XXXXXXXX', dbname='XXXXXXXX',
host='##.143.13.XXX', port=XXXX)
Thank you.
Try using DBI and pool packages from R.
library(DBI)
library(pool)
pool <- dbPool(drv = RMySQL::MySQL(), dbname = "dbName", host = "localhost", username = "root", password = "psw", port = 3306, unix.sock = "/var/run/mysqld/mysqld.sock")
df <- dbGetQuery(pool, "SELECT * FROM tablename;")
Provide MySQL socket path of the machine at unix.sock(in ubuntu : mysql_config --socket)

Able to connect AWS Redshift via dbConnect but not src_postgres

I am to connect to AWS Redshift using dbConnect query
conn_loss <- dbConnect(drv, host="hydrogen2.YOURHOST.us-east-1.redshift.amazonaws.com",
port="5439",
dbname="mydb",
user="master_user",
password=password)
However, when I try connecting using src_postgres
myRedshift <- src_postgres(dbname = "mydb",
host = "hydrogen2.YOURHOST.us-east-1.redshift.amazonaws.com",
port = 5439,
user = "master_user",
password = "password")
I get this error:
Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect

R connection to postgresql requiring SSL

I'm trying to connect R to a postgresql database that requires SSL.
Here's the connection string that works for me when using PSQL:
postgresql://USERNAME:PASSWORD#HOSTNAME:PORT/DBNAME?ssl=true, replacing all the uppercase strings with appropriate values.
In R, I don't know how to handle the SSL parameter. When I try
conn = dbConnect(RPostgreSQL::PostgreSQL(), host="HOST", dbname="DBNAME", user="USERNAME", password="PASSWORD", port=PORT)
I get
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect USERNAME#HOST on dbname "DBNAME"
)
When I try conn = dbConnect(RPostgreSQL::PostgreSQL(), host="HOST", dbname="DBNAME", user="USERNAME", password="PASSWORD", port=PORT, ssl=TRUE)
I get
Error in postgresqlNewConnection(drv, ...) : unused argument (ssl = TRUE)
Connect to Postgres via SSL using R suggests adding extra info to the dbname parameter. I've tried dbname="DBNAME ssl=TRUE" which results in RS-DBI driver: (could not connect (null)#HOST on dbname "(null)" I get the same result with sslmode=allow and sslmode=require (as suggested by the above post).
The documentation for the PostgreSQL driver says, under "User Authentication", "The passed string can be empty to use all default parameters, or it can contain one or more parameter settings separated by comma. Each parameter setting is in the form parameter = "value". Spaces around the equal sign are optional." But I haven't been able to get it to accept any parameters other than the three shown in the function prototype.
I'm out of ideas; help appreciated.
You can try this :
Create a configuration file like "configuration.yml" and add your setup :
db:
host : "your_localhost"
dbname : "your_database_name?ssl=true"
user : "your_user_name"
port : 5432
password : "your_password"
Install this packages :
install.packages(yaml, dependencies = TRUE)
install.package(RPostgreSQL, dependencies = TRUE)
install.packages(DBI, dependencies = TRUE)
Run :
driver <- DBI:::dbDriver("PostgreSQL")
con <- do.call( RPostgreSQL:::dbConnect,
c(drv = driver, yaml:::yaml.load_file("configuration.yml")$db)
)
/!\ Note /!\ : don't forget to add this statement
*?ssl=true*
on the configuration.yml file on the dbname field.
Hope this help !

RPostgreSQL can't connect

I'm having trouble connecting my R client to redshift through the RPostgreSQL package, despite it working very easily through psql. I've tried downloading and sourcing the redshift-ssl-ca-cert.pem file, but this still doesn't seem to work. Any ideas what could be causing this? Here's my R code:
library("RPostgreSQL")
drv <- dbDriver("PostgreSQL")
host = 'host.com'
dbname = 'dbname'
port = 1234
password = 'password'
username = 'user'
redshift_cert = paste0(FILE_PATH, 'redshift-ssl-ca-cert.pem')
pg_dsn = paste0(
'dbname=', dbname, ' ',
'sslrootcert=', redshift_cert, ' ',
'sslmode=verify-full'
)
con <- dbConnect(drv, dbname=pg_dsn, host=host, port=port, password=password, user=username)
and I always get this error message
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect user#host.com on dbname "dbname"
)
Meanwhile this command using psql works perfectly
psql 'host=host.com dbname=dbname sslmode=require port=1234 user=user password=password'
I've also tried other variations of sslmode including require and allow for the R code, but nothing works. Would appreciate any ideas thanks!

Resources