-
Notifications
You must be signed in to change notification settings - Fork 626
[CORE] Add reusable JNI input adapters for backend runtimes #12535
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,6 +273,14 @@ class ShuffleStreamReader : public StreamReader { | |
|
|
||
| } // namespace | ||
|
|
||
| namespace gluten { | ||
|
|
||
| std::shared_ptr<StreamReader> makeShuffleStreamReader(JNIEnv* env, jobject jShuffleStreamReader) { | ||
| return std::make_shared<::ShuffleStreamReader>(env, jShuffleStreamReader); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove "::"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is merely a defensive strategy intended to prevent misuse. |
||
| } | ||
|
|
||
| } // namespace gluten | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
@@ -566,7 +574,7 @@ Java_org_apache_gluten_vectorized_PlanEvaluatorJniWrapper_nativeCreateKernelWith | |
| inputIters.reserve(itersLen); | ||
| for (int idx = 0; idx < itersLen; idx++) { | ||
| jobject iter = env->GetObjectArrayElement(batchItrArray, idx); | ||
| auto arrayIter = std::make_unique<JniColumnarBatchIterator>(env, iter, ctx, idx); | ||
| auto arrayIter = ctx->createJniInputIterator({env, iter, idx}); | ||
| auto resultIter = std::make_shared<ResultIterator>(std::move(arrayIter)); | ||
| inputIters.push_back(std::move(resultIter)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * 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 "jni/JniCommon.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| using namespace gluten; | ||
|
|
||
| namespace { | ||
|
|
||
| class TestColumnarBatchIterator final : public ColumnarBatchIterator { | ||
| public: | ||
| std::shared_ptr<ColumnarBatch> next() override { | ||
| return nullptr; | ||
| } | ||
| }; | ||
|
|
||
| class TestRuntime final : public Runtime { | ||
| public: | ||
| TestRuntime() : Runtime("jni-input-iterator-test", nullptr, nullptr, {}) {} | ||
|
|
||
| std::unique_ptr<ColumnarBatchIterator> createJniInputIterator(const JniInputIteratorContext& context) override { | ||
| env = context.env; | ||
| iterator = context.jColumnarBatchIterator; | ||
| iteratorIndex = context.iteratorIndex; | ||
| return std::make_unique<TestColumnarBatchIterator>(); | ||
| } | ||
|
|
||
| JNIEnv* env{nullptr}; | ||
| jobject iterator{nullptr}; | ||
| int32_t iteratorIndex{-1}; | ||
| }; | ||
|
|
||
| TEST(JniInputIterator, DispatchesThroughRuntime) { | ||
| static int envMarker; | ||
| static int iteratorMarker; | ||
| auto* env = reinterpret_cast<JNIEnv*>(&envMarker); | ||
| auto iterator = reinterpret_cast<jobject>(&iteratorMarker); | ||
|
|
||
| TestRuntime runtime; | ||
| Runtime* baseRuntime = &runtime; | ||
| auto result = baseRuntime->createJniInputIterator({env, iterator, 7}); | ||
|
|
||
| ASSERT_NE(result, nullptr); | ||
| EXPECT_EQ(runtime.env, env); | ||
|
wangxinshuo-bolt marked this conversation as resolved.
Outdated
|
||
| EXPECT_EQ(runtime.iterator, iterator); | ||
| EXPECT_EQ(runtime.iteratorIndex, 7); | ||
| } | ||
|
|
||
| } // namespace | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to wrap it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShuffleStreamReaderis a private implementation withinJniWrapper.cc; we need a function to expose the mechanism for creatingShuffleStreamReaderinstances for different backends.