10#include <unordered_set>
15 {
"Extract",
"Extract"},
19static void runInsertSpatialDataToAHyperFile() {
20 std::cout <<
"EXAMPLE - Insert spatial data into a single table within a new Hyper file" << std::endl;
21 const std::string pathToDatabase =
"data/spatial_data.hyper";
54 std::vector<hyperapi::TableDefinition::Column> inserterDefinition{
62 std::string textToGeographyCastExpression =
"CAST(" +
hyperapi::escapeName(
"Location_as_text") +
" AS GEOGRAPHY)";
63 std::vector<hyperapi::Inserter::ColumnMapping> columnMappings{
69 hyperapi::Inserter inserter(connection, extractTable, columnMappings, inserterDefinition);
70 inserter.addRow(
"Seattle",
"point(-122.338083 47.647528)");
71 inserter.addRow(
"Munich",
"point(11.584329 48.139257)");
77 int64_t rowCount = connection.executeScalarQuery<int64_t>(
"SELECT COUNT(*) FROM " + extractTable.
getTableName().
toString());
78 std::cout <<
"The number of rows in table " << extractTable.
getTableName() <<
" is " << rowCount <<
"." << std::endl;
80 std::cout <<
"The connection to the Hyper file has been closed." << std::endl;
82 std::cout <<
"The Hyper Process has been shut down." << std::endl;
87 runInsertSpatialDataToAHyperFile();
89 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 geography() noexcept
Returns the GEOGRAPHY SQL type.
static SqlType text() noexcept
Returns the TEXT 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.