wjones127 commented on a change in pull request #8844:
URL: https://github.com/apache/arrow/pull/8844#discussion_r606018159
##########
File path: cpp/src/gandiva/like_holder.cc
##########
@@ -62,39 +56,95 @@ const FunctionNode LikeHolder::TryOptimize(const
FunctionNode& node) {
return node;
}
+const FunctionNode SQLLikeHolder::TryOptimize(const FunctionNode& node) {
+ Result<std::string> pattern_result = GetPattern(node);
+ if (!pattern_result.ok()) {
+ return node;
+ }
+ std::string sql_pattern = pattern_result.ValueOrDie();
+
+ std::string pcre_pattern;
+ auto conversion_status = RegexUtil::SqlLikePatternToPcre(sql_pattern,
pcre_pattern);
+ if (!conversion_status.ok()) {
+ return node;
+ }
+
+ auto literal_type = node.children().at(1)->return_type();
+ auto pcre_node =
+ std::make_shared<LiteralNode>(literal_type, LiteralHolder(pcre_pattern),
false);
+ auto new_node = FunctionNode("regexp_matches", {node.children().at(0),
pcre_node},
+ node.return_type());
+
+ return RegexpMatchesHolder::TryOptimize(new_node);
+}
+
static bool IsArrowStringLiteral(arrow::Type::type type) {
return type == arrow::Type::STRING || type == arrow::Type::BINARY;
}
-Status LikeHolder::Make(const FunctionNode& node, std::shared_ptr<LikeHolder>*
holder) {
+Status RegexpMatchesHolder::ValidateArguments(const FunctionNode& node) {
ARROW_RETURN_IF(node.children().size() != 2,
- Status::Invalid("'like' function requires two parameters"));
+ Status::Invalid("'" + node.descriptor()->name() +
+ "' function requires two parameters"));
auto literal = dynamic_cast<LiteralNode*>(node.children().at(1).get());
ARROW_RETURN_IF(
literal == nullptr,
- Status::Invalid("'like' function requires a literal as the second
parameter"));
+ Status::Invalid("'" + node.descriptor()->name() +
+ "' function requires a literal as the second
parameter"));
auto literal_type = literal->return_type()->id();
ARROW_RETURN_IF(
!IsArrowStringLiteral(literal_type),
- Status::Invalid(
- "'like' function requires a string literal as the second
parameter"));
+ Status::Invalid("'" + node.descriptor()->name() +
+ "' function requires a string literal as the second
parameter"));
- return Make(arrow::util::get<std::string>(literal->holder()), holder);
+ return Status::OK();
}
-Status LikeHolder::Make(const std::string& sql_pattern,
- std::shared_ptr<LikeHolder>* holder) {
- std::string pcre_pattern;
- ARROW_RETURN_NOT_OK(RegexUtil::SqlLikePatternToPcre(sql_pattern,
pcre_pattern));
+Result<std::string> RegexpMatchesHolder::GetPattern(const FunctionNode& node) {
Review comment:
FYI This looks to be the first use of `Arrow::Result` in the Gandiva
codebase, but this seems to be what the main arrow C++ codebase is using
recently. Let me know if you object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]