Testing of R Scripts Installed within Aster Database - Aster R

Teradata Aster® R User GuideUpdate 3

Product
Aster R
Release Number
7.00.02.01
Published
December 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
fop1497542774450.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
fbp1477004286096
lifecycle
previous
Product Category
Software
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.
  1. 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
  2. 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
  3. 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()