Skip to content

Commit

Permalink
vector: Fix join by array meet error "no supertype for types Array(Fl…
Browse files Browse the repository at this point in the history
…oat32), Nullable(Array(Float32))" (pingcap#9490)

ref pingcap#9032

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
JaySon-Huang and ti-chi-bot[bot] committed Sep 29, 2024
1 parent 698a9ef commit 1f30845
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 66 deletions.
60 changes: 30 additions & 30 deletions dbms/src/DataTypes/getLeastSupertype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,36 +100,6 @@ DataTypePtr getLeastSupertype(const DataTypes & types)
return getLeastSupertype(non_nothing_types);
}

/// For Arrays
{
bool have_array = false;
bool all_arrays = true;

DataTypes nested_types;
nested_types.reserve(types.size());

for (const auto & type : types)
{
if (const DataTypeArray * type_array = typeid_cast<const DataTypeArray *>(type.get()))
{
have_array = true;
nested_types.emplace_back(type_array->getNestedType());
}
else
all_arrays = false;
}

if (have_array)
{
if (!all_arrays)
throw Exception(
getExceptionMessagePrefix(types) + " because some of them are Array and some of them are not",
ErrorCodes::NO_COMMON_TYPE);

return std::make_shared<DataTypeArray>(getLeastSupertype(nested_types));
}
}

/// For tuples
{
bool have_tuple = false;
Expand Down Expand Up @@ -204,6 +174,36 @@ DataTypePtr getLeastSupertype(const DataTypes & types)
}
}

/// For Arrays, canBeInsideNullable = true, should check it after handling Nullable
{
bool have_array = false;
bool all_arrays = true;

DataTypes nested_types;
nested_types.reserve(types.size());

for (const auto & type : types)
{
if (const DataTypeArray * type_array = typeid_cast<const DataTypeArray *>(type.get()))
{
have_array = true;
nested_types.emplace_back(type_array->getNestedType());
}
else
all_arrays = false;
}

if (have_array)
{
if (!all_arrays)
throw Exception(
getExceptionMessagePrefix(types) + " because some of them are Array and some of them are not",
ErrorCodes::NO_COMMON_TYPE);

return std::make_shared<DataTypeArray>(getLeastSupertype(nested_types));
}
}

/// Non-recursive rules

std::unordered_set<TypeIndex> type_ids;
Expand Down
56 changes: 28 additions & 28 deletions dbms/src/DataTypes/getMostSubtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,6 @@ DataTypePtr getMostSubtype(const DataTypes & types, bool throw_if_result_is_noth
return get_nothing_or_throw(" because some of them are Nothing");
}

/// For Arrays
{
bool have_array = false;
bool all_arrays = true;

DataTypes nested_types;
nested_types.reserve(types.size());

for (const auto & type : types)
{
if (const auto * const type_array = typeid_cast<const DataTypeArray *>(type.get()))
{
have_array = true;
nested_types.emplace_back(type_array->getNestedType());
}
else
all_arrays = false;
}

if (have_array)
{
if (!all_arrays)
return get_nothing_or_throw(" because some of them are Array and some of them are not");

return std::make_shared<DataTypeArray>(getMostSubtype(nested_types, false, force_support_conversion));
}
}

/// For tuples
{
bool have_tuple = false;
Expand Down Expand Up @@ -210,6 +182,34 @@ DataTypePtr getMostSubtype(const DataTypes & types, bool throw_if_result_is_noth
}
}

/// For Arrays, canBeInsideNullable = true, should check it after handling Nullable
{
bool have_array = false;
bool all_arrays = true;

DataTypes nested_types;
nested_types.reserve(types.size());

for (const auto & type : types)
{
if (const auto * const type_array = typeid_cast<const DataTypeArray *>(type.get()))
{
have_array = true;
nested_types.emplace_back(type_array->getNestedType());
}
else
all_arrays = false;
}

if (have_array)
{
if (!all_arrays)
return get_nothing_or_throw(" because some of them are Array and some of them are not");

return std::make_shared<DataTypeArray>(getMostSubtype(nested_types, false, force_support_conversion));
}
}

/// Non-recursive rules

/// For String and FixedString, the common type is FixedString.
Expand Down
15 changes: 12 additions & 3 deletions dbms/src/DataTypes/tests/gtest_data_type_get_common_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ try
->equals(*typeFromString("Array(Array(UInt8))")));
ASSERT_TRUE(getLeastSupertype(typesFromString("Array(Array(UInt8)) Array(Array(Int8))"))
->equals(*typeFromString("Array(Array(Int16))")));
ASSERT_TRUE(
getLeastSupertype(typesFromString("Array(Date) Array(DateTime)"))->equals(*typeFromString("Array(DateTime)")));
ASSERT_TRUE(getLeastSupertype(typesFromString("Array(Date) Array(DateTime)")) //
->equals(*typeFromString("Array(DateTime)")));
ASSERT_TRUE(getLeastSupertype(typesFromString("Array(String) Array(FixedString(32))"))
->equals(*typeFromString("Array(String)")));
ASSERT_TRUE(getLeastSupertype(typesFromString("Array(Float32) Array(Float32)")) //
->equals(*typeFromString("Array(Float32)")));
ASSERT_TRUE(getLeastSupertype(typesFromString("Array(Float32) Nullable(Array(Float32))")) //
->equals(*typeFromString("Nullable(Array(Float32))")));

ASSERT_TRUE(
getLeastSupertype(typesFromString("Nullable(Nothing) Nothing"))->equals(*typeFromString("Nullable(Nothing)")));
Expand Down Expand Up @@ -214,11 +218,16 @@ try
->equals(*typeFromString("Array(Array(UInt8))")));
ASSERT_TRUE(getMostSubtype(typesFromString("Array(Array(UInt8)) Array(Array(Int8))"))
->equals(*typeFromString("Array(Array(UInt8))")));
ASSERT_TRUE(getMostSubtype(typesFromString("Array(Date) Array(DateTime)"))->equals(*typeFromString("Array(Date)")));
ASSERT_TRUE(getMostSubtype(typesFromString("Array(Date) Array(DateTime)")) //
->equals(*typeFromString("Array(Date)")));
ASSERT_TRUE(getMostSubtype(typesFromString("Array(String) Array(FixedString(32))"))
->equals(*typeFromString("Array(FixedString(32))")));
ASSERT_TRUE(getMostSubtype(typesFromString("Array(String) Array(FixedString(32))"))
->equals(*typeFromString("Array(FixedString(32))")));
ASSERT_TRUE(getMostSubtype(typesFromString("Array(Float32) Array(Float32)")) //
->equals(*typeFromString("Array(Float32)")));
ASSERT_TRUE(getMostSubtype(typesFromString("Array(Float32) Nullable(Array(Float32))")) //
->equals(*typeFromString("Array(Float32)")));

ASSERT_TRUE(getMostSubtype(typesFromString("Nullable(Nothing) Nothing"))->equals(*typeFromString("Nothing")));
ASSERT_TRUE(getMostSubtype(typesFromString("Nullable(UInt8) Int8"))->equals(*typeFromString("UInt8")));
Expand Down
6 changes: 1 addition & 5 deletions dbms/src/Flash/Mpp/MPPTaskScheduleEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ bool MPPTaskScheduleEntry::schedule(ScheduleState state)
if (schedule_state == ScheduleState::WAITING)
{
auto log_level = state == ScheduleState::SCHEDULED ? Poco::Message::PRIO_DEBUG : Poco::Message::PRIO_WARNING;
LOG_IMPL(
log,
log_level,
"task is {}.",
state == ScheduleState::SCHEDULED ? "scheduled" : " failed to schedule");
LOG_IMPL(log, log_level, "task is {}.", state == ScheduleState::SCHEDULED ? "scheduled" : "failed to schedule");
schedule_state = state;
schedule_cv.notify_one();
return true;
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Storages/DeltaMerge/ColumnStat.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ readText(ColumnStats & column_sats, DMFileFormat::Version ver, ReadBuffer & buf)
.serialized_bytes = serialized_bytes,
// ... here ignore some fields with default initializers
.vector_index = {},
#ifndef NDEBUG
.additional_data_for_test = {},
#endif
});
}
}
Expand Down

0 comments on commit 1f30845

Please sign in to comment.