Files
doris/be/src/vec/runtime/ipv6_value.h
Pxl 43c646363e [Bug](runtime-filter) support ip rf and use exception to replace dche… (#41531)
…ck when PrimitiveType to PColumnType (#39985)

use exception to replace dcheck when PrimitiveType to PColumnType
```cpp
*** SIGABRT unknown detail explain (@0x11d3f) received by PID 73023 (TID 74292 OR 0x7fd758225640) from PID 73023; stack trace: ***
 0# doris::signal::(anonymous namespace)::FailureSignalHandler(int, siginfo_t*, void*) at /home/zcp/repo_center/doris_master/doris/be/src/common/signal_handler.h:421
 1# 0x00007FDDBE6B9520 in /lib/x86_64-linux-gnu/libc.so.6
 2# pthread_kill at ./nptl/pthread_kill.c:89
 3# raise at ../sysdeps/posix/raise.c:27
 4# abort at ./stdlib/abort.c:81
 5# 0x000056123F81A94D in /root/output/be/lib/doris_be
 6# 0x000056123F80CF8A in /root/output/be/lib/doris_be
 7# google::LogMessage::SendToLog() in /root/output/be/lib/doris_be
 8# google::LogMessage::Flush() in /root/output/be/lib/doris_be
 9# google::LogMessageFatal::~LogMessageFatal() in /root/output/be/lib/doris_be
10# doris::to_proto(doris::PrimitiveType) at /home/zcp/repo_center/doris_master/doris/be/src/exprs/runtime_filter.cpp:114
11# doris::IRuntimeFilter::push_to_remote(doris::TNetworkAddress const*) at /home/zcp/repo_center/doris_master/doris/be/src/exprs/runtime_filter.cpp:1143
12# doris::IRuntimeFilter::publish(bool)::$_0::operator()(doris::IRuntimeFilter*) const at /home/zcp/repo_center/doris_master/doris/be/src/exprs/runtime_filter.cpp:959
13# doris::IRuntimeFilter::publish(bool)::$_2::operator()() const at /home/zcp/repo_center/doris_master/doris/be/src/exprs/runtime_filter.cpp:983
14# doris::IRuntimeFilter::publish(bool) at /home/zcp/repo_center/doris_master/doris/be/src/exprs/runtime_filter.cpp:997
```

## Proposed changes
pick from #39985
2024-12-30 20:56:11 +08:00

101 lines
3.1 KiB
C++

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 <regex>
#include <sstream>
#include <string>
#include "vec/common/format_ip.h"
#include "vec/core/types.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_number_base.h"
namespace doris {
class IPv6Value {
public:
IPv6Value() { _value = 0; }
explicit IPv6Value(IPv6 ipv6) { _value = ipv6; }
const IPv6& value() const { return _value; }
IPv6& value() { return _value; }
void set_value(IPv6 ipv6) { _value = ipv6; }
bool from_string(const std::string& ipv6_str) { return from_string(_value, ipv6_str); }
static bool from_string(IPv6& value, const char* ipv6_str, size_t len) {
if (len == 0) {
return false;
}
size_t begin = 0;
size_t end = len - 1;
while (begin < len && std::isspace(ipv6_str[begin])) {
++begin;
}
while (end > begin && std::isspace(ipv6_str[end])) {
--end;
}
// parse and store in little-endian
return vectorized::parse_ipv6_whole(ipv6_str + begin, ipv6_str + end + 1,
reinterpret_cast<unsigned char*>(&value));
}
static bool from_string(IPv6& value, const std::string& ipv6_str) {
return from_string(value, ipv6_str.c_str(), ipv6_str.size());
}
std::string to_string() const { return to_string(_value); }
static std::string to_string(IPv6 value) {
char buf[IPV6_MAX_TEXT_LENGTH + 1];
char* start = buf;
char* end = buf;
auto* src = reinterpret_cast<unsigned char*>(&value);
// load and format in little-endian
vectorized::format_ipv6(src, end);
size_t len = end - start;
return {buf, len};
}
static bool is_valid_string(const char* ipv6_str, size_t len) {
if (len == 0 || len > IPV6_MAX_TEXT_LENGTH) {
return false;
}
IPv6 value;
size_t begin = 0;
size_t end = len - 1;
while (begin < len && std::isspace(ipv6_str[begin])) {
++begin;
}
while (end > begin && std::isspace(ipv6_str[end])) {
--end;
}
return vectorized::parse_ipv6_whole(ipv6_str + begin, ipv6_str + end + 1,
reinterpret_cast<unsigned char*>(&value));
}
private:
IPv6 _value;
};
} // namespace doris