Quantcast
Channel: Teradata Downloads - Connectivity
Viewing all articles
Browse latest Browse all 445

Load Nulls with R & JDBC Fastload Problem

$
0
0

Hi all,
I try to load some data from R directly to Teradata 14.10 via JDBC Fastload.
The data contains some Nulls for numeric values and I have not been able to load this data so far. 
The code below is an example.
Three columns are generated. One integer, one char and one integer again.
The last column will have about 25% nulls.
If you comment out line 48 no nulls will be generated and you can see that the load per se is working.
From what I read so far I understand that nulls need to be set differently and I tried to do that within the msinsert function but obvously without success.
Is this a bug? I saw some other posts on JDBC and Nulls but I am not sure that the issue is the same.
 
Any support is very apprichiated.

Ulrich

library(RJDBC)
################
#def functions
################
myinsert <- function(arg1,arg2,arg3){
  .jcall(ps,"V","setInt",as.integer(1),as.integer(arg1))
  .jcall(ps,"V","setString",as.integer(2),arg2)
  if (is.na(arg3)==TRUE) {
    .jcall(ps,"V","setNull",as.integer(3),Types.INTEGER)
  } else {
    .jcall(ps,"V","setInt",as.integer(3),as.integer(arg3))
  }
  .jcall(ps,"V","addBatch")
}


MHmakeRandomString <- function(n=1, lenght=12)
{
  randomString <- c(1:n)                  # initialize vector
  for (i in 1:n)
  {
    randomString[i] <- paste(sample(c(0:9, letters, LETTERS),
                                    lenght, replace=TRUE),
                             collapse="")
  }
  return(randomString)
}

################
#DB Connect
################
.jaddClassPath("/MyPath/TeraJDBC__indep_indep.14.10.00.17/terajdbc4.jar")
.jaddClassPath("/MyPath/TeraJDBC__indep_indep.14.10.00.17/tdgssconfig.jar")
drv = JDBC("com.teradata.jdbc.TeraDriver","/MyPath/TeraJDBC__indep_indep.14.10.00.17/tdgssconfig.jar","/MyPath/TeraJDBC__indep_indep.14.10.00.17/terajdbc4.jar")
conn = dbConnect(drv,"jdbc:teradata://neo/CHARSET=UTF8,LOG=ERROR,DBS_PORT=1025,TYPE=FASTLOAD,TMODE=TERA,SESSIONS=1","uli","m00rhuhn") 

################
#main
################

##gen test data
dim = 10000
i = 1:dim
s = MHmakeRandomString(dim,12)
j = sample(1:10000, dim)
i1 <- j %% 4 == 0
#assign some NA
j[i1] <- NaN



## set up table
dbSendUpdate(conn,"drop table foo;")
dbSendUpdate(conn,"create table foo (a int, b varchar(100),c int);")

#set autocommit false
.jcall(conn@jc,"V","setAutoCommit",FALSE)
##prepare
ps = .jcall(conn@jc,"Ljava/sql/PreparedStatement;","prepareStatement","insert into foo values(?,?,?)")

#start time
ptm <- proc.time()

## batch insert
for(n in 1:dim){ 
  myinsert(i[[n]],s[[n]],j[[n]])
}
#run time
proc.time() - ptm

#apply & commit
.jcall(ps,"[I","executeBatch")
dbCommit(conn)
.jcall(ps,"V","close")
.jcall(conn@jc,"V","setAutoCommit",TRUE)

#get some sample results
dbGetQuery(conn,"select top 100 * from foo")
dbGetQuery(conn,"select count(*) from foo")

#disconnect
dbDisconnect(conn)

 
 

Forums: 

Viewing all articles
Browse latest Browse all 445

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>