Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It was for my own consumption, sorry opened by mistake #111

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 90 additions & 85 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,103 +10,108 @@ include_directories(src/include)
include_directories(third_party/substrait)
include_directories(third_party/)

# refer source by absolute path. So that we can use the same source in the child profile too (i.e. test/c)
set(THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party")
set(PROTOBUF_SOURCES
third_party/google/protobuf/any.cc
third_party/google/protobuf/any.pb.cc
third_party/google/protobuf/any_lite.cc
third_party/google/protobuf/arena.cc
third_party/google/protobuf/arenastring.cc
third_party/google/protobuf/descriptor.cc
third_party/google/protobuf/descriptor.pb.cc
third_party/google/protobuf/descriptor_database.cc
third_party/google/protobuf/dynamic_message.cc
third_party/google/protobuf/empty.pb.cc
third_party/google/protobuf/extension_set.cc
third_party/google/protobuf/extension_set_heavy.cc
third_party/google/protobuf/generated_enum_util.cc
third_party/google/protobuf/generated_message_bases.cc
third_party/google/protobuf/generated_message_reflection.cc
third_party/google/protobuf/generated_message_table_driven.cc
third_party/google/protobuf/generated_message_table_driven_lite.cc
third_party/google/protobuf/generated_message_util.cc
third_party/google/protobuf/implicit_weak_message.cc
third_party/google/protobuf/inlined_string_field.cc
third_party/google/protobuf/map.cc
third_party/google/protobuf/map_field.cc
third_party/google/protobuf/message.cc
third_party/google/protobuf/message_lite.cc
third_party/google/protobuf/parse_context.cc
third_party/google/protobuf/port_def.inc
third_party/google/protobuf/port_undef.inc
third_party/google/protobuf/reflection_ops.cc
third_party/google/protobuf/repeated_field.cc
third_party/google/protobuf/repeated_ptr_field.cc
third_party/google/protobuf/text_format.cc
third_party/google/protobuf/unknown_field_set.cc
third_party/google/protobuf/wire_format.cc
third_party/google/protobuf/wire_format_lite.cc
third_party/google/protobuf/io/coded_stream.cc
third_party/google/protobuf/io/io_win32.cc
third_party/google/protobuf/io/strtod.cc
third_party/google/protobuf/io/tokenizer.cc
third_party/google/protobuf/io/zero_copy_stream.cc
third_party/google/protobuf/io/zero_copy_stream_impl.cc
third_party/google/protobuf/io/zero_copy_stream_impl_lite.cc
third_party/google/protobuf/stubs/common.cc
third_party/google/protobuf/stubs/int128.cc
third_party/google/protobuf/stubs/status.cc
third_party/google/protobuf/stubs/stringpiece.cc
third_party/google/protobuf/stubs/stringprintf.cc
third_party/google/protobuf/stubs/structurally_valid.cc
third_party/google/protobuf/stubs/strutil.cc
third_party/google/protobuf/stubs/substitute.cc
third_party/google/protobuf/stubs/bytestream.cc
third_party/google/protobuf/util/json_util.cc
third_party/google/protobuf/util/internal/datapiece.cc
third_party/google/protobuf/util/internal/default_value_objectwriter.cc
third_party/google/protobuf/util/internal/error_listener.cc
third_party/google/protobuf/util/internal/json_escaping.cc
third_party/google/protobuf/util/internal/json_objectwriter.cc
third_party/google/protobuf/util/internal/json_stream_parser.cc
third_party/google/protobuf/util/json_util.cc
third_party/google/protobuf/util/internal/object_writer.cc
third_party/google/protobuf/util/internal/proto_writer.cc
third_party/google/protobuf/util/internal/protostream_objectsource.cc
third_party/google/protobuf/util/internal/protostream_objectwriter.cc
third_party/google/protobuf/source_context.pb.cc
third_party/google/protobuf/stubs/statusor.cc
third_party/google/protobuf/stubs/time.cc
third_party/google/protobuf/type.pb.cc
third_party/google/protobuf/wrappers.pb.cc
third_party/google/protobuf/struct.pb.cc
third_party/google/protobuf/util/internal/type_info.cc
third_party/google/protobuf/util/internal/field_mask_utility.cc
third_party/google/protobuf/util/type_resolver_util.cc
third_party/google/protobuf/util/internal/utility.cc)
${THIRD_PARTY_DIR}/google/protobuf/any.cc
${THIRD_PARTY_DIR}/google/protobuf/any.pb.cc
${THIRD_PARTY_DIR}/google/protobuf/any_lite.cc
${THIRD_PARTY_DIR}/google/protobuf/arena.cc
${THIRD_PARTY_DIR}/google/protobuf/arenastring.cc
${THIRD_PARTY_DIR}/google/protobuf/descriptor.cc
${THIRD_PARTY_DIR}/google/protobuf/descriptor.pb.cc
${THIRD_PARTY_DIR}/google/protobuf/descriptor_database.cc
${THIRD_PARTY_DIR}/google/protobuf/dynamic_message.cc
${THIRD_PARTY_DIR}/google/protobuf/empty.pb.cc
${THIRD_PARTY_DIR}/google/protobuf/extension_set.cc
${THIRD_PARTY_DIR}/google/protobuf/extension_set_heavy.cc
${THIRD_PARTY_DIR}/google/protobuf/generated_enum_util.cc
${THIRD_PARTY_DIR}/google/protobuf/generated_message_bases.cc
${THIRD_PARTY_DIR}/google/protobuf/generated_message_reflection.cc
${THIRD_PARTY_DIR}/google/protobuf/generated_message_table_driven.cc
${THIRD_PARTY_DIR}/google/protobuf/generated_message_table_driven_lite.cc
${THIRD_PARTY_DIR}/google/protobuf/generated_message_util.cc
${THIRD_PARTY_DIR}/google/protobuf/implicit_weak_message.cc
${THIRD_PARTY_DIR}/google/protobuf/inlined_string_field.cc
${THIRD_PARTY_DIR}/google/protobuf/map.cc
${THIRD_PARTY_DIR}/google/protobuf/map_field.cc
${THIRD_PARTY_DIR}/google/protobuf/message.cc
${THIRD_PARTY_DIR}/google/protobuf/message_lite.cc
${THIRD_PARTY_DIR}/google/protobuf/parse_context.cc
${THIRD_PARTY_DIR}/google/protobuf/port_def.inc
${THIRD_PARTY_DIR}/google/protobuf/port_undef.inc
${THIRD_PARTY_DIR}/google/protobuf/reflection_ops.cc
${THIRD_PARTY_DIR}/google/protobuf/repeated_field.cc
${THIRD_PARTY_DIR}/google/protobuf/repeated_ptr_field.cc
${THIRD_PARTY_DIR}/google/protobuf/text_format.cc
${THIRD_PARTY_DIR}/google/protobuf/unknown_field_set.cc
${THIRD_PARTY_DIR}/google/protobuf/wire_format.cc
${THIRD_PARTY_DIR}/google/protobuf/wire_format_lite.cc
${THIRD_PARTY_DIR}/google/protobuf/io/coded_stream.cc
${THIRD_PARTY_DIR}/google/protobuf/io/io_win32.cc
${THIRD_PARTY_DIR}/google/protobuf/io/strtod.cc
${THIRD_PARTY_DIR}/google/protobuf/io/tokenizer.cc
${THIRD_PARTY_DIR}/google/protobuf/io/zero_copy_stream.cc
${THIRD_PARTY_DIR}/google/protobuf/io/zero_copy_stream_impl.cc
${THIRD_PARTY_DIR}/google/protobuf/io/zero_copy_stream_impl_lite.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/common.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/int128.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/status.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/stringpiece.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/stringprintf.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/structurally_valid.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/strutil.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/substitute.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/bytestream.cc
${THIRD_PARTY_DIR}/google/protobuf/util/json_util.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/datapiece.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/default_value_objectwriter.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/error_listener.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/json_escaping.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/json_objectwriter.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/json_stream_parser.cc
${THIRD_PARTY_DIR}/google/protobuf/util/json_util.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/object_writer.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/proto_writer.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/protostream_objectsource.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/protostream_objectwriter.cc
${THIRD_PARTY_DIR}/google/protobuf/source_context.pb.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/statusor.cc
${THIRD_PARTY_DIR}/google/protobuf/stubs/time.cc
${THIRD_PARTY_DIR}/google/protobuf/type.pb.cc
${THIRD_PARTY_DIR}/google/protobuf/wrappers.pb.cc
${THIRD_PARTY_DIR}/google/protobuf/struct.pb.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/type_info.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/field_mask_utility.cc
${THIRD_PARTY_DIR}/google/protobuf/util/type_resolver_util.cc
${THIRD_PARTY_DIR}/google/protobuf/util/internal/utility.cc)

set(SUBSTRAIT_SOURCES
third_party/substrait/substrait/algebra.pb.cc
third_party/substrait/substrait/capabilities.pb.cc
third_party/substrait/substrait/function.pb.cc
third_party/substrait/substrait/parameterized_types.pb.cc
third_party/substrait/substrait/plan.pb.cc
third_party/substrait/substrait/type.pb.cc
third_party/substrait/substrait/type_expressions.pb.cc
third_party/substrait/substrait/extensions/extensions.pb.cc)
${THIRD_PARTY_DIR}/substrait/substrait/algebra.pb.cc
${THIRD_PARTY_DIR}/substrait/substrait/capabilities.pb.cc
${THIRD_PARTY_DIR}/substrait/substrait/function.pb.cc
${THIRD_PARTY_DIR}/substrait/substrait/parameterized_types.pb.cc
${THIRD_PARTY_DIR}/substrait/substrait/plan.pb.cc
${THIRD_PARTY_DIR}/substrait/substrait/type.pb.cc
${THIRD_PARTY_DIR}/substrait/substrait/type_expressions.pb.cc
${THIRD_PARTY_DIR}/substrait/substrait/extensions/extensions.pb.cc)

# refer source by absolute path. So that we can use the same source in the child profile too (i.e. test/c)
set(EXTENSION_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(EXTENSION_SOURCES
src/to_substrait.cpp
src/from_substrait.cpp
src/substrait_extension.cpp
src/custom_extensions.cpp
src/custom_extensions_generated.cpp
${EXTENSION_SOURCES_DIR}/to_substrait.cpp
${EXTENSION_SOURCES_DIR}/from_substrait.cpp
${EXTENSION_SOURCES_DIR}/substrait_extension.cpp
${EXTENSION_SOURCES_DIR}/custom_extensions.cpp
${EXTENSION_SOURCES_DIR}/custom_extensions_generated.cpp
${SUBSTRAIT_SOURCES}
${PROTOBUF_SOURCES})

add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})

set(PARAMETERS "-warnings")
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${EXTENSION_SOURCES})
add_subdirectory(test/c)

install(
TARGETS ${EXTENSION_NAME}
Expand Down
1 change: 1 addition & 0 deletions extension_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ duckdb_extension_load(substrait
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/include
LOAD_TESTS
DONT_LINK
)
9 changes: 7 additions & 2 deletions test/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ include_directories(../../duckdb/src/include)
include_directories(../../duckdb/test/include)
include_directories(../../duckdb/third_party/catch)

set(ALL_SOURCES test_substrait_c_api.cpp)
# get all source files from test/helpers
file(GLOB TEST_HELPER_SOURCES "../../duckdb/test/helpers/*.cpp")
set(ALL_SOURCES ${EXTENSION_SOURCES} ${TEST_HELPER_SOURCES} test_substrait_c_api.cpp)

# this add_executable is needed to make unit test a target
add_executable(test_substrait test_substrait_c_api.cpp ${ALL_SOURCES})
# add duckdb static library to the test so that duckdb symbols are available
target_link_libraries(test_substrait duckdb_static)

add_library_unity(test_substrait OBJECT ${ALL_SOURCES})
set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:test_substrait>
PARENT_SCOPE)
16 changes: 10 additions & 6 deletions test/c/test_substrait_c_api.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
#include "test_helpers.hpp"
#include "duckdb/parser/parser.hpp"
#include "duckdb/planner/logical_operator.hpp"
#include "duckdb/main/connection_manager.hpp"
#include "substrait_extension.hpp"

#include <chrono>
#include <thread>

using namespace duckdb;
using namespace std;

int main(int argc, char* argv[]) {
// Call Catch2's session to run tests
return Catch::Session().run(argc, argv);
}

TEST_CASE("Test C Get and To Substrait API", "[substrait-api]") {
DuckDB db(nullptr);
db.LoadExtension<duckdb::DUCKDB_EXTENSION_CLASS>();
SubstraitExtension substrait_extension;
substrait_extension.Load(db);
Connection con(db);
con.EnableQueryVerification();
// create the database
Expand All @@ -33,7 +36,8 @@ TEST_CASE("Test C Get and To Substrait API", "[substrait-api]") {

TEST_CASE("Test C Get and To Json-Substrait API", "[substrait-api]") {
DuckDB db(nullptr);
db.LoadExtension<duckdb::DUCKDB_EXTENSION_CLASS>();
SubstraitExtension substrait_extension;
substrait_extension.Load(db);
Connection con(db);
con.EnableQueryVerification();
// create the database
Expand Down