Create an R script myexample.R, using an editor such as vi, and install it on the Aster Database cluster. Use the SQL-MapReduce Stream function to execute this R script using the Aster Command Tool (ACT) client.
-
Create the R script myexample.R. Replace the AsterDSN in the example with the DSN defined in the odbc.ini file.
#Test library("TeradataAsterR") library("methods") conn<-ta.connect("AsterDSN") dt<-data.frame() dt<-rbind(dt,c(5,2,19,9581,15.6246871106)) dt<-rbind(dt,c(8,4,43,6830,10.8187293343)) dt<-rbind(dt,c(1,1,74,5697,17.3705606244)) dt<-rbind(dt,c(5,3,78,8139,14.3446582505)) names(dt)<-c("id1","id2","sens1","sens2","sens3") #create table test_data tadf <- ta.create(dt, table = "test_data", schemaName = "public", colTypes = c( id1 = "integer", id2 = "integer", sens1 = "integer", sens2 = "integer", sens3 = "double" ), tableType = "dimension", row.names=FALSE) #print data stored in table tadf
-
Install and execute the script using the ACT client on the queen node. Replace the dbname, username and password with the corresponding settings defined in the odbc.ini file.
# act -d dbname -U username -w password dbname=> \install myexample.R dbname=> select * from stream (on (select 1) script ('Rexec --vanilla myexample.R')); key | value --------------------------------+------- id1 id2 sens1 sens2 sens3 | 1 5 2 19 9581 15.62469 | 2 8 4 43 6830 10.81873 | 3 1 1 74 5697 17.37056 | 4 5 3 78 8139 14.34466 | (5 rows) dbname=> \d test_data dbname=> Drop table test_data; dbname=> \q
-
Execute the script using the R client on the queen node. Replace the AsterDSN with the DSN defined in the odbc.ini file.
# /home/beehive/bin/utils/exec/Rexec R > library(TeradataAsterR) > library(methods) > ta.connect("AsterDSN") > ta.install.scripts(“myexample.R'”) > ta.source(“myexample.R'”) > q()