Skip to content

Commit

Permalink
Better selection of rows to write in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
patzaw committed Aug 28, 2020
1 parent 259babd commit ad868f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
16 changes: 1 addition & 15 deletions R/ClickHouse.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,31 +199,17 @@ ch_insert <- function(
on.exit(RClickhouse::dbSendQuery(con, "USE default"))

if(nrow(value)>0){
# classes <- unlist(lapply(value, function(v){
# class(v)[[1]]
# }))
# for (c in names(classes[classes=="character"])) {
# # value[[c]] <- .Internal(setEncoding(value[[c]], "UTF-8"))
# Encoding(value[[c]]) <- "UTF-8"
# }
# for (c in names(classes[classes=="factor"])) {
# # levels(value[[c]]) <- .Internal(setEncoding(
# # levels(value[[c]]), "UTF-8"
# # ))
# Encoding(levels(value[[c]])) <- "UTF-8"
# }
s <- by*(0:(nrow(value)%/%by))
e <- c(s[-1], nrow(value))
s <- s+1
s <- s[which(!duplicated(e))]
e <- e[which(!duplicated(e))]
for(i in 1:length(s)){
em <- try(
# RClickhouse:::insert(con@ptr, qname, value[s[i]:e[i],,drop=FALSE]),
DBI::dbWriteTable(
con,
tableName, #qname,
value[s[i]:e[i],,drop=FALSE],
dplyr::select(value, s[i]:e[i]),
append=TRUE
),
silent=TRUE
Expand Down
Loading

0 comments on commit ad868f2

Please sign in to comment.