Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions be/src/vec/common/format_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ inline void format_ipv4(const unsigned char* src, char*& dst, uint8_t mask_tail_
*/
template <typename T, typename EOFfunction>
requires(std::is_same<typename std::remove_cv<T>::type, char>::value)
inline bool parse_ipv4(T*& src, EOFfunction eof, unsigned char* dst, int64_t first_octet = -1) {
inline bool parse_ipv4(T*& src, EOFfunction eof, unsigned char* dst, int32_t first_octet = -1) {
if (src == nullptr || first_octet > IPV4_MAX_OCTET_VALUE) {
return false;
}

int64_t result = 0;
UInt32 result = 0;
int offset = (IPV4_BINARY_LENGTH - 1) * IPV4_OCTET_BITS;
if (first_octet >= 0) {
result |= first_octet << offset;
Expand All @@ -142,7 +142,7 @@ inline bool parse_ipv4(T*& src, EOFfunction eof, unsigned char* dst, int64_t fir
return false;
}

int64_t value = 0;
UInt32 value = 0;
size_t len = 0;
while (is_numeric_ascii(*src) && len <= 3) {
value = value * DECIMAL_BASE + (*src - '0');
Expand Down
4 changes: 1 addition & 3 deletions be/src/vec/functions/function_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ ColumnPtr convert_to_ipv4(ColumnPtr column, const PaddedPODArray<UInt8>* null_ma
vec_null_map_to = &col_null_map_to->get_data();
}

auto col_res = ToColumn::create();

auto col_res = ToColumn::create(column_size, 0);
auto& vec_res = col_res->get_data();
vec_res.resize(column_size);

const ColumnString::Chars& vec_src = column_string->get_chars();
const ColumnString::Offsets& offsets_src = column_string->get_offsets();
Expand Down
23 changes: 22 additions & 1 deletion be/test/vec/columns/column_ip_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include <gtest/gtest.h>

#include "vec/columns/column.h"
#include "vec/columns/column_array.h"
#include "vec/columns/common_column_test.h"
#include "vec/core/types.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_factory.hpp"
#include "vec/data_types/data_type_nullable.h"
#include "vec/functions/function_ip.h"

// this test is gonna to make a template ColumnTest
// for example column_ip should test these functions
Expand Down Expand Up @@ -312,4 +312,25 @@ TEST_F(ColumnIPTest, HashTest) {
assert_update_crc_hashes_callback(ip_cols, serde, pts);
};

TEST_F(ColumnIPTest, IPv6ValueFromStringTest) {
std::string ipv6_str = "1111:2222:3333:4444:5555:6666:123.123.123.123";
IPv6 ipv6_val = 0;
ASSERT_EQ(IPv6Value::from_string(ipv6_val, ipv6_str.data(), ipv6_str.size()), true);
ASSERT_EQ("1111:2222:3333:4444:5555:6666:7b7b:7b7b", IPv6Value(ipv6_val).to_string());
};

TEST_F(ColumnIPTest, IPv4ValueFromStringTest) {
std::string ipv4_str = "127.0.0.1";
IPv4 ipv4_val = 0;
ASSERT_EQ(IPv4Value::from_string(ipv4_val, ipv4_str.data(), ipv4_str.size()), true);
ASSERT_EQ("127.0.0.1", IPv4Value(ipv4_val).to_string());
};

TEST_F(ColumnIPTest, IPv4Parse) {
std::string ipv4_str = "127.0.0.1";
Int64 result_value = 0;
ASSERT_EQ(try_parse_ipv4(ipv4_str.data(), result_value), true);
ASSERT_EQ(2130706433, result_value);
};

} // namespace doris::vectorized
Loading