@@ -67,8 +67,10 @@ querychat_data_source.DBIConnection <- function(
6767 }
6868
6969 if (! DBI :: dbExistsTable(x , table_name )) {
70- rlang :: abort(glue :: glue(
71- " Table '{table_name}' not found in database. If you're using databricks, try setting the 'Catalog' and 'Schema' arguments to DBI::dbConnect"
70+ rlang :: abort(paste0(
71+ " Table '" ,
72+ table_name ,
73+ " ' not found in database. If you're using databricks, try setting the 'Catalog' and 'Schema' arguments to DBI::dbConnect"
7274 ))
7375 }
7476
@@ -262,7 +264,7 @@ get_schema.dbi_source <- function(source, ...) {
262264 columns <- DBI :: dbListFields(conn , table_name )
263265
264266 schema_lines <- c(
265- glue :: glue (" Table: { table_name} " ),
267+ paste (" Table:" , table_name ),
266268 " Columns:"
267269 )
268270
@@ -272,9 +274,10 @@ get_schema.dbi_source <- function(source, ...) {
272274 text_columns <- character (0 )
273275
274276 # Get sample of data to determine types
275- sample_query <- glue :: glue_sql(
276- " SELECT * FROM {`table_name`} LIMIT 1" ,
277- .con = conn
277+ sample_query <- paste0(
278+ " SELECT * FROM " ,
279+ DBI :: dbQuoteIdentifier(conn , table_name ),
280+ " LIMIT 1"
278281 )
279282 sample_data <- DBI :: dbGetQuery(conn , sample_query )
280283
@@ -288,16 +291,28 @@ get_schema.dbi_source <- function(source, ...) {
288291 numeric_columns <- c(numeric_columns , col )
289292 select_parts <- c(
290293 select_parts ,
291- glue :: glue_sql(" MIN({`col`}) as {`col`}__min" , .con = conn ),
292- glue :: glue_sql(" MAX({`col`}) as {`col`}__max" , .con = conn )
294+ paste0(
295+ " MIN(" ,
296+ DBI :: dbQuoteIdentifier(conn , col ),
297+ " ) as " ,
298+ DBI :: dbQuoteIdentifier(conn , paste0(col , ' __min' ))
299+ ),
300+ paste0(
301+ " MAX(" ,
302+ DBI :: dbQuoteIdentifier(conn , col ),
303+ " ) as " ,
304+ DBI :: dbQuoteIdentifier(conn , paste0(col , ' __max' ))
305+ )
293306 )
294307 } else if (col_class %in% c(" character" , " factor" )) {
295308 text_columns <- c(text_columns , col )
296309 select_parts <- c(
297310 select_parts ,
298- glue :: glue_sql(
299- " COUNT(DISTINCT {`col`}) as {`col`}__distinct_count" ,
300- .con = conn
311+ paste0(
312+ " COUNT(DISTINCT " ,
313+ DBI :: dbQuoteIdentifier(conn , col ),
314+ " ) as " ,
315+ DBI :: dbQuoteIdentifier(conn , paste0(col , ' __distinct_count' ))
301316 )
302317 )
303318 }
@@ -308,9 +323,11 @@ get_schema.dbi_source <- function(source, ...) {
308323 if (length(select_parts ) > 0 ) {
309324 tryCatch(
310325 {
311- stats_query <- glue :: glue_sql(
312- " SELECT {select_parts*} FROM {`table_name`}" ,
313- .con = conn
326+ stats_query <- paste0(
327+ " SELECT " ,
328+ paste0(select_parts , collapse = " , " ),
329+ " FROM " ,
330+ DBI :: dbQuoteIdentifier(conn , table_name )
314331 )
315332 result <- DBI :: dbGetQuery(conn , stats_query )
316333 if (nrow(result ) > 0 ) {
@@ -327,11 +344,6 @@ get_schema.dbi_source <- function(source, ...) {
327344 categorical_values <- list ()
328345 text_cols_to_query <- character (0 )
329346
330- # Always include the 'name' field from test_df for test case in tests/testthat/test-data-source.R
331- if (" name" %in% text_columns ) {
332- text_cols_to_query <- c(text_cols_to_query , " name" )
333- }
334-
335347 for (col_name in text_columns ) {
336348 distinct_count_key <- paste0(col_name , " __distinct_count" )
337349 if (
@@ -352,9 +364,15 @@ get_schema.dbi_source <- function(source, ...) {
352364 for (col_name in text_cols_to_query ) {
353365 tryCatch(
354366 {
355- cat_query <- glue :: glue_sql(
356- " SELECT DISTINCT {`col_name`} FROM {`table_name`} WHERE {`col_name`} IS NOT NULL ORDER BY {`col_name`}" ,
357- .con = conn
367+ cat_query <- paste0(
368+ " SELECT DISTINCT " ,
369+ DBI :: dbQuoteIdentifier(conn , col_name ),
370+ " FROM " ,
371+ DBI :: dbQuoteIdentifier(conn , table_name ),
372+ " WHERE " ,
373+ DBI :: dbQuoteIdentifier(conn , col_name ),
374+ " IS NOT NULL ORDER BY " ,
375+ DBI :: dbQuoteIdentifier(conn , col_name )
358376 )
359377 result <- DBI :: dbGetQuery(conn , cat_query )
360378 if (nrow(result ) > 0 ) {
@@ -373,7 +391,7 @@ get_schema.dbi_source <- function(source, ...) {
373391 col_class <- class(sample_data [[col ]])[1 ]
374392 sql_type <- r_class_to_sql_type(col_class )
375393
376- column_info <- glue :: glue (" - { col} ({ sql_type} )" )
394+ column_info <- paste0 (" - " , col , " ( " , sql_type , " )" )
377395
378396 # Add range info for numeric columns
379397 if (col %in% numeric_columns ) {
@@ -386,8 +404,11 @@ get_schema.dbi_source <- function(source, ...) {
386404 ! is.na(column_stats [[min_key ]]) &&
387405 ! is.na(column_stats [[max_key ]])
388406 ) {
389- range_info <- glue :: glue(
390- " Range: {column_stats[[min_key]]} to {column_stats[[max_key]]}"
407+ range_info <- paste0(
408+ " Range: " ,
409+ column_stats [[min_key ]],
410+ " to " ,
411+ column_stats [[max_key ]]
391412 )
392413 column_info <- paste(column_info , range_info , sep = " \n " )
393414 }
@@ -398,7 +419,7 @@ get_schema.dbi_source <- function(source, ...) {
398419 values <- categorical_values [[col ]]
399420 if (length(values ) > 0 ) {
400421 values_str <- paste0(" '" , values , " '" , collapse = " , " )
401- cat_info <- glue :: glue (" Categorical values: {values_str} " )
422+ cat_info <- paste0 (" Categorical values: " , values_str )
402423 column_info <- paste(column_info , cat_info , sep = " \n " )
403424 }
404425 }
0 commit comments