### Query ClickHouse with basic SELECT Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Executes a SQL query against the ClickHouse database and retrieves the results. This example selects specific columns from the 'mtcars' table based on a condition. ```R dbGetQuery(con, "SELECT car, mpg, cyl, hp FROM mtcars WHERE hp>=110") ``` -------------------------------- ### Get ClickHouse Connection Information Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Retrieves general information about the ClickHouse database connection. ```R dbGetInfo(dbObj, ...) ``` -------------------------------- ### Create and use an alternative database Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Demonstrates how to create a new database in ClickHouse and then switch the active database for subsequent operations within the current session. The `dbname` argument in `dbConnect` can also pre-select a database. ```R dbSendQuery(con, "CREATE DATABASE swiss") dbSendQuery(con, "USE swiss") ``` -------------------------------- ### Create and Use Alternative Database in ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Demonstrates creating a new database and switching to it within the ClickHouse session. The `dbname` argument in `dbConnect` can also be used to specify the database upon connection. ```R dbSendQuery(con, "CREATE DATABASE swiss") dbSendQuery(con, "USE swiss") ``` -------------------------------- ### Create ClickHouseHTTP DBI Driver Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Initializes a ClickHouseHTTP DBI driver, which is the entry point for establishing connections to ClickHouse. ```APIDOC ## ClickHouseHTTP() ### Description Create a ClickHouseHTTP DBI driver ### Usage ``` ClickHouseHTTP() ``` ### Value A ClickHouseHTTPDriver ``` -------------------------------- ### Access table from a different database Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Illustrates how to access a table located in a different database (e.g., 'default') from the currently active one. This is done by fully qualifying the table name using `SQL()`. ```R dbReadTable(con, SQL("default.mtcars")) ``` -------------------------------- ### Establish HTTP Connection to ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Connect to a ClickHouse instance using HTTP. Ensure the ClickHouseHTTP package and DBI are loaded. ```R library(DBI) ### HTTP connection ---- con <- dbConnect( ClickHouseHTTP::ClickHouseHTTP(), host = "localhost", port = 8123 ) ``` -------------------------------- ### Create ClickHouseHTTP DBI Driver Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Instantiates a ClickHouseHTTP driver object for use with DBI functions. ```R ClickHouseHTTP() ``` -------------------------------- ### Connect to ClickHouse via HTTPS (without SSL verification) Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Establishes a connection to a ClickHouse database using the HTTPS protocol. Use `ssl_verifypeer = FALSE` for connections where SSL certificate verification is not required or feasible. ```R con <- dbConnect( ClickHouseHTTP::ClickHouseHTTP(), host = "localhost", port = 8443, https = TRUE, ssl_verifypeer = FALSE ) ``` -------------------------------- ### Connect to ClickHouse via HTTP Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Establishes a connection to a ClickHouse database using the HTTP protocol. Ensure the ClickHouse server is accessible on the specified host and port. ```R library(DBI) con <- dbConnect( ClickHouseHTTP::ClickHouseHTTP(), host = "localhost", port = 8123 ) ``` -------------------------------- ### ClickHouseHTTPConnection Methods Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Provides methods for interacting with a ClickHouse database connection, including sending queries, retrieving information, and managing tables. ```APIDOC ## dbSendQuery ### Description Send SQL query to ClickHouse ### Usage ```R dbSendQuery(conn, statement, format = c("Arrow", "TabSeparatedWithNamesAndTypes"), file = NA, ...) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `statement`: the SQL query statement `format`: the format used by ClickHouse to send the results. Two formats are supported: "Arrow" (default) and "TabSeparatedWithNamesAndTypes" `file`: a path to a file to send along the query (default: NA) `...`: Other parameters passed on to methods ``` ```APIDOC ## dbGetInfo ### Description Information about the ClickHouse database ### Usage ```R dbGetInfo(dbObj, ...) ``` ### Arguments `dbObj`: a ClickHouseHTTPConnection object `...`: Other parameters passed on to methods ``` ```APIDOC ## dbListTables ### Description List tables in ClickHouse ### Usage ```R dbListTables(conn, database = NA, ...) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `...`: Other parameters passed on to methods ``` ```APIDOC ## dbExistsTable ### Description Does a table exist? ### Usage ```R dbExistsTable(conn, name, database = NA, ...) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `name`: the name of the table `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `...`: Other parameters passed on to methods ``` ```APIDOC ## dbReadTable ### Description Read database tables as data frames ### Usage ```R dbReadTable(conn, name, database = NA, ...) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `name`: the name of the table `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `...`: Other parameters passed on to methods ``` ```APIDOC ## dbListFields ### Description List field names of a table ### Usage ```R dbListFields(conn, name, database = NA, ...) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `name`: the name of the table `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `...`: Other parameters passed on to methods ``` ```APIDOC ## dbRemoveTable ### Description Remove a table from the database ### Usage ```R dbRemoveTable(conn, name, database = NA, ...) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `name`: the name of the table `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `...`: Other parameters passed on to methods ``` ```APIDOC ## dbCreateTable ### Description Create a table in ClickHouse ### Usage ```R dbCreateTable(conn, name, database = NA, fields, engine = "TinyLog", overwrite = FALSE, ..., row.names = NULL, temporary = FALSE) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `name`: the name of the table to create `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `fields`: a character vector with the name of the fields and their ClickHouse type (e.g. `c("text_col String", "num_col Nullable(Float64)", "nul_col Array(Int32)")` ) `engine`: the ClickHouse table engine as described in ClickHouse documentation. Examples: * "TinyLog" (default) * "MergeTree() ORDER BY (expr)" (expr generally correspond to fields separated by ",") `overwrite`: if TRUE and if a table with the same name exists, then it is deleted before creating the new one (default: FALSE) `...`: Other parameters passed on to methods `row.names`: unsupported parameter (add for compatibility reason) `temporary`: unsupported parameter (add for compatibility reason) ``` ```APIDOC ## dbAppendTable ### Description Insert rows into a table ### Usage ```R dbAppendTable(conn, name, database = NA, value, ..., row.names = NULL) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `name`: the name of the table `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `value`: a data.frame `...`: Other parameters passed on to methods `row.names`: unsupported parameter (add for compatibility reason) ``` ```APIDOC ## dbWriteTable ### Description Write a table in ClickHouse ### Usage ```R dbWriteTable(conn, name, database = NA, value, overwrite = FALSE, append = FALSE, engine = "TinyLog", ..., row.names = NULL) ``` ### Arguments `conn`: a ClickHouseHTTPConnection object created with `dbConnect()` `name`: the name of the table `database`: the database to consider. If NA (default), the default database or the one in use in the session (if a session is defined). `value`: a data.frame `overwrite`: if TRUE and if a table with the same name exists, then it is deleted before creating the new one (default: FALSE) `append`: if TRUE, the values are added to the database table if it exists (default: FALSE). `engine`: the ClickHouse table engine as described in ClickHouse documentation. Examples: * "TinyLog" (default) * "MergeTree() ORDER BY (expr)" (expr generally correspond to fields separated by ",") `...`: Other parameters passed on to methods `row.names`: unsupported parameter (add for compatibility reason) ``` -------------------------------- ### List Tables in ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Retrieves a list of all tables within the specified or default database. ```R dbListTables(conn, database = NA, ...) ``` -------------------------------- ### Query ClickHouse Table with Default Format Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Execute a SQL query on ClickHouse and retrieve results. By default, uses the Apache Arrow format. ```R dbGetQuery(con, "SELECT car, mpg, cyl, hp FROM mtcars WHERE hp>=110") ``` -------------------------------- ### Create Table in ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Creates a new table in ClickHouse with specified fields and engine. Supports overwriting existing tables. ```R dbCreateTable( conn, name, database = NA, fields, engine = "TinyLog", overwrite = FALSE, ..., row.names = NULL, temporary = FALSE ) ``` -------------------------------- ### Write and read table with special column names and list types Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Shows how to write an R data frame containing a list column (which maps to ClickHouse Array type) and column names with spaces to ClickHouse. It then reads the data back to verify. ```R data("swiss") swiss <- as_tibble(swiss, rownames = "province") swiss <- mutate(swiss, "pr letters" = strsplit(province, "")) dbWriteTable( con, "swiss", swiss, engine = "MergeTree() ORDER BY (Fertility, province)" ) swissFromDB <- dbReadTable(con, "swiss") ``` -------------------------------- ### dbConnect for ClickHouseHTTP Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Establishes a connection to a ClickHouse database using the HTTP or HTTPS protocol. It supports various parameters for host, port, authentication, SSL verification, and session management. ```APIDOC ## Driver for the ClickHouse database using HTTP(S) interface ### Description Driver for the ClickHouse database using HTTP(S) interface Connect to a ClickHouse database using the ClickHouseHTTP DBI ### Usage ```R ## S4 method for signature 'ClickHouseHTTPDriver' dbConnect( drv, host = "localhost", port = 8123L, dbname = "default", user = "default", password = "", https = FALSE, ssl_verifypeer = TRUE, host_path = NA, use_session = FALSE, session_timeout = 3600L, convert_uint = TRUE, extended_headers = list(), reset_handle = FALSE, settings = list(), ... ) ``` ### Arguments `drv` | A driver object created by `ClickHouseHTTP()` ---|--- `host` | name of the database host (default: "localhost") `port` | port on which the database is listening (default: 8123L) `dbname` | name of the default database (default: "default") `user` | user name (default: "default") `password` | user password (default: "") `https` | a logical to use the HTTPS protocol (default: FALSE) `ssl_verifypeer` | a logical to verify SSL certificate when using HTTPS (default: TRUE) `host_path` | a path to use on host (e.g. "ClickHouse/"): it allows to connect on a server behind a reverse proxy for example `use_session` | a logical indicating if a session should be created and use in ClickHouse (default: FALSE) `session_timeout` | timeout in seconds (default: 3600L seconds) `convert_uint` | a logical: if TRUE (default), UInt ClickHouse data types are converted in the following R classes: * UInt8 : logical * UInt16: Date (when using Arrow format in dbSendQuery,ClickHouseHTTPConnection,character-method) * UInt32: POSIXct (when using Arrow format in dbSendQuery,ClickHouseHTTPConnection,character-method) `extended_headers` | a named list with other HTTP headers (for example: `extended_headers=list("X-Authorization"="Bearer ")` can be used for OAuth access delegation) `reset_handle` | a logical indicating how to manage Curl handles (see httr::handle_pool). If TRUE, handle reset is used (default: FALSE). `settings` | list of Clickhouse settings `...` | Other parameters passed on to methods ### Value A ClickHouseHTTPConnection ### See Also ClickHouseHTTPConnection ### Examples ```R ## Not run: ## Connection ---- library(DBI) ### HTTP connection ---- con <- dbConnect( ClickHouseHTTP::ClickHouseHTTP(), host = "localhost", port = 8123 ) ``` ``` -------------------------------- ### Establish HTTPS Connection to ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Connect to a ClickHouse instance using HTTPS, with an option to disable SSL peer verification. Ensure the ClickHouseHTTP package and DBI are loaded. ```R library(DBI) ### HTTPS connection (without ssl peer verification) ---- con <- dbConnect( ClickHouseHTTP::ClickHouseHTTP(), host = "localhost", port = 8443, https = TRUE, ssl_verifypeer = FALSE ) ``` -------------------------------- ### Execute ClickHouse query with TabSeparated format Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Executes a SQL query against ClickHouse and specifies the 'TabSeparatedWithNamesAndTypes' format for the result. This can be useful for specific data processing needs. ```R selCars <- dbGetQuery( con, "SELECT car, mpg, cyl, hp FROM mtcars WHERE hp>=110", format = "TabSeparatedWithNamesAndTypes" ) ``` -------------------------------- ### Query ClickHouse Table with TabSeparated Format Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Execute a SQL query on ClickHouse and retrieve results using the TabSeparatedWithNamesAndTypes format. This can be faster than Arrow for wide tables but slower for long tables. ```R selCars <- dbGetQuery( con, "SELECT car, mpg, cyl, hp FROM mtcars WHERE hp>=110", format = "TabSeparatedWithNamesAndTypes" ) ## Identifying the original ClickHouse data types attr(selCars, "type") ``` -------------------------------- ### Read Table from a Different Database Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Access a table located in a different database (e.g., 'default') than the currently selected one. Uses SQL object for specifying the full table path. ```R dbReadTable(con, SQL("default.mtcars")) ``` -------------------------------- ### Query ClickHouse using TabSeparatedWithNamesAndTypes format Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Retrieves data from ClickHouse using a specific format, `TabSeparatedWithNamesAndTypes`, which differs from the default Apache Arrow format. This can be useful for compatibility or specific parsing needs. ```R selCars <- dbGetQuery( con, "SELECT car, mpg, cyl, hp FROM mtcars WHERE hp>=110", format = "TabSeparatedWithNamesAndTypes" ) attr(selCars, "type") ``` -------------------------------- ### List Fields of a Table in ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Retrieves the names and types of fields for a specified table in ClickHouse. ```R dbListFields(conn, name, database = NA, ...) ``` -------------------------------- ### Write Table with Custom Engine and Array Column Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Write an R data frame to ClickHouse, specifying a custom table engine and supporting R list columns which map to ClickHouse Array types. Note the support for spaces in column names. ```R data("swiss") swiss <- as_tibble(swiss, rownames = "province") swiss <- mutate(swiss, "pr letters" = strsplit(province, "")) dbWriteTable( con, "swiss", swiss, engine = "MergeTree() ORDER BY (Fertility, province)" ) ``` -------------------------------- ### Send SQL Query to ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Sends an SQL query to the ClickHouse database. Supports Arrow or TabSeparatedWithNamesAndTypes formats for results. Can optionally save results to a file. ```R dbSendQuery( conn, statement, format = c("Arrow", "TabSeparatedWithNamesAndTypes"), file = NA, ... ) ``` -------------------------------- ### Read Table from ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Read an entire table from ClickHouse into an R data frame. Assumes a connection 'con' is established. ```R carsFromDB <- dbReadTable(con, "mtcars") ``` -------------------------------- ### Write R data frame with complex types to ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Writes an R data frame to ClickHouse, including columns with R `list` types which are mapped to ClickHouse `Array` types. Supports spaces in column names and custom table engines. ```R data("swiss") swiss <- as_tibble(swiss, rownames = "province") swiss <- mutate(swiss, "pr letters" = strsplit(province, "")) dbWriteTable( con, "swiss", swiss, engine = "MergeTree() ORDER BY (Fertility, province)" ) ``` -------------------------------- ### Check if Table Exists in ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Verifies the existence of a specific table within the ClickHouse database. ```R dbExistsTable(conn, name, database = NA, ...) ``` -------------------------------- ### Write a table to ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Writes an R data frame to a ClickHouse table. The `engine` argument can be used to specify table engine details like ordering. ```R library(dplyr) data("mtcars") mtcars <- as_tibble(mtcars, rownames = "car") dbWriteTable(con, "mtcars", mtcars) ``` -------------------------------- ### Read Table from ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Reads the entire content of a specified table from ClickHouse into a data frame. ```R dbReadTable(conn, name, database = NA, ...) ``` -------------------------------- ### Character Recovery Function for ClickHouseHTTP Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Use this function to recover special characters in strings when using the TabSeparatedWithNamesAndTypes format. It handles newline, tab, carriage return, backspace, bell, form feed, single quote, and backslash characters. ```R .sp_ch_recov <- function(x){ stringi::stri_replace_all_regex( x, c( "\n", "\t", "\r", "\b", "\a", "\f", "\'", "\\" ), c("\n", "\t", "\r", "\b", "\a", "\f", "'", "\\"), vectorize_all=FALSE ) } ``` -------------------------------- ### Write R Data Frame to ClickHouse Table Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Write an R data frame to a ClickHouse table. Requires the dplyr package for data manipulation and assumes a connection 'con' is already established. ```R library(dplyr) data("mtcars") mtcars <- as_tibble(mtcars, rownames = "car") dbWriteTable(con, "mtcars", mtcars) ``` -------------------------------- ### Append Rows to ClickHouse Table Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Appends new rows of data to an existing table in ClickHouse. ```R dbAppendTable(conn, name, database = NA, value, ..., row.names = NULL) ``` -------------------------------- ### Write Table to ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Writes a data frame to a ClickHouse table. Can overwrite or append data, and specifies the table engine. ```R dbWriteTable( conn, name, database = NA, value, overwrite = FALSE, append = FALSE, engine = "TinyLog", ... ) ``` -------------------------------- ### Read a table from ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Reads data from a ClickHouse table into an R data frame. This is a basic read operation for a table previously written or existing in the database. ```R carsFromDB <- dbReadTable(con, "mtcars") ``` -------------------------------- ### Identify ClickHouse data types Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Retrieves the ClickHouse data types associated with the columns of a query result. This is useful for understanding the underlying data structure. ```R attr(selCars, "type") ``` -------------------------------- ### Remove Table from ClickHouse Source: https://cran.r-project.org/web/packages/ClickHouseHTTP/refman/ClickHouseHTTP.html Deletes a specified table from the ClickHouse database. ```R dbRemoveTable(conn, name, database = NA, ...) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.