An example of how to load data from a CSV file into a new Hyper file.
An example of how to load data from a CSV file into a new Hyper file.
#include <iostream>
#include <string>
"Customer",
static void runCreateHyperFileFromCSV() {
std::cout << "EXAMPLE - Load data from CSV into table in new Hyper file" << std::endl;
const std::string pathToDatabase = "data/customer.hyper";
{
std::unordered_map<std::string, std::string> processParameters = {
{"log_file_max_count", "2"},
{"log_file_size_limit", "100M"}};
{
std::unordered_map<std::string, std::string> connectionParameters = {{"lc_time", "en_US"}};
std::string pathToCSV = "data/customers.csv";
std::cout << "Issuing the SQL COPY command to load the csv file into the table. Since the first line" << std::endl;
std::cout << "of our csv file contains the column names, we use the `header` option to skip it." << std::endl;
int64_t rowCount = connection.executeCommand(
" with (format csv, NULL 'NULL', delimiter ',', header)");
std::cout << "The number of rows in table " << customerTable.getTableName() << " is " << rowCount << "." << std::endl;
}
std::cout << "The connection to the Hyper file has been closed." << std::endl;
}
std::cout << "The Hyper Process has been shut down." << std::endl;
}
int main() {
try {
runCreateHyperFileFromCSV();
return 1;
}
return 0;
}
The catalog class gives access to the metadata of the attached databases of a connection.
void createTable(const hyperapi::TableDefinition &table_definition) const
Creates a SQL table with the given table definition.
Defines a Hyper connection.
Defines an exception object that is thrown on failure by the functions in the Hyper API C++ library.
std::string toString() const
Returns a formatted string containing the message and hint of the error and all causes.
static SqlType bigInt() noexcept
Returns the BIG INTEGER SQL type.
static SqlType text() noexcept
Returns the TEXT SQL type.
A Column of a table definition.
The main header of the Hyper API for C++.
@ NotNullable
The column cannot contain NULL values.
@ SendUsageDataToTableau
Telemetry data will be sent to tableau to help improve the Hyper API.
@ CreateAndReplace
Create the database. If it already exists, drop the old one first.
std::string escapeStringLiteral(string_view input)
Escapes the given string for safe usage in SQL query or command strings as a string literal.