Skip to content

Commit dbd2c52

Browse files
committed
adding files
1 parent 13518bd commit dbd2c52

File tree

79 files changed

+195058
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+195058
-0
lines changed

CPP/CMakeLists.txt

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# -----------------------------------------------------------------------------
2+
#
3+
# This file is the copyrighted property of Tableau Software and is protected
4+
# by registered patents and other applicable U.S. and international laws and
5+
# regulations.
6+
#
7+
# Unlicensed use of the contents of this file is prohibited. Please refer to
8+
# the NOTICES.txt file for further details.
9+
#
10+
# -----------------------------------------------------------------------------
11+
12+
# This is an example CMake project that builds and tests the included C++ example code.
13+
#
14+
# To configure this project, run
15+
#
16+
# cmake <optional CMake arguments> -S "<directory of this file>"
17+
#
18+
# You can optionally override the directory where the Tableau Hyper API for C++ is searched by specifying
19+
#
20+
# -D CMAKE_PREFIX_PATH:PATH="<directory of Tableau Hyper API for C++>/share/cmake"
21+
#
22+
# By default, the `hyperd` executable is searched in the `bin/hyper/` directory of the `tableauhyperapi-cxx` package.
23+
# You can override the directory by specifying
24+
#
25+
# -D HYPER_PATH:PATH="<directory of hyperd>"
26+
#
27+
# To build and test the examples, run
28+
#
29+
# cmake --build .
30+
# ctest
31+
32+
cmake_minimum_required(VERSION 3.1)
33+
34+
# If CMAKE_PREFIX_PATH is not specified, provide a convenient default, so that the `find_package()` below can find
35+
# the Hyper API. This default assumes this `CMakeLists.txt` to be in its original location under `examples/`.
36+
if (NOT DEFINED CMAKE_PREFIX_PATH)
37+
get_filename_component(HAPI_PACKAGE_LOCATION "${CMAKE_SOURCE_DIR}/.." REALPATH)
38+
set(CMAKE_PREFIX_PATH "${HAPI_PACKAGE_LOCATION}/share/cmake" CACHE PATH "CMake prefix path" FORCE)
39+
endif ()
40+
41+
project("Tableau Hyper API for C++ Examples" LANGUAGES CXX)
42+
43+
find_package(tableauhyperapi-cxx REQUIRED CONFIG)
44+
45+
# Determine some directories in the `tableauhyperapi-c` package for use below.
46+
get_filename_component(tableauhyperapi-c_BINARY_DIR "${tableauhyperapi-c_DIR}/../../bin" ABSOLUTE)
47+
get_filename_component(tableauhyperapi-c_LIBRARY_DIR "${tableauhyperapi-c_DIR}/../../lib" ABSOLUTE)
48+
if (WIN32)
49+
set(tableauhyperapi-c_DYLIB_DIR "${tableauhyperapi-c_BINARY_DIR}")
50+
else ()
51+
set(tableauhyperapi-c_DYLIB_DIR "${tableauhyperapi-c_LIBRARY_DIR}")
52+
endif ()
53+
54+
set(CMAKE_CXX_STANDARD 11)
55+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
56+
57+
enable_testing()
58+
59+
# Copy over the superstore CSV dataset.
60+
file(COPY "${CMAKE_SOURCE_DIR}/data/sample_extracts/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/data")
61+
file(COPY "${CMAKE_SOURCE_DIR}/data/superstore_normalized/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/data")
62+
if (WIN32)
63+
# On Windows, the Hyper API is copied into the binary directory so the examples can pick it up during execution.
64+
# On Posix systems, the Hyper API path is already compiled into the RPATH of the examples.
65+
file(COPY "${tableauhyperapi-c_DYLIB_DIR}/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
66+
endif ()
67+
68+
# -----------------------------------------------------------------------------
69+
# `create_hyper_file_from_csv.cpp`
70+
71+
add_executable(create_hyper_file_from_csv create_hyper_file_from_csv.cpp)
72+
target_link_libraries(create_hyper_file_from_csv PRIVATE Tableau::tableauhyperapi-cxx)
73+
add_test(
74+
NAME create_hyper_file_from_csv
75+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:create_hyper_file_from_csv>
76+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
77+
78+
# -----------------------------------------------------------------------------
79+
# `delete_data_in_existing_hyper_file.cpp`
80+
81+
add_executable(delete_data_in_existing_hyper_file delete_data_in_existing_hyper_file.cpp)
82+
target_link_libraries(delete_data_in_existing_hyper_file PRIVATE Tableau::tableauhyperapi-cxx)
83+
add_test(
84+
NAME delete_data_in_existing_hyper_file
85+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:delete_data_in_existing_hyper_file>
86+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
87+
88+
# -----------------------------------------------------------------------------
89+
# `insert_data_into_multiple_tables.cpp`
90+
91+
add_executable(insert_data_into_multiple_tables insert_data_into_multiple_tables.cpp)
92+
target_link_libraries(insert_data_into_multiple_tables PRIVATE Tableau::tableauhyperapi-cxx)
93+
add_test(
94+
NAME insert_data_into_multiple_tables
95+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:insert_data_into_multiple_tables>
96+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
97+
98+
# -----------------------------------------------------------------------------
99+
# `insert_data_into_single_table.cpp`
100+
101+
add_executable(insert_data_into_single_table insert_data_into_single_table.cpp)
102+
target_link_libraries(insert_data_into_single_table PRIVATE Tableau::tableauhyperapi-cxx)
103+
add_test(
104+
NAME insert_data_into_single_table
105+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:insert_data_into_single_table>
106+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
107+
108+
# -----------------------------------------------------------------------------
109+
# `insert_data_into_single_table.cpp`
110+
111+
add_executable(insert_data_with_expressions insert_data_with_expressions.cpp)
112+
target_link_libraries(insert_data_with_expressions PRIVATE Tableau::tableauhyperapi-cxx)
113+
add_test(
114+
NAME insert_data_with_expressions
115+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:insert_data_with_expressions>
116+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
117+
118+
# -----------------------------------------------------------------------------
119+
# `insert_spatial_data_to_a_hyper_file.cpp`
120+
121+
add_executable(insert_spatial_data_to_a_hyper_file insert_spatial_data_to_a_hyper_file.cpp)
122+
target_link_libraries(insert_spatial_data_to_a_hyper_file PRIVATE Tableau::tableauhyperapi-cxx)
123+
add_test(
124+
NAME insert_spatial_data_to_a_hyper_file
125+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:insert_spatial_data_to_a_hyper_file>
126+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
127+
128+
# -----------------------------------------------------------------------------
129+
# `read_and_print_data_from_existing_hyper_file.cpp`
130+
131+
add_executable(read_and_print_data_from_existing_hyper_file read_and_print_data_from_existing_hyper_file.cpp)
132+
target_link_libraries(read_and_print_data_from_existing_hyper_file PRIVATE Tableau::tableauhyperapi-cxx)
133+
add_test(
134+
NAME read_and_print_data_from_existing_hyper_file
135+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:read_and_print_data_from_existing_hyper_file>
136+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
137+
138+
# -----------------------------------------------------------------------------
139+
# `update_data_in_existing_hyper_file.cpp`
140+
141+
add_executable(update_data_in_existing_hyper_file update_data_in_existing_hyper_file.cpp)
142+
target_link_libraries(update_data_in_existing_hyper_file PRIVATE Tableau::tableauhyperapi-cxx)
143+
add_test(
144+
NAME update_data_in_existing_hyper_file
145+
COMMAND ${CMAKE_COMMAND} -E env HYPER_PATH=${HYPER_PATH} $<TARGET_FILE:update_data_in_existing_hyper_file>
146+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
147+

CPP/create_hyper_file_from_csv.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// -----------------------------------------------------------------------------
2+
//
3+
// This file is the copyrighted property of Tableau Software and is protected
4+
// by registered patents and other applicable U.S. and international laws and
5+
// regulations.
6+
//
7+
// You may adapt this file and modify it to fit into your context and use it
8+
// as a template to start your own projects.
9+
//
10+
// -----------------------------------------------------------------------------
11+
12+
/**
13+
* \example create_hyper_file_from_csv.cpp
14+
*
15+
* An example of how to load data from a CSV file into a new Hyper file.
16+
*/
17+
18+
#include <hyperapi/hyperapi.hpp>
19+
#include <iostream>
20+
#include <string>
21+
22+
static const hyperapi::TableDefinition customerTable{
23+
"Customer", // Since the table name is not prefixed with an explicit schema name, the table will reside in the default "public" namespace.
24+
{hyperapi::TableDefinition::Column{"Customer ID", hyperapi::SqlType::text(), hyperapi::Nullability::NotNullable},
25+
hyperapi::TableDefinition::Column{"Customer Name", hyperapi::SqlType::text(), hyperapi::Nullability::NotNullable},
26+
hyperapi::TableDefinition::Column{"Loyalty Reward Points", hyperapi::SqlType::bigInt(), hyperapi::Nullability::NotNullable},
27+
hyperapi::TableDefinition::Column{"Segment", hyperapi::SqlType::text(), hyperapi::Nullability::NotNullable}}};
28+
29+
static void runCreateHyperFileFromCSV() {
30+
std::cout << "EXAMPLE - Load data from CSV into table in new Hyper file" << std::endl;
31+
const std::string pathToDatabase = "data/customer.hyper";
32+
33+
// Starts the Hyper Process with telemetry enabled to send data to Tableau.
34+
// To opt out, simply set telemetry=hyperapi::Telemetry::DoNotSendUsageDataToTableau.
35+
{
36+
// Optional process parameters. They are documented in the Tableau Hyper documentation, chapter "Process Settings"
37+
// (https://help.tableau.com/current/api/hyper_api/en-us/reference/sql/processsettings.html).
38+
std::unordered_map<std::string, std::string> processParameters = {
39+
// Limits the number of Hyper event log files to two.
40+
{"log_file_max_count", "2"},
41+
// Limits the size of Hyper event log files to 100 megabytes.
42+
{"log_file_size_limit", "100M"}};
43+
44+
hyperapi::HyperProcess hyper(hyperapi::Telemetry::SendUsageDataToTableau, "example", processParameters);
45+
// Creates new Hyper file "customer.hyper".
46+
// Replaces existing file with hyperapi::CreateMode::CreateAndReplace if it already exists.
47+
{
48+
// Optional connection parameters. They are documented in the Tableau Hyper documentation, chapter "Connection Settings"
49+
// (https://help.tableau.com/current/api/hyper_api/en-us/reference/sql/connectionsettings.html).
50+
std::unordered_map<std::string, std::string> connectionParameters = {{"lc_time", "en_US"}};
51+
52+
hyperapi::Connection connection(hyper.getEndpoint(), pathToDatabase, hyperapi::CreateMode::CreateAndReplace, connectionParameters);
53+
const hyperapi::Catalog& catalog = connection.getCatalog();
54+
55+
catalog.createTable(customerTable);
56+
57+
// Using path to current file, create a path that locates CSV file packaged with these examples.
58+
std::string pathToCSV = "data/customers.csv";
59+
60+
// Load all rows into "Customers" table from the CSV file.
61+
// `executeCommand` executes a SQL statement and returns the impacted row count.
62+
int64_t rowCount = connection.executeCommand(
63+
"COPY " + customerTable.getTableName().toString() + " from " + hyperapi::escapeStringLiteral(pathToCSV) +
64+
" with (format csv, NULL 'NULL', delimiter ',', header)");
65+
66+
std::cout << "The number of rows in table " << customerTable.getTableName() << " is " << rowCount << "." << std::endl;
67+
}
68+
std::cout << "The connection to the Hyper file has been closed." << std::endl;
69+
}
70+
std::cout << "The Hyper Process has been shut down." << std::endl;
71+
}
72+
73+
int main() {
74+
try {
75+
runCreateHyperFileFromCSV();
76+
} catch (const hyperapi::HyperException& e) {
77+
std::cout << e.toString() << std::endl;
78+
return 1;
79+
}
80+
return 0;
81+
}

0 commit comments

Comments
 (0)