Skip to content

Commit 556412c

Browse files
committed
add log statement inside + changes to the tester
made this test only run when sidecar is enabled custom add fn file
1 parent 94b1a4e commit 556412c

File tree

6 files changed

+123
-10
lines changed

6 files changed

+123
-10
lines changed

presto-native-execution/presto_cpp/main/dynamic_registry/examples/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# limitations under the License.
1212

1313
add_library(presto_example_function_dynamic SHARED DynamicFunction.cpp)
14-
add_library(presto_example_varchar_function_dynamic SHARED
15-
DynamicVarcharFunction.cpp)
16-
add_library(presto_example_non_default_function_dynamic SHARED
17-
DynamicNonDefaultFunction.cpp)
14+
add_library(presto_example_varchar_function_dynamic SHARED DynamicVarcharFunction.cpp)
15+
add_library(presto_example_non_default_function_dynamic SHARED DynamicNonDefaultFunction.cpp)
16+
add_library(add_function_dynamic SHARED CustomAddDynamic.cpp)
17+
1818

1919
set(CMAKE_DYLIB_TEST_LINK_LIBRARIES fmt::fmt gflags::gflags)
2020
target_link_libraries(presto_example_function_dynamic
@@ -23,6 +23,8 @@ target_link_libraries(presto_example_varchar_function_dynamic
2323
PRIVATE ${CMAKE_DYLIB_TEST_LINK_LIBRARIES})
2424
target_link_libraries(presto_example_non_default_function_dynamic
2525
PRIVATE ${CMAKE_DYLIB_TEST_LINK_LIBRARIES})
26+
target_link_libraries(add_function_dynamic
27+
PRIVATE ${CMAKE_DYLIB_TEST_LINK_LIBRARIES})
2628

2729
if(APPLE)
2830
set(COMMON_LIBRARY_LINK_OPTIONS "-Wl,-undefined,dynamic_lookup")
@@ -36,3 +38,5 @@ target_link_options(presto_example_varchar_function_dynamic PRIVATE
3638
${COMMON_LIBRARY_LINK_OPTIONS})
3739
target_link_options(presto_example_non_default_function_dynamic PRIVATE
3840
${COMMON_LIBRARY_LINK_OPTIONS})
41+
target_link_options(add_function_dynamic PRIVATE
42+
${COMMON_LIBRARY_LINK_OPTIONS})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
#include "presto_cpp/main/dynamic_registry/DynamicFunctionRegistrar.h"
16+
// This file defines a mock function that will be dynamically linked and
17+
// registered. There are no restrictions as to how the function needs to be
18+
// defined, but the library (.so) needs to provide a `void registerExtensions()`
19+
// C function in the top-level namespace.
20+
//
21+
// (note the extern "C" directive to prevent the compiler from mangling the
22+
// symbol name).
23+
24+
namespace facebook::velox::common::dynamicRegistry {
25+
26+
template <typename T>
27+
struct DynamicFunction {
28+
VELOX_DEFINE_FUNCTION_TYPES(T);
29+
FOLLY_ALWAYS_INLINE bool call(
30+
int64_t& result,
31+
const arg_type<int64_t>& x1,
32+
const arg_type<int64_t>& x2) {
33+
LOG(INFO) <<"inside the custom_add fn!!!";
34+
result = x1 + x2;
35+
return true;
36+
}
37+
};
38+
} // namespace facebook::velox::common::dynamicRegistry
39+
40+
extern "C" {
41+
// In this case, we assume that facebook::presto::registerPrestoFunction
42+
// will be available and resolve when this library gets loaded.
43+
void registerExtensions() {
44+
facebook::presto::registerPrestoFunction<
45+
facebook::velox::common::dynamicRegistry::DynamicFunction,
46+
int64_t,
47+
int64_t,
48+
int64_t>("custom_add");
49+
}
50+
}

presto-native-tests/src/test/java/com/facebook/presto/nativetests/TestDynamicFunctions.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
114
package com.facebook.presto.nativetests;
215

316
import com.facebook.presto.nativeworker.NativeQueryRunnerUtils;
@@ -38,18 +51,26 @@ protected void createTables()
3851
protected QueryRunner createQueryRunner() throws Exception
3952
{
4053
Path workingDir = Paths.get(System.getProperty("user.dir"));
41-
// TODO make sure in CI working dir is the right path. should be PRESTO_HOME there but locally, its at working dir.
54+
// Path pluginDir = workingDir
55+
// .resolve("presto-native-tests")
56+
// .resolve("src")
57+
// .resolve("test")
58+
// .resolve("resources")
59+
// .resolve("plugin");
4260
Path pluginDir = workingDir
43-
.resolve("src")
44-
.resolve("test")
45-
.resolve("resources")
46-
.resolve("plugin");
61+
.resolve("presto-native-execution")
62+
.resolve("_build")
63+
.resolve("debug") //TODO change to release for CI
64+
.resolve("presto_cpp")
65+
.resolve("main")
66+
.resolve("dynamic_registry")
67+
.resolve("examples");
4768
boolean sidecar = parseBoolean(System.getProperty("sidecarEnabled"));
4869
QueryRunner queryRunner = PrestoNativeQueryRunnerUtils.nativeHiveQueryRunnerBuilder()
4970
.setStorageFormat(System.getProperty("storageFormat"))
5071
.setAddStorageFormatToPath(true)
5172
.setUseThrift(true)
52-
.setCoordinatorSidecarEnabled(sidecar)
73+
.setCoordinatorSidecarEnabled(true)
5374
.setPluginDirectory(Optional.of(pluginDir.toString()))
5475
.build();
5576
if (sidecar) {
@@ -58,6 +79,18 @@ protected QueryRunner createQueryRunner() throws Exception
5879
return queryRunner;
5980
}
6081

82+
@Override
83+
@Parameters("sidecarEnabled")
84+
@Test
85+
public void testCustomAdd()
86+
{
87+
if (parseBoolean(System.getProperty("sidecarEnabled"))) {
88+
assertQuery(
89+
"SELECT custom_add(orderkey, custkey) FROM orders",
90+
"SELECT orderkey + custkey FROM orders");
91+
}
92+
}
93+
6194
// Aggregate functions are not supported currently.
6295
@Override
6396
@Test (enabled = false)
Binary file not shown.

presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestCustomFunctions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
114
package com.facebook.presto.tests;
215

316
import org.intellij.lang.annotations.Language;

presto-tests/src/test/java/com/facebook/presto/tests/TestCustomFunctions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
114
package com.facebook.presto.tests;
215

316
import com.facebook.presto.testing.QueryRunner;

0 commit comments

Comments
 (0)