Support Questions

Find answers, ask questions, and share your expertise

Error while connecting Hive using JDBC in R script

avatar
New Contributor

Hi

I have an R script that tries to connect to hive using JDBC to pull tables from the hive and perform some processing on the data.

However I'm getting an error at the connection part and am not really sure how to resolve this. Tried different sources on net but couldn't find an answer.

Below is my R code where the error appears and also the error seen on the screen.

cp = c(paste0(BASE_PATH, JAR_DIRECTORY, HADOOP_COMMON_JAR), paste0(BASE_PATH, JAR_DIRECTORY, HIVE_JDBC_JAR))

.jinit(classpath=cp)

drv <- JDBC("org.apache.hive.jdbc.HiveDriver", paste0(BASE_PATH, JAR_DIRECTORY, HIVE_JDBC_JAR), identifier.quote="`")

conn <- dbConnect(drv, "jdbc:hive2://10.0.1.10:10000") //Error is here

Error:

Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :

java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://xx.x.x.x:10000: java.net.ConnectException: Connection refused (Connection refused)

Calls: dbConnect -> dbConnect -> .local -> .jcall -> .jcheck -> .

Call Execution halted

Any help would be appreciated and I'm happy to provide more insights if required

Thanks

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Sai Kumar Manapragada

java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://xx.x.x.x:10000: java.net.ConnectException: Connection refused (Connection refused)

As you are getting the Above error hence it will be worth checking if the HiveServer2 IP And Port is accessible from the machine where you are running the R Script or not?

So please check if Hive Server2 port 10000 is accessible from the R Script host. This is to isolate any Network Issue or Firewall Issues.

# telnet 10.0.1.10 10000
(OR)
# nc -v 10.0.1.10 10000

.

Also on the HiveServer2 host please check if the IP Address is correct and the Port 10000 is opened on the correct network interface.

# service iptables status
# netstat -tnlpa | grep 10000
# ifconfig | grep 10.0.1.10

.

Also please check your HiveSerevr2 (hive-site.xml) config to find out if the Listen Address is set correctly to point to the correct IP / Hostname.

.

View solution in original post

2 REPLIES 2

avatar
Master Mentor

@Sai Kumar Manapragada

java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://xx.x.x.x:10000: java.net.ConnectException: Connection refused (Connection refused)

As you are getting the Above error hence it will be worth checking if the HiveServer2 IP And Port is accessible from the machine where you are running the R Script or not?

So please check if Hive Server2 port 10000 is accessible from the R Script host. This is to isolate any Network Issue or Firewall Issues.

# telnet 10.0.1.10 10000
(OR)
# nc -v 10.0.1.10 10000

.

Also on the HiveServer2 host please check if the IP Address is correct and the Port 10000 is opened on the correct network interface.

# service iptables status
# netstat -tnlpa | grep 10000
# ifconfig | grep 10.0.1.10

.

Also please check your HiveSerevr2 (hive-site.xml) config to find out if the Listen Address is set correctly to point to the correct IP / Hostname.

.

avatar
New Contributor

@Jay Kumar SenSharma. Thanks, the connection to 10000 was refused when I did telnet. Also i don't see anything running on that port when I did netstat.

Apparently, I didn't know that hiveserver2 must be started explicitly and hence was the error.

Do you know what is the property that needs to added to hive-site.xml inorder for me to access the web UI?

Nevertheless, thank you very much. You've helped me great.