An example of how to read and print data from an existing Hyper file.
An example of how to read and print data from an existing Hyper file.
 
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_set>
 
static void copy(const std::string& sourcePath, const std::string& destinationPath) {
   std::ifstream source(sourcePath, std::ios::binary);
   std::ofstream destination(destinationPath, std::ios::binary);
   destination << source.rdbuf();
   source.close();
   destination.close();
}
 
static void runReadAndPrintDataFromExistingHyperFile() {
   std::cout << "EXAMPLE - Read data from an existing Hyper file" << std::endl;
 
   
   
   const std::string pathToSourceDatabase = "data/superstore_sample_denormalized.hyper";
 
   
   const std::string pathToDatabase = "data/superstore_sample_denormalized_read.hyper";
   copy(pathToSourceDatabase, pathToDatabase);
 
   
   
   {
 
      
      {
 
         
         std::unordered_set<hyperapi::TableName> tableNames = catalog.
getTableNames(
"Extract");
         for (auto& tableName : tableNames) {
            std::cout << 
"Table " << tableName << 
" has qualified name: " << tableDefinition.
getTableName() << std::endl;
            for (auto& column : tableDefinition.getColumns()) {
               std::cout << 
"\t Column " << column.
getName() << 
" has type " << column.getType() << 
" and nullability " << column.getNullability()
                         << std::endl;
            }
            std::cout << std::endl;
         }
 
         
         std::cout << "These are all rows in the table " << extractTable.toString() << ":" << std::endl;
 
         hyperapi::Result rowsInTable = connection.executeQuery(
"SELECT * FROM " + extractTable.toString());
 
               std::cout << value << '\t';
            }
            std::cout << '\n';
         }
      }
      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 {
      runReadAndPrintDataFromExistingHyperFile();
      return 1;
   }
   return 0;
}
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.