-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat(native): Support custom schemas in native sidecar function registry #26236
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -35,3 +35,5 @@ target_link_libraries( | |
| velox_type_fbhive | ||
| velox_tpcds_connector | ||
| ) | ||
|
|
||
| add_subdirectory(hive) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Licensed 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. | ||
|
|
||
| add_subdirectory(functions) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Licensed 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. | ||
|
|
||
| add_library(presto_hive_functions HiveFunctionRegistration.cpp) | ||
| target_link_libraries( | ||
| presto_hive_functions | ||
| presto_dynamic_function_registrar | ||
| velox_functions_string | ||
| ) | ||
|
|
||
| if(PRESTO_ENABLE_TESTING) | ||
| add_subdirectory(tests) | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed 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 "presto_cpp/main/connectors/hive/functions/HiveFunctionRegistration.h" | ||
|
|
||
| #include "presto_cpp/main/connectors/hive/functions/InitcapFunction.h" | ||
| #include "presto_cpp/main/functions/dynamic_registry/DynamicFunctionRegistrar.h" | ||
|
|
||
| using namespace facebook::velox; | ||
| namespace facebook::presto::hive::functions { | ||
|
|
||
| namespace { | ||
| void registerHiveFunctions() { | ||
| // Register functions under the 'hive.default' namespace. | ||
| facebook::presto::registerPrestoFunction<InitCapFunction, Varchar, Varchar>( | ||
| "initcap", "hive.default"); | ||
|
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. This presumes that initcap is available on the Presto coordinator, but I don't think it's added by default. Wouldn't this need to be registered through registerExtensions/with a shared library?
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. @tdcmeehan This code was previously hard-wired in side-car to always load HiveFunctions. So the worker registration was done in this way. In our current state if the Hive catalog is not added on co-ordinator, its functions will not be queried. Right now, native catalog support is not very clear. In my mind, we can register catalog functions on the worker along with their session properties if needed. The side-car then needs to discover catalogs from the worker and populate its function namespaces. Right now, the polling is driven from the co-ordinator plugin setup which doesn't seem quite right. Am I misunderstanding this ? |
||
| } | ||
| } // namespace | ||
|
|
||
| void registerHiveNativeFunctions() { | ||
| static std::once_flag once; | ||
| std::call_once(once, []() { registerHiveFunctions(); }); | ||
| } | ||
|
|
||
| } // namespace facebook::presto::hive::functions | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Licensed 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. | ||
| */ | ||
| #pragma once | ||
|
|
||
| namespace facebook::presto::hive::functions { | ||
|
|
||
| // Registers Hive-specific native functions into the 'hive.default' namespace. | ||
| // This method is safe to call multiple times; it performs one-time registration | ||
| // guarded by an internal call_once. | ||
| void registerHiveNativeFunctions(); | ||
|
|
||
| } // namespace facebook::presto::hive::functions |
|
Joe-Abraham marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "velox/functions/Macros.h" | ||
| #include "velox/functions/lib/string/StringImpl.h" | ||
|
|
||
| namespace facebook::presto::hive::functions { | ||
|
|
||
| /// The InitCapFunction capitalizes the first character of each word in a | ||
| /// string, and lowercases the rest. | ||
| template <typename T> | ||
| struct InitCapFunction { | ||
| VELOX_DEFINE_FUNCTION_TYPES(T); | ||
|
|
||
| // ASCII input always produces ASCII result. This is required for ASCII fast | ||
| // path | ||
| static constexpr bool is_default_ascii_behavior = true; | ||
|
Joe-Abraham marked this conversation as resolved.
Joe-Abraham marked this conversation as resolved.
Joe-Abraham marked this conversation as resolved.
|
||
|
|
||
| FOLLY_ALWAYS_INLINE void call( | ||
| out_type<velox::Varchar>& result, | ||
| const arg_type<velox::Varchar>& input) { | ||
| velox::functions::stringImpl::initcap< | ||
| /*strictSpace=*/false, | ||
| /*isAscii=*/false, | ||
| /*turkishCasing=*/true, | ||
| /*greekFinalSigma=*/true>(result, input); | ||
| } | ||
|
|
||
| FOLLY_ALWAYS_INLINE void callAscii( | ||
| out_type<velox::Varchar>& result, | ||
| const arg_type<velox::Varchar>& input) { | ||
| velox::functions::stringImpl::initcap< | ||
| /*strictSpace=*/false, | ||
| /*isAscii=*/true, | ||
| /*turkishCasing=*/true, | ||
| /*greekFinalSigma=*/true>(result, input); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace facebook::presto::hive::functions | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Licensed 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. | ||
|
|
||
| add_executable(presto_hive_functions_test InitcapTest.cpp) | ||
|
|
||
| add_test( | ||
| NAME presto_hive_functions_test | ||
| COMMAND presto_hive_functions_test | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ) | ||
|
|
||
| target_link_libraries( | ||
| presto_hive_functions_test | ||
| presto_hive_functions | ||
| presto_common | ||
| velox_functions_test_lib | ||
| GTest::gtest | ||
| GTest::gtest_main | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Licensed 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 <gtest/gtest.h> | ||
|
|
||
| #include "presto_cpp/main/connectors/hive/functions/HiveFunctionRegistration.h" | ||
| #include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h" | ||
|
|
||
| namespace facebook::presto::functions::test { | ||
| class InitcapTest : public velox::functions::test::FunctionBaseTest { | ||
| protected: | ||
| static void SetUpTestCase() { | ||
| velox::functions::test::FunctionBaseTest::SetUpTestCase(); | ||
| facebook::presto::hive::functions::registerHiveNativeFunctions(); | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(InitcapTest, initcap) { | ||
| const auto initcap = [&](const std::optional<std::string>& value) { | ||
| return evaluateOnce<std::string>("\"hive.default.initcap\"(c0)", value); | ||
| }; | ||
|
|
||
| // Unicode only. | ||
| EXPECT_EQ( | ||
| initcap("àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ"), | ||
| "Àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ"); | ||
| EXPECT_EQ(initcap("αβγδεζηθικλμνξοπρςστυφχψ"), "Αβγδεζηθικλμνξοπρςστυφχψ"); | ||
| // Mix of ascii and unicode. | ||
| EXPECT_EQ(initcap("αβγδεζ world"), "Αβγδεζ World"); | ||
| EXPECT_EQ(initcap("αfoo wβ"), "Αfoo Wβ"); | ||
| // Ascii only. | ||
| EXPECT_EQ(initcap("hello world"), "Hello World"); | ||
| EXPECT_EQ(initcap("HELLO WORLD"), "Hello World"); | ||
| EXPECT_EQ(initcap("1234"), "1234"); | ||
| EXPECT_EQ(initcap("a b c d"), "A B C D"); | ||
| EXPECT_EQ(initcap("abcd"), "Abcd"); | ||
| // Numbers. | ||
| EXPECT_EQ(initcap("123"), "123"); | ||
| EXPECT_EQ(initcap("1abc"), "1abc"); | ||
| // Edge cases. | ||
| EXPECT_EQ(initcap(""), ""); | ||
| EXPECT_EQ(initcap(std::nullopt), std::nullopt); | ||
|
|
||
| // Test with various whitespace characters | ||
| EXPECT_EQ(initcap("YQ\tY"), "Yq\tY"); | ||
| EXPECT_EQ(initcap("YQ\nY"), "Yq\nY"); | ||
| EXPECT_EQ(initcap("YQ\rY"), "Yq\rY"); | ||
| EXPECT_EQ(initcap("hello\tworld\ntest"), "Hello\tWorld\nTest"); | ||
| EXPECT_EQ(initcap("foo\r\nbar"), "Foo\r\nBar"); | ||
|
|
||
| // Test with multiple consecutive whitespaces | ||
| EXPECT_EQ(initcap("hello world"), "Hello World"); | ||
| EXPECT_EQ(initcap("a b c"), "A B C"); | ||
| EXPECT_EQ(initcap("test\t\tvalue"), "Test\t\tValue"); | ||
| EXPECT_EQ(initcap("line\n\n\nbreak"), "Line\n\n\nBreak"); | ||
|
|
||
| // Test with leading and trailing whitespaces | ||
| EXPECT_EQ(initcap(" hello"), " Hello"); | ||
| EXPECT_EQ(initcap("world "), "World "); | ||
| EXPECT_EQ(initcap(" spaces "), " Spaces "); | ||
| EXPECT_EQ(initcap("\thello"), "\tHello"); | ||
| EXPECT_EQ(initcap("\nworld"), "\nWorld"); | ||
| EXPECT_EQ(initcap("test\n"), "Test\n"); | ||
|
|
||
| // Test with mixed whitespace types | ||
| EXPECT_EQ(initcap("hello \t\nworld"), "Hello \t\nWorld"); | ||
| EXPECT_EQ(initcap("a\tb\nc\rd"), "A\tB\nC\rD"); | ||
| EXPECT_EQ(initcap(" \t\n "), " \t\n "); | ||
| } | ||
| } // namespace facebook::presto::functions::test |
Uh oh!
There was an error while loading. Please reload this page.