Connecting to Teradata in R via the teradataR package

Analytics
Highlighted

Connecting to Teradata in R via the teradataR package


It appears that I can successfully connect to Teradata via R, but when I try to perform some function on my td.data.frame, it provides the following error after the last line of my code:



 "42S02 -3807 [NCR][ODBC Teradata Driver][Teradata Database] Object 'my_sample_table' does not exist. "



My code:





library("teradataR")

library("RODBC")

tdConnect("MyTDdb")

tdf <- td.data.frame("my_sample_table","my_db")

my.stats <- td.stats(tdf,"Numerical_Column_of_Interest", c("cnt","min","max","mean"))

 



Note:  I changed the database and table names, but the concept is the same.  I am fairly confident that my td.data.frame() line works because when I put in a bogus table name, it errors out.  When I put in a good table name, it takes about 2 mins to finish running.  I also get the same error message when I try different functions, not just td.stat().



Any ideas on how to make this work?  I have spent about and hour searching google and have found very little documentation or samples on the teradataR package.



 



 


14 REPLIES
Enthusiast

Re: Connecting to Teradata in R via the teradataR package


You migh need to set the default DB on the connect statement.



the following worked for me:



library(RJDBC)
Lade nötiges Paket: DBI
Lade nötiges Paket: rJava
> .jaddClassPath("path/terajdbc4.jar")
> .jaddClassPath("path/tdgssconfig.jar")
> library(teradataR)
>
> tdConnect("xxx","user","password","sys_calendar","jdbc")
>
> tdf <- td.data.frame("calendar")
> my.stats <- td.stats(tdf,"year_of_calendar", c("cnt","min","max","mean"))
> my.stats
col xcnt xmin xmax xmean
1 year_of_calendar 73414 1900 2100 2000

Re: Connecting to Teradata in R via the teradataR package


Ulrich, that worked great, thanks!  Thanks for the quick response.


Fan

Re: Connecting to Teradata in R via the teradataR package


I am trying to connect via JDBC using Ulrich's approach but I am not having success.  Everything appears to work fine until I try to create the data frame:



 



> tdf<-td.data.frame("ccaef")


Warning message:


In td.data.frame("ccaef") :


  Teradata table not found.  Result is empty data frame.


 


I am able to successfully use the same db connection details to connect via a SAS libref statement.


 


I am running on Red Hat Linux.  I saw the following:


 


JDBC support added to allow Windows or Mac users to run the package with JDBC


 


Stated here:



 


Does this mean that the JDBC approach is not currently supported on Red Hat?


 


Thanks.

Enthusiast

Re: Connecting to Teradata in R via the teradataR package


does the table exists in the DB you specified in the tdConnect?



I am not aware that JDBC would not work on Red Hat - it works on Suse


Fan

Re: Connecting to Teradata in R via the teradataR package


Yes, the table does exist.  I have re-confirmed.  Glad to hear that it works on Linux.



Here is my code:



 



library(RJDBC)


 


.jaddClassPath("/teradata_poc/programs/lib/terajdbc4.jar")


.jaddClassPath("/teradata_poc/programs/lib/tdgssconfig.jar")


 


library(teradataR)


 


tdConnect("10.33.2.136","my_uid","my_pwd","EDEE_POC","jdbc ")


 


tdf<-td.data.frame("ccaef")

Enthusiast

Re: Connecting to Teradata in R via the teradataR package


Can you run my sys_calendar example - as calendar should be available on every system.



On a mac I had once the problem that I had to rerun library .jaddClassPath... sections twice...


Fan

Re: Connecting to Teradata in R via the teradataR package


I get the same results even after running the .jaddClassPath sections twice.


Fan

Re: Connecting to Teradata in R via the teradataR package


Hi Ulrich,



I am still not able to connect via JDBC but that is ok.  We were able to get ODBC support installed on our Linux environment and that is working for me.



Thanks for your assistance.


Enthusiast

Re: Connecting to Teradata in R via the teradataR package

Just to avoid future problems


tdConnect("10.33.2.136","my_uid","my_pwd","EDEE_POC"," jdbc ")


is not getting a connection due to the blanks in " jdbc "


it has to be "jdbc"


 


tdConnect("10.33.2.136","my_uid","my_pwd","EDEE_POC","jdbc")


unfortunatly no error messag is raised...