|
21 | 21 | #include <gen_cpp/olap_file.pb.h>
|
22 | 22 | #include <thrift/protocol/TDebugProtocol.h>
|
23 | 23 |
|
24 |
| -#include <boost/regex.hpp> |
25 |
| -#include <sstream> |
26 | 24 | #include <string>
|
27 | 25 | #include <vector>
|
28 | 26 |
|
|
40 | 38 | using apache::thrift::ThriftDebugString;
|
41 | 39 | using std::vector;
|
42 | 40 | using std::string;
|
43 |
| -using std::stringstream; |
44 | 41 |
|
45 | 42 | using ::google::protobuf::RepeatedPtrField;
|
46 | 43 |
|
47 | 44 | namespace doris {
|
48 |
| -using namespace ErrorCode; |
49 | 45 |
|
50 | 46 | // construct sub condition from TCondition
|
51 | 47 | std::string construct_sub_predicate(const TCondition& condition) {
|
@@ -314,38 +310,35 @@ Status DeleteHandler::parse_condition(const DeleteSubPredicatePB& sub_cond, TCon
|
314 | 310 | // value: matches "1597751948193618247 and length(source)<1;\n;\n"
|
315 | 311 | //
|
316 | 312 | // For more info, see DeleteHandler::construct_sub_predicates
|
317 |
| -// FIXME(gavin): support unicode. And this is a tricky implementation, it should |
318 |
| -// not be the final resolution, refactor it. |
| 313 | +// FIXME(gavin): This is a tricky implementation, it should not be the final resolution, refactor it. |
319 | 314 | const char* const CONDITION_STR_PATTERN =
|
320 |
| - // .----------------- column-name ----------------. .----------------------- operator ------------------------. .------------ value ----------. |
321 |
| - R"(([_a-zA-Z@0-9\s/][.a-zA-Z0-9_+-/?@#$%^&*"\s,:]*)\s*((?:=)|(?:!=)|(?:>>)|(?:<<)|(?:>=)|(?:<=)|(?:\*=)|(?: IS ))\s*('((?:[\s\S]+)?)'|(?:[\s\S]+)?))"; |
322 |
| - // '----------------- group 1 --------------------' '--------------------- group 2 ---------------------------' | '-- group 4--' | |
323 |
| - // match any of: = != >> << >= <= *= " IS " '----------- group 3 ---------' |
324 |
| - // match **ANY THING** without(4) |
325 |
| - // or with(3) single quote |
326 |
| -boost::regex DELETE_HANDLER_REGEX(CONDITION_STR_PATTERN); |
| 315 | + // .----------------- column-name --------------------------. .----------------------- operator ------------------------. .------------ value ----------. |
| 316 | + R"(([_a-zA-Z@0-9\s/\p{L}][.a-zA-Z0-9_+-/?@#$%^&*"\s,:\p{L}]*)\s*((?:=)|(?:!=)|(?:>>)|(?:<<)|(?:>=)|(?:<=)|(?:\*=)|(?: IS ))\s*('((?:[\s\S]+)?)'|(?:[\s\S]+)?))"; |
| 317 | + // '----------------- group 1 ------------------------------' '--------------------- group 2 ---------------------------' | '-- group 4--' | |
| 318 | + // match any of: = != >> << >= <= *= " IS " '----------- group 3 ---------' |
| 319 | + // match **ANY THING** without(4) |
| 320 | + // or with(3) single quote |
327 | 321 | // clang-format on
|
| 322 | +RE2 DELETE_HANDLER_REGEX(CONDITION_STR_PATTERN); |
328 | 323 |
|
329 | 324 | Status DeleteHandler::parse_condition(const std::string& condition_str, TCondition* condition) {
|
330 |
| - bool matched = false; |
331 |
| - boost::smatch what; |
332 |
| - try { |
333 |
| - VLOG_NOTICE << "condition_str: " << condition_str; |
334 |
| - matched = boost::regex_match(condition_str, what, DELETE_HANDLER_REGEX) && |
335 |
| - condition_str.size() == what[0].str().size(); // exact match |
336 |
| - } catch (boost::regex_error& e) { |
337 |
| - VLOG_NOTICE << "fail to parse expr. [expr=" << condition_str << "; error=" << e.what() |
338 |
| - << "]"; |
339 |
| - } |
| 325 | + std::string col_name, op, value, g4; |
| 326 | + |
| 327 | + bool matched = RE2::FullMatch(condition_str, DELETE_HANDLER_REGEX, &col_name, &op, &value, |
| 328 | + &g4); // exact match |
| 329 | + |
340 | 330 | if (!matched) {
|
341 |
| - return Status::Error<ErrorCode::INVALID_ARGUMENT>("fail to sub condition. condition={}", |
342 |
| - condition_str); |
| 331 | + return Status::InvalidArgument("fail to sub condition. condition={}", condition_str); |
343 | 332 | }
|
344 | 333 |
|
345 |
| - condition->column_name = what[1].str(); |
346 |
| - condition->condition_op = what[2].str() == " IS " ? "IS" : what[2].str(); |
| 334 | + condition->column_name = col_name; |
| 335 | + condition->condition_op = op == " IS " ? "IS" : op; |
347 | 336 | // match string with single quotes, a = b or a = 'b'
|
348 |
| - condition->condition_values.push_back(what[3 + !!what[4].matched].str()); |
| 337 | + if (!g4.empty()) { |
| 338 | + condition->condition_values.push_back(g4); |
| 339 | + } else { |
| 340 | + condition->condition_values.push_back(value); |
| 341 | + } |
349 | 342 | VLOG_NOTICE << "parsed condition_str: col_name={" << condition->column_name << "} op={"
|
350 | 343 | << condition->condition_op << "} val={" << condition->condition_values.back()
|
351 | 344 | << "}";
|
|
0 commit comments