11#include <unordered_set>
16static void copy(
const std::string& sourcePath,
const std::string& destinationPath) {
17 std::ifstream source(sourcePath, std::ios::binary);
18 std::ofstream destination(destinationPath, std::ios::binary);
19 destination << source.rdbuf();
24static void runReadAndPrintDataFromExistingHyperFile() {
25 std::cout <<
"EXAMPLE - Read data from an existing Hyper file" << std::endl;
29 const std::string pathToSourceDatabase =
"data/superstore_sample_denormalized.hyper";
32 const std::string pathToDatabase =
"data/superstore_sample_denormalized_read.hyper";
33 copy(pathToSourceDatabase, pathToDatabase);
46 std::unordered_set<hyperapi::TableName> tableNames = catalog.
getTableNames(
"Extract");
47 for (
auto& tableName : tableNames) {
49 std::cout <<
"Table " << tableName <<
" has qualified name: " << tableDefinition.
getTableName() << std::endl;
50 for (
auto& column : tableDefinition.getColumns()) {
51 std::cout <<
"\t Column " << column.
getName() <<
" has type " << column.getType() <<
" and nullability " << column.getNullability()
54 std::cout << std::endl;
59 std::cout <<
"These are all rows in the table " << extractTable.toString() <<
":" << std::endl;
61 hyperapi::Result rowsInTable = connection.executeQuery(
"SELECT * FROM " + extractTable.toString());
64 std::cout << value <<
'\t';
69 std::cout <<
"The connection to the Hyper file has been closed." << std::endl;
71 std::cout <<
"The Hyper Process has been shut down." << std::endl;
76 runReadAndPrintDataFromExistingHyperFile();
78 std::cout << e.
toString() << std::endl;
The catalog class gives access to the metadata of the attached databases of a connection.
std::unordered_set< TableName > getTableNames(const SchemaName &schema) const
Gets the names of all tables in the given schema.
TableDefinition getTableDefinition(const TableName &tableName) const
Gets the table definition for an existing table.
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.
Base class for a result of a query.
const TableName & getTableName() const noexcept
Returns the name of the table.
Represents an escaped SQL table name.
const Name & getName() const noexcept
The main header of the Hyper API for C++.
@ SendUsageDataToTableau
Telemetry data will be sent to tableau to help improve the Hyper API.