Allow comparing Ipv4 and IPv6 values

This commit is contained in:
Francisco Javier Jurado Moreno 2024-05-23 14:50:14 +02:00
parent cbacab0bf4
commit 12d582155e

View File

@ -1170,14 +1170,12 @@ public:
bool both_represented_by_number = arguments[0]->isValueRepresentedByNumber() && arguments[1]->isValueRepresentedByNumber(); bool both_represented_by_number = arguments[0]->isValueRepresentedByNumber() && arguments[1]->isValueRepresentedByNumber();
bool has_date = left.isDateOrDate32() || right.isDateOrDate32(); bool has_date = left.isDateOrDate32() || right.isDateOrDate32();
if (!((both_represented_by_number && !has_date) /// Do not allow to compare date and number. if (!((both_represented_by_number && !has_date) /// Do not allow to compare date and number.
|| (left.isStringOrFixedString() || right.isStringOrFixedString()) /// Everything can be compared with string by conversion. || (left.isStringOrFixedString() || right.isStringOrFixedString()) /// Everything can be compared with string by conversion.
/// You can compare the date, datetime, or datatime64 and an enumeration with a constant string. /// You can compare the date, datetime, or datatime64 and an enumeration with a constant string.
|| ((left.isDate() || left.isDate32() || left.isDateTime() || left.isDateTime64()) && (right.isDate() || right.isDate32() || right.isDateTime() || right.isDateTime64()) && left.idx == right.idx) /// only date vs date, or datetime vs datetime || ((left.isDate() || left.isDate32() || left.isDateTime() || left.isDateTime64()) && (right.isDate() || right.isDate32() || right.isDateTime() || right.isDateTime64()) && left.idx == right.idx) /// only date vs date, or datetime vs datetime
|| (left.isUUID() && right.isUUID()) || (left.isUUID() && right.isUUID())
|| (left.isIPv4() && right.isIPv4()) || ((left.isIPv4() || left.isIPv6()) && (left.isIPv4() || left.isIPv6()))
|| (left.isIPv6() && right.isIPv6())
|| (left.isEnum() && right.isEnum() && arguments[0]->getName() == arguments[1]->getName()) /// only equivalent enum type values can be compared against || (left.isEnum() && right.isEnum() && arguments[0]->getName() == arguments[1]->getName()) /// only equivalent enum type values can be compared against
|| (left_tuple && right_tuple && left_tuple->getElements().size() == right_tuple->getElements().size()) || (left_tuple && right_tuple && left_tuple->getElements().size() == right_tuple->getElements().size())
|| (arguments[0]->equals(*arguments[1])))) || (arguments[0]->equals(*arguments[1]))))
@ -1266,6 +1264,8 @@ public:
const bool left_is_float = which_left.isFloat(); const bool left_is_float = which_left.isFloat();
const bool right_is_float = which_right.isFloat(); const bool right_is_float = which_right.isFloat();
const bool left_is_ipv4 = which_left.isIPv4();
const bool right_is_ipv4 = which_right.isIPv4();
const bool left_is_ipv6 = which_left.isIPv6(); const bool left_is_ipv6 = which_left.isIPv6();
const bool right_is_ipv6 = which_right.isIPv6(); const bool right_is_ipv6 = which_right.isIPv6();
const bool left_is_fixed_string = which_left.isFixedString(); const bool left_is_fixed_string = which_left.isFixedString();
@ -1334,6 +1334,15 @@ public:
return executeGenericIdenticalTypes(left_column.get(), right_column.get()); return executeGenericIdenticalTypes(left_column.get(), right_column.get());
} }
else if ((left_is_ipv4 || left_is_ipv6) && (right_is_ipv4 || right_is_ipv6))
{
ColumnPtr left_column = left_is_ipv6 ?
col_with_type_and_name_left.column : castColumn(col_with_type_and_name_left, right_type);
ColumnPtr right_column = right_is_ipv6 ?
col_with_type_and_name_right.column : castColumn(col_with_type_and_name_right, left_type);
return executeGenericIdenticalTypes(left_column.get(), right_column.get());
}
else if ((isColumnedAsDecimal(left_type) || isColumnedAsDecimal(right_type))) else if ((isColumnedAsDecimal(left_type) || isColumnedAsDecimal(right_type)))
{ {
// Comparing Date/Date32 and DateTime64 requires implicit conversion, // Comparing Date/Date32 and DateTime64 requires implicit conversion,