github-actions[bot] commented on code in PR #24965:
URL: https://github.com/apache/doris/pull/24965#discussion_r1370261480


##########
be/src/olap/types.h:
##########
@@ -957,6 +969,102 @@ struct 
FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT>
     }
 };
 
+template <>
+struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4>
+        : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> {
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
+        uint32_t value = 
StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(),
+                                                                        
scan_key.size(), &result);
+
+        if (result == StringParser::PARSE_FAILURE) {
+            return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet 
PARSE_FAILURE");
+        }
+        *reinterpret_cast<uint32_t*>(buf) = value;
+        return Status::OK();
+    }
+
+    static std::string to_string(const void* src) {
+        uint32_t value = *reinterpret_cast<const uint32_t*>(src);
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 24 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                            ^
   ```
   



##########
be/src/olap/types.h:
##########
@@ -957,6 +969,102 @@ struct 
FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT>
     }
 };
 
+template <>
+struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4>
+        : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> {
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
+        uint32_t value = 
StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(),
+                                                                        
scan_key.size(), &result);
+
+        if (result == StringParser::PARSE_FAILURE) {
+            return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet 
PARSE_FAILURE");
+        }
+        *reinterpret_cast<uint32_t*>(buf) = value;
+        return Status::OK();
+    }
+
+    static std::string to_string(const void* src) {
+        uint32_t value = *reinterpret_cast<const uint32_t*>(src);
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                                  ^
   ```
   



##########
be/src/olap/types.h:
##########
@@ -957,6 +969,102 @@ struct 
FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT>
     }
 };
 
+template <>
+struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4>
+        : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> {
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
+        uint32_t value = 
StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(),
+                                                                        
scan_key.size(), &result);
+
+        if (result == StringParser::PARSE_FAILURE) {
+            return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet 
PARSE_FAILURE");
+        }
+        *reinterpret_cast<uint32_t*>(buf) = value;
+        return Status::OK();
+    }
+
+    static std::string to_string(const void* src) {
+        uint32_t value = *reinterpret_cast<const uint32_t*>(src);
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 16 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                                                             ^
   ```
   



##########
be/src/olap/types.h:
##########
@@ -957,6 +969,102 @@ struct 
FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT>
     }
 };
 
+template <>
+struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4>
+        : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> {
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
+        uint32_t value = 
StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(),
+                                                                        
scan_key.size(), &result);
+
+        if (result == StringParser::PARSE_FAILURE) {
+            return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet 
PARSE_FAILURE");
+        }
+        *reinterpret_cast<uint32_t*>(buf) = value;
+        return Status::OK();
+    }
+
+    static std::string to_string(const void* src) {
+        uint32_t value = *reinterpret_cast<const uint32_t*>(src);
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
+           << ((value >> 8) & 0xFF) << '.' << (value & 0xFF);

Review Comment:
   warning: 8 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
              << ((value >> 8) & 0xFF) << '.' << (value & 0xFF);
                            ^
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.cpp:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "vec/data_types/data_type_ipv4.h"
+
+#include "util/binary_cast.hpp"
+#include "util/string_parser.hpp"
+#include "vec/columns/column.h"
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/string_buffer.hpp"
+#include "vec/data_types/data_type.h"
+#include "vec/io/io_helper.h"
+#include "vec/io/reader_buffer.h"
+
+namespace doris::vectorized {
+bool DataTypeIPv4::equals(const IDataType& rhs) const {
+    return typeid(rhs) == typeid(*this);
+}
+
+std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) 
const {
+    auto result = check_column_const_set_readability(column, row_num);
+    ColumnPtr ptr = result.first;
+    row_num = result.second;
+    IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num);
+    return convert_ipv4_to_string(value);
+}
+
+void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, 
BufferWritable& ostr) const {
+    std::string value = to_string(column, row_num);
+    ostr.write(value.data(), value.size());
+}
+
+Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const {
+    auto* column_data = static_cast<ColumnIPv4*>(column);
+    StringParser::ParseResult result;
+    IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), 
rb.count(), &result);
+    column_data->insert_value(val);
+    return Status::OK();
+}
+
+std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) {
+    std::stringstream ss;
+    ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)

Review Comment:
   warning: 24 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
       ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)
                       ^
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.cpp:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "vec/data_types/data_type_ipv4.h"
+
+#include "util/binary_cast.hpp"
+#include "util/string_parser.hpp"
+#include "vec/columns/column.h"
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/string_buffer.hpp"
+#include "vec/data_types/data_type.h"
+#include "vec/io/io_helper.h"
+#include "vec/io/reader_buffer.h"
+
+namespace doris::vectorized {
+bool DataTypeIPv4::equals(const IDataType& rhs) const {
+    return typeid(rhs) == typeid(*this);
+}
+
+std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) 
const {
+    auto result = check_column_const_set_readability(column, row_num);
+    ColumnPtr ptr = result.first;
+    row_num = result.second;
+    IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num);
+    return convert_ipv4_to_string(value);
+}
+
+void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, 
BufferWritable& ostr) const {
+    std::string value = to_string(column, row_num);
+    ostr.write(value.data(), value.size());
+}
+
+Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const {
+    auto* column_data = static_cast<ColumnIPv4*>(column);
+    StringParser::ParseResult result;
+    IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), 
rb.count(), &result);
+    column_data->insert_value(val);
+    return Status::OK();
+}
+
+std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) {
+    std::stringstream ss;
+    ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)

Review Comment:
   warning: 8 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
       ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)
                                                                                
       ^
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.h:
##########
@@ -0,0 +1,75 @@
+// 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 <gen_cpp/Types_types.h>
+#include <stddef.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <string>
+
+#include "common/status.h"
+#include "runtime/define_primitive_type.h"
+#include "vec/core/types.h"
+#include "vec/data_types/data_type.h"
+#include "vec/data_types/data_type_number_base.h"
+#include "vec/data_types/serde/data_type_ipv4_serde.h"
+
+namespace doris {
+namespace vectorized {
+class BufferWritable;
+class ReadBuffer;
+class IColumn;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+class DataTypeIPv4 final : public DataTypeNumberBase<IPv4> {
+public:
+    TypeIndex get_type_id() const override { return TypeIndex::IPv4; }
+    TPrimitiveType::type get_type_as_tprimitive_type() const override {
+        return TPrimitiveType::IPV4;
+    }
+    const char* get_family_name() const override { return "IPv4"; }
+    std::string do_get_name() const override { return "IPv4"; }
+
+    bool can_be_inside_nullable() const override { return true; }
+
+    bool equals(const IDataType& rhs) const override;
+    std::string to_string(const IColumn& column, size_t row_num) const 
override;
+    void to_string(const IColumn& column, size_t row_num, BufferWritable& 
ostr) const override;
+    Status from_string(ReadBuffer& rb, IColumn* column) const override;
+
+    static std::string convert_ipv4_to_string(IPv4 ipv4);
+    static bool convert_string_to_ipv4(IPv4& x, std::string ipv4);
+
+    Field get_field(const TExprNode& node) const override { return (IPv4) 
node.ipv4_literal.value; }

Review Comment:
   warning: method 'get_field' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static Field get_field(const TExprNode& node) override { return (IPv4) 
node.ipv4_literal.value; }
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.cpp:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "vec/data_types/data_type_ipv4.h"
+
+#include "util/binary_cast.hpp"
+#include "util/string_parser.hpp"
+#include "vec/columns/column.h"
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/string_buffer.hpp"
+#include "vec/data_types/data_type.h"
+#include "vec/io/io_helper.h"
+#include "vec/io/reader_buffer.h"
+
+namespace doris::vectorized {
+bool DataTypeIPv4::equals(const IDataType& rhs) const {
+    return typeid(rhs) == typeid(*this);
+}
+
+std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) 
const {
+    auto result = check_column_const_set_readability(column, row_num);
+    ColumnPtr ptr = result.first;
+    row_num = result.second;
+    IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num);
+    return convert_ipv4_to_string(value);
+}
+
+void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, 
BufferWritable& ostr) const {
+    std::string value = to_string(column, row_num);
+    ostr.write(value.data(), value.size());
+}
+
+Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const {
+    auto* column_data = static_cast<ColumnIPv4*>(column);
+    StringParser::ParseResult result;
+    IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), 
rb.count(), &result);
+    column_data->insert_value(val);
+    return Status::OK();
+}
+
+std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) {
+    std::stringstream ss;
+    ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)
+       << '.' << (ipv4 & 0xFF);

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
          << '.' << (ipv4 & 0xFF);
                            ^
   ```
   



##########
be/src/vec/data_types/serde/data_type_ipv4_serde.cpp:
##########
@@ -0,0 +1,53 @@
+// 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.
+
+#include "data_type_ipv4_serde.h"
+
+#include <arrow/builder.h>
+
+#include "vec/columns/column_const.h"
+
+namespace doris {
+namespace vectorized {
+
+template <bool is_binary_format>
+Status DataTypeIPv4SerDe::_write_column_to_mysql(const IColumn& column,
+                                                 
MysqlRowBuffer<is_binary_format>& result,
+                                                 int row_idx, bool col_const) 
const {
+    auto& data = assert_cast<const ColumnVector<IPv4>&>(column).get_data();
+    auto col_index = index_check_const(row_idx, col_const);
+    IPv4Value ipv4_val(data[col_index]);
+    if (UNLIKELY(0 != result.push_ipv4(ipv4_val))) {
+        return Status::InternalError("pack mysql buffer failed.");
+    }
+    return Status::OK();
+}
+
+Status DataTypeIPv4SerDe::write_column_to_mysql(const IColumn& column,
+                                                MysqlRowBuffer<true>& 
row_buffer, int row_idx,
+                                                bool col_const) const {
+    return _write_column_to_mysql(column, row_buffer, row_idx, col_const);
+}
+
+Status DataTypeIPv4SerDe::write_column_to_mysql(const IColumn& column,

Review Comment:
   warning: method 'write_column_to_mysql' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/vec/data_types/serde/data_type_ipv4_serde.cpp:47:
   ```diff
   -                                                 bool col_const) const {
   +                                                 bool col_const) {
   ```
   
   be/src/vec/data_types/serde/data_type_ipv4_serde.h:43:
   ```diff
   -     Status write_column_to_mysql(const IColumn& column, 
MysqlRowBuffer<false>& row_buffer,
   -                                  int row_idx, bool col_const) const 
override;
   +     static Status write_column_to_mysql(const IColumn& column, 
MysqlRowBuffer<false>& row_buffer,
   +                                  int row_idx, bool col_const) override;
   ```
   



##########
be/src/vec/runtime/ipv4_value.h:
##########
@@ -0,0 +1,124 @@
+// 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 <stdint.h>
+
+#include <algorithm>
+#include <regex>
+#include <sstream>
+#include <string>
+
+#include "util/string_parser.hpp"
+
+namespace doris {
+
+class IPv4Value {
+public:
+    IPv4Value() = default;
+
+    explicit IPv4Value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    explicit IPv4Value(std::string ipv4) {}
+
+    [[nodiscard]] const vectorized::IPv4& value() const { return _value; }
+
+    vectorized::IPv4& value() { return _value; }
+
+    void set_value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    bool from_string(std::string ipv4) { return from_string(_value, ipv4); }
+
+    [[nodiscard]] std::string to_string() const { return to_string(_value); }
+
+    static bool from_string(vectorized::IPv4& value, std::string ipv4) {
+        remove_ipv4_space(ipv4);
+
+        // shortest ipv4 string is `0.0.0.0` whose length is 7
+        if (ipv4.size() < 7 || !is_valid_string(ipv4)) {
+            return false;
+        }
+
+        vectorized::IPv4 octets[4] = {0};
+        std::istringstream iss(ipv4);
+        std::string octet;
+        uint8_t octet_index = 0;
+
+        while (getline(iss, octet, '.')) {
+            if (octet_index >= 4) {
+                return false;
+            }
+
+            StringParser::ParseResult result;
+            vectorized::IPv4 val = 
StringParser::string_to_unsigned_int<vectorized::IPv4>(
+                    octet.c_str(), octet.length(), &result);
+            if (result != StringParser::PARSE_SUCCESS || val > 255) {
+                return false;
+            }
+
+            octets[octet_index++] = val;
+        }
+
+        if (octet_index != 4) {
+            return false;
+        }
+
+        value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | 
octets[3];
+        return true;
+    }
+
+    static std::string to_string(vectorized::IPv4 value) {
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                                  ^
   ```
   



##########
be/src/vec/runtime/ipv4_value.h:
##########
@@ -0,0 +1,124 @@
+// 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 <stdint.h>
+
+#include <algorithm>
+#include <regex>
+#include <sstream>
+#include <string>
+
+#include "util/string_parser.hpp"
+
+namespace doris {
+
+class IPv4Value {
+public:
+    IPv4Value() = default;
+
+    explicit IPv4Value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    explicit IPv4Value(std::string ipv4) {}
+
+    [[nodiscard]] const vectorized::IPv4& value() const { return _value; }
+
+    vectorized::IPv4& value() { return _value; }
+
+    void set_value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    bool from_string(std::string ipv4) { return from_string(_value, ipv4); }
+
+    [[nodiscard]] std::string to_string() const { return to_string(_value); }
+
+    static bool from_string(vectorized::IPv4& value, std::string ipv4) {
+        remove_ipv4_space(ipv4);
+
+        // shortest ipv4 string is `0.0.0.0` whose length is 7
+        if (ipv4.size() < 7 || !is_valid_string(ipv4)) {
+            return false;
+        }
+
+        vectorized::IPv4 octets[4] = {0};
+        std::istringstream iss(ipv4);
+        std::string octet;
+        uint8_t octet_index = 0;
+
+        while (getline(iss, octet, '.')) {
+            if (octet_index >= 4) {
+                return false;
+            }
+
+            StringParser::ParseResult result;
+            vectorized::IPv4 val = 
StringParser::string_to_unsigned_int<vectorized::IPv4>(
+                    octet.c_str(), octet.length(), &result);
+            if (result != StringParser::PARSE_SUCCESS || val > 255) {
+                return false;
+            }
+
+            octets[octet_index++] = val;
+        }
+
+        if (octet_index != 4) {
+            return false;
+        }
+
+        value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | 
octets[3];
+        return true;
+    }
+
+    static std::string to_string(vectorized::IPv4 value) {
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 16 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                                                             ^
   ```
   



##########
be/src/olap/types.h:
##########
@@ -957,6 +969,102 @@ struct 
FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT>
     }
 };
 
+template <>
+struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4>
+        : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> {
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
+        uint32_t value = 
StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(),
+                                                                        
scan_key.size(), &result);
+
+        if (result == StringParser::PARSE_FAILURE) {
+            return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet 
PARSE_FAILURE");
+        }
+        *reinterpret_cast<uint32_t*>(buf) = value;
+        return Status::OK();
+    }
+
+    static std::string to_string(const void* src) {
+        uint32_t value = *reinterpret_cast<const uint32_t*>(src);
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                                                                   ^
   ```
   



##########
be/src/olap/types.h:
##########
@@ -957,6 +969,102 @@ struct 
FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT>
     }
 };
 
+template <>
+struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4>
+        : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> {
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
+        uint32_t value = 
StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(),
+                                                                        
scan_key.size(), &result);
+
+        if (result == StringParser::PARSE_FAILURE) {
+            return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet 
PARSE_FAILURE");
+        }
+        *reinterpret_cast<uint32_t*>(buf) = value;
+        return Status::OK();
+    }
+
+    static std::string to_string(const void* src) {
+        uint32_t value = *reinterpret_cast<const uint32_t*>(src);
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
+           << ((value >> 8) & 0xFF) << '.' << (value & 0xFF);

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
              << ((value >> 8) & 0xFF) << '.' << (value & 0xFF);
                                 ^
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.cpp:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "vec/data_types/data_type_ipv4.h"
+
+#include "util/binary_cast.hpp"
+#include "util/string_parser.hpp"
+#include "vec/columns/column.h"
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/string_buffer.hpp"
+#include "vec/data_types/data_type.h"
+#include "vec/io/io_helper.h"
+#include "vec/io/reader_buffer.h"
+
+namespace doris::vectorized {
+bool DataTypeIPv4::equals(const IDataType& rhs) const {
+    return typeid(rhs) == typeid(*this);
+}
+
+std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) 
const {
+    auto result = check_column_const_set_readability(column, row_num);
+    ColumnPtr ptr = result.first;
+    row_num = result.second;
+    IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num);
+    return convert_ipv4_to_string(value);
+}
+
+void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, 
BufferWritable& ostr) const {
+    std::string value = to_string(column, row_num);
+    ostr.write(value.data(), value.size());
+}
+
+Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const {
+    auto* column_data = static_cast<ColumnIPv4*>(column);
+    StringParser::ParseResult result;
+    IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), 
rb.count(), &result);
+    column_data->insert_value(val);
+    return Status::OK();
+}
+
+std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) {
+    std::stringstream ss;
+    ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
       ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)
                             ^
   ```
   



##########
be/src/olap/types.h:
##########
@@ -957,6 +969,102 @@ struct 
FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_LARGEINT>
     }
 };
 
+template <>
+struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4>
+        : public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_IPV4> {
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
+        uint32_t value = 
StringParser::string_to_unsigned_int<uint32_t>(scan_key.c_str(),
+                                                                        
scan_key.size(), &result);
+
+        if (result == StringParser::PARSE_FAILURE) {
+            return Status::Error<ErrorCode::INVALID_ARGUMENT>(
+                    "FieldTypeTraits<OLAP_FIELD_TYPE_IPV4>::from_string meet 
PARSE_FAILURE");
+        }
+        *reinterpret_cast<uint32_t*>(buf) = value;
+        return Status::OK();
+    }
+
+    static std::string to_string(const void* src) {
+        uint32_t value = *reinterpret_cast<const uint32_t*>(src);
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
+           << ((value >> 8) & 0xFF) << '.' << (value & 0xFF);

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
              << ((value >> 8) & 0xFF) << '.' << (value & 0xFF);
                                                          ^
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.cpp:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "vec/data_types/data_type_ipv4.h"
+
+#include "util/binary_cast.hpp"
+#include "util/string_parser.hpp"
+#include "vec/columns/column.h"
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/string_buffer.hpp"
+#include "vec/data_types/data_type.h"
+#include "vec/io/io_helper.h"
+#include "vec/io/reader_buffer.h"
+
+namespace doris::vectorized {
+bool DataTypeIPv4::equals(const IDataType& rhs) const {
+    return typeid(rhs) == typeid(*this);
+}
+
+std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) 
const {
+    auto result = check_column_const_set_readability(column, row_num);
+    ColumnPtr ptr = result.first;
+    row_num = result.second;
+    IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num);
+    return convert_ipv4_to_string(value);
+}
+
+void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, 
BufferWritable& ostr) const {
+    std::string value = to_string(column, row_num);
+    ostr.write(value.data(), value.size());
+}
+
+Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const {
+    auto* column_data = static_cast<ColumnIPv4*>(column);
+    StringParser::ParseResult result;
+    IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), 
rb.count(), &result);
+    column_data->insert_value(val);
+    return Status::OK();
+}
+
+std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) {
+    std::stringstream ss;
+    ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)

Review Comment:
   warning: 16 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
       ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)
                                                       ^
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.cpp:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "vec/data_types/data_type_ipv4.h"
+
+#include "util/binary_cast.hpp"
+#include "util/string_parser.hpp"
+#include "vec/columns/column.h"
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/string_buffer.hpp"
+#include "vec/data_types/data_type.h"
+#include "vec/io/io_helper.h"
+#include "vec/io/reader_buffer.h"
+
+namespace doris::vectorized {
+bool DataTypeIPv4::equals(const IDataType& rhs) const {
+    return typeid(rhs) == typeid(*this);
+}
+
+std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) 
const {
+    auto result = check_column_const_set_readability(column, row_num);
+    ColumnPtr ptr = result.first;
+    row_num = result.second;
+    IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num);
+    return convert_ipv4_to_string(value);
+}
+
+void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, 
BufferWritable& ostr) const {
+    std::string value = to_string(column, row_num);
+    ostr.write(value.data(), value.size());
+}
+
+Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const {
+    auto* column_data = static_cast<ColumnIPv4*>(column);
+    StringParser::ParseResult result;
+    IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), 
rb.count(), &result);
+    column_data->insert_value(val);
+    return Status::OK();
+}
+
+std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) {
+    std::stringstream ss;
+    ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
       ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)
                                                             ^
   ```
   



##########
be/src/vec/data_types/data_type_ipv4.cpp:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "vec/data_types/data_type_ipv4.h"
+
+#include "util/binary_cast.hpp"
+#include "util/string_parser.hpp"
+#include "vec/columns/column.h"
+#include "vec/columns/column_const.h"
+#include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/string_buffer.hpp"
+#include "vec/data_types/data_type.h"
+#include "vec/io/io_helper.h"
+#include "vec/io/reader_buffer.h"
+
+namespace doris::vectorized {
+bool DataTypeIPv4::equals(const IDataType& rhs) const {
+    return typeid(rhs) == typeid(*this);
+}
+
+std::string DataTypeIPv4::to_string(const IColumn& column, size_t row_num) 
const {
+    auto result = check_column_const_set_readability(column, row_num);
+    ColumnPtr ptr = result.first;
+    row_num = result.second;
+    IPv4 value = assert_cast<const ColumnIPv4&>(*ptr).get_element(row_num);
+    return convert_ipv4_to_string(value);
+}
+
+void DataTypeIPv4::to_string(const IColumn& column, size_t row_num, 
BufferWritable& ostr) const {
+    std::string value = to_string(column, row_num);
+    ostr.write(value.data(), value.size());
+}
+
+Status DataTypeIPv4::from_string(ReadBuffer& rb, IColumn* column) const {
+    auto* column_data = static_cast<ColumnIPv4*>(column);
+    StringParser::ParseResult result;
+    IPv4 val = StringParser::string_to_unsigned_int<IPv4>(rb.position(), 
rb.count(), &result);
+    column_data->insert_value(val);
+    return Status::OK();
+}
+
+std::string DataTypeIPv4::convert_ipv4_to_string(IPv4 ipv4) {
+    std::stringstream ss;
+    ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
       ss << ((ipv4 >> 24) & 0xFF) << '.' << ((ipv4 >> 16) & 0xFF) << '.' << 
((ipv4 >> 8) & 0xFF)
                                                                                
            ^
   ```
   



##########
be/src/vec/data_types/serde/data_type_ipv4_serde.cpp:
##########
@@ -0,0 +1,53 @@
+// 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.
+
+#include "data_type_ipv4_serde.h"
+
+#include <arrow/builder.h>
+
+#include "vec/columns/column_const.h"
+
+namespace doris {
+namespace vectorized {

Review Comment:
   warning: nested namespaces can be concatenated 
[modernize-concat-nested-namespaces]
   
   ```suggestion
   namespace doris::vectorized {
   ```
   
   be/src/vec/data_types/serde/data_type_ipv4_serde.cpp:51:
   ```diff
   - } // namespace vectorized
   - } // namespace doris
   + } // namespace doris
   ```
   



##########
be/src/vec/data_types/serde/data_type_ipv4_serde.cpp:
##########
@@ -0,0 +1,53 @@
+// 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.
+
+#include "data_type_ipv4_serde.h"
+
+#include <arrow/builder.h>
+
+#include "vec/columns/column_const.h"
+
+namespace doris {
+namespace vectorized {
+
+template <bool is_binary_format>
+Status DataTypeIPv4SerDe::_write_column_to_mysql(const IColumn& column,
+                                                 
MysqlRowBuffer<is_binary_format>& result,
+                                                 int row_idx, bool col_const) 
const {
+    auto& data = assert_cast<const ColumnVector<IPv4>&>(column).get_data();
+    auto col_index = index_check_const(row_idx, col_const);
+    IPv4Value ipv4_val(data[col_index]);
+    if (UNLIKELY(0 != result.push_ipv4(ipv4_val))) {
+        return Status::InternalError("pack mysql buffer failed.");
+    }
+    return Status::OK();
+}
+
+Status DataTypeIPv4SerDe::write_column_to_mysql(const IColumn& column,

Review Comment:
   warning: method 'write_column_to_mysql' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/vec/data_types/serde/data_type_ipv4_serde.cpp:41:
   ```diff
   -                                                 bool col_const) const {
   -     return _write_column_to_mysql(column, row_buffer, row_idx, col_const);
   +                                                 bool col_const) static     
                                            bool col_const) const {
   +     return _write_column_to_mysql(column, row_buffer, row_idx, col_const);
   ```
   



##########
be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:
##########
@@ -0,0 +1,53 @@
+// 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.
+
+#include "data_type_ipv6_serde.h"
+
+#include <arrow/builder.h>
+
+#include "vec/columns/column_const.h"
+
+namespace doris {
+namespace vectorized {

Review Comment:
   warning: nested namespaces can be concatenated 
[modernize-concat-nested-namespaces]
   
   ```suggestion
   namespace doris::vectorized {
   ```
   
   be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:51:
   ```diff
   - } // namespace vectorized
   - } // namespace doris
   + } // namespace doris
   ```
   



##########
be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:
##########
@@ -0,0 +1,53 @@
+// 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.
+
+#include "data_type_ipv6_serde.h"
+
+#include <arrow/builder.h>
+
+#include "vec/columns/column_const.h"
+
+namespace doris {
+namespace vectorized {
+
+template <bool is_binary_format>
+Status DataTypeIPv6SerDe::_write_column_to_mysql(const IColumn& column,
+                                                 
MysqlRowBuffer<is_binary_format>& result,
+                                                 int row_idx, bool col_const) 
const {
+    auto& data = assert_cast<const ColumnVector<IPv6>&>(column).get_data();
+    auto col_index = index_check_const(row_idx, col_const);
+    IPv6Value ipv6_val(data[col_index]);
+    if (UNLIKELY(0 != result.push_ipv6(ipv6_val))) {
+        return Status::InternalError("pack mysql buffer failed.");
+    }
+    return Status::OK();
+}
+
+Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column,
+                                                MysqlRowBuffer<true>& 
row_buffer, int row_idx,
+                                                bool col_const) const {
+    return _write_column_to_mysql(column, row_buffer, row_idx, col_const);
+}
+
+Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column,

Review Comment:
   warning: method 'write_column_to_mysql' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:47:
   ```diff
   -                                                 bool col_const) const {
   +                                                 bool col_const) {
   ```
   
   be/src/vec/data_types/serde/data_type_ipv6_serde.h:46:
   ```diff
   -     Status write_column_to_mysql(const IColumn& column, 
MysqlRowBuffer<false>& row_buffer,
   -                                  int row_idx, bool col_const) const 
override;
   +     static Status write_column_to_mysql(const IColumn& column, 
MysqlRowBuffer<false>& row_buffer,
   +                                  int row_idx, bool col_const) override;
   ```
   



##########
be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:
##########
@@ -0,0 +1,53 @@
+// 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.
+
+#include "data_type_ipv6_serde.h"
+
+#include <arrow/builder.h>
+
+#include "vec/columns/column_const.h"
+
+namespace doris {
+namespace vectorized {
+
+template <bool is_binary_format>
+Status DataTypeIPv6SerDe::_write_column_to_mysql(const IColumn& column,
+                                                 
MysqlRowBuffer<is_binary_format>& result,
+                                                 int row_idx, bool col_const) 
const {
+    auto& data = assert_cast<const ColumnVector<IPv6>&>(column).get_data();
+    auto col_index = index_check_const(row_idx, col_const);
+    IPv6Value ipv6_val(data[col_index]);
+    if (UNLIKELY(0 != result.push_ipv6(ipv6_val))) {
+        return Status::InternalError("pack mysql buffer failed.");
+    }
+    return Status::OK();
+}
+
+Status DataTypeIPv6SerDe::write_column_to_mysql(const IColumn& column,

Review Comment:
   warning: method 'write_column_to_mysql' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/vec/data_types/serde/data_type_ipv6_serde.cpp:41:
   ```diff
   -                                                 bool col_const) const {
   +                                                 bool col_const) {
   ```
   
   be/src/vec/data_types/serde/data_type_ipv6_serde.h:44:
   ```diff
   -     Status write_column_to_mysql(const IColumn& column, 
MysqlRowBuffer<true>& row_buffer,
   -                                  int row_idx, bool col_const) const 
override;
   +     static Status write_column_to_mysql(const IColumn& column, 
MysqlRowBuffer<true>& row_buffer,
   +                                  int row_idx, bool col_const) override;
   ```
   



##########
be/src/vec/runtime/ipv4_value.h:
##########
@@ -0,0 +1,124 @@
+// 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 <stdint.h>
+
+#include <algorithm>
+#include <regex>
+#include <sstream>
+#include <string>
+
+#include "util/string_parser.hpp"
+
+namespace doris {
+
+class IPv4Value {
+public:
+    IPv4Value() = default;
+
+    explicit IPv4Value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    explicit IPv4Value(std::string ipv4) {}
+
+    [[nodiscard]] const vectorized::IPv4& value() const { return _value; }
+
+    vectorized::IPv4& value() { return _value; }
+
+    void set_value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    bool from_string(std::string ipv4) { return from_string(_value, ipv4); }
+
+    [[nodiscard]] std::string to_string() const { return to_string(_value); }
+
+    static bool from_string(vectorized::IPv4& value, std::string ipv4) {
+        remove_ipv4_space(ipv4);
+
+        // shortest ipv4 string is `0.0.0.0` whose length is 7
+        if (ipv4.size() < 7 || !is_valid_string(ipv4)) {
+            return false;
+        }
+
+        vectorized::IPv4 octets[4] = {0};
+        std::istringstream iss(ipv4);
+        std::string octet;
+        uint8_t octet_index = 0;
+
+        while (getline(iss, octet, '.')) {
+            if (octet_index >= 4) {
+                return false;
+            }
+
+            StringParser::ParseResult result;
+            vectorized::IPv4 val = 
StringParser::string_to_unsigned_int<vectorized::IPv4>(
+                    octet.c_str(), octet.length(), &result);
+            if (result != StringParser::PARSE_SUCCESS || val > 255) {
+                return false;
+            }
+
+            octets[octet_index++] = val;
+        }
+
+        if (octet_index != 4) {
+            return false;
+        }
+
+        value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | 
octets[3];
+        return true;
+    }
+
+    static std::string to_string(vectorized::IPv4 value) {
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 0xFF is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                                                                   ^
   ```
   



##########
be/src/vec/runtime/ipv4_value.h:
##########
@@ -0,0 +1,124 @@
+// 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 <stdint.h>
+
+#include <algorithm>
+#include <regex>
+#include <sstream>
+#include <string>
+
+#include "util/string_parser.hpp"
+
+namespace doris {
+
+class IPv4Value {
+public:
+    IPv4Value() = default;
+
+    explicit IPv4Value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    explicit IPv4Value(std::string ipv4) {}
+
+    [[nodiscard]] const vectorized::IPv4& value() const { return _value; }
+
+    vectorized::IPv4& value() { return _value; }
+
+    void set_value(vectorized::IPv4 ipv4) { _value = ipv4; }
+
+    bool from_string(std::string ipv4) { return from_string(_value, ipv4); }
+
+    [[nodiscard]] std::string to_string() const { return to_string(_value); }
+
+    static bool from_string(vectorized::IPv4& value, std::string ipv4) {
+        remove_ipv4_space(ipv4);
+
+        // shortest ipv4 string is `0.0.0.0` whose length is 7
+        if (ipv4.size() < 7 || !is_valid_string(ipv4)) {
+            return false;
+        }
+
+        vectorized::IPv4 octets[4] = {0};
+        std::istringstream iss(ipv4);
+        std::string octet;
+        uint8_t octet_index = 0;
+
+        while (getline(iss, octet, '.')) {
+            if (octet_index >= 4) {
+                return false;
+            }
+
+            StringParser::ParseResult result;
+            vectorized::IPv4 val = 
StringParser::string_to_unsigned_int<vectorized::IPv4>(
+                    octet.c_str(), octet.length(), &result);
+            if (result != StringParser::PARSE_SUCCESS || val > 255) {
+                return false;
+            }
+
+            octets[octet_index++] = val;
+        }
+
+        if (octet_index != 4) {
+            return false;
+        }
+
+        value = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | 
octets[3];
+        return true;
+    }
+
+    static std::string to_string(vectorized::IPv4 value) {
+        std::stringstream ss;
+        ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'

Review Comment:
   warning: 24 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
           ss << ((value >> 24) & 0xFF) << '.' << ((value >> 16) & 0xFF) << '.'
                            ^
   ```
   



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to