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

[GJ-7] Add a native test for Velox compute #8

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
18 changes: 18 additions & 0 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,24 @@ set_source_files_properties(${PROTO_OUTPUT_FILES} PROPERTIES GENERATED TRUE)
get_filename_component(PROTO_DIR ${proto_directory}/,
DIRECTORY)

if(TESTS)
find_package(GTest)
macro(package_add_test TESTNAME)
add_executable(${TESTNAME} ${ARGN})
target_link_libraries(${TESTNAME} gtest gtest_main spark_columnar_jni dl ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(${TESTNAME} PUBLIC ${source_root_directory} ${VELOX_HOME} ${VELOX_REALEASE_PATH})
gtest_discover_tests(${TESTNAME}
WORKING_DIRECTORY ${PROJECT_DIR}
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
)
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
endmacro()
include(GoogleTest)
ENABLE_TESTING()
add_custom_target(test ${CMAKE_CTEST_COMMAND} -R TestArrowCompute --output-on-failure)
add_subdirectory(tests)
endif()

set(CODEGEN_HEADERS
third_party/
)
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/jni/jni_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <gandiva/tree_expr_builder.h>
#include <google/protobuf/io/coded_stream.h>

#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -345,6 +347,9 @@ arrow::Status ParseSubstraitPlan(
env->ReleaseByteArrayElements(exprs_arr, exprs_bytes, JNI_ABORT);
return arrow::Status::UnknownError("Unable to parse");
}
// std::fstream sub("/tmp/sub.data", std::ios::binary|std::ios::out);
// ws_plan.SerializeToOstream(&sub);
// sub.close();
auto converter = std::make_shared<SubstraitVeloxPlanConverter>();
*out_iter = converter->getResIter(converter->toVeloxPlan(ws_plan));
return arrow::Status::OK();
Expand Down
Binary file added cpp/src/resources/sub.data
Binary file not shown.
1 change: 1 addition & 0 deletions cpp/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package_add_test(TestVeloxCompute velox_compute_test.cc)
44 changes: 44 additions & 0 deletions cpp/src/tests/velox_compute_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <arrow/array.h>
#include <arrow/pretty_print.h>
#include <gtest/gtest.h>

#include <fstream>
#include <iostream>
#include <memory>

#include "proto/substrait_to_velox_plan.h"
#include "proto/substrait_utils.h"

namespace gazellejni {

TEST(TestVeloxCompute, QueryTest) {
std::fstream sub("./resources/sub.data", std::ios::binary | std::ios::in);
substrait::Plan ws_plan;
ws_plan.ParseFromIstream(&sub);
auto converter = std::make_shared<SubstraitVeloxPlanConverter>();
auto out_iter = converter->getResIter(converter->toVeloxPlan(ws_plan));
while (out_iter->HasNext()) {
std::shared_ptr<arrow::RecordBatch> result_batch;
out_iter->Next(&result_batch);
arrow::PrettyPrint(*result_batch.get(), 2, &std::cout);
}
}

} // namespace gazellejni