From 56b720d65a19884b7b38156c2ffd1f339ddb8873 Mon Sep 17 00:00:00 2001 From: ggjh-159 Date: Mon, 6 Jul 2026 11:01:32 +0800 Subject: [PATCH 1/2] feat(function): add Flink-flavored REGEXP_EXTRACT in functions/flinksql --- CMakeLists.txt | 2 ++ velox/functions/CMakeLists.txt | 4 +++ velox/functions/flinksql/CMakeLists.txt | 23 ++++++++++++++ velox/functions/flinksql/RegexFunctions.cpp | 30 +++++++++++++++++++ velox/functions/flinksql/RegexFunctions.h | 33 +++++++++++++++++++++ velox/functions/flinksql/Register.cpp | 29 ++++++++++++++++++ velox/functions/flinksql/Register.h | 29 ++++++++++++++++++ 7 files changed, 150 insertions(+) create mode 100644 velox/functions/flinksql/CMakeLists.txt create mode 100644 velox/functions/flinksql/RegexFunctions.cpp create mode 100644 velox/functions/flinksql/RegexFunctions.h create mode 100644 velox/functions/flinksql/Register.cpp create mode 100644 velox/functions/flinksql/Register.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 78933dd2a3e..abd65cd26c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,7 @@ option(VELOX_ENABLE_FILESYSTEM_CONNECTOR "Build FileSystem connector." ON) option(VELOX_ENABLE_TPCH_CONNECTOR "Build TPC-H connector." ON) option(VELOX_ENABLE_PRESTO_FUNCTIONS "Build Presto SQL functions." ON) option(VELOX_ENABLE_SPARK_FUNCTIONS "Build Spark SQL functions." ON) +option(VELOX_ENABLE_FLINK_FUNCTIONS "Build Flink SQL functions." ON) option(VELOX_ENABLE_EXPRESSION "Build expression." ON) option( VELOX_ENABLE_EXAMPLES @@ -183,6 +184,7 @@ if(${VELOX_BUILD_MINIMAL} OR ${VELOX_BUILD_MINIMAL_WITH_DWIO}) set(VELOX_ENABLE_FILESYSTEM_CONNECTOR ON) set(VELOX_ENABLE_TPCH_CONNECTOR OFF) set(VELOX_ENABLE_SPARK_FUNCTIONS OFF) + set(VELOX_ENABLE_FLINK_FUNCTIONS OFF) set(VELOX_ENABLE_EXAMPLES OFF) set(VELOX_ENABLE_S3 OFF) set(VELOX_ENABLE_GCS OFF) diff --git a/velox/functions/CMakeLists.txt b/velox/functions/CMakeLists.txt index 77e5f83428d..f27fe676cb3 100644 --- a/velox/functions/CMakeLists.txt +++ b/velox/functions/CMakeLists.txt @@ -30,6 +30,10 @@ if(${VELOX_ENABLE_SPARK_FUNCTIONS}) add_subdirectory(sparksql) endif() +if(${VELOX_ENABLE_FLINK_FUNCTIONS}) + add_subdirectory(flinksql) +endif() + if(${VELOX_ENABLE_REMOTE_FUNCTIONS}) add_subdirectory(remote) endif() diff --git a/velox/functions/flinksql/CMakeLists.txt b/velox/functions/flinksql/CMakeLists.txt new file mode 100644 index 00000000000..a94b04d1aaf --- /dev/null +++ b/velox/functions/flinksql/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# 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. + +velox_add_library( + velox_functions_flink + Register.cpp + RegexFunctions.cpp) + +velox_link_libraries( + velox_functions_flink + velox_functions_lib + Folly::folly) diff --git a/velox/functions/flinksql/RegexFunctions.cpp b/velox/functions/flinksql/RegexFunctions.cpp new file mode 100644 index 00000000000..9c2a9b95246 --- /dev/null +++ b/velox/functions/flinksql/RegexFunctions.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * 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 "velox/functions/flinksql/RegexFunctions.h" + +#include "velox/functions/lib/Re2Functions.h" + +namespace facebook::velox::functions::flinksql { + +std::shared_ptr makeRegexExtract( + const std::string& name, + const std::vector& inputArgs, + const core::QueryConfig& config) { + // Flink semantics: returns NULL on no match, allows non-constant patterns. + return makeRe2Extract(name, inputArgs, config, /*emptyNoMatch=*/false); +} + +} // namespace facebook::velox::functions::flinksql diff --git a/velox/functions/flinksql/RegexFunctions.h b/velox/functions/flinksql/RegexFunctions.h new file mode 100644 index 00000000000..06fe3ba0451 --- /dev/null +++ b/velox/functions/flinksql/RegexFunctions.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * 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 +#include + +#include "velox/expression/Expr.h" +#include "velox/vector/BaseVector.h" + +namespace facebook::velox::functions::flinksql { + +// Flink-flavored REGEXP_EXTRACT: returns NULL on no match, allows non-constant +// patterns. +std::shared_ptr makeRegexExtract( + const std::string& name, + const std::vector& inputArgs, + const core::QueryConfig& config); + +} // namespace facebook::velox::functions::flinksql diff --git a/velox/functions/flinksql/Register.cpp b/velox/functions/flinksql/Register.cpp new file mode 100644 index 00000000000..fed696e1eaf --- /dev/null +++ b/velox/functions/flinksql/Register.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * 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 "velox/functions/flinksql/Register.h" + +#include "velox/expression/VectorFunction.h" +#include "velox/functions/flinksql/RegexFunctions.h" +#include "velox/functions/lib/Re2Functions.h" + +namespace facebook::velox::functions::flinksql { + +void registerFunctions(const std::string& prefix) { + exec::registerStatefulVectorFunction( + prefix + "regexp_extract", re2ExtractSignatures(), makeRegexExtract); +} + +} // namespace facebook::velox::functions::flinksql diff --git a/velox/functions/flinksql/Register.h b/velox/functions/flinksql/Register.h new file mode 100644 index 00000000000..e94f3e0b60a --- /dev/null +++ b/velox/functions/flinksql/Register.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * 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 + +namespace facebook::velox::functions::flinksql { + +// Register Flink SQL functions. +// +// Idempotent within a process when called with overwrite=true at the +// exec::registerStatefulVectorFunction layer; existing registrations with the +// same name are replaced. +void registerFunctions(const std::string& prefix = ""); + +} // namespace facebook::velox::functions::flinksql From f62465a055e65a2d249e5c20acb46c3f25e0dc74 Mon Sep 17 00:00:00 2001 From: ggjh-159 Date: Mon, 13 Jul 2026 16:01:33 +0800 Subject: [PATCH 2/2] style: fix cmake-format violation in flinksql CMakeLists --- velox/functions/flinksql/CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/velox/functions/flinksql/CMakeLists.txt b/velox/functions/flinksql/CMakeLists.txt index a94b04d1aaf..bfc280886eb 100644 --- a/velox/functions/flinksql/CMakeLists.txt +++ b/velox/functions/flinksql/CMakeLists.txt @@ -12,12 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -velox_add_library( - velox_functions_flink - Register.cpp - RegexFunctions.cpp) +velox_add_library(velox_functions_flink Register.cpp RegexFunctions.cpp) -velox_link_libraries( - velox_functions_flink - velox_functions_lib - Folly::folly) +velox_link_libraries(velox_functions_flink velox_functions_lib Folly::folly)