@@ -22,13 +22,7 @@ DDB_SetReceiveVectorNA <- function(vec, NAIndex) {
2222# which will be uploaded
2323# (Used for dealing with NULLs in C++)
2424DDB_SetUploadVectorNA <- function (vec ) {
25- NAIndex <- vector(mode = " integer" , length = 0 )
26- for (j in 1 : length(vec )) {
27- if (is.na(vec [j ]) == TRUE ) {
28- NAIndex <- c(NAIndex , j - 1 )
29- }
30- }
31- return (NAIndex )
25+ return (which(is.na(vec )))
3226}
3327
3428# @Function
@@ -138,20 +132,20 @@ DDB_GetEntity <- function(xxdb_type) {
138132 if (ReturnScalarNA()) {
139133 result <- NA
140134 } else {
141- result <- ReturnScalarString ()
135+ result <- ReturnScalarDate ()
142136 }
143137 Clear()
144- return (as.Date( result ) )
138+ return (result )
145139
146140 } else if (xxdb_type == 15 ) {
147141 # Scalar DateTime
148142 if (ReturnScalarNA()) {
149143 result <- NA
150144 } else {
151- result <- ReturnScalarString ()
145+ result <- ReturnScalarTime ()
152146 }
153147 Clear()
154- return (as.POSIXct( result ) )
148+ return (result )
155149
156150 } else if (xxdb_type == 5 ) {
157151 # Logical Vector
@@ -182,17 +176,17 @@ DDB_GetEntity <- function(xxdb_type) {
182176
183177 } else if (xxdb_type == 16 ) {
184178 # Vector Date
185- result <- ReturnVectorString ()
179+ result <- ReturnVectorDate ()
186180 result <- DDB_SetReceiveVectorNA(result , ReturnVectorNAIndex())
187181 Clear()
188- return (as.Date( result ) )
182+ return (result )
189183
190184 } else if (xxdb_type == 17 ) {
191185 # Vector DateTime
192- result <- ReturnVectorString ()
186+ result <- ReturnVectorTime ()
193187 result <- DDB_SetReceiveVectorNA(result , ReturnVectorNAIndex())
194188 Clear()
195- return (as.POSIXct( result ) )
189+ return (result )
196190
197191 } else if (xxdb_type == 9 ) {
198192 # Logical Matrix
@@ -272,20 +266,21 @@ DDB_GetEntity <- function(xxdb_type) {
272266 result <- cbind(result , clm )
273267
274268 } else if (typelist [i ] == 16 ) {
275- clm <- ReturnTableColumnString (i )
269+ clm <- ReturnTableColumnDate (i )
276270 NAIndex <- ReturnTableColumnNAIndex(i )
277271 for (j in NAIndex ) {
278272 clm [j ] <- NA
279- }
280- result <- cbind(result , as.Date( clm ) )
273+ }
274+ result <- cbind(result , clm )
281275
282276 } else if (typelist [i ] == 17 ) {
283- clm <- ReturnTableColumnString(i )
277+ # date time
278+ clm <- ReturnTableColumnTime(i )
284279 NAIndex <- ReturnTableColumnNAIndex(i )
285280 for (j in NAIndex ) {
286281 clm [j ] <- NA
287282 }
288- result <- cbind(result , as.POSIXct( clm ) )
283+ result <- cbind(result , clm )
289284
290285 } else {
291286 print(" error in DataFrame" )
@@ -346,7 +341,7 @@ DDB_GetEntity <- function(xxdb_type) {
346341 if (ReturnScalarNA(i )) {
347342 result <- NA
348343 } else {
349- result <- ReturnScalarString (i )
344+ result <- ReturnScalarDate (i )
350345 }
351346 result <- as.Date(result )
352347
@@ -355,7 +350,7 @@ DDB_GetEntity <- function(xxdb_type) {
355350 if (ReturnScalarNA(i )) {
356351 result <- NA
357352 } else {
358- result <- ReturnScalarString (i )
353+ result <- ReturnScalarTime (i )
359354 }
360355 result <- as.POSIXct(result )
361356
@@ -380,15 +375,15 @@ DDB_GetEntity <- function(xxdb_type) {
380375
381376 } else if (anytypelist [i ] == 16 ) {
382377 # Vector Date
383- result <- ReturnVectorString (i )
378+ result <- ReturnVectorDate (i )
384379 result <- DDB_SetReceiveVectorNA(result , ReturnVectorNAIndex(i ))
385- result <- as.Date( result )
380+ result <- result
386381
387382 } else if (anytypelist [i ] == 17 ) {
388383 # Vector DateTime
389- result <- ReturnVectorString (i )
384+ result <- ReturnVectorTime (i )
390385 result <- DDB_SetReceiveVectorNA(result , ReturnVectorNAIndex(i ))
391- result <- as.POSIXct( result )
386+ result <- result
392387
393388 } else if (anytypelist [i ] == 9 ) {
394389 # Logical Matrix
@@ -458,20 +453,20 @@ DDB_GetEntity <- function(xxdb_type) {
458453 result <- cbind(result , clm )
459454
460455 } else if (typelist [k ] == 16 ) {
461- clm <- ReturnTableColumnString (k , i )
456+ clm <- ReturnTableColumnDate (k , i )
462457 NAIndex <- ReturnTableColumnNAIndex(k , i )
463458 for (j in NAIndex ) {
464459 clm [j ] <- NA
465460 }
466- result <- cbind(result , as.Date( clm ) )
461+ result <- cbind(result , clm )
467462
468463 } else if (typelist [k ] == 17 ) {
469- clm <- ReturnTableColumnString (k , i )
464+ clm <- ReturnTableColumnTime (k , i )
470465 NAIndex <- ReturnTableColumnNAIndex(k , i )
471466 for (j in NAIndex ) {
472467 clm [j ] <- NA
473468 }
474- result <- cbind(result , as.POSIXct( clm ) )
469+ result <- cbind(result , clm )
475470
476471 } else {
477472 print(" error in DataFrame" )
@@ -539,12 +534,12 @@ DDB_UploadScalarDate <- function(date) {
539534# Parse a date type vector to C++ string vector to upload,
540535# at the same time, deal with NA in vector
541536DDB_UploadVectorDate <- function (vec ) {
542- date_str_vec <- vector(mode = " character" , length = 0 )
543- for (i in 1 : length(vec )) {
544- date_str_vec <- c(date_str_vec , as.character(vec [i ]))
545- }
537+ # date_str_vec <- vector(mode = "character", length = 0)
538+ # for (i in 1:length(vec)) {
539+ # date_str_vec <- c(date_str_vec, as.character(vec[i]))
540+ # }
546541 NAIndex <- DDB_SetUploadVectorNA(vec )
547- UploadVectorDate(date_str_vec , NAIndex )
542+ UploadVectorDate(vec , NAIndex )
548543}
549544
550545# @Function
@@ -557,12 +552,12 @@ DDB_UploadScalarDateTime <- function(datetime) {
557552# Parse a datetime type vector to C++ string vector to upload
558553# at the same time, deal with NA in vector
559554DDB_UploadVectorDateTime <- function (vec ) {
560- date_time_str_vec <- vector(mode = " character" , length = 0 )
561- for (i in 1 : length(vec )) {
562- date_time_str_vec <- c(date_time_str_vec , as.character(vec [i ]))
563- }
555+ # date_time_str_vec <- vector(mode = "character", length = 0)
556+ # for (i in 1:length(vec)) {
557+ # date_time_str_vec <- c(date_time_str_vec, as.character(vec[i]))
558+ # }
564559 NAIndex <- DDB_SetUploadVectorNA(vec )
565- UploadVectorDateTime(date_time_str_vec , NAIndex )
560+ UploadVectorDateTime(vec , NAIndex )
566561}
567562
568563# @Function
@@ -589,13 +584,25 @@ DDB_UploadVector <- function(vec) {
589584 NAIndex <- DDB_SetUploadVectorNA(vec )
590585 UploadVectorDouble(vec , NAIndex )
591586
592- } else if (is.character(vec )) {
587+ } else if (is.character(vec ) || class( vec ) == " factor " ) {
593588
594589 NAIndex <- DDB_SetUploadVectorNA(vec )
595590 UploadVectorString(vec , NAIndex )
596591
597- } else {
592+ } else if (length(class(vec )) > 1 &&
593+ class(vec )[1 ] == " POSIXct" ) {
594+
595+ NAIndex <- DDB_SetUploadVectorNA(vec )
596+ UploadVectorDateTime(vec , NAIndex )
597+
598+ } else if (class(vec ) == " Date" ) {
599+ NAIndex <- DDB_SetUploadVectorNA(vec )
600+ UploadVectorDate(vec , NAIndex )
601+
602+ }
603+ else {
598604 print(" [ERROR] Vector type not support yet." )
605+ print(" If you try to upload a dataframe, please add stringsAsFactors=FALSE" )
599606 return (NULL )
600607 }
601608
@@ -719,14 +726,10 @@ DDB_UploadEntity <- function(args) {
719726 DDB_UploadVector(args [[i ]])
720727 } else if (is.vector(args [[i ]]) && length(args [[i ]]) == 1 ) {
721728 DDB_UploadScalar(args [[i ]])
722- } else if (class(args [[i ]]) == " Date" && length(args [[i ]]) == 1 ) {
723- DDB_UploadScalarDate(args [[i ]])
724- } else if (class(args [[i ]]) == " Date" && length(args [[i ]]) > 1 ) {
725- DDB_UploadVectorDate(args [[i ]])
726- } else if (class(args [[i ]]) == c(" POSIXct" , " POSIXt" ) && length(args [[i ]]) == 1 ) {
727- DDB_UploadScalarDateTime(args [[i ]])
728- } else if (class(args [[i ]]) == c(" POSIXct" , " POSIXt" ) && length(args [[i ]]) > 1 ) {
729+ } else if (length(class(args [[i ]])) == 2 && class(args [[i ]])[1 ] == " POSIXct" ) {
729730 DDB_UploadVectorDateTime(args [[i ]])
731+ } else if (class(args [[i ]]) == " Date" ) {
732+ DDB_UploadVectorDate(args [[i ]])
730733 } else {
731734 print(" Data form not support yet" )
732735 Clear()
0 commit comments