An example of how to push down computations to Hyper during data insertion using expressions.
An example of how to push down computations to Hyper during data insertion using expressions.
#include <iostream>
#include <string>
#include <unordered_set>
{"Extract", "Extract"},
static void runInsertDataWithExpressions() {
std::cout << "EXAMPLE - Push down computations to Hyper during data insertion using expressions" << std::endl;
const std::string pathToDatabase = "data/orders.hyper";
{
{
std::vector<hyperapi::TableDefinition::Column> inserterDefinition{
std::string shipPriorityAsIntCaseExpression =
"CASE " +
hyperapi::escapeName(
"Ship Priority Text") +
std::vector<hyperapi::Inserter::ColumnMapping> columnMappings{
{
hyperapi::Inserter inserter(connection, extractTable, columnMappings, inserterDefinition);
inserter.addRow(399, "2012-09-13 10:00:00", "Express Class", "Urgent");
inserter.addRow(530, "2012-07-12 14:00:00", "Standard Class", "Low");
inserter.execute();
}
int64_t rowCount = connection.executeScalarQuery<int64_t>("SELECT COUNT(*) FROM " + extractTable.getTableName().toString());
std::cout << "The number of rows in table " << extractTable.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 {
runInsertDataWithExpressions();
return 1;
}
return 0;
}
The catalog class gives access to the metadata of the attached databases of a connection.
void createSchema(const SchemaName &schemaName) const
Creates a SQL schema with the given name.
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.
Maps an expression to a column
static SqlType text() noexcept
Returns the TEXT SQL type.
static SqlType integer() noexcept
Returns the INTEGER SQL type.
static SqlType timestamp() noexcept
Returns the TIMESTAMP 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 escapeName(string_view input)
Escapes the given string for safe usage in SQL query or command strings as an identifier.
std::string escapeStringLiteral(string_view input)
Escapes the given string for safe usage in SQL query or command strings as a string literal.