diff --git a/NEWS.md b/NEWS.md index 456b504..4b1b405 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # implyr (development version) +* Fixed bugs in table creation (#47, @karoliskascenas) * Added more SQL translations # implyr 0.3.0 diff --git a/R/db-impala.R b/R/db-impala.R index d5e60d2..0390464 100644 --- a/R/db-impala.R +++ b/R/db-impala.R @@ -719,6 +719,12 @@ db_create_table.impala_connection <- is_nchar_one_string_or_null(field_terminator), is_nchar_one_string_or_null(line_terminator) ) + if (isTRUE(grepl("^[[:cntrl:]]{1}$", field_terminator))) { + field_terminator <- gsub("\"", "", deparse(field_terminator), fixed = TRUE) + } + if (isTRUE(grepl("^[[:cntrl:]]{1}$", line_terminator))) { + line_terminator <- gsub("\"", "", deparse(line_terminator), fixed = TRUE) + } if (temporary) { stop( "Impala does not support temporary tables. Set temporary = FALSE in db_create_table().", @@ -743,6 +749,8 @@ db_create_table.impala_connection <- }, ident(table), " ", + fields, + " ", if (!is.null(field_terminator) || !is.null(line_terminator)) { sql("ROW FORMAT DELIMITED ") @@ -756,7 +764,6 @@ db_create_table.impala_connection <- if (!is.null(file_format)) { sql(paste0("STORED AS ", file_format, " ")) }, - fields, con = con) dbExecute(con, sql) } diff --git a/R/src_impala.R b/R/src_impala.R index 359fe92..6d7f8af 100644 --- a/R/src_impala.R +++ b/R/src_impala.R @@ -329,7 +329,7 @@ copy_to.src_impala <- temporary = TRUE, unique_indexes = NULL, indexes = NULL, - analyze = TRUE, + analyze = FALSE, external = FALSE, force = FALSE, field_terminator = NULL, @@ -383,7 +383,7 @@ copy_to.src_impala <- external = external, force = force, field_terminator = field_terminator, - line_terminator = field_terminator, + line_terminator = line_terminator, file_format = file_format, ... ) diff --git a/tests/testthat/test-copy_to.R b/tests/testthat/test-copy_to.R index af08079..5c2b43d 100644 --- a/tests/testthat/test-copy_to.R +++ b/tests/testthat/test-copy_to.R @@ -7,7 +7,14 @@ test_that("copy_to() succeeds on a very small data frame", { table_name <- paste0(sample(letters, 10, replace = TRUE), collapse = "") dbExecute(impala, paste0("DROP TABLE IF EXISTS ", table_name)) Sys.sleep(2) - copy_to(impala, nycflights13::airlines[1:5, ], name = table_name, temporary = FALSE, analyze = FALSE) + copy_to( + impala, + nycflights13::airlines[1:5, ], + name = table_name, + temporary = FALSE, + field_terminator = "\t", + line_terminator = "\n" + ) airlines_impala <- dbGetQuery(impala, paste0("SELECT * FROM ", table_name, " ORDER BY carrier")) # right-trim variable length strings because RJDBC pads them with spaces