10#include <unordered_set>
15 {
"Extract",
"Extract"},
21static void runInsertDataWithExpressions() {
22 std::cout <<
"EXAMPLE - Push down computations to Hyper during data insertion using expressions" << std::endl;
23 const std::string pathToDatabase =
"data/orders.hyper";
55 std::vector<hyperapi::TableDefinition::Column> inserterDefinition{
66 std::string shipPriorityAsIntCaseExpression =
"CASE " +
hyperapi::escapeName(
"Ship Priority Text") +
71 std::vector<hyperapi::Inserter::ColumnMapping> columnMappings{
79 hyperapi::Inserter inserter(connection, extractTable, columnMappings, inserterDefinition);
80 inserter.addRow(399,
"2012-09-13 10:00:00",
"Express Class",
"Urgent");
81 inserter.addRow(530,
"2012-07-12 14:00:00",
"Standard Class",
"Low");
87 int64_t rowCount = connection.executeScalarQuery<int64_t>(
"SELECT COUNT(*) FROM " + extractTable.
getTableName().
toString());
88 std::cout <<
"The number of rows in table " << extractTable.
getTableName() <<
" is " << rowCount <<
"." << std::endl;
90 std::cout <<
"The connection to the Hyper file has been closed." << std::endl;
92 std::cout <<
"The Hyper Process has been shut down." << std::endl;
97 runInsertDataWithExpressions();
99 std::cout << e.
toString() << std::endl;
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.
const TableName & getTableName() const noexcept
Returns the name of the table.
std::string toString() const
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.