github-actions[bot] commented on code in PR #29681:
URL: https://github.com/apache/doris/pull/29681#discussion_r1444400799
##########
be/src/vec/functions/function_ip.h:
##########
@@ -745,4 +742,88 @@ class FunctionIsIPv6String : public IFunction {
}
};
+class FunctionIsIPAddressInRange : public IFunction {
+public:
+ static constexpr auto name = "is_ip_address_in_range";
+ static FunctionPtr create() { return
std::make_shared<FunctionIsIPAddressInRange>(); }
+
+ String get_name() const override { return name; }
+
+ size_t get_number_of_arguments() const override { return 2; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
Review Comment:
warning: method 'get_return_type_impl' can be made static
[readability-convert-member-functions-to-static]
```suggestion
static DataTypePtr get_return_type_impl(const DataTypes& arguments)
override {
```
##########
be/src/vec/runtime/ip_address_cidr.h:
##########
@@ -0,0 +1,162 @@
+// 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.
+// This file is copied from
+//
https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/isIPAddressContainedIn.cpp
+// and modified by Doris
+
+#pragma once
+
+#include "vec/common/format_ip.h"
+
+namespace doris {
+
+class IPAddressVariant {
+public:
+ explicit IPAddressVariant(std::string_view address_str) {
+ vectorized::Int64 v4;
+ if (vectorized::parseIPv4whole(address_str.begin(), address_str.end(),
reinterpret_cast<unsigned char *>(&v4))) {
+ _addr = static_cast<vectorized::UInt32>(v4);
+ } else {
+ _addr = IPv6AddrType();
+ if (!vectorized::parseIPv6whole(
+ address_str.begin(), address_str.end(),
std::get<IPv6AddrType>(_addr).data())) {
+ throw Exception(ErrorCode::INVALID_ARGUMENT, "Neither IPv4 nor
IPv6 address: '{}'", address_str);
+ }
+ }
+ }
+
+ vectorized::UInt32 as_v4() const {
Review Comment:
warning: method 'as_v4' can be made static
[readability-convert-member-functions-to-static]
```suggestion
static vectorized::UInt32 as_v4() {
```
##########
be/src/vec/runtime/ip_address_cidr.h:
##########
@@ -0,0 +1,162 @@
+// 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.
+// This file is copied from
+//
https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/isIPAddressContainedIn.cpp
+// and modified by Doris
+
+#pragma once
+
+#include "vec/common/format_ip.h"
+
+namespace doris {
+
+class IPAddressVariant {
+public:
+ explicit IPAddressVariant(std::string_view address_str) {
+ vectorized::Int64 v4;
+ if (vectorized::parseIPv4whole(address_str.begin(), address_str.end(),
reinterpret_cast<unsigned char *>(&v4))) {
+ _addr = static_cast<vectorized::UInt32>(v4);
+ } else {
+ _addr = IPv6AddrType();
+ if (!vectorized::parseIPv6whole(
+ address_str.begin(), address_str.end(),
std::get<IPv6AddrType>(_addr).data())) {
+ throw Exception(ErrorCode::INVALID_ARGUMENT, "Neither IPv4 nor
IPv6 address: '{}'", address_str);
+ }
+ }
+ }
+
+ vectorized::UInt32 as_v4() const {
+ if (const auto* val = std::get_if<IPv4AddrType>(&_addr)) {
+ return *val;
+ }
+ return 0;
+ }
+
+ const vectorized::UInt8* as_v6() const {
+ if (const auto* val = std::get_if<IPv6AddrType>(&_addr)) {
+ return val->data();
+ }
+ return nullptr;
+ }
+
+private:
+ using IPv4AddrType = vectorized::UInt32;
+ using IPv6AddrType = std::array<vectorized::UInt8, IPV6_BINARY_LENGTH>;
+
+ std::variant<IPv4AddrType, IPv6AddrType> _addr;
+};
+
+struct IPAddressCIDR {
+ IPAddressVariant _address;
+ vectorized::UInt8 _prefix;
+};
+
+bool match_ipv4_subnet(uint32_t addr, uint32_t cidr_addr, uint8_t prefix) {
+ uint32_t mask = (prefix >= 32) ? 0xffffffffu : ~(0xffffffffu >> prefix);
Review Comment:
warning: integer literal has suffix 'u', which is not uppercase
[readability-uppercase-literal-suffix]
```suggestion
uint32_t mask = (prefix >= 32) ? 0xffffffffu : ~(0xffffffffU >> prefix);
```
##########
be/src/vec/runtime/ip_address_cidr.h:
##########
@@ -0,0 +1,162 @@
+// 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.
+// This file is copied from
+//
https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/isIPAddressContainedIn.cpp
+// and modified by Doris
+
+#pragma once
+
+#include "vec/common/format_ip.h"
+
+namespace doris {
+
+class IPAddressVariant {
+public:
+ explicit IPAddressVariant(std::string_view address_str) {
+ vectorized::Int64 v4;
+ if (vectorized::parseIPv4whole(address_str.begin(), address_str.end(),
reinterpret_cast<unsigned char *>(&v4))) {
+ _addr = static_cast<vectorized::UInt32>(v4);
+ } else {
+ _addr = IPv6AddrType();
+ if (!vectorized::parseIPv6whole(
+ address_str.begin(), address_str.end(),
std::get<IPv6AddrType>(_addr).data())) {
+ throw Exception(ErrorCode::INVALID_ARGUMENT, "Neither IPv4 nor
IPv6 address: '{}'", address_str);
+ }
+ }
+ }
+
+ vectorized::UInt32 as_v4() const {
+ if (const auto* val = std::get_if<IPv4AddrType>(&_addr)) {
+ return *val;
+ }
+ return 0;
+ }
+
+ const vectorized::UInt8* as_v6() const {
+ if (const auto* val = std::get_if<IPv6AddrType>(&_addr)) {
+ return val->data();
+ }
+ return nullptr;
+ }
+
+private:
+ using IPv4AddrType = vectorized::UInt32;
+ using IPv6AddrType = std::array<vectorized::UInt8, IPV6_BINARY_LENGTH>;
+
+ std::variant<IPv4AddrType, IPv6AddrType> _addr;
+};
+
+struct IPAddressCIDR {
+ IPAddressVariant _address;
+ vectorized::UInt8 _prefix;
+};
+
+bool match_ipv4_subnet(uint32_t addr, uint32_t cidr_addr, uint8_t prefix) {
+ uint32_t mask = (prefix >= 32) ? 0xffffffffu : ~(0xffffffffu >> prefix);
Review Comment:
warning: integer literal has suffix 'u', which is not uppercase
[readability-uppercase-literal-suffix]
```suggestion
uint32_t mask = (prefix >= 32) ? 0xffffffffU : ~(0xffffffffu >> prefix);
```
##########
be/src/vec/functions/function_ip.h:
##########
@@ -745,4 +742,88 @@
}
};
+class FunctionIsIPAddressInRange : public IFunction {
+public:
+ static constexpr auto name = "is_ip_address_in_range";
+ static FunctionPtr create() { return
std::make_shared<FunctionIsIPAddressInRange>(); }
+
+ String get_name() const override { return name; }
+
+ size_t get_number_of_arguments() const override { return 2; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ if (arguments.size() != 2) {
+ throw Exception(ErrorCode::INVALID_ARGUMENT,
+ "Number of arguments for function {} doesn't
match: passed {}, should be 2",
+ get_name(), arguments.size());
+ }
+ const auto& addr_type = arguments[0];
+ const auto& cidr_type = arguments[1];
+ if (!is_string(remove_nullable(addr_type)) ||
!is_string(remove_nullable(cidr_type))) {
+ throw Exception(ErrorCode::INVALID_ARGUMENT, "The arguments of
function {} must be String", get_name());
+ }
+ return std::make_shared<DataTypeUInt8>();
+ }
+
+ bool use_default_implementation_for_nulls() const override { return false;
}
+
+ Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) const override
{
Review Comment:
warning: method 'execute_impl' can be made static
[readability-convert-member-functions-to-static]
```suggestion
static Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
size_t result, size_t input_rows_count) override {
```
##########
be/src/vec/runtime/ip_address_cidr.h:
##########
@@ -0,0 +1,162 @@
+// 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.
+// This file is copied from
+//
https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/isIPAddressContainedIn.cpp
+// and modified by Doris
+
+#pragma once
+
+#include "vec/common/format_ip.h"
+
+namespace doris {
+
+class IPAddressVariant {
+public:
+ explicit IPAddressVariant(std::string_view address_str) {
+ vectorized::Int64 v4;
+ if (vectorized::parseIPv4whole(address_str.begin(), address_str.end(),
reinterpret_cast<unsigned char *>(&v4))) {
+ _addr = static_cast<vectorized::UInt32>(v4);
+ } else {
+ _addr = IPv6AddrType();
+ if (!vectorized::parseIPv6whole(
+ address_str.begin(), address_str.end(),
std::get<IPv6AddrType>(_addr).data())) {
+ throw Exception(ErrorCode::INVALID_ARGUMENT, "Neither IPv4 nor
IPv6 address: '{}'", address_str);
+ }
+ }
+ }
+
+ vectorized::UInt32 as_v4() const {
+ if (const auto* val = std::get_if<IPv4AddrType>(&_addr)) {
+ return *val;
+ }
+ return 0;
+ }
+
+ const vectorized::UInt8* as_v6() const {
Review Comment:
warning: method 'as_v6' can be made static
[readability-convert-member-functions-to-static]
```suggestion
static const vectorized::UInt8* as_v6() {
```
--
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]