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

feat: enable roundtrip testing of textplan conversion #81

Merged
merged 2 commits into from
Aug 24, 2023
Merged
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
80 changes: 34 additions & 46 deletions src/substrait/textplan/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,38 @@ add_test_case(
gtest
gtest_main)

option(SUBSTRAIT_CPP_ROUNDTRIP_TESTING
"Enable substrait-cpp textplan roundtrip tests." OFF)

if(${SUBSTRAIT_CPP_ROUNDTRIP_TESTING})
add_test_case(
round_trip_test
SOURCES
RoundtripTest.cpp
EXTRA_LINK_LIBS
substrait_textplan_converter
substrait_textplan_loader
substrait_textplan_normalizer
substrait_common
substrait_proto
parse_result_matchers
protobuf-matchers
fmt::fmt-header-only
gmock
gtest
gtest_main)

cmake_path(GET CMAKE_CURRENT_SOURCE_DIR PARENT_PATH TEXTPLAN_SOURCE_DIR)

add_custom_command(
TARGET round_trip_test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Copying unit test data.."
COMMAND ${CMAKE_COMMAND} -E make_directory
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data"
COMMAND
${CMAKE_COMMAND} -E copy
"${TEXTPLAN_SOURCE_DIR}/converter/data/q6_first_stage.json"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data/q6_first_stage.json"
COMMAND ${CMAKE_COMMAND} -E copy "${TEXTPLAN_SOURCE_DIR}/data/*.json"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data/")

message(
STATUS
"test data will be here: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data")
else()

message(
STATUS
"Round trip testing is turned off. Add SUBSTRAIT_CPP_ROUNDTRIP_TESTING=on to enable."
)
add_test_case(
substrait_textplan_round_trip_test
SOURCES
RoundtripTest.cpp
EXTRA_LINK_LIBS
mbrobbel marked this conversation as resolved.
Show resolved Hide resolved
substrait_textplan_converter
substrait_textplan_loader
substrait_textplan_normalizer
substrait_common
substrait_proto
parse_result_matchers
protobuf-matchers
fmt::fmt-header-only
gmock
gtest
gtest_main)

endif()
cmake_path(GET CMAKE_CURRENT_SOURCE_DIR PARENT_PATH TEXTPLAN_SOURCE_DIR)

add_custom_command(
TARGET substrait_textplan_round_trip_test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Copying unit test data.."
COMMAND ${CMAKE_COMMAND} -E make_directory
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data"
COMMAND
${CMAKE_COMMAND} -E copy
"${TEXTPLAN_SOURCE_DIR}/converter/data/q6_first_stage.json"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data/q6_first_stage.json"
COMMAND ${CMAKE_COMMAND} -E copy "${TEXTPLAN_SOURCE_DIR}/data/*.json"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data/")

message(
STATUS "test data will be here: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data"
)
12 changes: 7 additions & 5 deletions src/substrait/textplan/tests/RoundtripTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include "substrait/textplan/tests/ParseResultMatchers.h"

using ::protobuf_matchers::EqualsProto;
using ::protobuf_matchers::IgnoringFieldPaths;
using ::protobuf_matchers::Partially;
using ::protobuf_matchers::IgnoringFields;
using ::testing::AllOf;

namespace io::substrait::textplan {
Expand Down Expand Up @@ -98,7 +97,11 @@ TEST_P(RoundTripBinaryToTextFixture, RoundTrip) {
ASSERT_THAT(
result,
::testing::AllOf(
ParsesOk(), HasErrors({}), AsBinaryPlan(EqualsProto(normalizedPlan))))
ParsesOk(),
HasErrors({}),
AsBinaryPlan(IgnoringFields(
{"substrait.proto.RelCommon.Emit.output_mapping"},
EqualsProto(normalizedPlan)))))
<< std::endl
<< "Intermediate result:" << std::endl
<< addLineNumbers(outputText) << std::endl
Expand All @@ -115,8 +118,7 @@ INSTANTIATE_TEST_SUITE_P(
if (lastSlash != std::string::npos) {
identifier = identifier.substr(lastSlash);
}
if (identifier.length() > 5 &&
identifier.substr(identifier.length() - 5) == ".json") {
if (endsWith(identifier, ".json")) {
identifier = identifier.substr(0, identifier.length() - 5);
}

Expand Down